Fix smooth_gesture_util to adjust the gesture record properly.

Add unittest that fails crbug/399671 but pass with the fix.

BUG=399671

Review URL: https://codereview.chromium.org/488763004

Cr-Commit-Position: refs/heads/master@{#291249}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291249 0039d316-1c4b-4281-b951-d872f2087c98
parent a59fa454
...@@ -22,15 +22,16 @@ def GetAdjustedInteractionIfContainGesture(timeline, interaction_record): ...@@ -22,15 +22,16 @@ def GetAdjustedInteractionIfContainGesture(timeline, interaction_record):
return copy.copy(interaction_record) return copy.copy(interaction_record)
gesture_events = [ gesture_events = [
ev for ev ev for ev
in timeline.GetAllToplevelSlicesOfName( in timeline.IterAllAsyncSlicesOfName('SyntheticGestureController::running')
'SyntheticGestureController::running') if ev.parent_slice is None and
if ev.start <= interaction_record.end and ev.start <= interaction_record.end and
ev.end >= interaction_record.start] ev.end >= interaction_record.start]
if len(gesture_events) == 0: if len(gesture_events) == 0:
return copy.copy(interaction_record) return copy.copy(interaction_record)
if len(gesture_events) > 1: if len(gesture_events) > 1:
raise Exception('More than one possible synthetic gesture marker found in ' raise Exception('More than one possible synthetic gesture marker found in '
'interaction_record %s.' % interaction_record.label) 'interaction_record %s.' % interaction_record.label)
return tir_module.TimelineInteractionRecord(interaction_record.label, return tir_module.TimelineInteractionRecord(
gesture_events[0].start, interaction_record.label, gesture_events[0].start,
gesture_events[0].end) gesture_events[0].end, gesture_events[0],
interaction_record._flags) # pylint: disable=W0212
# Copyright 2014 The Chromium Authors. All rights reserved. # Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import time
import unittest 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.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 telemetry.web_perf import timeline_interaction_record as tir_module
from measurements import smooth_gesture_util as sg_util
class SmoothGestureUtilTest(unittest.TestCase): class SmoothGestureUtilTest(unittest.TestCase):
def testGetAdjustedInteractionIfContainGesture(self): def testGetAdjustedInteractionIfContainGesture(self):
...@@ -14,15 +22,32 @@ class SmoothGestureUtilTest(unittest.TestCase): ...@@ -14,15 +22,32 @@ class SmoothGestureUtilTest(unittest.TestCase):
renderer_main.name = 'CrRendererMain' renderer_main.name = 'CrRendererMain'
# [ X ] [ Y ] # [ X ] [ Y ]
# [ sub_async_slice_X ]
# [ record_1] # [ record_1]
# [ record_6] # [ record_6]
# [ record_2 ] [ record_3 ] # [ record_2 ] [ record_3 ]
# [ record_4 ] # [ record_4 ]
# [ record_5 ] # [ record_5 ]
renderer_main.BeginSlice('X', 'SyntheticGestureController::running', 10, 0) #
renderer_main.EndSlice(30, 30) # Note: X and Y are async slice with name
renderer_main.BeginSlice('Y', 'SyntheticGestureController::running', 60, 0) # SyntheticGestureController::running
renderer_main.EndSlice(80, 80)
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) model.FinalizeImport(shift_world_to_zero=False)
...@@ -70,3 +95,61 @@ class SmoothGestureUtilTest(unittest.TestCase): ...@@ -70,3 +95,61 @@ class SmoothGestureUtilTest(unittest.TestCase):
self.assertEquals(adjusted_record_6.end, 25) self.assertEquals(adjusted_record_6.end, 25)
self.assertTrue(adjusted_record_6 is not record_6) 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):
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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment