diff options
author | dominikg@chromium.org <dominikg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-08 22:03:53 +0000 |
---|---|---|
committer | dominikg@chromium.org <dominikg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-08 22:03:53 +0000 |
commit | dc8b1cd41a13c81f6bac9e5cc69e73b91afa02df (patch) | |
tree | 7f6949c78431d8dab27eca1ebe4efa28a08fcc96 /tools | |
parent | c489d0e173e59219e9835f5a82b7defe31c23a7f (diff) | |
download | chromium_src-dc8b1cd41a13c81f6bac9e5cc69e73b91afa02df.zip chromium_src-dc8b1cd41a13c81f6bac9e5cc69e73b91afa02df.tar.gz chromium_src-dc8b1cd41a13c81f6bac9e5cc69e73b91afa02df.tar.bz2 |
Telemetry: Add 'wait_after' parameter to gesture actions.
Gesture actions can kick off animations on some pages. We want to be able to
measure the interval from the beginning of the gesture to the end of the
animation (without gaps). The 'wait_after' parameter allows the user to specify
a condition on which to wait after performing a gesture. The resulting active
range of the page action covers both the gesture and the condition.
BUG=323275
Review URL: https://codereview.chromium.org/117283004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243663 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
3 files changed, 54 insertions, 2 deletions
diff --git a/tools/telemetry/telemetry/core/timeline/bounds.py b/tools/telemetry/telemetry/core/timeline/bounds.py index 0175c8f..de5ce716 100644 --- a/tools/telemetry/telemetry/core/timeline/bounds.py +++ b/tools/telemetry/telemetry/core/timeline/bounds.py @@ -48,7 +48,7 @@ class Bounds(object): self.max_ = None def AddBounds(self, bounds): - if bounds.isEmpty: + if bounds.is_empty: return self.AddValue(bounds.min_) self.AddValue(bounds.max_) diff --git a/tools/telemetry/telemetry/page/actions/gesture_action.py b/tools/telemetry/telemetry/page/actions/gesture_action.py index df129d1..f8f5c9f 100644 --- a/tools/telemetry/telemetry/page/actions/gesture_action.py +++ b/tools/telemetry/telemetry/page/actions/gesture_action.py @@ -4,11 +4,17 @@ import telemetry.core.timeline.bounds as timeline_bounds from telemetry.page.actions import page_action +from telemetry.page.actions import wait class GestureAction(page_action.PageAction): def __init__(self, attributes=None): super(GestureAction, self).__init__(attributes) + if hasattr(self, 'wait_after'): + self.wait_action = wait.WaitAction(self.wait_after) + else: + self.wait_action = None + def RunAction(self, page, tab, previous_action): tab.ExecuteJavaScript( 'console.time("' + self._GetUniqueTimelineMarkerName() + '")') @@ -18,6 +24,9 @@ class GestureAction(page_action.PageAction): tab.ExecuteJavaScript( 'console.timeEnd("' + self._GetUniqueTimelineMarkerName() + '")') + if self.wait_action: + self.wait_action.RunAction(page, tab, previous_action) + def RunGesture(self, page, tab, previous_action): raise NotImplementedError() @@ -46,4 +55,10 @@ class GestureAction(page_action.PageAction): raise page_action.PageActionInvalidTimelineMarker( 'More than one possible synthetic gesture marker found in timeline.') - return timeline_bounds.Bounds.CreateFromEvent(gesture_events[0]) + active_range = timeline_bounds.Bounds.CreateFromEvent(gesture_events[0]) + + if self.wait_action: + active_range.AddBounds( + self.wait_action.GetActiveRangeOnTimeline(timeline)) + + return active_range diff --git a/tools/telemetry/telemetry/page/actions/gesture_action_unittest.py b/tools/telemetry/telemetry/page/actions/gesture_action_unittest.py new file mode 100644 index 0000000..011111f --- /dev/null +++ b/tools/telemetry/telemetry/page/actions/gesture_action_unittest.py @@ -0,0 +1,37 @@ +# 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. + +import time + +from telemetry.page.actions import gesture_action +from telemetry.unittest import tab_test_case + +class MockGestureAction(gesture_action.GestureAction): + """Mock gesture action that simply sleeps for a specified amount of time.""" + def __init__(self, attributes=None): + super(MockGestureAction, self).__init__(attributes) + self._SetTimelineMarkerBaseName('MockGestureAction::RunAction') + + def RunGesture(self, page, tab, previous_action): + duration = getattr(self, 'duration', 2) + + time.sleep(duration) + + +class GestureActionTest(tab_test_case.TabTestCase): + def testGestureAction(self): + """Test that GestureAction.RunAction() calls RunGesture().""" + action = MockGestureAction({ 'duration': 1 }) + + start_time = time.time() + action.RunAction(None, self._tab, None) + self.assertGreaterEqual(time.time() - start_time, 1.0) + + def testWaitAfter(self): + action = MockGestureAction({ 'duration': 1, + 'wait_after': { 'seconds': 1 } }) + + start_time = time.time() + action.RunAction(None, self._tab, None) + self.assertGreaterEqual(time.time() - start_time, 2.0) |