Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: tools/perf/measurements/smooth_gesture_util_unittest.py

Issue 488763004: Fix smooth_gesture_util to adjust the gesture record properly (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/perf/measurements/smooth_gesture_util.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 unittest 5 import unittest
5 6
7 from measurements import smooth_gesture_util as sg_util
8 from telemetry.core.platform import tracing_category_filter
9 from telemetry.core.platform import tracing_options
10 from telemetry.page import page as page_module
11 from telemetry.page import page_test
12 from telemetry.timeline import async_slice
6 from telemetry.timeline import model as model_module 13 from telemetry.timeline import model as model_module
14 from telemetry.unittest import page_test_test_case
7 from telemetry.web_perf import timeline_interaction_record as tir_module 15 from telemetry.web_perf import timeline_interaction_record as tir_module
8 from measurements import smooth_gesture_util as sg_util 16
9 17
10 class SmoothGestureUtilTest(unittest.TestCase): 18 class SmoothGestureUtilTest(unittest.TestCase):
11 def testGetAdjustedInteractionIfContainGesture(self): 19 def testGetAdjustedInteractionIfContainGesture(self):
12 model = model_module.TimelineModel() 20 model = model_module.TimelineModel()
13 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2) 21 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2)
14 renderer_main.name = 'CrRendererMain' 22 renderer_main.name = 'CrRendererMain'
15 23
16 # [ X ] [ Y ] 24 # [ X ] [ Y ]
ernstm 2014/08/20 22:13:35 Is the sub_async_slice_X missing here?
nednguyen 2014/08/21 16:35:03 Done.
17 # [ record_1] 25 # [ record_1]
18 # [ record_6] 26 # [ record_6]
19 # [ record_2 ] [ record_3 ] 27 # [ record_2 ] [ record_3 ]
20 # [ record_4 ] 28 # [ record_4 ]
21 # [ record_5 ] 29 # [ record_5 ]
22 renderer_main.BeginSlice('X', 'SyntheticGestureController::running', 10, 0) 30 #
23 renderer_main.EndSlice(30, 30) 31 # Note: X and Y are async slice with name
24 renderer_main.BeginSlice('Y', 'SyntheticGestureController::running', 60, 0) 32 # SyntheticGestureController::running
25 renderer_main.EndSlice(80, 80) 33
34 async_slice_X = async_slice.AsyncSlice(
35 'X', 'SyntheticGestureController::running', 10, duration=20,
36 start_thread=renderer_main, end_thread=renderer_main)
37
38 sub_async_slice_X = async_slice.AsyncSlice(
39 'X', 'SyntheticGestureController::running', 10, duration=20,
40 start_thread=renderer_main, end_thread=renderer_main)
41 sub_async_slice_X.parent_slice = async_slice_X
42 async_slice_X.AddSubSlice(sub_async_slice_X)
43
44 async_slice_Y = async_slice.AsyncSlice(
45 'X', 'SyntheticGestureController::running', 60, duration=20,
46 start_thread=renderer_main, end_thread=renderer_main)
47
48 renderer_main.AddAsyncSlice(async_slice_X)
49 renderer_main.AddAsyncSlice(async_slice_Y)
26 50
27 model.FinalizeImport(shift_world_to_zero=False) 51 model.FinalizeImport(shift_world_to_zero=False)
28 52
29 record_1 = tir_module.TimelineInteractionRecord('Gesture_included', 15, 25) 53 record_1 = tir_module.TimelineInteractionRecord('Gesture_included', 15, 25)
30 record_2 = tir_module.TimelineInteractionRecord( 54 record_2 = tir_module.TimelineInteractionRecord(
31 'Gesture_overlapped_left', 5, 25) 55 'Gesture_overlapped_left', 5, 25)
32 record_3 = tir_module.TimelineInteractionRecord( 56 record_3 = tir_module.TimelineInteractionRecord(
33 'Gesture_overlapped_right', 25, 35) 57 'Gesture_overlapped_right', 25, 35)
34 record_4 = tir_module.TimelineInteractionRecord( 58 record_4 = tir_module.TimelineInteractionRecord(
35 'Gesture_containing', 5, 35) 59 'Gesture_containing', 5, 35)
(...skipping 27 matching lines...) Expand all
63 self.assertEquals(adjusted_record_5.start, 35) 87 self.assertEquals(adjusted_record_5.start, 35)
64 self.assertEquals(adjusted_record_5.end, 45) 88 self.assertEquals(adjusted_record_5.end, 45)
65 self.assertTrue(adjusted_record_5 is not record_5) 89 self.assertTrue(adjusted_record_5 is not record_5)
66 90
67 adjusted_record_6 = sg_util.GetAdjustedInteractionIfContainGesture( 91 adjusted_record_6 = sg_util.GetAdjustedInteractionIfContainGesture(
68 model, record_6) 92 model, record_6)
69 self.assertEquals(adjusted_record_6.start, 15) 93 self.assertEquals(adjusted_record_6.start, 15)
70 self.assertEquals(adjusted_record_6.end, 25) 94 self.assertEquals(adjusted_record_6.end, 25)
71 self.assertTrue(adjusted_record_6 is not record_6) 95 self.assertTrue(adjusted_record_6 is not record_6)
72 96
97
98 class ScrollingPage(page_module.Page):
99 def __init__(self, url, page_set, base_dir):
100 super(ScrollingPage, self).__init__(url, page_set, base_dir)
101
102 def RunSmoothness(self, action_runner):
103 interaction = action_runner.BeginGestureInteraction(
104 'ScrollAction', is_smooth=True)
105 # Add 0.5s gap between when Gesture records are issued to when we actually
106 # scroll the page.
107 time.sleep(0.5)
108 action_runner.ScrollPage()
109 time.sleep(0.5)
110 interaction.End()
111
112
113 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
114 def testSmoothGestureAdjusted(self):
115 ps = self.CreateEmptyPageSet()
116 ps.AddPage(ScrollingPage(
117 'file://scrollable_page.html', ps, base_dir=ps.base_dir))
118 models = []
119 tab_ids = []
120 class ScrollingGestureTestMeasurement(page_test.PageTest):
121 def __init__(self):
122 super(ScrollingGestureTestMeasurement, self).__init__(
123 'RunSmoothness', False)
124
125 def WillRunActions(self, _page, tab):
126 options = tracing_options.TracingOptions()
127 options.enable_chrome_trace = True
128 tab.browser.platform.tracing_controller.Start(
129 options, tracing_category_filter.TracingCategoryFilter())
130
131 def DidRunActions(self, _page, tab):
132 models.append(model_module.TimelineModel(
133 tab.browser.platform.tracing_controller.Stop()))
134 tab_ids.append(tab.id)
135
136 self.RunMeasurement(ScrollingGestureTestMeasurement(), ps)
137 timeline_model = models[0]
138 renderer_thread = timeline_model.GetRendererThreadFromTabId(
139 tab_ids[0])
140 smooth_record = None
141 for e in renderer_thread.async_slices:
142 if tir_module.IsTimelineInteractionRecord(e.name):
143 smooth_record = tir_module.TimelineInteractionRecord.FromAsyncEvent(e)
144 self.assertIsNotNone(smooth_record)
145 adjusted_smooth_gesture = (
146 sg_util.GetAdjustedInteractionIfContainGesture(
147 timeline_model, smooth_record))
148 # Test that the scroll gesture starts at at least 500ms after the start of
149 # the interaction record and ends at at least 500ms before the end of
150 # interaction record.
151 self.assertLessEqual(
152 500, adjusted_smooth_gesture.start - smooth_record.start)
153 self.assertLessEqual(
154 500, smooth_record.end - adjusted_smooth_gesture.end)
OLDNEW
« no previous file with comments | « tools/perf/measurements/smooth_gesture_util.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698