Skip to content

Commit

Permalink
Make stuff strong-mode happy (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins authored Aug 18, 2016
1 parent d843b82 commit 43ded89
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 43 deletions.
2 changes: 2 additions & 0 deletions .analysis_options
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
analyzer:
strong-mode: true
7 changes: 4 additions & 3 deletions lib/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ Future<WebDriver> createDriver(CommandProcessor processor,

Map response = await processor.post(
uri.resolve('session'), {'desiredCapabilities': desired},
value: false);
value: false) as Map<String, dynamic>;
return new WebDriver(processor, uri, response['sessionId'],
new UnmodifiableMapView(response['value']));
new UnmodifiableMapView(response['value'] as Map<String, dynamic>));
}

Future<WebDriver> fromExistingSession(
Expand All @@ -66,7 +66,8 @@ Future<WebDriver> fromExistingSession(
uri = defaultUri;
}

var response = await processor.get(uri.resolve('session/$sessionId'));
var response = await processor.get(uri.resolve('session/$sessionId'))
as Map<String, dynamic>;
return new WebDriver(
processor, uri, sessionId, new UnmodifiableMapView(response));
}
8 changes: 4 additions & 4 deletions lib/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ class _HtmlCommandProcessor implements CommandProcessor {
final Lock _lock = new Lock();

@override
Future<Object> post(Uri uri, dynamic params, {bool value: true}) =>
Future<dynamic> post(Uri uri, dynamic params, {bool value: true}) =>
_request('POST', uri, params, value);

@override
Future<Object> get(Uri uri, {bool value: true}) =>
Future<dynamic> get(Uri uri, {bool value: true}) =>
_request('GET', uri, null, value);

@override
Future<Object> delete(Uri uri, {bool value: true}) =>
Future<dynamic> delete(Uri uri, {bool value: true}) =>
_request('DELETE', uri, null, value);

@override
Future close() async {}

Future<Object> _request(
Future<dynamic> _request(
String method, Uri uri, dynamic params, bool value) async {
await _lock.acquire();
var sendData = null;
Expand Down
6 changes: 3 additions & 3 deletions lib/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class IOCommandProcessor implements CommandProcessor {
final Lock _lock = new Lock();

@override
Future<Object> post(Uri uri, dynamic params, {bool value: true}) async {
Future<dynamic> post(Uri uri, dynamic params, {bool value: true}) async {
await _lock.acquire();
HttpClientRequest request = await client.postUrl(uri);
_setUpRequest(request);
Expand All @@ -73,15 +73,15 @@ class IOCommandProcessor implements CommandProcessor {
}

@override
Future<Object> get(Uri uri, {bool value: true}) async {
Future<dynamic> get(Uri uri, {bool value: true}) async {
await _lock.acquire();
HttpClientRequest request = await client.getUrl(uri);
_setUpRequest(request);
return await _processResponse(await request.close(), value);
}

@override
Future<Object> delete(Uri uri, {bool value: true}) async {
Future<dynamic> delete(Uri uri, {bool value: true}) async {
await _lock.acquire();
HttpClientRequest request = await client.deleteUrl(uri);
_setUpRequest(request);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const String _element = 'ELEMENT';
class Attributes extends _WebDriverBase {
Attributes._(driver, command) : super(driver, command);

Future<String> operator [](String name) => _get(name);
Future<String> operator [](String name) => _get(name) as Future<String>;
}

abstract class SearchContext {
Expand Down
3 changes: 2 additions & 1 deletion lib/src/exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Cookies extends _WebDriverBase {

/// Retrieve all cookies visible to the current page.
Stream<Cookie> get all async* {
var cookies = await _get('');
var cookies = await _get('') as List<Map<String, dynamic>>;
for (var cookie in cookies) {
yield new Cookie.fromJson(cookie);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/src/web_driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class WebDriver implements SearchContext {
final _onCommandController =
new StreamController<WebDriverCommandEvent>.broadcast();

final List _commandListeners = new List<WebDriverListener>();
final _commandListeners = new List<WebDriverListener>();

WebDriver(this._commandProcessor, Uri uri, String id, this.capabilities,
{this.filterStackTraces: true})
Expand All @@ -49,7 +49,7 @@ class WebDriver implements SearchContext {
_commandListeners.add(listener);

/// The current url.
Future<String> get currentUrl => getRequest('url');
Future<String> get currentUrl => getRequest('url') as Future<String>;

/// navigate to the specified url
Future get(/* Uri | String */ url) async {
Expand All @@ -60,7 +60,7 @@ class WebDriver implements SearchContext {
}

/// The title of the current page.
Future<String> get title => getRequest('title');
Future<String> get title => getRequest('title') as Future<String>;

/// Search for multiple elements within the entire current page.
@override
Expand All @@ -83,7 +83,7 @@ class WebDriver implements SearchContext {
}

/// An artist's rendition of the current page's source.
Future<String> get pageSource => getRequest('source');
Future<String> get pageSource => getRequest('source') as Future<String>;

/// Close the current window, quitting the browser if it is the last window.
Future close() async {
Expand Down
13 changes: 7 additions & 6 deletions lib/src/web_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ class WebElement extends _WebDriverBase implements SearchContext {
}

/// Is this radio button/checkbox selected?
Future<bool> get selected => _get('selected');
Future<bool> get selected => _get('selected') as Future<bool>;

/// Is this form element enabled?
Future<bool> get enabled => _get('enabled');
Future<bool> get enabled => _get('enabled') as Future<bool>;

/// Is this element visible in the page?
Future<bool> get displayed => _get('displayed');
Future<bool> get displayed => _get('displayed') as Future<bool>;

/// The location within the document of this element.
Future<Point> get location async {
Expand All @@ -76,10 +76,10 @@ class WebElement extends _WebDriverBase implements SearchContext {
}

/// The tag name for this element.
Future<String> get name => _get('name');
Future<String> get name => _get('name') as Future<String>;

/// Visible text within this element.
Future<String> get text => _get('text');
Future<String> get text => _get('text') as Future<String>;

///Find an element nested within this element.
///
Expand Down Expand Up @@ -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<bool> equals(WebElement other) => _get('equals/${other.id}');
Future<bool> equals(WebElement other) =>
_get('equals/${other.id}') as Future<bool>;

Map<String, String> toJson() => {_element: id};

Expand Down
3 changes: 2 additions & 1 deletion lib/src/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 7 additions & 9 deletions lib/support/forwarder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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<Null> forward(HttpRequest request) async {
try {
if (!request.uri.path.startsWith(prefix)) {
request.response.statusCode = HttpStatus.NOT_FOUND;
Expand All @@ -89,11 +88,11 @@ class WebDriverForwarder {
if (endpoint.startsWith('/')) {
endpoint = endpoint.substring(1);
}
var params;
Map<String, dynamic> 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<String, dynamic>;
}
}
var value = await _forward(request.method, endpoint, params);
Expand All @@ -114,7 +113,7 @@ class WebDriverForwarder {
}
}

Future _forward(String method, String endpoint,
Future<dynamic> _forward(String method, String endpoint,
[Map<String, dynamic> params]) async {
List<String> endpointTokens = path.split(endpoint);
if (endpointTokens.isEmpty) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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<String, dynamic>;
break;
}

Expand Down
4 changes: 2 additions & 2 deletions test/html_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, dynamic> additionalCapabilities}) {
var capabilities = Capabilities.chrome;

if (additionalCapabilities != null) {
capabilities.addAll(additionalCapabilities);
Expand Down
4 changes: 2 additions & 2 deletions test/io_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, dynamic> additionalCapabilities}) {
var capabilities = Capabilities.chrome;
Map env = Platform.environment;

Map chromeOptions = {};
Expand Down
2 changes: 1 addition & 1 deletion test/src/command_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void runTests() {
group('CommandEvent', () {
WebDriver driver;

var events = [];
var events = <WebDriverCommandEvent>[];
var sub;

setUp(() async {
Expand Down
4 changes: 2 additions & 2 deletions test/src/keyboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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]'));
Expand Down
2 changes: 1 addition & 1 deletion test/src/logs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void runTests() {
WebDriver driver;

setUp(() async {
Map capabilities = {
Map<String, dynamic> capabilities = {
Capabilities.loggingPrefs: {LogType.performance: LogLevel.info}
};

Expand Down
3 changes: 2 additions & 1 deletion test/src/web_driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down
3 changes: 2 additions & 1 deletion test/test_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ final Matcher isPoint = new isInstanceOf<Point<int>>();

String testPagePath;

typedef Future<WebDriver> createTestDriverFn({Map additionalCapabilities});
typedef Future<WebDriver> createTestDriverFn(
{Map<String, dynamic> additionalCapabilities});

createTestDriverFn createTestDriver;

Expand Down

0 comments on commit 43ded89

Please sign in to comment.