Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Unified Diff: tools/chrome_remote_control/chrome_remote_control/tab.py

Issue 10875044: Basic framework for devtools-based scrolling tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add backends and modular discovery. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/chrome_remote_control/chrome_remote_control/tab.py
diff --git a/tools/chrome_remote_control/chrome_remote_control/tab.py b/tools/chrome_remote_control/chrome_remote_control/tab.py
new file mode 100644
index 0000000000000000000000000000000000000000..cea0a54bb6b27c395984d43ca278b60ccf1ae6eb
--- /dev/null
+++ b/tools/chrome_remote_control/chrome_remote_control/tab.py
@@ -0,0 +1,90 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+import json
+import time
+import websocket
+import socket
+
+class EvaluateException(Exception):
+ pass
+
+class TabRuntime(object):
+ def __init__(self, inspector_backend):
+ self._inspector_backend = inspector_backend
+ self._inspector_backend.RegisterDomain(
+ 'Runtime',
+ self._OnNotification,
+ self._OnClose)
+
+ def _OnNotification(self, msg):
+ pass
+
+ def _OnClose(self):
+ pass
+
+ def Evaluate(self, expr):
+ request = {
+ "method": "Runtime.evaluate",
+ "params": {
+ "expression": expr,
+ "returnByValue": True
+ }
+ }
+ res = self._inspector_backend.SyncRequest(request)
+ if res["result"]["wasThrown"]:
+ # TODO(nduca): propagate stacks from javascript up to the python
+ # exception.
+ raise EvaluateException(res["result"]["result"]["description"])
+ if res["result"]["result"]["type"] == 'undefined':
+ return None
+ return res["result"]["result"]["value"]
+
+class Tab(object):
+ def __init__(self, inspector_backend):
+ self._inspector_backend = inspector_backend
+ self.runtime = TabRuntime(self._inspector_backend)
+
+ def Close(self):
+ self._inspector_backend.Close()
+ self._inspector_backend = None
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *args):
+ if self._inspector_backend:
+ self.Close()
dtu 2012/08/27 22:27:27 Makes more sense in __del__, so it'll take effect
+
+ def BeginToLoadURL(self, url):
+ # In order to tell when the document has actually changed,
+ # we go to about:blank first and wait. When that has happened, we
+ # to go the new URL and detect the document being non-about:blank as
+ # indication that the new document is loading.
+ self.runtime.Evaluate("document.location = 'about:blank';")
+ while True:
dtu 2012/08/27 22:27:27 while self.runtime.Evaluate("document.location.hre
+ hr = self.runtime.Evaluate("document.location.href")
+ if hr == "about:blank":
+ break
+ time.sleep(0.01)
+
+ self.runtime.Evaluate("document.location = '%s';" % url)
+ while True:
dtu 2012/08/27 22:27:27 while self.runtime.Evaluate("document.location.hre
+ hr = self.runtime.Evaluate("document.location.href")
+ if hr != "about:blank":
+ break
+ time.sleep(0.01)
+
+ def WaitForDocumentReadyStateToBeComplete(self):
+ while True:
dtu 2012/08/27 22:27:27 while self.runtime.Evaluate("document.readyState")
+ rs = self.runtime.Evaluate("document.readyState")
+ if rs == 'complete':
+ break
+ time.sleep(0.01)
+
+ def WaitForDocumentReadyStateToBeInteractiveOrBetter(self):
+ while True:
+ rs = self.runtime.Evaluate("document.readyState")
+ if rs == 'complete' or rs == 'interactive':
+ break
+ time.sleep(0.01)

Powered by Google App Engine
This is Rietveld 408576698