OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 import time | 4 import time |
5 import unittest | 5 import unittest |
6 | 6 |
7 from measurements import smooth_gesture_util as sg_util | 7 from measurements import smooth_gesture_util as sg_util |
8 from telemetry.core.platform import tracing_category_filter | 8 from telemetry.core.platform import tracing_category_filter |
9 from telemetry.core.platform import tracing_options | 9 from telemetry.core.platform import tracing_options |
10 from telemetry.page import page as page_module | 10 from telemetry.page import page as page_module |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 model, record_6) | 93 model, record_6) |
94 self.assertEquals(adjusted_record_6.start, 15) | 94 self.assertEquals(adjusted_record_6.start, 15) |
95 self.assertEquals(adjusted_record_6.end, 25) | 95 self.assertEquals(adjusted_record_6.end, 25) |
96 self.assertTrue(adjusted_record_6 is not record_6) | 96 self.assertTrue(adjusted_record_6 is not record_6) |
97 | 97 |
98 | 98 |
99 class ScrollingPage(page_module.Page): | 99 class ScrollingPage(page_module.Page): |
100 def __init__(self, url, page_set, base_dir): | 100 def __init__(self, url, page_set, base_dir): |
101 super(ScrollingPage, self).__init__(url, page_set, base_dir) | 101 super(ScrollingPage, self).__init__(url, page_set, base_dir) |
102 | 102 |
103 def RunSmoothness(self, action_runner): | 103 def RunPageInteractions(self, action_runner): |
104 interaction = action_runner.BeginGestureInteraction( | 104 interaction = action_runner.BeginGestureInteraction( |
105 'ScrollAction', is_smooth=True) | 105 'ScrollAction', is_smooth=True) |
106 # Add 0.5s gap between when Gesture records are issued to when we actually | 106 # Add 0.5s gap between when Gesture records are issued to when we actually |
107 # scroll the page. | 107 # scroll the page. |
108 time.sleep(0.5) | 108 time.sleep(0.5) |
109 action_runner.ScrollPage() | 109 action_runner.ScrollPage() |
110 time.sleep(0.5) | 110 time.sleep(0.5) |
111 interaction.End() | 111 interaction.End() |
112 | 112 |
113 | 113 |
114 class SmoothGestureTest(page_test_test_case.PageTestTestCase): | 114 class SmoothGestureTest(page_test_test_case.PageTestTestCase): |
115 def testSmoothGestureAdjusted(self): | 115 def testSmoothGestureAdjusted(self): |
116 ps = self.CreateEmptyPageSet() | 116 ps = self.CreateEmptyPageSet() |
117 ps.AddUserStory(ScrollingPage( | 117 ps.AddUserStory(ScrollingPage( |
118 'file://scrollable_page.html', ps, base_dir=ps.base_dir)) | 118 'file://scrollable_page.html', ps, base_dir=ps.base_dir)) |
119 models = [] | 119 models = [] |
120 tab_ids = [] | 120 tab_ids = [] |
121 class ScrollingGestureTestMeasurement(page_test.PageTest): | 121 class ScrollingGestureTestMeasurement(page_test.PageTest): |
122 def __init__(self): | 122 def __init__(self): |
123 # pylint: disable=bad-super-call | 123 # pylint: disable=bad-super-call |
124 super(ScrollingGestureTestMeasurement, self).__init__( | 124 super(ScrollingGestureTestMeasurement, self).__init__( |
125 'RunSmoothness', False) | 125 'RunPageInteractions', False) |
126 | 126 |
127 def WillRunActions(self, _page, tab): | 127 def WillRunActions(self, _page, tab): |
128 options = tracing_options.TracingOptions() | 128 options = tracing_options.TracingOptions() |
129 options.enable_chrome_trace = True | 129 options.enable_chrome_trace = True |
130 tab.browser.platform.tracing_controller.Start( | 130 tab.browser.platform.tracing_controller.Start( |
131 options, tracing_category_filter.TracingCategoryFilter()) | 131 options, tracing_category_filter.TracingCategoryFilter()) |
132 | 132 |
133 def DidRunActions(self, _page, tab): | 133 def DidRunActions(self, _page, tab): |
134 models.append(model_module.TimelineModel( | 134 models.append(model_module.TimelineModel( |
135 tab.browser.platform.tracing_controller.Stop())) | 135 tab.browser.platform.tracing_controller.Stop())) |
(...skipping 14 matching lines...) Expand all Loading... |
150 adjusted_smooth_gesture = ( | 150 adjusted_smooth_gesture = ( |
151 sg_util.GetAdjustedInteractionIfContainGesture( | 151 sg_util.GetAdjustedInteractionIfContainGesture( |
152 timeline_model, smooth_record)) | 152 timeline_model, smooth_record)) |
153 # Test that the scroll gesture starts at at least 500ms after the start of | 153 # Test that the scroll gesture starts at at least 500ms after the start of |
154 # the interaction record and ends at at least 500ms before the end of | 154 # the interaction record and ends at at least 500ms before the end of |
155 # interaction record. | 155 # interaction record. |
156 self.assertLessEqual( | 156 self.assertLessEqual( |
157 500, adjusted_smooth_gesture.start - smooth_record.start) | 157 500, adjusted_smooth_gesture.start - smooth_record.start) |
158 self.assertLessEqual( | 158 self.assertLessEqual( |
159 500, smooth_record.end - adjusted_smooth_gesture.end) | 159 500, smooth_record.end - adjusted_smooth_gesture.end) |
OLD | NEW |