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