diff options
author | tonyg@chromium.org <tonyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-03 23:09:23 +0000 |
---|---|---|
committer | tonyg@chromium.org <tonyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-03 23:09:23 +0000 |
commit | 3ff927902f1eb0e4894df1b65c9aeb0841813c8d (patch) | |
tree | e9112e82109d0962a5e0baeb96b4539b27b1dd0d /tools | |
parent | 08dc2c4a2b0682653f16b8666acdfa5606b618da (diff) | |
download | chromium_src-3ff927902f1eb0e4894df1b65c9aeb0841813c8d.zip chromium_src-3ff927902f1eb0e4894df1b65c9aeb0841813c8d.tar.gz chromium_src-3ff927902f1eb0e4894df1b65c9aeb0841813c8d.tar.bz2 |
[Telemetry] Add a script_to_evaluate_on_commit argument to tab.Navigate().
This script string is evaluated after the context of the page exists, but
before any script on the page itself has executed. This will be used by the page
cyclers for installing onload and onbeforeunload event handlers on the page.
BUG=None
TEST=tools/telemetry/run_tests --browser=system inspector_page_unittest.InspectorPageTest.testScriptToEvaluateOnCommit
NOTRY=True
Review URL: https://chromiumcodereview.appspot.com/13489002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192185 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
6 files changed, 38 insertions, 9 deletions
diff --git a/tools/telemetry/telemetry/core/chrome/inspector_backend.py b/tools/telemetry/telemetry/core/chrome/inspector_backend.py index ee5c06c..c10e987 100644 --- a/tools/telemetry/telemetry/core/chrome/inspector_backend.py +++ b/tools/telemetry/telemetry/core/chrome/inspector_backend.py @@ -169,8 +169,8 @@ class InspectorBackend(object): def PerformActionAndWaitForNavigate(self, action_function, timeout): self._page.PerformActionAndWaitForNavigate(action_function, timeout) - def Navigate(self, url, timeout): - self._page.Navigate(url, timeout) + def Navigate(self, url, script_to_evaluate_on_commit, timeout): + self._page.Navigate(url, script_to_evaluate_on_commit, timeout) def GetCookieByName(self, name, timeout): return self._page.GetCookieByName(name, timeout) diff --git a/tools/telemetry/telemetry/core/chrome/inspector_page.py b/tools/telemetry/telemetry/core/chrome/inspector_page.py index d0c4a3a..d5eac72 100644 --- a/tools/telemetry/telemetry/core/chrome/inspector_page.py +++ b/tools/telemetry/telemetry/core/chrome/inspector_page.py @@ -62,8 +62,13 @@ class InspectorPage(object): DisablePageNotifications() - def Navigate(self, url, timeout=60): - """Navigates to url""" + def Navigate(self, url, script_to_evaluate_on_commit=None, timeout=60): + """Navigates to |url|. + + If |script_to_evaluate_on_commit| is given, the script source string will be + evaluated when the navigation is committed. This is after the context of + the page exists, but before any script on the page itself has executed. + """ def DoNavigate(): # Navigate the page. However, there seems to be a bug in chrome devtools @@ -79,7 +84,14 @@ class InspectorPage(object): } } self._inspector_backend.SendAndIgnoreResponse(request) - + if script_to_evaluate_on_commit: + request = { + 'method': 'Page.addScriptToEvaluateOnLoad', + 'params': { + 'scriptSource': script_to_evaluate_on_commit, + } + } + self._inspector_backend.SendAndIgnoreResponse(request) self.PerformActionAndWaitForNavigate(DoNavigate, timeout) def GetCookieByName(self, name, timeout=60): diff --git a/tools/telemetry/telemetry/core/chrome/inspector_page_unittest.py b/tools/telemetry/telemetry/core/chrome/inspector_page_unittest.py index 32917fd..4395c7b 100644 --- a/tools/telemetry/telemetry/core/chrome/inspector_page_unittest.py +++ b/tools/telemetry/telemetry/core/chrome/inspector_page_unittest.py @@ -55,3 +55,13 @@ class InspectorPageTest(tab_test_case.TabTestCase): self._tab.WaitForDocumentReadyStateToBeComplete() self._tab.ExecuteJavaScript('document.cookie="foo=bar"') self.assertEquals(self._tab.GetCookieByName('foo'), 'bar') + + def testScriptToEvaluateOnCommit(self): + unittest_data_dir = os.path.join(os.path.dirname(__file__), + '..', '..', '..', 'unittest_data') + self._browser.SetHTTPServerDirectories(unittest_data_dir) + self._tab.Navigate( + self._browser.http_server.UrlOf('blank.html'), + script_to_evaluate_on_commit='var foo = "bar";') + self._tab.WaitForDocumentReadyStateToBeComplete() + self.assertEquals(self._tab.EvaluateJavaScript('foo'), 'bar') diff --git a/tools/telemetry/telemetry/core/tab.py b/tools/telemetry/telemetry/core/tab.py index 979b645..d684ba6 100644 --- a/tools/telemetry/telemetry/core/tab.py +++ b/tools/telemetry/telemetry/core/tab.py @@ -82,9 +82,15 @@ class Tab(web_contents.WebContents): self._inspector_backend.PerformActionAndWaitForNavigate( action_function, timeout) - def Navigate(self, url, timeout=DEFAULT_TAB_TIMEOUT): - """Navigates to url.""" - self._inspector_backend.Navigate(url, timeout) + def Navigate(self, url, script_to_evaluate_on_commit=None, + timeout=DEFAULT_TAB_TIMEOUT): + """Navigates to url. + + If |script_to_evaluate_on_commit| is given, the script source string will be + evaluated when the navigation is committed. This is after the context of + the page exists, but before any script on the page itself has executed. + """ + self._inspector_backend.Navigate(url, script_to_evaluate_on_commit, timeout) def GetCookieByName(self, name, timeout=DEFAULT_TAB_TIMEOUT): """Returns the value of the cookie by the given |name|.""" diff --git a/tools/telemetry/telemetry/page/page.py b/tools/telemetry/telemetry/page/page.py index 0185021..9a076bf 100644 --- a/tools/telemetry/telemetry/page/page.py +++ b/tools/telemetry/telemetry/page/page.py @@ -26,6 +26,7 @@ class Page(object): self._attributes['credentials'] = None self._attributes['disabled'] = False self._attributes['wait_time_after_navigate'] = 2 + self._attributes['script_to_evaluate_on_commit'] = None if attributes: self._attributes.update(attributes) diff --git a/tools/telemetry/telemetry/page/page_runner.py b/tools/telemetry/telemetry/page/page_runner.py index 0baf987..0dd8d52 100644 --- a/tools/telemetry/telemetry/page/page_runner.py +++ b/tools/telemetry/telemetry/page/page_runner.py @@ -324,7 +324,7 @@ class PageRunner(object): return False test.WillNavigateToPage(page, tab) - tab.Navigate(target_side_url) + tab.Navigate(target_side_url, page.script_to_evaluate_on_commit) test.DidNavigateToPage(page, tab) # Wait for unpredictable redirects. |