Index: tools/perf/page_sets/tough_ad_cases.py |
diff --git a/tools/perf/page_sets/tough_ad_cases.py b/tools/perf/page_sets/tough_ad_cases.py |
index 22725c90bc110a129ccd42f03e2d5badc5f154e2..73a9e74f7b908c225618ef1295ec2c37f8236e60 100644 |
--- a/tools/perf/page_sets/tough_ad_cases.py |
+++ b/tools/perf/page_sets/tough_ad_cases.py |
@@ -2,8 +2,10 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
-from telemetry.core import exceptions |
+from page_sets import repeatable_synthesize_scroll_gesture_shared_state |
+ |
from telemetry.page import page as page_module |
+from telemetry.web_perf import timeline_interaction_record |
from telemetry import story |
@@ -35,10 +37,17 @@ class SwiffyPage(page_module.Page): |
class ScrollingPage(page_module.Page): |
def __init__(self, url, page_set, top_start_ratio=.5, |
- make_javascript_deterministic=True): |
- super(ScrollingPage, self).__init__(url=url, page_set=page_set, |
- make_javascript_deterministic=make_javascript_deterministic) |
+ make_javascript_deterministic=True, scroll_multiplier=0.5): |
Sami
2015/08/19 11:54:46
What does it mean to scroll .5 times?-)
alex clarke (OOO till 29th)
2015/08/19 15:40:58
It's a distance multiplier, hopefully that is more
|
+ super(ScrollingPage, self).__init__( |
+ url=url, |
+ page_set=page_set, |
+ make_javascript_deterministic=make_javascript_deterministic, |
+ shared_page_state_class=( |
+ repeatable_synthesize_scroll_gesture_shared_state.\ |
+ RepeatableSynthesizeScrollGestureSharedState)) |
self._top_start_ratio = top_start_ratio |
+ self._scroll_multiplier = scroll_multiplier |
+ self._screensize = [] |
def RunNavigateSteps(self, action_runner): |
# Rewrite file urls to point to the replay server instead. |
@@ -49,29 +58,36 @@ class ScrollingPage(page_module.Page): |
url = self._url |
action_runner.tab.Navigate(url) |
- # Give the page one second to become interactive and start scrolling after |
- # the timeout regardless of the document's ready state. |
- try: |
- action_runner.tab.WaitForDocumentReadyStateToBeInteractiveOrBetter(1) |
- except exceptions.TimeoutException: |
- pass |
- # Wait for the document to have a body so that we can scroll. |
- # Simultaneously (to reduce latency), insert a no-op touch handler on the |
- # body. Most ads have touch handlers and we want to simulate the worst case |
- # of the user trying to scroll the page by grabbing an ad. |
+ # Wait for the page to be scrollable. |
action_runner.WaitForJavaScriptCondition( |
- '!(document.body == null || ' |
- ' document.body.addEventListener("touchstart", function() {}))') |
+ 'document.body != null && ' |
+ 'document.body.scrollHeight > window.screen.height') |
- def RunPageInteractions(self, action_runner): |
- for _ in range(10): |
- with action_runner.CreateGestureInteraction('ScrollAction', |
- repeatable=True): |
- action_runner.ScrollPage(distance=500, |
- top_start_ratio=self._top_start_ratio) |
- action_runner.Wait(.25) |
+ # Get the dimensions of the screen. Simultaneously (to reduce latency), |
+ # insert a no-op touch handler on the body. Most ads have touch handlers |
+ # and we want to simulate the worst case of the user trying to scroll the |
+ # page by grabbing an ad. |
+ js_result = action_runner.EvaluateJavaScript( |
+ 'window.screen.availWidth + "," + window.screen.availHeight + "," + ' |
+ '(document.body.addEventListener("touchstart", function() {}) ? 1 : 0)') |
+ self._screensize = [int(n) for n in js_result.split(',')] |
+ def RunPageInteractions(self, action_runner): |
+ scroll_distance = int(self._scroll_multiplier * self._screensize[1]) |
+ |
+ # Set up a browser driven repeating scroll. The delay between the scrolls |
+ # should be unaffected by render thread responsivness (or lack there of). |
+ action_runner.tab.SynthesizeScrollGesture( |
+ x=int(self._screensize[0] / 2), |
+ y=self._screensize[1] - int(self._screensize[1] * 0.25), |
+ xDistance=0, |
+ yDistance=-scroll_distance, |
+ repeatCount=9, |
+ repeatDelayMs=250, |
+ interactionMarkerName=timeline_interaction_record.GetJavaScriptMarker( |
+ 'Gesture_ScrollAction', [timeline_interaction_record.REPEATABLE])) |
+ |
class ScrollingForbesPage(ScrollingPage): |
def __init__(self, url, page_set): |
@@ -128,7 +144,8 @@ class ScrollingToughAdCasesPageSet(story.StorySet): |
cloud_storage_bucket=story.INTERNAL_BUCKET) |
self.AddStory(ScrollingPage('file://tough_ad_cases/' |
- 'swiffy_collection.html', self, make_javascript_deterministic=False)) |
+ 'swiffy_collection.html', self, make_javascript_deterministic=False, |
+ scroll_multiplier=0.25)) |
self.AddStory(ScrollingPage('http://www.latimes.com', self)) |
self.AddStory(ScrollingForbesPage('http://www.forbes.com/sites/parmyolson/' |
'2015/07/29/jana-mobile-data-facebook-internet-org/', self)) |
@@ -142,6 +159,7 @@ class ScrollingToughAdCasesPageSet(story.StorySet): |
#self.AddStory(ScrollingPage('http://time.com/3977891/' |
# 'donald-trump-debate-republican/', self)) |
self.AddStory(ScrollingPage('http://www.theguardian.com/uk', self)) |
- self.AddStory(ScrollingPage('http://m.tmz.com', self)) |
+ self.AddStory(ScrollingPage('http://m.tmz.com', self, |
+ scroll_multiplier=0.25)) |
self.AddStory(ScrollingPage('http://androidpolice.com', self, |
top_start_ratio=0)) |