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

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

Issue 10875044: Basic framework for devtools-based scrolling tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/browser.py
diff --git a/tools/chrome_remote_control/chrome_remote_control/browser.py b/tools/chrome_remote_control/chrome_remote_control/browser.py
new file mode 100644
index 0000000000000000000000000000000000000000..b454fbe549ec9cb47192ae0e65dff75f063ce90b
--- /dev/null
+++ b/tools/chrome_remote_control/chrome_remote_control/browser.py
@@ -0,0 +1,82 @@
+# 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 os as real_os
+import sys as real_sys
+import subprocess as real_subprocess
+import urllib2
+import json
+import tab
+
+import browser_finder
+
+class Browser(object):
+ def __init__(self, options):
+ self._executable = browser_finder.Find(options)
+ if not self._executable:
+ raise Exception("Cannot create browser, no executable found!")
+
+ # TODO(nduca): Delete the user data dir or create one that is unique.
+ tmpdir = "/tmp/simple-browser-controller-profile"
+ if real_os.path.exists(tmpdir):
+ ret = real_os.system("rm -rf -- %s" % tmpdir)
+ assert ret == 0
+ self._port = options.remote_debugging_port
+ args = [self._executable,
+ "--no-first-run",
+ "--remote-debugging-port=%i" % self._port]
+ if not options.dont_override_profile:
+ args.append("--user-data-dir=%s" % tmpdir)
+ args.extend(options.args)
+ if options.hide_stdout:
+ self._devnull = open(real_os.devnull, 'w')
+ self._proc = real_subprocess.Popen(
+ args,stdout=self._devnull, stderr=self._devnull)
+ else:
+ self._devnull = None
+ self._proc = real_subprocess.Popen(args)
+
+ try:
+ self._WaitForBrowserToComeUp()
+ except:
+ self.Close()
+ raise
+
+ def _WaitForBrowserToComeUp(self):
+ while True:
+ try:
+ self._ListTabs()
+ break
+ except urllib2.URLError, ex:
+ pass
+
+ def _ListTabs(self):
+ req = urllib2.urlopen("http://localhost:%i/json" % self._port)
+ data = req.read()
+ return json.loads(data)
+
+ @property
+ def num_tabs(self):
+ return len(self._ListTabs())
+
+ def GetNthTabURL(self, index):
+ return self._ListTabs()[index]["url"]
+
+ def ConnectToNthTab(self, index):
+ return tab.Tab(self, self._ListTabs()[index])
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *args):
+ if self._proc:
+ self.Close()
+
+ def Close(self):
+ self._proc.terminate()
+ self._proc.wait()
+ self._proc = None
+
+ if self._devnull:
+ self._devnull.close()

Powered by Google App Engine
This is Rietveld 408576698