diff options
author | chrishenry@google.com <chrishenry@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-06 05:29:13 +0000 |
---|---|---|
committer | chrishenry@google.com <chrishenry@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-06 05:29:13 +0000 |
commit | fb1464a058dd2ca636ac111110380122d1e0e2c9 (patch) | |
tree | 53dd4e128356cde2c8046f3fe84aba113e32d166 /tools | |
parent | f3d5009d2029c220ea0ed0e358cffd35c871d04e (diff) | |
download | chromium_src-fb1464a058dd2ca636ac111110380122d1e0e2c9.zip chromium_src-fb1464a058dd2ca636ac111110380122d1e0e2c9.tar.gz chromium_src-fb1464a058dd2ca636ac111110380122d1e0e2c9.tar.bz2 |
ActionRunner API cleanup:
1) BeginInteraction+EndInteraction becomes
interaction = action_runner.BeginInteraction(...)
interaction.End()
2) Add action_runner.ExecuteJavaScript.
3) Replaced all existing use cases.
Other cleanups:
1) s/JavascriptAction/JavaScriptAction/
2) s/GetJavascriptMarker/GetJavaScriptMarker/
BUG=361809
Review URL: https://codereview.chromium.org/313383002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275341 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
17 files changed, 133 insertions, 96 deletions
diff --git a/tools/perf/measurements/smoothness_controller.py b/tools/perf/measurements/smoothness_controller.py index fd38609..0739a8d 100644 --- a/tools/perf/measurements/smoothness_controller.py +++ b/tools/perf/measurements/smoothness_controller.py @@ -23,6 +23,7 @@ class SmoothnessController(object): def __init__(self): self._timeline_model = None self._tracing_timeline_data = None + self._interaction = None def Start(self, page, tab): custom_categories = ['webkit.console', 'benchmark'] @@ -32,12 +33,12 @@ class SmoothnessController(object): tab.browser.platform.StartRawDisplayFrameRateMeasurement() # Start the smooth marker for all smooth actions. runner = action_runner.ActionRunner(tab) - runner.BeginInteraction(RUN_SMOOTH_ACTIONS, [tir_module.IS_SMOOTH]) + self._interaction = runner.BeginInteraction( + RUN_SMOOTH_ACTIONS, is_smooth=True) def Stop(self, tab): # End the smooth marker for all smooth actions. - runner = action_runner.ActionRunner(tab) - runner.EndInteraction(RUN_SMOOTH_ACTIONS, [tir_module.IS_SMOOTH]) + self._interaction.End() # Stop tracing for smoothness metric. if tab.browser.platform.IsRawDisplayFrameRateSupported(): tab.browser.platform.StopRawDisplayFrameRateMeasurement() diff --git a/tools/perf/measurements/timeline_controller.py b/tools/perf/measurements/timeline_controller.py index aa1c6bb..b34ec4f 100644 --- a/tools/perf/measurements/timeline_controller.py +++ b/tools/perf/measurements/timeline_controller.py @@ -19,6 +19,7 @@ class TimelineController(object): self._model = None self._renderer_process = None self._smooth_records = [] + self._interaction = None def Start(self, page, tab): """Starts gathering timeline data. @@ -37,12 +38,12 @@ class TimelineController(object): tab.browser.StartTracing(','.join(categories)) # Start the smooth marker for all actions. runner = action_runner.ActionRunner(tab) - runner.BeginInteraction(RUN_SMOOTH_ACTIONS, [tir_module.IS_SMOOTH]) + self._interaction = runner.BeginInteraction( + RUN_SMOOTH_ACTIONS, is_smooth=True) def Stop(self, tab): # End the smooth marker for all actions. - runner = action_runner.ActionRunner(tab) - runner.EndInteraction(RUN_SMOOTH_ACTIONS, [tir_module.IS_SMOOTH]) + self._interaction.End() # Stop tracing. timeline_data = tab.browser.StopTracing() self._model = TimelineModel(timeline_data) diff --git a/tools/perf/page_sets/calendar_forward_backward.py b/tools/perf/page_sets/calendar_forward_backward.py index 0e369a3..f4ca483 100644 --- a/tools/perf/page_sets/calendar_forward_backward.py +++ b/tools/perf/page_sets/calendar_forward_backward.py @@ -32,16 +32,13 @@ class CalendarForwardBackwardPage(page_module.Page): 'condition': 'element', 'selector': 'div[class~="navForward"]' })) - action_runner.RunAction(JavascriptAction( - { - 'expression': ''' - (function() { - var elem = document.createElement('meta'); - elem.name='viewport'; - elem.content='initial-scale=1'; - document.body.appendChild(elem); - })();''' - })) + action_runner.ExecuteJavaScript(''' + (function() { + var elem = document.createElement('meta'); + elem.name='viewport'; + elem.content='initial-scale=1'; + document.body.appendChild(elem); + })();''') def RunEndure(self, action_runner): action_runner.RunAction(ClickElementAction( diff --git a/tools/perf/page_sets/gmail_compose_discard.py b/tools/perf/page_sets/gmail_compose_discard.py index 4bab258..264878b 100644 --- a/tools/perf/page_sets/gmail_compose_discard.py +++ b/tools/perf/page_sets/gmail_compose_discard.py @@ -29,18 +29,16 @@ class GmailComposeDiscardPage(page_module.Page): })) def ComposeClick(self, action_runner): - action_runner.RunAction(JavascriptAction({ - 'expression': ''' + action_runner.ExecuteJavaScript(''' var button=document.evaluate('//div[text()="COMPOSE"]', - document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null) + document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null) .singleNodeValue; var mousedownevent=new MouseEvent('mousedown',true,true,window,0,0,0,0,0, false,false,false,false,0,null); var mouseupevent=new MouseEvent('mouseup',true,true,window,0,0,0,0,0, false,false,false,false,0,null); button.dispatchEvent(mousedownevent); - button.dispatchEvent(mouseupevent);''' - })) + button.dispatchEvent(mouseupevent);''') def RunEndure(self, action_runner): action_runner.RunAction(WaitAction( diff --git a/tools/perf/page_sets/image_decoding_measurement.py b/tools/perf/page_sets/image_decoding_measurement.py index 7f7c19f..7b8fe616 100644 --- a/tools/perf/page_sets/image_decoding_measurement.py +++ b/tools/perf/page_sets/image_decoding_measurement.py @@ -16,10 +16,7 @@ class ImageDecodingMeasurementPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(JavascriptAction( - { - 'expression': 'runBenchmark();' - })) + action_runner.ExecuteJavaScript('runBenchmark();') action_runner.RunAction(WaitAction( { 'javascript': 'isDone' diff --git a/tools/perf/page_sets/key_silk_cases.py b/tools/perf/page_sets/key_silk_cases.py index 4a14829..a55bb4d 100644 --- a/tools/perf/page_sets/key_silk_cases.py +++ b/tools/perf/page_sets/key_silk_cases.py @@ -5,7 +5,6 @@ from telemetry.page.actions.all_page_actions import * from telemetry.page import page as page_module from telemetry.page import page_set as page_set_module -from telemetry.web_perf import timeline_interaction_record as tir_module class KeySilkCasesPage(page_module.Page): @@ -299,11 +298,11 @@ class Page16(KeySilkCasesPage): }''', 'speed': 5000 })) - action_runner.BeginInteraction('Wait', [tir_module.IS_SMOOTH]) + interaction = action_runner.BeginInteraction('Wait', is_smooth=True) action_runner.RunAction(WaitAction({ 'javascript': 'document.getElementsByClassName("message").length < 18' })) - action_runner.EndInteraction('Wait', [tir_module.IS_SMOOTH]) + interaction.End() def RunSmoothness(self, action_runner): self.SwipeToDismiss(action_runner) @@ -391,11 +390,11 @@ class Page19(KeySilkCasesPage): { 'selector': '#menu-button' })) - action_runner.BeginInteraction('Wait', [tir_module.IS_SMOOTH]) + interaction = action_runner.BeginInteraction('Wait', is_smooth=True) action_runner.RunAction(WaitAction({ 'javascript': 'document.getElementById("nav-drawer").active' })) - action_runner.EndInteraction('Wait', [tir_module.IS_SMOOTH]) + interaction.End() def RunNavigateSteps(self, action_runner): @@ -535,9 +534,9 @@ class Page23(KeySilkCasesPage): 'scroll_distance_function': 'function() { return window.innerHeight / 2; }' })) - action_runner.BeginInteraction('Wait', [tir_module.IS_SMOOTH]) + interaction = action_runner.BeginInteraction('Wait', is_smooth=True) action_runner.RunAction(WaitAction({'seconds' : 1})) - action_runner.EndInteraction('Wait', [tir_module.IS_SMOOTH]) + interaction.End() class Page24(KeySilkCasesPage): @@ -600,9 +599,9 @@ class Page25(KeySilkCasesPage): callback(document.getElementById(':f')); }''' })) - action_runner.BeginInteraction('Wait', [tir_module.IS_SMOOTH]) + interaction = action_runner.BeginInteraction('Wait', is_smooth=True) action_runner.RunAction(WaitAction({'seconds' : 1})) - action_runner.EndInteraction('Wait', [tir_module.IS_SMOOTH]) + interaction.End() class Page26(KeySilkCasesPage): diff --git a/tools/perf/page_sets/polymer.py b/tools/perf/page_sets/polymer.py index dc04c15..84b57d3 100644 --- a/tools/perf/page_sets/polymer.py +++ b/tools/perf/page_sets/polymer.py @@ -92,10 +92,8 @@ class PolymerShadowPage(PolymerPage): self.archive_data_file = 'data/polymer.json' def RunSmoothness(self, action_runner): - action_runner.RunAction(JavascriptAction( - { - 'expression': "document.getElementById('fab').scrollIntoView()" - })) + action_runner.ExecuteJavaScript( + "document.getElementById('fab').scrollIntoView()") action_runner.RunAction(WaitAction( { 'seconds': 5 @@ -105,12 +103,8 @@ class PolymerShadowPage(PolymerPage): def AnimateShadow(self, action_runner, eid): for i in range(1, 6): - action_runner.RunAction(JavascriptAction( - { - 'expression': ''' - document.getElementById("{0}").z = {1} - '''.format(eid, i) - })) + action_runner.ExecuteJavaScript( + 'document.getElementById("{0}").z = {1}'.format(eid, i)) action_runner.RunAction(WaitAction( { 'seconds': 1 diff --git a/tools/perf/page_sets/top_10.py b/tools/perf/page_sets/top_10.py index 34ffd11..0668d79 100644 --- a/tools/perf/page_sets/top_10.py +++ b/tools/perf/page_sets/top_10.py @@ -49,12 +49,12 @@ class GoogleCalendar(SimpleScrollPage): def RunNavigateSteps(self, action_runner): super(GoogleCalendar, self).RunNavigateSteps(action_runner) - action_runner.RunAction(JavascriptAction( - { 'expression' : - '(function() { var elem = document.createElement("meta");' - 'elem.name="viewport";' - 'elem.content="initial-scale=1";' - 'document.body.appendChild(elem); })();'})) + action_runner.ExecuteJavaScript(''' + (function() { var elem = document.createElement("meta"); + elem.name="viewport"; + elem.content="initial-scale=1"; + document.body.appendChild(elem); + })();''') action_runner.RunAction(WaitAction({'seconds' : 2})) action_runner.RunAction(WaitAction({ 'condition' : 'element', 'selector' : 'div[class~="navForward"]'})) diff --git a/tools/perf/page_sets/top_25.py b/tools/perf/page_sets/top_25.py index 9fead4b..3b615c6 100644 --- a/tools/perf/page_sets/top_25.py +++ b/tools/perf/page_sets/top_25.py @@ -205,16 +205,13 @@ class GoogleCalendarPage(Top25Page): 'condition': 'element', 'selector': 'div[class~="navForward"]' })) - action_runner.RunAction(JavascriptAction( - { - 'expression': ''' - (function() { - var elem = document.createElement('meta'); - elem.name='viewport'; - elem.content='initial-scale=1'; - document.body.appendChild(elem); - })();''' - })) + action_runner.ExecuteJavaScript(''' + (function() { + var elem = document.createElement('meta'); + elem.name='viewport'; + elem.content='initial-scale=1'; + document.body.appendChild(elem); + })();''') action_runner.RunAction(WaitAction( { 'seconds': 1 diff --git a/tools/perf/page_sets/webrtc_cases.py b/tools/perf/page_sets/webrtc_cases.py index aac321c..54c8f48 100644 --- a/tools/perf/page_sets/webrtc_cases.py +++ b/tools/perf/page_sets/webrtc_cases.py @@ -28,10 +28,7 @@ class Page1(WebrtcCasesPage): { 'seconds': 10 })) - action_runner.RunAction(JavascriptAction( - { - 'expression': 'checkForErrors();' - })) + action_runner.ExecuteJavaScript('checkForErrors();') class Page2(WebrtcCasesPage): diff --git a/tools/telemetry/telemetry/page/actions/action_runner.py b/tools/telemetry/telemetry/page/actions/action_runner.py index c084703..cba75b2 100644 --- a/tools/telemetry/telemetry/page/actions/action_runner.py +++ b/tools/telemetry/telemetry/page/actions/action_runner.py @@ -1,6 +1,8 @@ # Copyright 2014 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.page.actions.javascript import JavaScriptAction from telemetry.page.actions.navigate import NavigateAction from telemetry.web_perf import timeline_interaction_record as tir_module @@ -9,33 +11,44 @@ class ActionRunner(object): def __init__(self, tab): self._tab = tab - #TODO(nednguyen): remove this when crbug.com/361809 is marked fixed + # TODO(nednguyen): remove this (or make private) when + # crbug.com/361809 is marked fixed def RunAction(self, action): if not action.WillWaitAfterRun(): action.WillRunAction(self._tab) action.RunActionAndMaybeWait(self._tab) - def BeginInteraction(self, logical_name, flags): - """ Issues the begin of interaction record. - flags contains any flags in web_perf.timeline_interaction_record. - """ - assert self._tab - self._tab.ExecuteJavaScript('console.time("%s");' % - tir_module.TimelineInteractionRecord.GetJavascriptMarker(logical_name, - flags)) - - def EndInteraction(self, logical_name, flags): - """ Issues the begin of interaction record. - flags contains any flags in web_perf.timeline_interaction_record. + def BeginInteraction(self, label, is_smooth=False, is_responsive=False): + """Marks the beginning of an interaction record. + + An interaction record is a labeled time period containing + interaction that developers care about. Each set of metrics + specified in flags will be calculated for this time period.. The + End() method in the returned object must be called once to mark + the end of the timeline. + + Args: + label: A label for this particular interaction. This can be any + user-defined string, but must not contain '/'. + is_smooth: Whether to check for smoothness metrics for this interaction. + is_responsive: Whether to check for responsiveness metrics for + this interaction. """ - assert self._tab - self._tab.ExecuteJavaScript('console.timeEnd("%s");' % - tir_module.TimelineInteractionRecord.GetJavascriptMarker(logical_name, - flags)) + flags = [] + if is_smooth: + flags.append(tir_module.IS_SMOOTH) + if is_responsive: + flags.append(tir_module.IS_RESPONSIVE) + + interaction = Interaction(self._tab, label, flags) + interaction.Begin() + return interaction def NavigateToPage(self, page, timeout_seconds=None): - """ Navigate to page. - page is an instance of page.Page + """ Navigate to the given page. + + Args: + page: page is an instance of page.Page """ if page.is_file: target_side_url = self._tab.browser.http_server.UrlOf(page.file_path_url) @@ -47,3 +60,39 @@ class ActionRunner(object): if timeout_seconds: attributes['timeout_seconds'] = timeout_seconds self.RunAction(NavigateAction(attributes)) + + def ExecuteJavaScript(self, js_expression): + """Executes a given JavaScript expression. + + Example: runner.ExecuteJavaScript('var foo = 1;'); + + Args: + js_expression: The expression to execute (provided as string). + """ + self.RunAction(JavaScriptAction({'expression': js_expression})) + + +class Interaction(object): + def __init__(self, action_runner, label, flags): + assert action_runner + assert label + assert isinstance(flags, list) + + self._action_runner = action_runner + self._label = label + self._flags = flags + self._started = False + + def Begin(self): + assert not self._started + self._started = True + self._action_runner.ExecuteJavaScript('console.time("%s");' % + tir_module.TimelineInteractionRecord.GetJavaScriptMarker( + self._label, self._flags)) + + def End(self): + assert self._started + self._started = False + self._action_runner.ExecuteJavaScript('console.timeEnd("%s");' % + tir_module.TimelineInteractionRecord.GetJavaScriptMarker( + self._label, self._flags)) diff --git a/tools/telemetry/telemetry/page/actions/action_runner_unittest.py b/tools/telemetry/telemetry/page/actions/action_runner_unittest.py index ab33a19..8276097 100644 --- a/tools/telemetry/telemetry/page/actions/action_runner_unittest.py +++ b/tools/telemetry/telemetry/page/actions/action_runner_unittest.py @@ -1,6 +1,7 @@ # Copyright 2014 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.core.backends.chrome import tracing_backend from telemetry.core.timeline import model from telemetry.page.actions import action_runner as action_runner_module @@ -16,8 +17,9 @@ class ActionRunnerTest(tab_test_case.TabTestCase): self.Navigate('interaction_enabled_page.html') action_runner.RunAction(WaitAction({'seconds': 1})) self._browser.StartTracing(tracing_backend.DEFAULT_TRACE_CATEGORIES) - action_runner.BeginInteraction('TestInteraction', [tir_module.IS_SMOOTH]) - action_runner.EndInteraction('TestInteraction', [tir_module.IS_SMOOTH]) + interaction = action_runner.BeginInteraction( + 'TestInteraction', is_smooth=True) + interaction.End() trace_data = self._browser.StopTracing() timeline_model = model.TimelineModel(trace_data) @@ -32,3 +34,9 @@ class ActionRunnerTest(tab_test_case.TabTestCase): ' Trace data:\n%s' % repr(trace_data.EventData())) self.assertEqual('TestInteraction', records[0].logical_name) self.assertTrue(records[0].is_smooth) + + def testExecuteJavaScript(self): + action_runner = action_runner_module.ActionRunner(self._tab) + self.Navigate('blank.html') + action_runner.ExecuteJavaScript('var testing = 42;') + self.assertEqual(42, self._tab.EvaluateJavaScript('testing')) diff --git a/tools/telemetry/telemetry/page/actions/all_page_actions.py b/tools/telemetry/telemetry/page/actions/all_page_actions.py index 25fd7cf..6e69827 100644 --- a/tools/telemetry/telemetry/page/actions/all_page_actions.py +++ b/tools/telemetry/telemetry/page/actions/all_page_actions.py @@ -11,7 +11,6 @@ from telemetry.page.actions import page_action # TODO(nednguyen): Remove all of these imports when we done porting all actions # to action_runner from telemetry.page.actions.interact import InteractAction -from telemetry.page.actions.javascript import JavascriptAction from telemetry.page.actions.javascript_click import ClickElementAction from telemetry.page.actions.js_collect_garbage import JsCollectGarbageAction from telemetry.page.actions.loop import LoopAction diff --git a/tools/telemetry/telemetry/page/actions/gesture_action.py b/tools/telemetry/telemetry/page/actions/gesture_action.py index 0bbd977..04503e5 100644 --- a/tools/telemetry/telemetry/page/actions/gesture_action.py +++ b/tools/telemetry/telemetry/page/actions/gesture_action.py @@ -6,7 +6,6 @@ from telemetry.page.actions import page_action from telemetry.page.actions import wait from telemetry import decorators from telemetry.page.actions import action_runner -from telemetry.web_perf import timeline_interaction_record as tir_module class GestureAction(page_action.PageAction): def __init__(self, attributes=None): @@ -29,15 +28,16 @@ class GestureAction(page_action.PageAction): else: interaction_name = 'Gesture_%s' % self.__class__.__name__ + interaction = None if self.automatically_record_interaction: - runner.BeginInteraction(interaction_name, [tir_module.IS_SMOOTH]) + interaction = runner.BeginInteraction(interaction_name, is_smooth=True) self.RunGesture(tab) if self.wait_action: self.wait_action.RunAction(tab) - if self.automatically_record_interaction: - runner.EndInteraction(interaction_name, [tir_module.IS_SMOOTH]) + if interaction is not None: + interaction.End() def RunGesture(self, tab): raise NotImplementedError() diff --git a/tools/telemetry/telemetry/page/actions/javascript.py b/tools/telemetry/telemetry/page/actions/javascript.py index 4bd8d6b..8a0bb09 100644 --- a/tools/telemetry/telemetry/page/actions/javascript.py +++ b/tools/telemetry/telemetry/page/actions/javascript.py @@ -5,9 +5,9 @@ from telemetry.page.actions import page_action -class JavascriptAction(page_action.PageAction): +class JavaScriptAction(page_action.PageAction): def __init__(self, attributes=None): - super(JavascriptAction, self).__init__(attributes) + super(JavaScriptAction, self).__init__(attributes) def RunAction(self, tab): assert hasattr(self, 'expression') diff --git a/tools/telemetry/telemetry/web_perf/timeline_interaction_record.py b/tools/telemetry/telemetry/web_perf/timeline_interaction_record.py index c126400..45e6a34 100644 --- a/tools/telemetry/telemetry/web_perf/timeline_interaction_record.py +++ b/tools/telemetry/telemetry/web_perf/timeline_interaction_record.py @@ -124,7 +124,7 @@ class TimelineInteractionRecord(object): return bounds @staticmethod - def GetJavascriptMarker(logical_name, flags): + def GetJavaScriptMarker(logical_name, flags): """ Get the marker string of an interaction record with logical_name and flags. """ diff --git a/tools/telemetry/telemetry/web_perf/timeline_interaction_record_unittest.py b/tools/telemetry/telemetry/web_perf/timeline_interaction_record_unittest.py index d8ffb97..8a30d19 100644 --- a/tools/telemetry/telemetry/web_perf/timeline_interaction_record_unittest.py +++ b/tools/telemetry/telemetry/web_perf/timeline_interaction_record_unittest.py @@ -59,11 +59,11 @@ class TimelineInteractionRecordTests(unittest.TestCase): self.assertEquals(True, r.is_smooth) self.assertEquals(True, r.is_responsive) - def testGetJavascriptMarker(self): - smooth_marker = tir_module.TimelineInteractionRecord.GetJavascriptMarker( + def testGetJavaScriptMarker(self): + smooth_marker = tir_module.TimelineInteractionRecord.GetJavaScriptMarker( 'LogicalName', [tir_module.IS_SMOOTH]) self.assertEquals('Interaction.LogicalName/is_smooth', smooth_marker) - slr_marker = tir_module.TimelineInteractionRecord.GetJavascriptMarker( + slr_marker = tir_module.TimelineInteractionRecord.GetJavaScriptMarker( 'LogicalName', [tir_module.IS_SMOOTH, tir_module.IS_RESPONSIVE]) self.assertEquals('Interaction.LogicalName/is_smooth,is_responsive', slr_marker) |