Commit 21fcde82 authored by nednguyen@google.com's avatar nednguyen@google.com

Remove 'navigate' attribute from wait_until.

Change PerformActionAndWaitForNavigate to WaitForNavigate.

BUG=361809

Review URL: https://codereview.chromium.org/317913003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275487 0039d316-1c4b-4281-b951-d872f2087c98
parent 2ba1edf7
......@@ -512,37 +512,17 @@ class BlogspotPage(Top25Page):
}))
def RunStressMemory(self, action_runner):
action_runner.RunAction(ClickElementAction(
{
'text' : 'accessibility',
'wait_until': {
'condition': 'navigate'
}
}))
action_runner.RunAction(ClickElementAction({'text' : 'accessibility'}))
action_runner.WaitForNavigate()
action_runner.RunAction(ScrollAction())
action_runner.RunAction(ClickElementAction(
{
'text' : 'advanced',
'wait_until': {
'condition': 'navigate'
}
}))
action_runner.RunAction(ClickElementAction({'text' : 'advanced'}))
action_runner.WaitForNavigate()
action_runner.RunAction(ScrollAction())
action_runner.RunAction(ClickElementAction(
{
'text' : 'beginner',
'wait_until': {
'condition': 'navigate'
}
}))
action_runner.RunAction(ClickElementAction({'text' : 'beginner'}))
action_runner.WaitForNavigate()
action_runner.RunAction(ScrollAction())
action_runner.RunAction(ClickElementAction(
{
'text' : 'Home',
'wait_until': {
'condition': 'navigate'
}
}))
action_runner.RunAction(ClickElementAction({'text' : 'Home'}))
action_runner.WaitForNavigate()
class WordpressPage(Top25Page):
......@@ -569,30 +549,17 @@ class WordpressPage(Top25Page):
def RunStressMemory(self, action_runner):
action_runner.RunAction(ScrollAction())
action_runner.RunAction(ClickElementAction(
{
'wait_until': {
'condition': 'navigate'
},
'selector':
{'selector':
# pylint: disable=C0301
'a[href="http://en.blog.wordpress.com/2012/08/30/new-themes-able-and-sight/"]'
}))
action_runner.WaitForNavigate()
action_runner.RunAction(ScrollAction())
action_runner.RunAction(ClickElementAction(
{
'text' : 'Features',
'wait_until': {
'condition': 'navigate'
}
}))
action_runner.RunAction(ClickElementAction({'text' : 'Features'}))
action_runner.WaitForNavigate()
action_runner.RunAction(ScrollAction())
action_runner.RunAction(ClickElementAction(
{
'text' : 'News',
'wait_until': {
'condition': 'navigate'
}
}))
action_runner.RunAction(ClickElementAction({'text' : 'News'}))
action_runner.WaitForNavigate()
action_runner.RunAction(ScrollAction())
......@@ -616,48 +583,33 @@ class FacebookPage(Top25Page):
}))
def RunStressMemory(self, action_runner):
action_runner.RunAction(ClickElementAction(
{
'text' : 'About',
'wait_until': {
'condition': 'navigate'
}
}))
action_runner.RunAction(ClickElementAction({'text' : 'About'}))
action_runner.WaitForNavigate()
action_runner.RunAction(ClickElementAction(
{
'text' : 'The Audacity of Hope',
'wait_until': {
'condition': 'navigate'
}
}))
action_runner.WaitForNavigate()
action_runner.RunAction(ClickElementAction(
{
'text' : 'Back to Barack Obama\'s Timeline',
'wait_until': {
'condition': 'navigate'
}
}))
action_runner.WaitForNavigate()
action_runner.RunAction(ClickElementAction(
{
'text' : 'About',
'wait_until': {
'condition': 'navigate'
}
}))
action_runner.WaitForNavigate()
action_runner.RunAction(ClickElementAction(
{
'text' : 'Elected to U.S. Senate',
'wait_until': {
'condition': 'navigate'
}
}))
action_runner.WaitForNavigate()
action_runner.RunAction(ClickElementAction(
{
'text' : 'Home',
'wait_until': {
'condition': 'navigate'
}
}))
action_runner.WaitForNavigate()
def RunSmoothness(self, action_runner):
action_runner.RunAction(ScrollAction(
......
......@@ -158,8 +158,8 @@ class InspectorBackend(inspector_websocket.InspectorWebsocket):
# Page public methods.
def PerformActionAndWaitForNavigate(self, action_function, timeout):
self._page.PerformActionAndWaitForNavigate(action_function, timeout)
def WaitForNavigate(self, timeout):
self._page.WaitForNavigate(timeout)
def Navigate(self, url, script_to_evaluate_on_commit, timeout):
self._page.Navigate(url, script_to_evaluate_on_commit, timeout)
......
......@@ -30,7 +30,7 @@ class InspectorPage(object):
(not url == 'chrome://newtab/' and not url == 'about:blank'
and not 'parentId' in msg['params']['frame'])):
# Marks the navigation as complete and unblocks the
# PerformActionAndWaitForNavigate call.
# WaitForNavigate call.
self._navigation_pending = False
def _OnClose(self):
......@@ -70,16 +70,14 @@ class InspectorPage(object):
res = self._inspector_backend.SyncRequest(request, timeout)
assert len(res['result'].keys()) == 0
def PerformActionAndWaitForNavigate(self, action_function, timeout=60):
"""Executes action_function, and waits for the navigation to complete.
def WaitForNavigate(self, timeout=60):
"""Waits for the navigation to complete.
action_function is expect to result in a navigation. This function returns
The current page is expect to be in a navigation. This function returns
when the navigation is complete or when the timeout has been exceeded.
"""
start_time = time.time()
remaining_time = timeout
action_function()
self._navigation_pending = True
try:
while self._navigation_pending and remaining_time > 0:
......@@ -99,7 +97,6 @@ class InspectorPage(object):
the page exists, but before any script on the page itself has executed.
"""
def DoNavigate():
self._SetScriptToEvaluateOnCommit(script_to_evaluate_on_commit)
request = {
'method': 'Page.navigate',
......@@ -109,7 +106,7 @@ class InspectorPage(object):
}
self._inspector_backend.SyncRequest(request, timeout)
self._navigation_url = url
self.PerformActionAndWaitForNavigate(DoNavigate, timeout)
self.WaitForNavigate(timeout)
def GetCookieByName(self, name, timeout=60):
"""Returns the value of the cookie by the given |name|."""
......
......@@ -21,14 +21,9 @@ class InspectorPageTest(tab_test_case.TabTestCase):
self._tab.EvaluateJavaScript('document.location.pathname;'),
'/page_with_link.html')
custom_action_called = [False]
def CustomAction():
custom_action_called[0] = True
self._tab.ExecuteJavaScript('document.getElementById("clickme").click();')
self._tab.WaitForNavigate()
self._tab.PerformActionAndWaitForNavigate(CustomAction)
self.assertTrue(custom_action_called[0])
self.assertEquals(
self._tab.EvaluateJavaScript('document.location.pathname;'),
'/blank.html')
......
......@@ -66,9 +66,8 @@ class WebDriverTabBackend(object):
# Webdriver has no API for DOM status.
raise NotImplementedError()
def PerformActionAndWaitForNavigate(self, action_function, _):
# TODO(chrisgao): Double check of navigation.
action_function()
def WaitForNavigate(self):
raise NotImplementedError()
def Navigate(self, url, script_to_evaluate_on_commit=None, timeout=None):
if script_to_evaluate_on_commit:
......
......@@ -237,16 +237,14 @@ class Tab(web_contents.WebContents):
for timestamp, bmp in frame_generator:
yield timestamp - start_time, bmp.Crop(*content_box)
def PerformActionAndWaitForNavigate(
self, action_function, timeout=DEFAULT_TAB_TIMEOUT):
"""Executes action_function, and waits for the navigation to complete.
def WaitForNavigate(self, timeout=DEFAULT_TAB_TIMEOUT):
"""Waits for the navigation to complete.
action_function must be a Python function that results in a navigation.
The current page is expect to be in a navigation.
This function returns when the navigation is complete or when
the timeout has been exceeded.
"""
self._inspector_backend.PerformActionAndWaitForNavigate(
action_function, timeout)
self._inspector_backend.WaitForNavigate(timeout)
def Navigate(self, url, script_to_evaluate_on_commit=None,
timeout=DEFAULT_TAB_TIMEOUT):
......
......@@ -8,6 +8,7 @@ from telemetry.web_perf import timeline_interaction_record as tir_module
class ActionRunner(object):
def __init__(self, tab):
self._tab = tab
......@@ -55,12 +56,16 @@ class ActionRunner(object):
else:
target_side_url = page.url
attributes = {
'url': target_side_url ,
'url': target_side_url,
'script_to_evaluate_on_commit': page.script_to_evaluate_on_commit}
if timeout_seconds:
attributes['timeout_seconds'] = timeout_seconds
self.RunAction(NavigateAction(attributes))
def WaitForNavigate(self, timeout_seconds=60):
self._tab.WaitForNavigate(timeout_seconds)
self._tab.WaitForDocumentReadyStateToBeInteractiveOrBetter()
def ExecuteJavaScript(self, js_expression):
"""Executes a given JavaScript expression.
......@@ -73,6 +78,7 @@ class ActionRunner(object):
class Interaction(object):
def __init__(self, action_runner, label, flags):
assert action_runner
assert label
......
......@@ -40,3 +40,16 @@ class ActionRunnerTest(tab_test_case.TabTestCase):
self.Navigate('blank.html')
action_runner.ExecuteJavaScript('var testing = 42;')
self.assertEqual(42, self._tab.EvaluateJavaScript('testing'))
def testWaitForNavigate(self):
self.Navigate('page_with_link.html')
action_runner = action_runner_module.ActionRunner(self._tab)
action_runner.RunAction(ClickElementAction({'xpath': 'id("clickme")'}))
action_runner.WaitForNavigate()
self.assertTrue(self._tab.EvaluateJavaScript(
'document.readyState == "interactive" || '
'document.readyState == "complete"'))
self.assertEquals(
self._tab.EvaluateJavaScript('document.location.pathname;'),
'/blank.html')
......@@ -13,13 +13,7 @@ class WaitUntil(object):
self._previous_action = previous_action
def RunActionAndWait(self, tab):
if getattr(self, 'condition', None) == 'navigate':
self._previous_action.WillRunAction(tab)
action_to_perform = lambda: self._previous_action.RunAction(tab)
tab.PerformActionAndWaitForNavigate(action_to_perform, self.timeout)
tab.WaitForDocumentReadyStateToBeInteractiveOrBetter()
elif getattr(self, 'condition', None) == 'href_change':
if getattr(self, 'condition', None) == 'href_change':
self._previous_action.WillRunAction(tab)
old_url = tab.EvaluateJavaScript('document.location.href')
self._previous_action.RunAction(tab)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment