diff options
author | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-23 09:20:10 +0000 |
---|---|---|
committer | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-23 09:20:10 +0000 |
commit | 7e0088fd44631669894798dc23b4faf146e9ab8d (patch) | |
tree | 6f9c0a767d584fcdda6dbc60c3e55bb35fcdb68c /tools/telemetry | |
parent | db4aacf545e3a9a47f25affeef20c479b673bc91 (diff) | |
download | chromium_src-7e0088fd44631669894798dc23b4faf146e9ab8d.zip chromium_src-7e0088fd44631669894798dc23b4faf146e9ab8d.tar.gz chromium_src-7e0088fd44631669894798dc23b4faf146e9ab8d.tar.bz2 |
Telemetry: adding memory tests & solving problems on the go.
BUG=158323
Review URL: https://codereview.chromium.org/11416134
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169322 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/telemetry')
4 files changed, 93 insertions, 41 deletions
diff --git a/tools/telemetry/telemetry/click_element_interaction.py b/tools/telemetry/telemetry/click_element_interaction.py new file mode 100644 index 0000000..33f714c --- /dev/null +++ b/tools/telemetry/telemetry/click_element_interaction.py @@ -0,0 +1,51 @@ +# 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 time + +from telemetry import page_interaction +from telemetry import util + +class ClickElementInteraction(page_interaction.PageInteraction): + def __init__(self, attributes=None): + super(ClickElementInteraction, self).__init__(attributes) + + def PerformInteraction(self, page, tab): + def DoClick(): + assert hasattr(self, 'selector') or hasattr(self, 'text') + if hasattr(self, 'selector'): + code = 'document.querySelector(\'' + self.selector + '\').click();' + tab.runtime.Execute(code) + else: + click_element = """ + function clickElement(element, text) { + if (element.innerHTML == text) { + element.click(); + return true; + } + for (var i in element.childNodes) { + if (clickElement(element.childNodes[i], text)) + return true; + } + return false; + }""" + tab.runtime.Execute(click_element) + code = 'clickElement(document, "' + self.text + '");' + if not tab.runtime.Evaluate(code): + raise page_interaction.PageInteractionFailed( + 'Cannot find element with text ' + self.text) + + if hasattr(self, 'wait_for_navigate'): + tab.page.PerformActionAndWaitForNavigate(DoClick) + elif hasattr(self, 'wait_for_href_change'): + old_url = tab.runtime.Evaluate('document.location.href') + DoClick() + util.WaitFor(lambda: tab.runtime.Evaluate( + 'document.location.href') != old_url, 60) + elif hasattr(self, 'wait_seconds'): + time.sleep(self.wait_seconds) + DoClick() + else: + DoClick() + + tab.WaitForDocumentReadyStateToBeComplete() diff --git a/tools/telemetry/telemetry/click_element_interaction_unittest.py b/tools/telemetry/telemetry/click_element_interaction_unittest.py new file mode 100644 index 0000000..ebfb240 --- /dev/null +++ b/tools/telemetry/telemetry/click_element_interaction_unittest.py @@ -0,0 +1,42 @@ +# 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 + +from telemetry import click_element_interaction +from telemetry import tab_test_case + +class ClickElementInteractionTest(tab_test_case.TabTestCase): + def testClickWithSelectorWaitForNavigation(self): + unittest_data_dir = os.path.join(os.path.dirname(__file__), + '..', 'unittest_data') + self._browser.SetHTTPServerDirectory(unittest_data_dir) + self._tab.page.Navigate( + self._browser.http_server.UrlOf('page_with_link.html')) + self._tab.WaitForDocumentReadyStateToBeComplete() + self.assertEquals(self._tab.runtime.Evaluate('document.location.pathname;'), + '/page_with_link.html') + + data = {'selector': 'a[id="clickme"]', 'wait_for_navigation': True} + i = click_element_interaction.ClickElementInteraction(data) + i.PerformInteraction({}, self._tab) + + self.assertEquals(self._tab.runtime.Evaluate('document.location.pathname;'), + '/blank.html') + + def testClickWithTextWaitForRefChange(self): + unittest_data_dir = os.path.join(os.path.dirname(__file__), + '..', 'unittest_data') + self._browser.SetHTTPServerDirectory(unittest_data_dir) + self._tab.page.Navigate( + self._browser.http_server.UrlOf('page_with_link.html')) + self._tab.WaitForDocumentReadyStateToBeComplete() + self.assertEquals(self._tab.runtime.Evaluate('document.location.pathname;'), + '/page_with_link.html') + + data = {'text': 'Click me', 'wait_for_href_change': True} + i = click_element_interaction.ClickElementInteraction(data) + i.PerformInteraction({}, self._tab) + + self.assertEquals(self._tab.runtime.Evaluate('document.location.pathname;'), + '/blank.html') diff --git a/tools/telemetry/telemetry/click_to_navigate_interaction.py b/tools/telemetry/telemetry/click_to_navigate_interaction.py deleted file mode 100644 index 3eafcf8..0000000 --- a/tools/telemetry/telemetry/click_to_navigate_interaction.py +++ /dev/null @@ -1,16 +0,0 @@ -# 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 page_interaction - -class ClickToNavigateInteraction(page_interaction.PageInteraction): - def __init__(self, attributes=None): - super(ClickToNavigateInteraction, self).__init__(attributes) - - def PerformInteraction(self, page, tab): - assert self.selector - code = 'document.querySelector(\'' + self.selector + '\').click();' - def DoClick(): - tab.runtime.Execute(code) - tab.page.PerformActionAndWaitForNavigate(DoClick) - tab.WaitForDocumentReadyStateToBeComplete() diff --git a/tools/telemetry/telemetry/click_to_navigate_interaction_unittest.py b/tools/telemetry/telemetry/click_to_navigate_interaction_unittest.py deleted file mode 100644 index f631c2a..0000000 --- a/tools/telemetry/telemetry/click_to_navigate_interaction_unittest.py +++ /dev/null @@ -1,25 +0,0 @@ -# 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 - -from telemetry import click_to_navigate_interaction -from telemetry import tab_test_case - -class ClickToNavigateInteractionTest(tab_test_case.TabTestCase): - def testClickToNavigateInteraction(self): - unittest_data_dir = os.path.join(os.path.dirname(__file__), - '..', 'unittest_data') - self._browser.SetHTTPServerDirectory(unittest_data_dir) - self._tab.page.Navigate( - self._browser.http_server.UrlOf('page_with_link.html')) - self._tab.WaitForDocumentReadyStateToBeComplete() - self.assertEquals(self._tab.runtime.Evaluate('document.location.pathname;'), - '/page_with_link.html') - - data = {'selector': 'a[id="clickme"]'} - i = click_to_navigate_interaction.ClickToNavigateInteraction(data) - i.PerformInteraction({}, self._tab) - - self.assertEquals(self._tab.runtime.Evaluate('document.location.pathname;'), - '/blank.html') |