Index: tools/telemetry/telemetry/tab.py |
diff --git a/tools/telemetry/telemetry/tab.py b/tools/telemetry/telemetry/tab.py |
index 3fc0dacc6c1002fb7027d8c4c6d3b128e7548e11..09feae1546539c4b9176b3e97fac9c2ca275259f 100644 |
--- a/tools/telemetry/telemetry/tab.py |
+++ b/tools/telemetry/telemetry/tab.py |
@@ -2,12 +2,7 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
-from telemetry import inspector_backend |
-from telemetry import inspector_console |
-from telemetry import inspector_page |
-from telemetry import inspector_runtime |
-from telemetry import inspector_timeline |
-from telemetry import util |
+from telemetry import tab_backend |
DEFAULT_TAB_TIMEOUT = 60 |
@@ -23,51 +18,20 @@ class Tab(object): |
tab.runtime.Evaluate('1+1') |
""" |
def __init__(self, browser, tab_controller, debugger_url): |
- self._browser = browser |
- self._tab_controller = tab_controller |
- self._debugger_url = debugger_url |
- |
- self._inspector_backend = None |
- self._console = None |
- self._page = None |
- self._runtime = None |
- self._timeline = None |
+ self._backend = tab_backend.TabBackend( |
nduca
2013/01/09 01:02:30
Is there a way to pass in the tab_backend on the c
dtu
2013/01/09 01:21:27
Done.
|
+ browser, tab_controller, debugger_url) |
def __del__(self): |
- self.Disconnect() |
- |
- def _Connect(self): |
- if self._inspector_backend: |
- return |
- |
- self._inspector_backend = inspector_backend.InspectorBackend( |
- self._tab_controller, self._debugger_url) |
- self._console = inspector_console.InspectorConsole( |
- self._inspector_backend, self) |
- self._page = inspector_page.InspectorPage(self._inspector_backend, self) |
- self._runtime = inspector_runtime.InspectorRuntime( |
- self._inspector_backend, self) |
- self._timeline = inspector_timeline.InspectorTimeline( |
- self._inspector_backend, self) |
- |
- def Disconnect(self): |
- """Closes the connection to this tab.""" |
- self._console = None |
- self._page = None |
- self._runtime = None |
- self._timeline = None |
- if self._inspector_backend: |
- self._inspector_backend.Close() |
- self._inspector_backend = None |
- self._browser = None |
+ self.Close() |
- def Close(self): |
- """Closes this tab. |
+ @property |
+ def browser(self): |
+ """The browser in which this tab resides.""" |
+ return self._backend.browser |
- Not all browsers or browser versions support this method. |
- Be sure to check browser.supports_tab_control.""" |
- self.Disconnect() |
- self._tab_controller.CloseTab(self._debugger_url) |
+ @property |
+ def url(self): |
+ return self._backend.url |
def Activate(self): |
"""Brings this tab to the foreground asynchronously. |
@@ -76,51 +40,83 @@ 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._Connect() |
- self._tab_controller.ActivateTab(self._debugger_url) |
+ self._backend.Activate() |
- @property |
- def browser(self): |
- """The browser in which this tab resides.""" |
- return self._browser |
+ def Close(self): |
+ """Closes this tab. |
- @property |
- def url(self): |
- return self._tab_controller.GetTabUrl(self._debugger_url) |
+ Not all browsers or browser versions support this method. |
+ Be sure to check browser.supports_tab_control.""" |
+ self._backend.Close() |
- @property |
- def console(self): |
- """Methods for interacting with the page's console object.""" |
- self._Connect() |
- return self._console |
+ def WaitForDocumentReadyStateToBeComplete(self, timeout=DEFAULT_TAB_TIMEOUT): |
+ self._backend.WaitForDocumentReadyStateToBeComplete(timeout) |
- @property |
- def page(self): |
- """Methods for interacting with the current page.""" |
- self._Connect() |
- return self._page |
+ def WaitForDocumentReadyStateToBeInteractiveOrBetter( |
+ self, timeout=DEFAULT_TAB_TIMEOUT): |
+ self._backend.WaitForDocumentReadyStateToBeInteractiveOrBetter(timeout) |
@property |
- def runtime(self): |
- """Methods for interacting with the page's javascript runtime.""" |
- self._Connect() |
- return self._runtime |
+ def screenshot_supported(self): |
+ """True if the browser instance is capable of capturing screenshots""" |
+ return self._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 timeline(self): |
- """Methods for interacting with the inspector timeline.""" |
- self._Connect() |
- return self._timeline |
+ def message_output_stream(self): |
+ return self._backend.message_output_stream |
- def WaitForDocumentReadyStateToBeComplete(self, timeout=DEFAULT_TAB_TIMEOUT): |
- util.WaitFor( |
- lambda: self._runtime.Evaluate('document.readyState') == 'complete', |
- timeout) |
+ @message_output_stream.setter |
+ def message_output_stream(self, stream): |
+ self._backend.message_output_stream = stream |
- def WaitForDocumentReadyStateToBeInteractiveOrBetter( |
- self, timeout=DEFAULT_TAB_TIMEOUT): |
- def IsReadyStateInteractiveOrBetter(): |
- rs = self._runtime.Evaluate('document.readyState') |
- return rs == 'complete' or rs == 'interactive' |
- util.WaitFor(IsReadyStateInteractiveOrBetter, timeout) |
+ def PerformActionAndWaitForNavigate( |
+ self, action_function, timeout=DEFAULT_TAB_TIMEOUT): |
+ """Executes action_function, and waits for the navigation to complete. |
nduca
2013/01/09 01:02:30
what is the type of action_function? Lets make sur
dtu
2013/01/09 01:21:27
Done.
|
+ |
+ action_function is expect to result in a navigation. This function returns |
+ when the navigation is complete or when the timeout has been exceeded. |
+ """ |
+ self._backend.PerformActionAndWaitForNavigate(action_function, timeout) |
+ |
+ def Navigate(self, url, timeout=DEFAULT_TAB_TIMEOUT): |
+ """Navigates to url.""" |
+ self._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 Execute(self, expr, timeout=DEFAULT_TAB_TIMEOUT): |
nduca
2013/01/09 01:02:30
ExecuteJavascript
dtu
2013/01/09 01:21:27
Done.
|
+ """Executes expr in javascript. Does not return the result. |
+ |
+ If the expression failed to evaluate, EvaluateException will be raised. |
+ """ |
+ self._backend.Execute(expr, timeout) |
+ |
+ def Evaluate(self, expr, timeout=DEFAULT_TAB_TIMEOUT): |
nduca
2013/01/09 01:02:30
EvaluateJavascript
dtu
2013/01/09 01:21:27
Done.
|
+ """Evalutes expr in javascript and returns the JSONized result. |
+ |
+ Consider using Execute 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.Evaluate(expr, timeout) |
+ |
+ @property |
+ def timeline_events(self): |
+ return self._backend.timeline_events |
+ |
+ def StartRecording(self): |
nduca
2013/01/09 01:02:30
StartRecording what?
dtu
2013/01/09 01:21:27
StartTimelineRecording? StartEventRecording? I don
|
+ self._backend.StartRecording() |
+ def StopRecording(self): |
+ self._backend.StopRecording() |