1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 from telemetry.core import web_contents
6 DEFAULT_TAB_TIMEOUT = 60
8 class Tab(web_contents.WebContents):
9 """Represents a tab in the browser
11 The important parts of the Tab object are in the runtime and page objects.
13 # Navigates the tab to a given url.
14 tab.Navigate('http://www.google.com/')
16 # Evaluates 1+1 in the tab's JavaScript context.
19 def __init__(self, inspector_backend):
20 super(Tab, self).__init__(inspector_backend)
23 super(Tab, self).__del__()
27 """The browser in which this tab resides."""
28 return self._inspector_backend.browser
32 return self._inspector_backend.url
36 """A dictionary populated with measured DOM statistics.
38 Currently this dictionary contains:
40 'document_count': integer,
41 'node_count': integer,
42 'event_listener_count': integer
45 dom_counters = self._inspector_backend.GetDOMStats(
46 timeout=DEFAULT_TAB_TIMEOUT)
47 assert (len(dom_counters) == 3 and
48 all([x in dom_counters for x in ['document_count', 'node_count',
49 'event_listener_count']]))
54 """Brings this tab to the foreground asynchronously.
56 Not all browsers or browser versions support this method.
57 Be sure to check browser.supports_tab_control.
59 Please note: this is asynchronous. There is a delay between this call
60 and the page's documentVisibilityState becoming 'visible', and yet more
61 delay until the actual tab is visible to the user. None of these delays
62 are included in this call."""
63 self._inspector_backend.Activate()
66 def screenshot_supported(self):
67 """True if the browser instance is capable of capturing screenshots"""
68 return self._inspector_backend.screenshot_supported
70 def Screenshot(self, timeout=DEFAULT_TAB_TIMEOUT):
71 """Capture a screenshot of the window for rendering validation"""
72 return self._inspector_backend.Screenshot(timeout)
74 def PerformActionAndWaitForNavigate(
75 self, action_function, timeout=DEFAULT_TAB_TIMEOUT):
76 """Executes action_function, and waits for the navigation to complete.
78 action_function must be a Python function that results in a navigation.
79 This function returns when the navigation is complete or when
80 the timeout has been exceeded.
82 self._inspector_backend.PerformActionAndWaitForNavigate(
83 action_function, timeout)
85 def Navigate(self, url, script_to_evaluate_on_commit=None,
86 timeout=DEFAULT_TAB_TIMEOUT):
89 If |script_to_evaluate_on_commit| is given, the script source string will be
90 evaluated when the navigation is committed. This is after the context of
91 the page exists, but before any script on the page itself has executed.
93 self._inspector_backend.Navigate(url, script_to_evaluate_on_commit, timeout)
95 def GetCookieByName(self, name, timeout=DEFAULT_TAB_TIMEOUT):
96 """Returns the value of the cookie by the given |name|."""
97 return self._inspector_backend.GetCookieByName(name, timeout)
99 def CollectGarbage(self):
100 self._inspector_backend.CollectGarbage()
102 def ClearCache(self):
103 """Clears the browser's HTTP disk cache and the tab's HTTP memory cache."""
104 self._inspector_backend.ClearCache()