Merge pull request #89 from DrMarcII/master

Lots of cleanup and new features.
diff --git a/.gitignore b/.gitignore
index 85beae1..8f859de 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
 .DS_Store
 packages
+.packages
 pubspec.lock
 .project
 .pub/
diff --git a/lib/core.dart b/lib/core.dart
index 4b71483..e85eeba 100644
--- a/lib/core.dart
+++ b/lib/core.dart
@@ -53,13 +53,15 @@
   }
 
   var response = await processor.post(
-      uri.resolve('session'), {'desiredCapabilities': desired}, value: false);
+      uri.resolve('session'), {'desiredCapabilities': desired},
+      value: false);
   return new WebDriver(processor, uri, response['sessionId'],
       new UnmodifiableMapView(response['value']));
 }
 
 Future<WebDriver> fromExistingSession(
-    CommandProcessor processor, String sessionId, {Uri uri}) async {
+    CommandProcessor processor, String sessionId,
+    {Uri uri}) async {
   if (uri == null) {
     uri = defaultUri;
   }
diff --git a/lib/src/command_event.dart b/lib/src/command_event.dart
index c678b82..490d91e 100644
--- a/lib/src/command_event.dart
+++ b/lib/src/command_event.dart
@@ -23,8 +23,14 @@
   final exception;
   final result;
 
-  WebDriverCommandEvent({this.method, this.endPoint, this.params,
-      this.startTime, this.endTime, this.exception, this.result,
+  WebDriverCommandEvent(
+      {this.method,
+      this.endPoint,
+      this.params,
+      this.startTime,
+      this.endTime,
+      this.exception,
+      this.result,
       this.stackTrace});
 
   String toString() => '[$startTime - $endTime] $method $endPoint($params) => '
diff --git a/lib/src/keyboard.dart b/lib/src/keyboard.dart
index afd7e45..fa211bb 100644
--- a/lib/src/keyboard.dart
+++ b/lib/src/keyboard.dart
@@ -76,7 +76,9 @@
 
   /// Send [keysToSend] to the active element.
   Future sendKeys(String keysToSend) async {
-    await _post('keys', {'value': [keysToSend]});
+    await _post('keys', {
+      'value': [keysToSend]
+    });
   }
 
   @override
diff --git a/lib/src/logs.dart b/lib/src/logs.dart
index 59a1974..46f4e43 100644
--- a/lib/src/logs.dart
+++ b/lib/src/logs.dart
@@ -41,9 +41,12 @@
 
   const LogEntry(this.message, this.timestamp, this.level);
 
-  LogEntry.fromMap(Map map) : this(map['message'],
-          new DateTime.fromMillisecondsSinceEpoch(map['timestamp'].toInt(),
-              isUtc: true), map['level']);
+  LogEntry.fromMap(Map map)
+      : this(
+            map['message'],
+            new DateTime.fromMillisecondsSinceEpoch(map['timestamp'].toInt(),
+                isUtc: true),
+            map['level']);
 
   @override
   String toString() => '$level[$timestamp]: $message';
diff --git a/lib/src/options.dart b/lib/src/options.dart
index 254546f..36b4c39 100644
--- a/lib/src/options.dart
+++ b/lib/src/options.dart
@@ -53,14 +53,19 @@
 class Cookie {
   /// The name of the cookie.
   final String name;
+
   /// The cookie value.
   final String value;
+
   /// (Optional) The cookie path.
   final String path;
+
   /// (Optional) The domain the cookie is visible to.
   final String domain;
+
   /// (Optional) Whether the cookie is a secure cookie.
   final bool secure;
+
   /// (Optional) When the cookie expires.
   final DateTime expiry;
 
@@ -71,7 +76,8 @@
     var expiry;
     if (json['expiry'] is num) {
       expiry = new DateTime.fromMillisecondsSinceEpoch(
-          json['expiry'].toInt() * 1000, isUtc: true);
+          json['expiry'].toInt() * 1000,
+          isUtc: true);
     }
     return new Cookie(json['name'], json['value'],
         path: json['path'],
diff --git a/lib/src/web_driver.dart b/lib/src/web_driver.dart
index 9c79992..6d76839 100644
--- a/lib/src/web_driver.dart
+++ b/lib/src/web_driver.dart
@@ -150,9 +150,9 @@
   /// Arguments may be any JSON-able object. WebElements will be converted to
   /// the corresponding DOM element. Likewise, any DOM Elements in the script
   /// result will be converted to WebElements.
-  Future executeAsync(String script, List args) => postRequest(
-          'execute_async', {'script': script, 'args': args})
-      .then(_recursiveElementify);
+  Future executeAsync(String script, List args) =>
+      postRequest('execute_async', {'script': script, 'args': args})
+          .then(_recursiveElementify);
 
   /// Inject a snippet of JavaScript into the page for execution in the context
   /// of the currently selected frame. The executed script is assumed to be
@@ -166,8 +166,9 @@
   /// Arguments may be any JSON-able object. WebElements will be converted to
   /// the corresponding DOM element. Likewise, any DOM Elements in the script
   /// result will be converted to WebElements.
-  Future execute(String script, List args) => postRequest(
-      'execute', {'script': script, 'args': args}).then(_recursiveElementify);
+  Future execute(String script, List args) =>
+      postRequest('execute', {'script': script, 'args': args})
+          .then(_recursiveElementify);
 
   dynamic _recursiveElementify(result) {
     if (result is Map) {
@@ -188,14 +189,18 @@
   }
 
   Future postRequest(String command, [params]) => _performRequest(
-      () => _commandProcessor.post(_resolve(command), params), 'POST', command,
+      () => _commandProcessor.post(_resolve(command), params),
+      'POST',
+      command,
       params);
 
   Future getRequest(String command) => _performRequest(
       () => _commandProcessor.get(_resolve(command)), 'GET', command, null);
 
   Future deleteRequest(String command) => _performRequest(
-      () => _commandProcessor.delete(_resolve(command)), 'DELETE', command,
+      () => _commandProcessor.delete(_resolve(command)),
+      'DELETE',
+      command,
       null);
 
   Future _performRequest(
@@ -204,7 +209,8 @@
     var trace = new Chain.current();
     if (filterStackTraces) {
       trace = trace.foldFrames(
-          (f) => f.library.startsWith('package:webdriver/'), terse: true);
+          (f) => f.library.startsWith('package:webdriver/'),
+          terse: true);
     }
     var result;
     var exception;
diff --git a/lib/src/web_element.dart b/lib/src/web_element.dart
index 3869348..f732cf8 100644
--- a/lib/src/web_element.dart
+++ b/lib/src/web_element.dart
@@ -19,8 +19,10 @@
 
   /// The context from which this element was found.
   final SearchContext context;
+
   /// How the element was located from the context.
   final dynamic /* String | Finder */ locator;
+
   /// The index of this element in the set of element founds. If the method
   /// used to find this element always returns one element, then this is null.
   final int index;
@@ -41,7 +43,9 @@
 
   /// Send [keysToSend] to this element.
   Future sendKeys(String keysToSend) async {
-    await _post('value', {'value': [keysToSend]});
+    await _post('value', {
+      'value': [keysToSend]
+    });
   }
 
   /// Clear the content of a text element.
diff --git a/lib/support/async.dart b/lib/support/async.dart
index 39d5911..137df94 100644
--- a/lib/support/async.dart
+++ b/lib/support/async.dart
@@ -24,8 +24,11 @@
 
 const clock = const Clock();
 
-Future waitFor(condition(), {matcher: null, Duration timeout: defaultTimeout,
-    Duration interval: defaultInterval}) => clock.waitFor(condition,
+Future waitFor(condition(),
+        {matcher: null,
+        Duration timeout: defaultTimeout,
+        Duration interval: defaultInterval}) =>
+    clock.waitFor(condition,
         matcher: matcher, timeout: timeout, interval: interval);
 
 class Clock {
@@ -46,7 +49,9 @@
   /// is returned. Otherwise, if [condition] throws, then that exception is
   /// rethrown. If [condition] doesn't throw then an [expect] exception is
   /// thrown.
-  Future waitFor(condition(), {matcher: null, Duration timeout: defaultTimeout,
+  Future waitFor(condition(),
+      {matcher: null,
+      Duration timeout: defaultTimeout,
       Duration interval: defaultInterval}) async {
     if (matcher != null && matcher is! ut.Matcher && matcher is! m.Matcher) {
       matcher = m.equals(matcher);
diff --git a/lib/support/forwarder.dart b/lib/support/forwarder.dart
index 651ec8b..c41d84f 100644
--- a/lib/support/forwarder.dart
+++ b/lib/support/forwarder.dart
@@ -58,18 +58,21 @@
 class WebDriverForwarder {
   /// [WebDriver] instance to forward commands to.
   final WebDriver driver;
+
   /// Path prefix that all forwarded commands will have.
   final Pattern prefix;
+
   /// Directory to save screenshots and page source to.
   final Directory outputDir;
+
   /// Search for elements in all shadow doms of the current document.
   bool useDeep;
 
   WebDriverForwarder(this.driver,
       {this.prefix: '/webdriver', Directory outputDir, this.useDeep: false})
       : this.outputDir = outputDir == null
-          ? Directory.systemTemp.createTempSync()
-          : outputDir;
+            ? Directory.systemTemp.createTempSync()
+            : outputDir;
 
   /// Forward [request] to [driver] and respond to the request with the returned
   /// value or any thrown exceptions.
@@ -97,11 +100,15 @@
       request.response
           .add(UTF8.encode(JSON.encode({'status': 0, 'value': value})));
     } on WebDriverException catch (e) {
-      request.response.add(UTF8.encode(JSON
-          .encode({'status': e.statusCode, 'value': {'message': e.message}})));
+      request.response.add(UTF8.encode(JSON.encode({
+        'status': e.statusCode,
+        'value': {'message': e.message}
+      })));
     } catch (e) {
-      request.response.add(UTF8.encode(
-          JSON.encode({'status': 13, 'value': {'message': e.toString()}})));
+      request.response.add(UTF8.encode(JSON.encode({
+        'status': 13,
+        'value': {'message': e.toString()}
+      })));
     } finally {
       await request.response.close();
     }
diff --git a/pubspec.yaml b/pubspec.yaml
index f5746cc..182dfeb 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -12,6 +12,7 @@
   matcher: '^0.12.0+1'
   path: '^1.3.6'
   stack_trace: '^1.3.4'
-  unittest: '^0.12.3'
+  unittest: '^0.11.6+1'
 dev_dependencies:
-  test: '^0.12.3+7'
+  test: '^0.12.3+8'
+
diff --git a/test/src/command_event.dart b/test/src/command_event.dart
index aea573f..0baa524 100644
--- a/test/src/command_event.dart
+++ b/test/src/command_event.dart
@@ -22,49 +22,54 @@
 import '../test_util.dart';
 
 void runTests() {
-  group('CommandEvent', () {
-    WebDriver driver;
+  group(
+      'CommandEvent',
+      () {
+        WebDriver driver;
 
-    var events = [];
-    var sub;
+        var events = [];
+        var sub;
 
-    setUp(() async {
-      driver = await createTestDriver();
-      sub = driver.onCommand.listen(events.add);
+        setUp(() async {
+          driver = await createTestDriver();
+          sub = driver.onCommand.listen(events.add);
 
-      await driver.get(testPagePath);
-    });
+          await driver.get(testPagePath);
+        });
 
-    tearDown(() async {
-      sub.cancel();
-      sub = null;
-      events.clear();
-      await driver.quit();
-      driver = null;
-    });
+        tearDown(() async {
+          sub.cancel();
+          sub = null;
+          events.clear();
+          await driver.quit();
+          driver = null;
+        });
 
-    test('handles exceptions', () async {
-      try {
-        await driver.switchTo.alert;
-      } catch (e) {}
-      await waitFor(() => events, matcher: hasLength(2));
-      expect(events[1].method, 'GET');
-      expect(events[1].endPoint, contains('alert'));
-      expect(events[1].exception, new isInstanceOf<WebDriverException>());
-      expect(events[1].result, isNull);
-      expect(events[1].startTime.isBefore(events[1].endTime), isTrue);
-      expect(events[1].stackTrace, new isInstanceOf<Chain>());
-    });
+        test('handles exceptions', () async {
+          try {
+            await driver.switchTo.alert;
+          } catch (e) {}
+          await waitFor(() => events, matcher: hasLength(2));
+          expect(events[1].method, 'GET');
+          expect(events[1].endPoint, contains('alert'));
+          expect(events[1].exception, new isInstanceOf<WebDriverException>());
+          expect(events[1].result, isNull);
+          expect(events[1].startTime.isBefore(events[1].endTime), isTrue);
+          expect(events[1].stackTrace, new isInstanceOf<Chain>());
+        });
 
-    test('handles normal operation', () async {
-      await driver.findElements(const By.cssSelector('nosuchelement')).toList();
-      await waitFor(() => events, matcher: hasLength(2));
-      expect(events[1].method, 'POST');
-      expect(events[1].endPoint, contains('elements'));
-      expect(events[1].exception, isNull);
-      expect(events[1].result, hasLength(0));
-      expect(events[1].startTime.isBefore(events[1].endTime), isTrue);
-      expect(events[1].stackTrace, new isInstanceOf<Chain>());
-    });
-  }, testOn: '!js');
+        test('handles normal operation', () async {
+          await driver
+              .findElements(const By.cssSelector('nosuchelement'))
+              .toList();
+          await waitFor(() => events, matcher: hasLength(2));
+          expect(events[1].method, 'POST');
+          expect(events[1].endPoint, contains('elements'));
+          expect(events[1].exception, isNull);
+          expect(events[1].result, hasLength(0));
+          expect(events[1].startTime.isBefore(events[1].endTime), isTrue);
+          expect(events[1].stackTrace, new isInstanceOf<Chain>());
+        });
+      },
+      testOn: '!js');
 }
diff --git a/test/src/navigation.dart b/test/src/navigation.dart
index 5739c68..c86bad6 100644
--- a/test/src/navigation.dart
+++ b/test/src/navigation.dart
@@ -31,13 +31,16 @@
 
     tearDown(() => driver.quit());
 
-    test('forward/back', () async {
-      await driver.get('http://www.yahoo.com');
-      await driver.navigate.back();
-      await waitFor(() => driver.title, matcher: contains('Google'));
-      await driver.navigate.forward();
-      await waitFor(() => driver.title, matcher: contains('Yahoo'));
-    }, skip: 'TODO(DrMarcII): fix test');
+    test(
+        'forward/back',
+        () async {
+          await driver.get('http://www.yahoo.com');
+          await driver.navigate.back();
+          await waitFor(() => driver.title, matcher: contains('Google'));
+          await driver.navigate.forward();
+          await waitFor(() => driver.title, matcher: contains('Yahoo'));
+        },
+        skip: 'TODO(DrMarcII): fix test');
 
     test('refresh', () async {
       var element = await driver.findElement(const By.name('q'));
diff --git a/test/src/web_driver.dart b/test/src/web_driver.dart
index 1c2f0d5..57870f8 100644
--- a/test/src/web_driver.dart
+++ b/test/src/web_driver.dart
@@ -38,14 +38,17 @@
         await driver.quit();
       });
 
-      test('firefox', () async {
-        WebDriver driver = await createTestDriver(
-            additionalCapabilities: Capabilities.firefox);
-        await driver.get('http://www.google.com');
-        var element = await driver.findElement(const By.name('q'));
-        expect(await element.name, 'input');
-        await driver.quit();
-      }, skip: runningOnTravis);
+      test(
+          'firefox',
+          () async {
+            WebDriver driver = await createTestDriver(
+                additionalCapabilities: Capabilities.firefox);
+            await driver.get('http://www.google.com');
+            var element = await driver.findElement(const By.name('q'));
+            expect(await element.name, 'input');
+            await driver.quit();
+          },
+          skip: runningOnTravis);
     });
 
     group('methods', () {
diff --git a/test/src/window.dart b/test/src/window.dart
index 0b60fe0..2e547bc 100644
--- a/test/src/window.dart
+++ b/test/src/window.dart
@@ -32,38 +32,47 @@
 
     tearDown(() => driver.quit());
 
-    test('size', () async {
-      var window = await driver.window;
-      var size = const Rectangle<int>(0, 0, 600, 400);
-      await window.setSize(size);
-      expect(await window.size, size);
-    }, skip: true);
+    test(
+        'size',
+        () async {
+          var window = await driver.window;
+          var size = const Rectangle<int>(0, 0, 600, 400);
+          await window.setSize(size);
+          expect(await window.size, size);
+        },
+        skip: true);
 
-    test('location', () async {
-      var window = await driver.window;
-      var position = const Point<int>(100, 200);
-      await window.setLocation(position);
-      expect(await window.location, position);
-    }, skip: true);
+    test(
+        'location',
+        () async {
+          var window = await driver.window;
+          var position = const Point<int>(100, 200);
+          await window.setLocation(position);
+          expect(await window.location, position);
+        },
+        skip: true);
 
     // May not work on some OS/browser combinations (notably Mac OS X).
-    test('maximize', () async {
-      var window = await driver.window;
-      await window.setSize(const Rectangle<int>(0, 0, 300, 200));
-      await window.setLocation(const Point<int>(100, 200));
-      await window.maximize();
+    test(
+        'maximize',
+        () async {
+          var window = await driver.window;
+          await window.setSize(const Rectangle<int>(0, 0, 300, 200));
+          await window.setLocation(const Point<int>(100, 200));
+          await window.maximize();
 
-      // maximizing can take some time
-      await waitFor(() async => (await window.size).height,
-          matcher: greaterThan(200));
+          // maximizing can take some time
+          await waitFor(() async => (await window.size).height,
+              matcher: greaterThan(200));
 
-      var location = await window.location;
-      var size = await window.size;
-      // Changed from `lessThan(100)` to pass the test on Mac.
-      expect(location.x, lessThanOrEqualTo(100));
-      expect(location.y, lessThan(200));
-      expect(size.height, greaterThan(200));
-      expect(size.width, greaterThan(300));
-    }, skip: true);
+          var location = await window.location;
+          var size = await window.size;
+          // Changed from `lessThan(100)` to pass the test on Mac.
+          expect(location.x, lessThanOrEqualTo(100));
+          expect(location.y, lessThan(200));
+          expect(size.height, greaterThan(200));
+          expect(size.width, greaterThan(300));
+        },
+        skip: true);
   });
 }
diff --git a/test/support/forwarder_test.dart b/test/support/forwarder_test.dart
index b6baa0e..e081cb6 100644
--- a/test/support/forwarder_test.dart
+++ b/test/support/forwarder_test.dart
@@ -113,8 +113,11 @@
       expect(await forwardedDriver.getRequest('element/div/text'),
           buttonNotClicked);
 
-      await forwardedDriver.execute(
-          'arguments[0].el.click();', [{'el': {'ELEMENT': 'button'}}]);
+      await forwardedDriver.execute('arguments[0].el.click();', [
+        {
+          'el': {'ELEMENT': 'button'}
+        }
+      ]);
 
       expect(
           await forwardedDriver.getRequest('element/div/text'), buttonClicked);