diff options
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) |