Chromium Code Reviews| Index: tools/perf/measurements/smooth_gesture_util_unittest.py |
| diff --git a/tools/perf/measurements/smooth_gesture_util_unittest.py b/tools/perf/measurements/smooth_gesture_util_unittest.py |
| index c3cbbee2ad45f28bdf5318cc691e3532f82b2f70..93208e486a0ffe3ccd57c9d3a3334b8157d1104e 100644 |
| --- a/tools/perf/measurements/smooth_gesture_util_unittest.py |
| +++ b/tools/perf/measurements/smooth_gesture_util_unittest.py |
| @@ -1,11 +1,19 @@ |
| # 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 |
| import unittest |
| +from measurements import smooth_gesture_util as sg_util |
| +from telemetry.core.platform import tracing_category_filter |
| +from telemetry.core.platform import tracing_options |
| +from telemetry.page import page as page_module |
| +from telemetry.page import page_test |
| +from telemetry.timeline import async_slice |
| from telemetry.timeline import model as model_module |
| +from telemetry.unittest import page_test_test_case |
| from telemetry.web_perf import timeline_interaction_record as tir_module |
| -from measurements import smooth_gesture_util as sg_util |
| + |
| class SmoothGestureUtilTest(unittest.TestCase): |
| def testGetAdjustedInteractionIfContainGesture(self): |
| @@ -19,10 +27,26 @@ class SmoothGestureUtilTest(unittest.TestCase): |
| # [ record_2 ] [ record_3 ] |
| # [ record_4 ] |
| # [ record_5 ] |
| - renderer_main.BeginSlice('X', 'SyntheticGestureController::running', 10, 0) |
| - renderer_main.EndSlice(30, 30) |
| - renderer_main.BeginSlice('Y', 'SyntheticGestureController::running', 60, 0) |
| - renderer_main.EndSlice(80, 80) |
| + # |
| + # Note: X and Y are async slice with name |
| + # SyntheticGestureController::running |
| + |
| + async_slice_X = async_slice.AsyncSlice( |
| + 'X', 'SyntheticGestureController::running', 10, duration=20, |
| + start_thread=renderer_main, end_thread=renderer_main) |
| + |
| + sub_async_slice_X = async_slice.AsyncSlice( |
| + 'X', 'SyntheticGestureController::running', 10, duration=20, |
| + start_thread=renderer_main, end_thread=renderer_main) |
| + sub_async_slice_X.parent_slice = async_slice_X |
| + async_slice_X.AddSubSlice(sub_async_slice_X) |
| + |
| + async_slice_Y = async_slice.AsyncSlice( |
| + 'X', 'SyntheticGestureController::running', 60, duration=20, |
| + start_thread=renderer_main, end_thread=renderer_main) |
| + |
| + renderer_main.AddAsyncSlice(async_slice_X) |
| + renderer_main.AddAsyncSlice(async_slice_Y) |
| model.FinalizeImport(shift_world_to_zero=False) |
| @@ -70,3 +94,61 @@ class SmoothGestureUtilTest(unittest.TestCase): |
| self.assertEquals(adjusted_record_6.end, 25) |
| self.assertTrue(adjusted_record_6 is not record_6) |
| + |
| +class ScrollingPage(page_module.Page): |
| + def __init__(self, url, page_set, base_dir): |
| + super(ScrollingPage, self).__init__(url, page_set, base_dir) |
| + |
| + def RunSmoothness(self, action_runner): |
| + interaction = action_runner.BeginGestureInteraction( |
| + 'ScrollAction', is_smooth=True) |
| + # Add 0.5s gap between when Gesture records are issued to when we actually |
| + # scroll the page. |
| + time.sleep(0.5) |
| + action_runner.ScrollPage() |
| + time.sleep(0.5) |
| + interaction.End() |
| + |
| + |
| +class SmoothGestureTest(page_test_test_case.PageTestTestCase): |
|
ernstm
2014/08/20 22:13:35
Should this be part of the smoke tests in tools/pe
nednguyen
2014/08/21 16:35:03
timeline_controller also use this SmoothGesture ut
|
| + def testSmoothGestureAdjusted(self): |
| + ps = self.CreateEmptyPageSet() |
| + ps.AddPage(ScrollingPage( |
| + 'file://scrollable_page.html', ps, base_dir=ps.base_dir)) |
| + models = [] |
| + tab_ids = [] |
| + class ScrollingGestureTestMeasurement(page_test.PageTest): |
| + def __init__(self): |
| + super(ScrollingGestureTestMeasurement, self).__init__( |
| + 'RunSmoothness', False) |
| + |
| + def WillRunActions(self, _page, tab): |
| + options = tracing_options.TracingOptions() |
| + options.enable_chrome_trace = True |
| + tab.browser.platform.tracing_controller.Start( |
| + options, tracing_category_filter.TracingCategoryFilter()) |
| + |
| + def DidRunActions(self, _page, tab): |
| + models.append(model_module.TimelineModel( |
| + tab.browser.platform.tracing_controller.Stop())) |
| + tab_ids.append(tab.id) |
| + |
| + self.RunMeasurement(ScrollingGestureTestMeasurement(), ps) |
| + timeline_model = models[0] |
| + renderer_thread = timeline_model.GetRendererThreadFromTabId( |
| + tab_ids[0]) |
| + smooth_record = None |
| + for e in renderer_thread.async_slices: |
| + if tir_module.IsTimelineInteractionRecord(e.name): |
| + smooth_record = tir_module.TimelineInteractionRecord.FromAsyncEvent(e) |
| + self.assertIsNotNone(smooth_record) |
| + adjusted_smooth_gesture = ( |
| + sg_util.GetAdjustedInteractionIfContainGesture( |
| + timeline_model, smooth_record)) |
| + # Test that the scroll gesture starts at at least 500ms after the start of |
| + # the interaction record and ends at at least 500ms before the end of |
| + # interaction record. |
| + self.assertLessEqual( |
| + 500, adjusted_smooth_gesture.start - smooth_record.start) |
| + self.assertLessEqual( |
| + 500, smooth_record.end - adjusted_smooth_gesture.end) |