diff options
author | achuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-04 23:30:03 +0000 |
---|---|---|
committer | achuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-04 23:30:03 +0000 |
commit | 85a478fd9cbcc4f4f59719a42ce4d7c9bdb1bf0a (patch) | |
tree | d90fc35924531051cad350f76d73c77f54493223 /tools | |
parent | 9d7a393e71d5f0eef42500552e770709506050ae (diff) | |
download | chromium_src-85a478fd9cbcc4f4f59719a42ce4d7c9bdb1bf0a.zip chromium_src-85a478fd9cbcc4f4f59719a42ce4d7c9bdb1bf0a.tar.gz chromium_src-85a478fd9cbcc4f4f59719a42ce4d7c9bdb1bf0a.tar.bz2 |
Introduce web_contents.
BUG=169954
TEST=run_tests.py
Review URL: https://codereview.chromium.org/12194027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180552 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rw-r--r-- | tools/telemetry/telemetry/tab.py | 74 | ||||
-rw-r--r-- | tools/telemetry/telemetry/web_contents.py | 58 |
2 files changed, 73 insertions, 59 deletions
diff --git a/tools/telemetry/telemetry/tab.py b/tools/telemetry/telemetry/tab.py index fc235a4..0e6ed67 100644 --- a/tools/telemetry/telemetry/tab.py +++ b/tools/telemetry/telemetry/tab.py @@ -1,10 +1,11 @@ # 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. +from telemetry import web_contents DEFAULT_TAB_TIMEOUT = 60 -class Tab(object): +class Tab(web_contents.WebContents): """Represents a tab in the browser The important parts of the Tab object are in the runtime and page objects. @@ -15,20 +16,20 @@ class Tab(object): # Evaluates 1+1 in the tab's JavaScript context. tab.Evaluate('1+1') """ - def __init__(self, backend): - self._backend = backend + def __init__(self, inspector_backend): + super(Tab, self).__init__(inspector_backend) def Disconnect(self): - self._backend.Disconnect() + self._inspector_backend.Disconnect() @property def browser(self): """The browser in which this tab resides.""" - return self._backend.browser + return self._inspector_backend.browser @property def url(self): - return self._backend.url + return self._inspector_backend.url def Activate(self): """Brings this tab to the foreground asynchronously. @@ -40,38 +41,23 @@ class Tab(object): and the page's documentVisibilityState becoming 'visible', and yet more delay until the actual tab is visible to the user. None of these delays are included in this call.""" - self._backend.Activate() + self._inspector_backend.Activate() def Close(self): """Closes this tab. Not all browsers or browser versions support this method. Be sure to check browser.supports_tab_control.""" - self._backend.Close() - - def WaitForDocumentReadyStateToBeComplete(self, timeout=DEFAULT_TAB_TIMEOUT): - self._backend.WaitForDocumentReadyStateToBeComplete(timeout) - - def WaitForDocumentReadyStateToBeInteractiveOrBetter( - self, timeout=DEFAULT_TAB_TIMEOUT): - self._backend.WaitForDocumentReadyStateToBeInteractiveOrBetter(timeout) + self._inspector_backend.Close() @property def screenshot_supported(self): """True if the browser instance is capable of capturing screenshots""" - return self._backend.screenshot_supported + return self._inspector_backend.screenshot_supported def Screenshot(self, timeout=DEFAULT_TAB_TIMEOUT): """Capture a screenshot of the window for rendering validation""" - return self._backend.Screenshot(timeout) - - @property - def message_output_stream(self): - return self._backend.message_output_stream - - @message_output_stream.setter - def message_output_stream(self, stream): - self._backend.message_output_stream = stream + return self._inspector_backend.Screenshot(timeout) def PerformActionAndWaitForNavigate( self, action_function, timeout=DEFAULT_TAB_TIMEOUT): @@ -81,43 +67,13 @@ class Tab(object): This function returns when the navigation is complete or when the timeout has been exceeded. """ - self._backend.PerformActionAndWaitForNavigate(action_function, timeout) + self._inspector_backend.PerformActionAndWaitForNavigate( + action_function, timeout) def Navigate(self, url, timeout=DEFAULT_TAB_TIMEOUT): """Navigates to url.""" - self._backend.Navigate(url, timeout) + self._inspector_backend.Navigate(url, timeout) def GetCookieByName(self, name, timeout=DEFAULT_TAB_TIMEOUT): """Returns the value of the cookie by the given |name|.""" - return self._backend.GetCookieByName(name, timeout) - - def ExecuteJavaScript(self, expr, timeout=DEFAULT_TAB_TIMEOUT): - """Executes expr in JavaScript. Does not return the result. - - If the expression failed to evaluate, EvaluateException will be raised. - """ - self._backend.ExecuteJavaScript(expr, timeout) - - def EvaluateJavaScript(self, expr, timeout=DEFAULT_TAB_TIMEOUT): - """Evalutes expr in JavaScript and returns the JSONized result. - - Consider using ExecuteJavaScript for cases where the result of the - expression is not needed. - - If evaluation throws in JavaScript, a Python EvaluateException will - be raised. - - If the result of the evaluation cannot be JSONized, then an - EvaluationException will be raised. - """ - return self._backend.EvaluateJavaScript(expr, timeout) - - @property - def timeline_model(self): - return self._backend.timeline_model - - def StartTimelineRecording(self): - self._backend.StartTimelineRecording() - - def StopTimelineRecording(self): - self._backend.StopTimelineRecording() + return self._inspector_backend.GetCookieByName(name, timeout) diff --git a/tools/telemetry/telemetry/web_contents.py b/tools/telemetry/telemetry/web_contents.py new file mode 100644 index 0000000..c11d9c5 --- /dev/null +++ b/tools/telemetry/telemetry/web_contents.py @@ -0,0 +1,58 @@ +# 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. + +DEFAULT_WEB_CONTENTS_TIMEOUT = 60 + +class WebContents(object): + """Represents web contents in the browser""" + def __init__(self, inspector_backend): + self._inspector_backend = inspector_backend + + def WaitForDocumentReadyStateToBeComplete(self, + timeout=DEFAULT_WEB_CONTENTS_TIMEOUT): + self._inspector_backend.WaitForDocumentReadyStateToBeComplete(timeout) + + def WaitForDocumentReadyStateToBeInteractiveOrBetter(self, + timeout=DEFAULT_WEB_CONTENTS_TIMEOUT): + self._inspector_backend.WaitForDocumentReadyStateToBeInteractiveOrBetter( + timeout) + + def ExecuteJavaScript(self, expr, timeout=DEFAULT_WEB_CONTENTS_TIMEOUT): + """Executes expr in JavaScript. Does not return the result. + + If the expression failed to evaluate, EvaluateException will be raised. + """ + self._inspector_backend.ExecuteJavaScript(expr, timeout) + + def EvaluateJavaScript(self, expr, timeout=DEFAULT_WEB_CONTENTS_TIMEOUT): + """Evalutes expr in JavaScript and returns the JSONized result. + + Consider using ExecuteJavaScript for cases where the result of the + expression is not needed. + + If evaluation throws in JavaScript, a Python EvaluateException will + be raised. + + If the result of the evaluation cannot be JSONized, then an + EvaluationException will be raised. + """ + return self._inspector_backend.EvaluateJavaScript(expr, timeout) + + @property + def message_output_stream(self): + return self._inspector_backend.message_output_stream + + @message_output_stream.setter + def message_output_stream(self, stream): + self._inspector_backend.message_output_stream = stream + + @property + def timeline_model(self): + return self._inspector_backend.timeline_model + + def StartTimelineRecording(self): + self._inspector_backend.StartTimelineRecording() + + def StopTimelineRecording(self): + self._inspector_backend.StopTimelineRecording() |