From 43ded89fcbf7179a8210f08807078aa66a69e28a Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Thu, 18 Aug 2016 14:17:00 -0700 Subject: [PATCH] Make stuff strong-mode happy (#122) --- .analysis_options | 2 ++ lib/core.dart | 7 ++++--- lib/html.dart | 8 ++++---- lib/io.dart | 6 +++--- lib/src/common.dart | 2 +- lib/src/exception.dart | 3 ++- lib/src/options.dart | 2 +- lib/src/web_driver.dart | 8 ++++---- lib/src/web_element.dart | 13 +++++++------ lib/src/window.dart | 3 ++- lib/support/forwarder.dart | 16 +++++++--------- test/html_test.dart | 4 ++-- test/io_config.dart | 4 ++-- test/src/command_event.dart | 2 +- test/src/keyboard.dart | 4 ++-- test/src/logs.dart | 2 +- test/src/web_driver.dart | 3 ++- test/test_util.dart | 3 ++- 18 files changed, 49 insertions(+), 43 deletions(-) create mode 100644 .analysis_options diff --git a/.analysis_options b/.analysis_options new file mode 100644 index 00000000..a10d4c5a --- /dev/null +++ b/.analysis_options @@ -0,0 +1,2 @@ +analyzer: + strong-mode: true diff --git a/lib/core.dart b/lib/core.dart index 5fc89bf4..cd6fd07a 100644 --- a/lib/core.dart +++ b/lib/core.dart @@ -54,9 +54,9 @@ Future createDriver(CommandProcessor processor, Map response = await processor.post( uri.resolve('session'), {'desiredCapabilities': desired}, - value: false); + value: false) as Map; return new WebDriver(processor, uri, response['sessionId'], - new UnmodifiableMapView(response['value'])); + new UnmodifiableMapView(response['value'] as Map)); } Future fromExistingSession( @@ -66,7 +66,8 @@ Future fromExistingSession( uri = defaultUri; } - var response = await processor.get(uri.resolve('session/$sessionId')); + var response = await processor.get(uri.resolve('session/$sessionId')) + as Map; return new WebDriver( processor, uri, sessionId, new UnmodifiableMapView(response)); } diff --git a/lib/html.dart b/lib/html.dart index 794cdf99..1072077b 100644 --- a/lib/html.dart +++ b/lib/html.dart @@ -48,21 +48,21 @@ class _HtmlCommandProcessor implements CommandProcessor { final Lock _lock = new Lock(); @override - Future post(Uri uri, dynamic params, {bool value: true}) => + Future post(Uri uri, dynamic params, {bool value: true}) => _request('POST', uri, params, value); @override - Future get(Uri uri, {bool value: true}) => + Future get(Uri uri, {bool value: true}) => _request('GET', uri, null, value); @override - Future delete(Uri uri, {bool value: true}) => + Future delete(Uri uri, {bool value: true}) => _request('DELETE', uri, null, value); @override Future close() async {} - Future _request( + Future _request( String method, Uri uri, dynamic params, bool value) async { await _lock.acquire(); var sendData = null; diff --git a/lib/io.dart b/lib/io.dart index 38c5180a..af3bc4ad 100644 --- a/lib/io.dart +++ b/lib/io.dart @@ -57,7 +57,7 @@ class IOCommandProcessor implements CommandProcessor { final Lock _lock = new Lock(); @override - Future post(Uri uri, dynamic params, {bool value: true}) async { + Future post(Uri uri, dynamic params, {bool value: true}) async { await _lock.acquire(); HttpClientRequest request = await client.postUrl(uri); _setUpRequest(request); @@ -73,7 +73,7 @@ class IOCommandProcessor implements CommandProcessor { } @override - Future get(Uri uri, {bool value: true}) async { + Future get(Uri uri, {bool value: true}) async { await _lock.acquire(); HttpClientRequest request = await client.getUrl(uri); _setUpRequest(request); @@ -81,7 +81,7 @@ class IOCommandProcessor implements CommandProcessor { } @override - Future delete(Uri uri, {bool value: true}) async { + Future delete(Uri uri, {bool value: true}) async { await _lock.acquire(); HttpClientRequest request = await client.deleteUrl(uri); _setUpRequest(request); diff --git a/lib/src/common.dart b/lib/src/common.dart index 632783a3..8e514a99 100644 --- a/lib/src/common.dart +++ b/lib/src/common.dart @@ -21,7 +21,7 @@ const String _element = 'ELEMENT'; class Attributes extends _WebDriverBase { Attributes._(driver, command) : super(driver, command); - Future operator [](String name) => _get(name); + Future operator [](String name) => _get(name) as Future; } abstract class SearchContext { diff --git a/lib/src/exception.dart b/lib/src/exception.dart index fd4c0ca1..f67ad961 100644 --- a/lib/src/exception.dart +++ b/lib/src/exception.dart @@ -93,7 +93,8 @@ abstract class WebDriverException implements Exception { String toString() => '$runtimeType ($statusCode): $message'; @override - bool operator ==(other) => other != null && + bool operator ==(other) => + other != null && other.runtimeType == this.runtimeType && other.statusCode == this.statusCode && other.message == this.message; diff --git a/lib/src/options.dart b/lib/src/options.dart index 5aaad686..eb664406 100644 --- a/lib/src/options.dart +++ b/lib/src/options.dart @@ -34,7 +34,7 @@ class Cookies extends _WebDriverBase { /// Retrieve all cookies visible to the current page. Stream get all async* { - var cookies = await _get(''); + var cookies = await _get('') as List>; for (var cookie in cookies) { yield new Cookie.fromJson(cookie); } diff --git a/lib/src/web_driver.dart b/lib/src/web_driver.dart index 04c5a365..20dc1e0c 100644 --- a/lib/src/web_driver.dart +++ b/lib/src/web_driver.dart @@ -31,7 +31,7 @@ class WebDriver implements SearchContext { final _onCommandController = new StreamController.broadcast(); - final List _commandListeners = new List(); + final _commandListeners = new List(); WebDriver(this._commandProcessor, Uri uri, String id, this.capabilities, {this.filterStackTraces: true}) @@ -49,7 +49,7 @@ class WebDriver implements SearchContext { _commandListeners.add(listener); /// The current url. - Future get currentUrl => getRequest('url'); + Future get currentUrl => getRequest('url') as Future; /// navigate to the specified url Future get(/* Uri | String */ url) async { @@ -60,7 +60,7 @@ class WebDriver implements SearchContext { } /// The title of the current page. - Future get title => getRequest('title'); + Future get title => getRequest('title') as Future; /// Search for multiple elements within the entire current page. @override @@ -83,7 +83,7 @@ class WebDriver implements SearchContext { } /// An artist's rendition of the current page's source. - Future get pageSource => getRequest('source'); + Future get pageSource => getRequest('source') as Future; /// Close the current window, quitting the browser if it is the last window. Future close() async { diff --git a/lib/src/web_element.dart b/lib/src/web_element.dart index f732cf8f..6bda2f36 100644 --- a/lib/src/web_element.dart +++ b/lib/src/web_element.dart @@ -54,13 +54,13 @@ class WebElement extends _WebDriverBase implements SearchContext { } /// Is this radio button/checkbox selected? - Future get selected => _get('selected'); + Future get selected => _get('selected') as Future; /// Is this form element enabled? - Future get enabled => _get('enabled'); + Future get enabled => _get('enabled') as Future; /// Is this element visible in the page? - Future get displayed => _get('displayed'); + Future get displayed => _get('displayed') as Future; /// The location within the document of this element. Future get location async { @@ -76,10 +76,10 @@ class WebElement extends _WebDriverBase implements SearchContext { } /// The tag name for this element. - Future get name => _get('name'); + Future get name => _get('name') as Future; /// Visible text within this element. - Future get text => _get('text'); + Future get text => _get('text') as Future; ///Find an element nested within this element. /// @@ -112,7 +112,8 @@ class WebElement extends _WebDriverBase implements SearchContext { /// Does this element represent the same element as another element? /// Not the same as == - Future equals(WebElement other) => _get('equals/${other.id}'); + Future equals(WebElement other) => + _get('equals/${other.id}') as Future; Map toJson() => {_element: id}; diff --git a/lib/src/window.dart b/lib/src/window.dart index 25b05cdf..6c1ac69d 100644 --- a/lib/src/window.dart +++ b/lib/src/window.dart @@ -54,7 +54,8 @@ class Window extends _WebDriverBase { int get hashCode => handle.hashCode * 3 + driver.hashCode; @override - bool operator ==(other) => other is Window && + bool operator ==(other) => + other is Window && other.driver == this.driver && other.handle == this.handle; diff --git a/lib/support/forwarder.dart b/lib/support/forwarder.dart index 2963f6e4..8d13c44d 100644 --- a/lib/support/forwarder.dart +++ b/lib/support/forwarder.dart @@ -19,8 +19,7 @@ import 'dart:convert' show JSON, UTF8; import 'dart:io' show ContentType, Directory, File, HttpRequest, HttpStatus; import 'package:path/path.dart' as path; -import 'package:webdriver/core.dart' - show By, WebDriver, WebDriverException; +import 'package:webdriver/core.dart' show By, WebDriver, WebDriverException; final _contentTypeJson = new ContentType('application', 'json', charset: 'utf-8'); @@ -76,7 +75,7 @@ class WebDriverForwarder { /// Forward [request] to [driver] and respond to the request with the returned /// value or any thrown exceptions. - Future forward(HttpRequest request) async { + Future forward(HttpRequest request) async { try { if (!request.uri.path.startsWith(prefix)) { request.response.statusCode = HttpStatus.NOT_FOUND; @@ -89,11 +88,11 @@ class WebDriverForwarder { if (endpoint.startsWith('/')) { endpoint = endpoint.substring(1); } - var params; + Map params; if (request.method == 'POST') { String requestBody = await UTF8.decodeStream(request); if (requestBody != null && requestBody.isNotEmpty) { - params = JSON.decode(requestBody); + params = JSON.decode(requestBody) as Map; } } var value = await _forward(request.method, endpoint, params); @@ -114,7 +113,7 @@ class WebDriverForwarder { } } - Future _forward(String method, String endpoint, + Future _forward(String method, String endpoint, [Map params]) async { List endpointTokens = path.split(endpoint); if (endpointTokens.isEmpty) { @@ -132,8 +131,7 @@ class WebDriverForwarder { case 'screenshot': if (method == 'POST') { // take a screenshot and save to file system - var file = - new File(path.join(outputDir.path, params['file'])); + var file = new File(path.join(outputDir.path, params['file'])); await file.writeAsBytes(await driver.captureScreenshotAsList()); return null; } @@ -169,7 +167,7 @@ class WebDriverForwarder { case 'execute_async': // /execute and /execute_async allow arbitrary JSON objects with // embedded WebElememt ids. - params = await _deepCopy(params); + params = await _deepCopy(params) as Map; break; } diff --git a/test/html_test.dart b/test/html_test.dart index 267abda0..401936ff 100644 --- a/test/html_test.dart +++ b/test/html_test.dart @@ -36,8 +36,8 @@ import 'test_util.dart' as test_util; void main() { test_util.runningOnTravis = false; - test_util.createTestDriver = ({Map additionalCapabilities}) { - Map capabilities = Capabilities.chrome; + test_util.createTestDriver = ({Map additionalCapabilities}) { + var capabilities = Capabilities.chrome; if (additionalCapabilities != null) { capabilities.addAll(additionalCapabilities); diff --git a/test/io_config.dart b/test/io_config.dart index fc853420..e17429db 100644 --- a/test/io_config.dart +++ b/test/io_config.dart @@ -23,8 +23,8 @@ import 'test_util.dart' as test_util; void config() { test_util.runningOnTravis = Platform.environment['TRAVIS'] == 'true'; - test_util.createTestDriver = ({Map additionalCapabilities}) { - Map capabilities = Capabilities.chrome; + test_util.createTestDriver = ({Map additionalCapabilities}) { + var capabilities = Capabilities.chrome; Map env = Platform.environment; Map chromeOptions = {}; diff --git a/test/src/command_event.dart b/test/src/command_event.dart index aea573f0..c3a25410 100644 --- a/test/src/command_event.dart +++ b/test/src/command_event.dart @@ -25,7 +25,7 @@ void runTests() { group('CommandEvent', () { WebDriver driver; - var events = []; + var events = []; var sub; setUp(() async { diff --git a/test/src/keyboard.dart b/test/src/keyboard.dart index 225d7ae8..0b1e677f 100644 --- a/test/src/keyboard.dart +++ b/test/src/keyboard.dart @@ -37,8 +37,8 @@ void runTests() { // Note: Firefox used as Chrome + Mac OSX prevents use of control/meta // in chords. // https://bugs.chromium.org/p/chromedriver/issues/detail?id=30 - driver = await createTestDriver( - additionalCapabilities: Capabilities.firefox); + driver = + await createTestDriver(additionalCapabilities: Capabilities.firefox); await driver.get(testPagePath); textInput = await driver.findElement(const By.cssSelector('input[type=text]')); diff --git a/test/src/logs.dart b/test/src/logs.dart index d1ec2bde..28358bfb 100644 --- a/test/src/logs.dart +++ b/test/src/logs.dart @@ -24,7 +24,7 @@ void runTests() { WebDriver driver; setUp(() async { - Map capabilities = { + Map capabilities = { Capabilities.loggingPrefs: {LogType.performance: LogLevel.info} }; diff --git a/test/src/web_driver.dart b/test/src/web_driver.dart index 39ffad87..58f959d3 100644 --- a/test/src/web_driver.dart +++ b/test/src/web_driver.dart @@ -143,7 +143,8 @@ void runTests() { var element = await driver.activeElement; expect(await element.name, 'body'); await (await driver - .findElement(const By.cssSelector('input[type=text]'))).click(); + .findElement(const By.cssSelector('input[type=text]'))) + .click(); element = await driver.activeElement; expect(await element.name, 'input'); }); diff --git a/test/test_util.dart b/test/test_util.dart index 0fdbb0d6..d32901b8 100644 --- a/test/test_util.dart +++ b/test/test_util.dart @@ -26,7 +26,8 @@ final Matcher isPoint = new isInstanceOf>(); String testPagePath; -typedef Future createTestDriverFn({Map additionalCapabilities}); +typedef Future createTestDriverFn( + {Map additionalCapabilities}); createTestDriverFn createTestDriver;