Commit 68c68147 authored by cblume's avatar cblume Committed by Commit bot

Adding tests for diagonal scrolling in telemetry.

Adding tests for diagonal scrolling to telemetry.

BUG=466867

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

Cr-Commit-Position: refs/heads/master@{#324346}
parent 76db6018
...@@ -216,6 +216,17 @@ class SmoothnessToughPinchZoomCases(benchmark.Benchmark): ...@@ -216,6 +216,17 @@ class SmoothnessToughPinchZoomCases(benchmark.Benchmark):
return 'smoothness.tough_pinch_zoom_cases' return 'smoothness.tough_pinch_zoom_cases'
@benchmark.Enabled('chromeos')
class SmoothnessToughScrollingWhileZoomedInCases(benchmark.Benchmark):
"""Measures rendering statistics for pinch-zooming then diagonal scrolling"""
test = smoothness.Smoothness
page_set = page_sets.ToughScrollingWhileZoomedInCasesPageSet
@classmethod
def Name(cls):
return 'smoothness.tough_scrolling_while_zoomed_in_cases'
@benchmark.Enabled('android') @benchmark.Enabled('android')
class SmoothnessPolymer(benchmark.Benchmark): class SmoothnessPolymer(benchmark.Benchmark):
"""Measures rendering statistics for Polymer cases. """Measures rendering statistics for Polymer cases.
......
# Copyright 2015 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 logging
from telemetry.page import shared_page_state
class DiagonalScrollingSupportedSharedState(shared_page_state.SharedPageState):
def CanRunOnBrowser(self, browser_info):
if not browser_info.HasDiagonalScrollingSupport():
logging.warning('Browser does not support synthetic diagonal scrolling,'
' skipping test')
return False
return True
# Copyright 2015 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.
from page_sets import diagonal_scrolling_supported_shared_state
from telemetry.page import shared_page_state
from telemetry.page import page as page_module
from telemetry.page import page_set as page_set_module
from telemetry.core.backends.chrome_inspector import devtools_client_backend
class ToughScrollingWhileZoomedInCasesPage(page_module.Page):
def __init__(self, url, page_set):
super(ToughScrollingWhileZoomedInCasesPage, self).__init__(
url=url,
page_set=page_set,
shared_page_state_class=(
diagonal_scrolling_supported_shared_state.
DiagonalScrollingSupportedSharedState))
def RunPageInteractions(self, action_runner):
# First, zoom into the page
action_runner.PinchPage(
scale_factor=20.0,
speed_in_pixels_per_second=10000)
# 20.0 was chosen because at the time it was close to the maximum.
# The more zoomed in, the more noticable the tile rasterization.
#
# 10,000 was chosen to complete this pre-step quickly.
# Then start measurements
interaction = action_runner.BeginGestureInteraction('ScrollAction')
# And begin the diagonal scroll
action_runner.ScrollPage(
direction='downright',
speed_in_pixels_per_second=10000)
# 10,000 was chosen because it is fast enough to completely stress the
# rasterization (on a Nexus 5) without saturating results.
interaction.End()
class ToughScrollingWhileZoomedInCasesPageSet(page_set_module.PageSet):
"""
Description: A collection of difficult scrolling tests
"""
def __init__(self):
super(ToughScrollingWhileZoomedInCasesPageSet, self).__init__(
user_agent_type='desktop',
archive_data_file='data/tough_pinch_zoom_cases.json',
bucket=page_set_module.PARTNER_BUCKET)
# The following urls were chosen because they tend to have >15%
# mean_pixels_approximated at this scrolling speed.
urls_list = [
'file://tough_scrolling_cases/background_fixed.html',
'file://tough_scrolling_cases/fixed_nonstacking.html',
'file://tough_scrolling_cases/iframe_scrolls.html',
'file://tough_scrolling_cases/wheel_div_prevdefault.html'
]
for url in urls_list:
self.AddUserStory(ToughScrollingWhileZoomedInCasesPage(url, self))
...@@ -45,3 +45,10 @@ class BrowserInfo(object): ...@@ -45,3 +45,10 @@ class BrowserInfo(object):
branch_num = ( branch_num = (
self._browser._browser_backend.devtools_client.GetChromeBranchNumber()) self._browser._browser_backend.devtools_client.GetChromeBranchNumber())
return branch_num >= 2339 return branch_num >= 2339
def HasDiagonalScrollingSupport(self):
# Diagonal scrolling was not supported in the ScrollAction until
# Chromium branch number 2332
branch_num = (
self._browser._browser_backend.devtools_client.GetChromeBranchNumber())
return branch_num >= 2332
...@@ -41,43 +41,71 @@ ...@@ -41,43 +41,71 @@
function ScrollAction(opt_callback, opt_distance_func) { function ScrollAction(opt_callback, opt_distance_func) {
var self = this; var self = this;
this.beginMeasuringHook = function() {} this.beginMeasuringHook = function() {};
this.endMeasuringHook = function() {} this.endMeasuringHook = function() {};
this.callback_ = opt_callback; this.callback_ = opt_callback;
this.distance_func_ = opt_distance_func; this.distance_func_ = opt_distance_func;
} }
ScrollAction.prototype.getScrollDistanceDown_ = function() {
var clientHeight;
// clientHeight is "special" for the body element.
if (this.element_ == document.body)
clientHeight = window.innerHeight;
else
clientHeight = this.element_.clientHeight;
return this.element_.scrollHeight -
this.element_.scrollTop -
clientHeight;
};
ScrollAction.prototype.getScrollDistanceUp_ = function() {
return this.element_.scrollTop;
};
ScrollAction.prototype.getScrollDistanceRight_ = function() {
var clientWidth;
// clientWidth is "special" for the body element.
if (this.element_ == document.body)
clientWidth = window.innerWidth;
else
clientWidth = this.element_.clientWidth;
return this.element_.scrollWidth - this.element_.scrollLeft - clientWidth;
};
ScrollAction.prototype.getScrollDistanceLeft_ = function() {
return this.element_.scrollLeft;
};
ScrollAction.prototype.getScrollDistance_ = function() { ScrollAction.prototype.getScrollDistance_ = function() {
if (this.distance_func_) if (this.distance_func_)
return this.distance_func_(); return this.distance_func_();
if (this.options_.direction_ == 'down') { if (this.options_.direction_ == 'down') {
var clientHeight; return this.getScrollDistanceDown_();
// clientHeight is "special" for the body element.
if (this.element_ == document.body)
clientHeight = window.innerHeight;
else
clientHeight = this.element_.clientHeight;
return this.element_.scrollHeight -
this.element_.scrollTop -
clientHeight;
} else if (this.options_.direction_ == 'up') { } else if (this.options_.direction_ == 'up') {
return this.element_.scrollTop; return this.getScrollDistanceUp_();
} else if (this.options_.direction_ == 'right') { } else if (this.options_.direction_ == 'right') {
var clientWidth; return this.getScrollDistanceRight_();
// clientWidth is "special" for the body element.
if (this.element_ == document.body)
clientWidth = window.innerWidth;
else
clientWidth = this.element_.clientWidth;
return this.element_.scrollWidth - this.element_.scrollLeft - clientWidth;
} else if (this.options_.direction_ == 'left') { } else if (this.options_.direction_ == 'left') {
return this.element_.scrollLeft; return this.getScrollDistanceLeft_();
} else if (this.options_.direction_ == 'upleft') {
return Math.min(this.getScrollDistanceUp_(),
this.getScrollDistanceLeft_());
} else if (this.options_.direction_ == 'upright') {
return Math.min(this.getScrollDistanceUp_(),
this.getScrollDistanceRight_());
} else if (this.options_.direction_ == 'downleft') {
return Math.min(this.getScrollDistanceDown_(),
this.getScrollDistanceLeft_());
} else if (this.options_.direction_ == 'downright') {
return Math.min(this.getScrollDistanceDown_(),
this.getScrollDistanceRight_());
} }
} };
ScrollAction.prototype.start = function(opt_options) { ScrollAction.prototype.start = function(opt_options) {
this.options_ = new ScrollGestureOptions(opt_options); this.options_ = new ScrollGestureOptions(opt_options);
......
...@@ -14,7 +14,9 @@ class ScrollAction(page_action.PageAction): ...@@ -14,7 +14,9 @@ class ScrollAction(page_action.PageAction):
distance=None, distance_expr=None, distance=None, distance_expr=None,
speed_in_pixels_per_second=800, use_touch=False): speed_in_pixels_per_second=800, use_touch=False):
super(ScrollAction, self).__init__() super(ScrollAction, self).__init__()
if direction not in ['down', 'up', 'left', 'right']: if direction not in ('down', 'up', 'left', 'right',
'downleft', 'downright',
'upleft', 'upright'):
raise page_action.PageActionNotSupported( raise page_action.PageActionNotSupported(
'Invalid scroll direction: %s' % self.direction) 'Invalid scroll direction: %s' % self.direction)
self._selector = selector self._selector = selector
...@@ -35,6 +37,14 @@ class ScrollAction(page_action.PageAction): ...@@ -35,6 +37,14 @@ class ScrollAction(page_action.PageAction):
distance_expr) distance_expr)
def WillRunAction(self, tab): def WillRunAction(self, tab):
if self._direction in ('downleft', 'downright', 'upleft', 'upright'):
# Diagonal scrolling support was added in Chrome branch number 2332.
branch_num = (
tab.browser._browser_backend.devtools_client.GetChromeBranchNumber())
if branch_num < 2332:
raise ValueError('Diagonal scrolling requires Chrome branch number'
' 2332 or later. Found branch number %d' %
branch_num)
for js_file in ['gesture_common.js', 'scroll.js']: for js_file in ['gesture_common.js', 'scroll.js']:
with open(os.path.join(os.path.dirname(__file__), js_file)) as f: with open(os.path.join(os.path.dirname(__file__), js_file)) as f:
js = f.read() js = f.read()
......
...@@ -7,7 +7,7 @@ import os ...@@ -7,7 +7,7 @@ import os
from telemetry import decorators from telemetry import decorators
from telemetry.internal.actions import scroll from telemetry.internal.actions import scroll
from telemetry.unittest_util import tab_test_case from telemetry.unittest_util import tab_test_case
from telemetry.core.backends.chrome_inspector import devtools_client_backend
class ScrollActionTest(tab_test_case.TabTestCase): class ScrollActionTest(tab_test_case.TabTestCase):
def testScrollAction(self): def testScrollAction(self):
...@@ -41,6 +41,42 @@ class ScrollActionTest(tab_test_case.TabTestCase): ...@@ -41,6 +41,42 @@ class ScrollActionTest(tab_test_case.TabTestCase):
self.assertTrue(scroll_position != 0, self.assertTrue(scroll_position != 0,
msg='scroll_position=%d;' % (scroll_position)) msg='scroll_position=%d;' % (scroll_position))
def testDiagonalScrollAction(self):
# Diagonal scrolling was not supported in the ScrollAction until Chrome
# branch number 2332
branch_num = self._tab.browser._browser_backend.devtools_client \
.GetChromeBranchNumber()
if branch_num < 2332:
return
self.Navigate('blank.html')
# Make page bigger than window so it's scrollable.
self._tab.ExecuteJavaScript("""document.body.style.height =
(2 * window.innerHeight + 1) + 'px';""")
self._tab.ExecuteJavaScript("""document.body.style.width =
(2 * window.innerWidth + 1) + 'px';""")
self.assertEquals(
self._tab.EvaluateJavaScript("""document.documentElement.scrollTop
|| document.body.scrollTop"""), 0)
self.assertEquals(
self._tab.EvaluateJavaScript("""document.documentElement.scrollLeft
|| document.body.scrollLeft"""), 0)
i = scroll.ScrollAction(direction='downright')
i.WillRunAction(self._tab)
i.RunAction(self._tab)
viewport_top = self._tab.EvaluateJavaScript(
'(document.documentElement.scrollTop || document.body.scrollTop)')
self.assertTrue(viewport_top != 0, msg='viewport_top=%d;' % viewport_top)
viewport_left = self._tab.EvaluateJavaScript(
'(document.documentElement.scrollLeft || document.body.scrollLeft)')
self.assertTrue(viewport_left != 0, msg='viewport_left=%d;' % viewport_left)
def testBoundingClientRect(self): def testBoundingClientRect(self):
self.Navigate('blank.html') self.Navigate('blank.html')
......
...@@ -396,7 +396,7 @@ class ActionRunner(object): ...@@ -396,7 +396,7 @@ class ActionRunner(object):
gesture, as a ratio of the visible bounding rectangle for gesture, as a ratio of the visible bounding rectangle for
document.body. document.body.
direction: The direction of scroll, either 'left', 'right', direction: The direction of scroll, either 'left', 'right',
'up', or 'down' 'up', 'down', 'upleft', 'upright', 'downleft', or 'downright'
distance: The distance to scroll (in pixel). distance: The distance to scroll (in pixel).
distance_expr: A JavaScript expression (as string) that can be distance_expr: A JavaScript expression (as string) that can be
evaluated to compute scroll distance. Example: evaluated to compute scroll distance. Example:
...@@ -436,7 +436,7 @@ class ActionRunner(object): ...@@ -436,7 +436,7 @@ class ActionRunner(object):
gesture, as a ratio of the visible bounding rectangle for gesture, as a ratio of the visible bounding rectangle for
the element. the element.
direction: The direction of scroll, either 'left', 'right', direction: The direction of scroll, either 'left', 'right',
'up', or 'down' 'up', 'down', 'upleft', 'upright', 'downleft', or 'downright'
distance: The distance to scroll (in pixel). distance: The distance to scroll (in pixel).
distance_expr: A JavaScript expression (as string) that can be distance_expr: A JavaScript expression (as string) that can be
evaluated to compute scroll distance. Example: evaluated to compute scroll distance. Example:
...@@ -470,7 +470,7 @@ class ActionRunner(object): ...@@ -470,7 +470,7 @@ class ActionRunner(object):
gesture, as a ratio of the visible bounding rectangle for gesture, as a ratio of the visible bounding rectangle for
document.body. document.body.
direction: The direction of scroll, either 'left', 'right', direction: The direction of scroll, either 'left', 'right',
'up', or 'down' 'up', 'down', 'upleft', 'upright', 'downleft', or 'downright'
distance: The distance to scroll (in pixel). distance: The distance to scroll (in pixel).
overscroll: The number of additional pixels to scroll back, in overscroll: The number of additional pixels to scroll back, in
addition to the givendistance. addition to the givendistance.
...@@ -508,7 +508,7 @@ class ActionRunner(object): ...@@ -508,7 +508,7 @@ class ActionRunner(object):
gesture, as a ratio of the visible bounding rectangle for gesture, as a ratio of the visible bounding rectangle for
document.body. document.body.
direction: The direction of scroll, either 'left', 'right', direction: The direction of scroll, either 'left', 'right',
'up', or 'down' 'up', 'down', 'upleft', 'upright', 'downleft', or 'downright'
distance: The distance to scroll (in pixel). distance: The distance to scroll (in pixel).
overscroll: The number of additional pixels to scroll back, in overscroll: The number of additional pixels to scroll back, in
addition to the givendistance. addition to the givendistance.
......
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