{"action":"created","comment":{"url":"https://api.github.com/repos/flutter/flutter/pulls/comments/53087413","id":53087413,"diff_hunk":"@@ -0,0 +1,166 @@\n+// Copyright 2016 The Chromium Authors. All rights reserved.\n+// Use of this source code is governed by a BSD-style license that can be\n+// found in the LICENSE file.\n+\n+import 'dart:async';\n+import 'package:vm_service_client/vm_service_client.dart';\n+import 'package:json_rpc_2/json_rpc_2.dart' as rpc;\n+\n+import 'error.dart';\n+import 'find.dart';\n+import 'gesture.dart';\n+import 'health.dart';\n+import 'message.dart';\n+\n+// Package-private for internal tests.\n+FlutterDriver newFlutterDriver(VMServiceClient serviceClient, VMRunnableIsolate isolate) =>\n+    new FlutterDriver._(serviceClient, isolate);\n+\n+// Package-private for internal tests.\n+typedef Future<VMServiceClient> InternalConnectFunction(String url);\n+\n+// Package-private for internal tests.\n+final InternalConnectFunction internalTrueConnectFunction = VMServiceClient.connect;\n+\n+// Package-private for internal tests.\n+InternalConnectFunction internalConnectFunction = internalTrueConnectFunction;\n+\n+/// Drives a Flutter Application running in another process.\n+class FlutterDriver {\n+\n+  static const String _flutterExtensionMethod = 'ext.flutter_driver';\n+  static final Logger _log = new Logger('FlutterDriver');\n+\n+  /// Connects to a Flutter application.\n+  ///\n+  /// Resumes the application if it is currently paused (e.g. at a breakpoint).\n+  ///\n+  /// [dartVmServiceUrl] is the URL to Dart observatory (a.k.a. VM service). By\n+  /// default it connects to `http://localhost:8181`.\n+  static Future<FlutterDriver> connect({String dartVmServiceUrl: 'http://localhost:8181'}) async {\n+    // Connect to Dart VM servcies\n+    _log.info('Connecting to Flutter application at $dartVmServiceUrl');\n+    VMServiceClient client = await internalConnectFunction(dartVmServiceUrl);\n+    VM vm = await client.getVM();\n+    _log.trace('Looking for the isolate');\n+    VMIsolate isolate = await vm.isolates.first.load();\n+    FlutterDriver driver = newFlutterDriver(client, isolate);\n+\n+    // Attempts to resume the isolate, but does not crash if it fails because\n+    // the isolate is already resumed. There could be a race with other tools,\n+    // such as a debugger, any of which could have resumed the isolate.\n+    Future resumeLeniently() {\n+      _log.trace('Attempting to resume isolate');\n+      return isolate.resume().catchError((e) {\n+        const vmMustBePausedCode = 101;\n+        if (e is rpc.RpcException && e.code == vmMustBePausedCode) {\n+          // No biggie; something else must have resumed the isolate\n+          _log.warning(\n+            'Attempted to resume an already resumed isolate. This may happen '\n+            'when we lose a race with another tool (usually a debugger) that '\n+            'is connected to the same isolate.');\n+        } else {\n+          // Failed to resume due to another reason. Fail hard.\n+          throw e;\n+        }\n+      });\n+    }\n+\n+    // Attempt to resume isolate if it was paused\n+    if (isolate.pauseEvent is VMPauseStartEvent) {\n+      _log.trace('Isolate is paused at start.');\n+\n+      // Waits for a signal from the VM service that the extension is registered\n+      Future waitForServiceExtension() {\n+        return isolate.onServiceExtensionAdded.firstWhere((VMServiceExtension ext) {\n+          return ext.method == _flutterExtensionMethod;\n+        });\n+      }\n+\n+      // If the isolate is paused at the start, e.g. via the --start-paused\n+      // option, then the VM service extension is not registered yet. Wait for\n+      // it to be registered.\n+      const timeout = const Object();","path":"packages/flutter_driver/lib/src/driver.dart","position":83,"original_position":83,"commit_id":"a7680c3b8c78c773b71f9152f885ff83a4bf9e2c","original_commit_id":"a7680c3b8c78c773b71f9152f885ff83a4bf9e2c","user":{"login":"yjbanov","id":211513,"avatar_url":"https://avatars.githubusercontent.com/u/211513?v=3","gravatar_id":"","url":"https://api.github.com/users/yjbanov","html_url":"https://github.com/yjbanov","followers_url":"https://api.github.com/users/yjbanov/followers","following_url":"https://api.github.com/users/yjbanov/following{/other_user}","gists_url":"https://api.github.com/users/yjbanov/gists{/gist_id}","starred_url":"https://api.github.com/users/yjbanov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yjbanov/subscriptions","organizations_url":"https://api.github.com/users/yjbanov/orgs","repos_url":"https://api.github.com/users/yjbanov/repos","events_url":"https://api.github.com/users/yjbanov/events{/privacy}","received_events_url":"https://api.github.com/users/yjbanov/received_events","type":"User","site_admin":false},"body":"done","created_at":"2016-02-16T22:07:11Z","updated_at":"2016-02-16T22:07:11Z","html_url":"https://github.com/flutter/flutter/pull/1842#discussion_r53087413","pull_request_url":"https://api.github.com/repos/flutter/flutter/pulls/1842","_links":{"self":{"href":"https://api.github.com/repos/flutter/flutter/pulls/comments/53087413"},"html":{"href":"https://github.com/flutter/flutter/pull/1842#discussion_r53087413"},"pull_request":{"href":"https://api.github.com/repos/flutter/flutter/pulls/1842"}}},"pull_request":{"url":"https://api.github.com/repos/flutter/flutter/pulls/1842","id":59247892,"html_url":"https://github.com/flutter/flutter/pull/1842","diff_url":"https://github.com/flutter/flutter/pull/1842.diff","patch_url":"https://github.com/flutter/flutter/pull/1842.patch","issue_url":"https://api.github.com/repos/flutter/flutter/issues/1842","number":1842,"state":"open","locked":false,"title":"WIP: flutter_driver package","user":{"login":"yjbanov","id":211513,"avatar_url":"https://avatars.githubusercontent.com/u/211513?v=3","gravatar_id":"","url":"https://api.github.com/users/yjbanov","html_url":"https://github.com/yjbanov","followers_url":"https://api.github.com/users/yjbanov/followers","following_url":"https://api.github.com/users/yjbanov/following{/other_user}","gists_url":"https://api.github.com/users/yjbanov/gists{/gist_id}","starred_url":"https://api.github.com/users/yjbanov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yjbanov/subscriptions","organizations_url":"https://api.github.com/users/yjbanov/orgs","repos_url":"https://api.github.com/users/yjbanov/repos","events_url":"https://api.github.com/users/yjbanov/events{/privacy}","received_events_url":"https://api.github.com/users/yjbanov/received_events","type":"User","site_admin":false},"body":"Requesting a high-level review for now.\r\n\r\nThis PR contains:\r\n\r\n- `FlutterDriver` API for e2e tests usable in conjunction with `package:test`\r\n- `FlutterDriverExtension` to be enabled by the application in order to allow an external agent to connect to it and drive user interactions and probe into the element tree\r\n- initial implementations of `tap`, `findByValueKey` and `getText` commands (to be expanded in future PRs)\r\n\r\nThis PR does not include:\r\n\r\n- `flutter drive` command\r\n- integration test between `FlutterDriver` and `FlutterDriverExtension` (this is ironic but requires `flutter drive`)\r\n\r\nThings to do before submitting:\r\n\r\n- [ ] review\r\n- [ ] squash commits into one with a decent description\r\n- [ ] wait for https://codereview.chromium.org/1670283002/ to be accepted and released (or we could temporarily point to my fork at https://github.com/yjbanov/vm_service_client/tree/isolate-sendRequest)\r\n- [ ] make sure `flutter_driver` unit-tests plug into the CI build\r\n","created_at":"2016-02-12T23:50:47Z","updated_at":"2016-02-16T22:07:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3df6830d7e0a1f524391f0454cbefd6987168687","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/flutter/flutter/pulls/1842/commits","review_comments_url":"https://api.github.com/repos/flutter/flutter/pulls/1842/comments","review_comment_url":"https://api.github.com/repos/flutter/flutter/pulls/comments{/number}","comments_url":"https://api.github.com/repos/flutter/flutter/issues/1842/comments","statuses_url":"https://api.github.com/repos/flutter/flutter/statuses/a7680c3b8c78c773b71f9152f885ff83a4bf9e2c","head":{"label":"yjbanov:flutter-driver","ref":"flutter-driver","sha":"a7680c3b8c78c773b71f9152f885ff83a4bf9e2c","user":{"login":"yjbanov","id":211513,"avatar_url":"https://avatars.githubusercontent.com/u/211513?v=3","gravatar_id":"","url":"https://api.github.com/users/yjbanov","html_url":"https://github.com/yjbanov","followers_url":"https://api.github.com/users/yjbanov/followers","following_url":"https://api.github.com/users/yjbanov/following{/other_user}","gists_url":"https://api.github.com/users/yjbanov/gists{/gist_id}","starred_url":"https://api.github.com/users/yjbanov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yjbanov/subscriptions","organizations_url":"https://api.github.com/users/yjbanov/orgs","repos_url":"https://api.github.com/users/yjbanov/repos","events_url":"https://api.github.com/users/yjbanov/events{/privacy}","received_events_url":"https://api.github.com/users/yjbanov/received_events","type":"User","site_admin":false},"repo":{"id":50871415,"name":"flutter","full_name":"yjbanov/flutter","owner":{"login":"yjbanov","id":211513,"avatar_url":"https://avatars.githubusercontent.com/u/211513?v=3","gravatar_id":"","url":"https://api.github.com/users/yjbanov","html_url":"https://github.com/yjbanov","followers_url":"https://api.github.com/users/yjbanov/followers","following_url":"https://api.github.com/users/yjbanov/following{/other_user}","gists_url":"https://api.github.com/users/yjbanov/gists{/gist_id}","starred_url":"https://api.github.com/users/yjbanov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yjbanov/subscriptions","organizations_url":"https://api.github.com/users/yjbanov/orgs","repos_url":"https://api.github.com/users/yjbanov/repos","events_url":"https://api.github.com/users/yjbanov/events{/privacy}","received_events_url":"https://api.github.com/users/yjbanov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yjbanov/flutter","description":"Framework for building high-performance, high-fidelity iOS and Android apps","fork":true,"url":"https://api.github.com/repos/yjbanov/flutter","forks_url":"https://api.github.com/repos/yjbanov/flutter/forks","keys_url":"https://api.github.com/repos/yjbanov/flutter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yjbanov/flutter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yjbanov/flutter/teams","hooks_url":"https://api.github.com/repos/yjbanov/flutter/hooks","issue_events_url":"https://api.github.com/repos/yjbanov/flutter/issues/events{/number}","events_url":"https://api.github.com/repos/yjbanov/flutter/events","assignees_url":"https://api.github.com/repos/yjbanov/flutter/assignees{/user}","branches_url":"https://api.github.com/repos/yjbanov/flutter/branches{/branch}","tags_url":"https://api.github.com/repos/yjbanov/flutter/tags","blobs_url":"https://api.github.com/repos/yjbanov/flutter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yjbanov/flutter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yjbanov/flutter/git/refs{/sha}","trees_url":"https://api.github.com/repos/yjbanov/flutter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yjbanov/flutter/statuses/{sha}","languages_url":"https://api.github.com/repos/yjbanov/flutter/languages","stargazers_url":"https://api.github.com/repos/yjbanov/flutter/stargazers","contributors_url":"https://api.github.com/repos/yjbanov/flutter/contributors","subscribers_url":"https://api.github.com/repos/yjbanov/flutter/subscribers","subscription_url":"https://api.github.com/repos/yjbanov/flutter/subscription","commits_url":"https://api.github.com/repos/yjbanov/flutter/commits{/sha}","git_commits_url":"https://api.github.com/repos/yjbanov/flutter/git/commits{/sha}","comments_url":"https://api.github.com/repos/yjbanov/flutter/comments{/number}","issue_comment_url":"https://api.github.com/repos/yjbanov/flutter/issues/comments{/number}","contents_url":"https://api.github.com/repos/yjbanov/flutter/contents/{+path}","compare_url":"https://api.github.com/repos/yjbanov/flutter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yjbanov/flutter/merges","archive_url":"https://api.github.com/repos/yjbanov/flutter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yjbanov/flutter/downloads","issues_url":"https://api.github.com/repos/yjbanov/flutter/issues{/number}","pulls_url":"https://api.github.com/repos/yjbanov/flutter/pulls{/number}","milestones_url":"https://api.github.com/repos/yjbanov/flutter/milestones{/number}","notifications_url":"https://api.github.com/repos/yjbanov/flutter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yjbanov/flutter/labels{/name}","releases_url":"https://api.github.com/repos/yjbanov/flutter/releases{/id}","deployments_url":"https://api.github.com/repos/yjbanov/flutter/deployments","created_at":"2016-02-01T21:09:40Z","updated_at":"2016-02-01T21:09:42Z","pushed_at":"2016-02-12T23:32:30Z","git_url":"git://github.com/yjbanov/flutter.git","ssh_url":"git@github.com:yjbanov/flutter.git","clone_url":"https://github.com/yjbanov/flutter.git","svn_url":"https://github.com/yjbanov/flutter","homepage":"http://flutter.io","size":12761,"stargazers_count":0,"watchers_count":0,"language":"Dart","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"flutter:master","ref":"master","sha":"f53c1edcab1216ba6ec42af3e4bd8b57e63a21fc","user":{"login":"flutter","id":14101776,"avatar_url":"https://avatars.githubusercontent.com/u/14101776?v=3","gravatar_id":"","url":"https://api.github.com/users/flutter","html_url":"https://github.com/flutter","followers_url":"https://api.github.com/users/flutter/followers","following_url":"https://api.github.com/users/flutter/following{/other_user}","gists_url":"https://api.github.com/users/flutter/gists{/gist_id}","starred_url":"https://api.github.com/users/flutter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flutter/subscriptions","organizations_url":"https://api.github.com/users/flutter/orgs","repos_url":"https://api.github.com/users/flutter/repos","events_url":"https://api.github.com/users/flutter/events{/privacy}","received_events_url":"https://api.github.com/users/flutter/received_events","type":"Organization","site_admin":false},"repo":{"id":31792824,"name":"flutter","full_name":"flutter/flutter","owner":{"login":"flutter","id":14101776,"avatar_url":"https://avatars.githubusercontent.com/u/14101776?v=3","gravatar_id":"","url":"https://api.github.com/users/flutter","html_url":"https://github.com/flutter","followers_url":"https://api.github.com/users/flutter/followers","following_url":"https://api.github.com/users/flutter/following{/other_user}","gists_url":"https://api.github.com/users/flutter/gists{/gist_id}","starred_url":"https://api.github.com/users/flutter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flutter/subscriptions","organizations_url":"https://api.github.com/users/flutter/orgs","repos_url":"https://api.github.com/users/flutter/repos","events_url":"https://api.github.com/users/flutter/events{/privacy}","received_events_url":"https://api.github.com/users/flutter/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/flutter/flutter","description":"Framework for building high-performance, high-fidelity iOS and Android apps","fork":false,"url":"https://api.github.com/repos/flutter/flutter","forks_url":"https://api.github.com/repos/flutter/flutter/forks","keys_url":"https://api.github.com/repos/flutter/flutter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/flutter/flutter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/flutter/flutter/teams","hooks_url":"https://api.github.com/repos/flutter/flutter/hooks","issue_events_url":"https://api.github.com/repos/flutter/flutter/issues/events{/number}","events_url":"https://api.github.com/repos/flutter/flutter/events","assignees_url":"https://api.github.com/repos/flutter/flutter/assignees{/user}","branches_url":"https://api.github.com/repos/flutter/flutter/branches{/branch}","tags_url":"https://api.github.com/repos/flutter/flutter/tags","blobs_url":"https://api.github.com/repos/flutter/flutter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/flutter/flutter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/flutter/flutter/git/refs{/sha}","trees_url":"https://api.github.com/repos/flutter/flutter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/flutter/flutter/statuses/{sha}","languages_url":"https://api.github.com/repos/flutter/flutter/languages","stargazers_url":"https://api.github.com/repos/flutter/flutter/stargazers","contributors_url":"https://api.github.com/repos/flutter/flutter/contributors","subscribers_url":"https://api.github.com/repos/flutter/flutter/subscribers","subscription_url":"https://api.github.com/repos/flutter/flutter/subscription","commits_url":"https://api.github.com/repos/flutter/flutter/commits{/sha}","git_commits_url":"https://api.github.com/repos/flutter/flutter/git/commits{/sha}","comments_url":"https://api.github.com/repos/flutter/flutter/comments{/number}","issue_comment_url":"https://api.github.com/repos/flutter/flutter/issues/comments{/number}","contents_url":"https://api.github.com/repos/flutter/flutter/contents/{+path}","compare_url":"https://api.github.com/repos/flutter/flutter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/flutter/flutter/merges","archive_url":"https://api.github.com/repos/flutter/flutter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/flutter/flutter/downloads","issues_url":"https://api.github.com/repos/flutter/flutter/issues{/number}","pulls_url":"https://api.github.com/repos/flutter/flutter/pulls{/number}","milestones_url":"https://api.github.com/repos/flutter/flutter/milestones{/number}","notifications_url":"https://api.github.com/repos/flutter/flutter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/flutter/flutter/labels{/name}","releases_url":"https://api.github.com/repos/flutter/flutter/releases{/id}","deployments_url":"https://api.github.com/repos/flutter/flutter/deployments","created_at":"2015-03-06T22:54:58Z","updated_at":"2016-02-16T06:38:24Z","pushed_at":"2016-02-16T21:45:12Z","git_url":"git://github.com/flutter/flutter.git","ssh_url":"git@github.com:flutter/flutter.git","clone_url":"https://github.com/flutter/flutter.git","svn_url":"https://github.com/flutter/flutter","homepage":"http://flutter.io","size":105571,"stargazers_count":2632,"watchers_count":2632,"language":"Dart","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":259,"mirror_url":null,"open_issues_count":597,"forks":259,"open_issues":597,"watchers":2632,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/flutter/flutter/pulls/1842"},"html":{"href":"https://github.com/flutter/flutter/pull/1842"},"issue":{"href":"https://api.github.com/repos/flutter/flutter/issues/1842"},"comments":{"href":"https://api.github.com/repos/flutter/flutter/issues/1842/comments"},"review_comments":{"href":"https://api.github.com/repos/flutter/flutter/pulls/1842/comments"},"review_comment":{"href":"https://api.github.com/repos/flutter/flutter/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/flutter/flutter/pulls/1842/commits"},"statuses":{"href":"https://api.github.com/repos/flutter/flutter/statuses/a7680c3b8c78c773b71f9152f885ff83a4bf9e2c"}}}}