OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 from telemetry.page import page as page_module | 4 from telemetry.page import page as page_module |
5 from telemetry.page import shared_page_state | 5 from telemetry.page import shared_page_state |
6 from telemetry import story | 6 from telemetry import story |
7 | 7 |
8 TIME_TO_WAIT_BEFORE_STARTING_IN_SECONDS = 5 | 8 TIME_TO_WAIT_BEFORE_STARTING_IN_SECONDS = 5 |
9 | 9 |
10 # TODO(ulan): Remove this once crbug.com/541508 is fixed. | 10 # TODO(ulan): Remove this once crbug.com/541508 is fixed. |
11 STARTUP_SCRIPT = ''' | 11 STARTUP_SCRIPT = ''' |
12 window.WebSocket = undefined; | 12 window.WebSocket = undefined; |
13 window.Worker = undefined; | 13 window.Worker = undefined; |
14 window.performance = undefined;''' | 14 window.performance = undefined;''' |
15 | 15 |
16 def _ScrollAction(action_runner, scroll_amount): | 16 def _ScrollAction(action_runner, scroll_amount, delay, repeat): |
17 action_runner.Wait(TIME_TO_WAIT_BEFORE_STARTING_IN_SECONDS) | 17 action_runner.Wait(TIME_TO_WAIT_BEFORE_STARTING_IN_SECONDS) |
18 with action_runner.CreateInteraction('Begin'): | 18 with action_runner.CreateInteraction('Begin'): |
19 action_runner.tab.browser.DumpMemory() | 19 action_runner.tab.browser.DumpMemory() |
20 with action_runner.CreateInteraction('Scrolling'): | 20 with action_runner.CreateInteraction('Scrolling'): |
21 action_runner.RepeatableBrowserDrivenScroll( | 21 action_runner.RepeatableBrowserDrivenScroll( |
22 y_scroll_distance_ratio=scroll_amount, | 22 y_scroll_distance_ratio=scroll_amount, |
23 repeat_count=0) | 23 repeat_delay_ms=delay, |
| 24 repeat_count=repeat) |
24 with action_runner.CreateInteraction('End'): | 25 with action_runner.CreateInteraction('End'): |
25 action_runner.tab.browser.DumpMemory() | 26 action_runner.tab.browser.DumpMemory() |
26 | 27 |
27 def _WaitAction(action_runner): | 28 def _WaitAction(action_runner): |
28 action_runner.WaitForJavaScriptCondition( | 29 action_runner.WaitForJavaScriptCondition( |
29 'document.body != null && ' | 30 'document.body != null && ' |
30 'document.body.scrollHeight > window.innerHeight && ' | 31 'document.body.scrollHeight > window.innerHeight && ' |
31 '!document.body.addEventListener("touchstart", function() {})') | 32 '!document.body.addEventListener("touchstart", function() {})') |
32 | 33 |
33 def _CreateInfiniteScrollPageClass(base_page_cls): | 34 def _CreateInfiniteScrollPageClass(base_page_cls): |
34 class DerivedSmoothPage(base_page_cls): # pylint: disable=no-init | 35 class DerivedSmoothPage(base_page_cls): # pylint: disable=no-init |
35 def RunPageInteractions(self, action_runner): | 36 def RunPageInteractions(self, action_runner): |
36 _WaitAction(action_runner) | 37 _WaitAction(action_runner) |
37 _ScrollAction(action_runner, self.scroll_amount) | 38 _ScrollAction(action_runner, self.scroll_amount, self.delay, self.repeat) |
38 return DerivedSmoothPage | 39 return DerivedSmoothPage |
39 | 40 |
40 class InfiniteScrollPage(page_module.Page): | 41 class InfiniteScrollPage(page_module.Page): |
41 def __init__(self, url, page_set, name, scroll_amount, credentials=None): | 42 def __init__(self, url, page_set, name, scroll_amount, delay, repeat, |
| 43 credentials=None): |
42 super(InfiniteScrollPage, self).__init__( | 44 super(InfiniteScrollPage, self).__init__( |
43 url=url, page_set=page_set, name=name, | 45 url=url, page_set=page_set, name=name, |
44 shared_page_state_class=shared_page_state.SharedPageState, | 46 shared_page_state_class=shared_page_state.SharedPageState, |
45 credentials_path='data/credentials.json') | 47 credentials_path='data/credentials.json') |
46 self.credentials = credentials | 48 self.credentials = credentials |
47 self.script_to_evaluate_on_commit = STARTUP_SCRIPT | 49 self.script_to_evaluate_on_commit = STARTUP_SCRIPT |
48 self.scroll_amount = scroll_amount | 50 self.scroll_amount = scroll_amount |
| 51 self.delay = delay |
| 52 self.repeat = repeat |
49 | 53 |
50 class InfiniteScrollPageSet(story.StorySet): | 54 class InfiniteScrollPageSet(story.StorySet): |
51 """ Top pages that can be scrolled for many pages. """ | 55 """ Top pages that can be scrolled for many pages. """ |
52 def __init__(self): | 56 def __init__(self): |
53 super(InfiniteScrollPageSet, self).__init__( | 57 super(InfiniteScrollPageSet, self).__init__( |
54 archive_data_file='data/infinite_scroll.json', | 58 archive_data_file='data/infinite_scroll.json', |
55 cloud_storage_bucket=story.PARTNER_BUCKET) | 59 cloud_storage_bucket=story.PARTNER_BUCKET) |
56 # The scroll distance is chosen such that the page can be scrolled | 60 # The scroll distance is chosen such that the page can be scrolled |
57 # continiously throught the test without hitting the end of the page. | 61 # continiously throught the test without hitting the end of the page. |
58 SCROLL_FAR = 30 | 62 SCROLL_FAR = 30 |
59 SCROLL_NEAR = 13 | 63 SCROLL_NEAR = 13 |
| 64 SCROLL_PAGE = 1 |
60 pages = [ | 65 pages = [ |
61 ('https://www.facebook.com/shakira', 'facebook', SCROLL_FAR), | 66 ('https://www.facebook.com/shakira', 'facebook', SCROLL_FAR, 0, 0), |
62 ('https://twitter.com/taylorswift13', 'twitter', SCROLL_FAR), | 67 ('https://twitter.com/taylorswift13', 'twitter', SCROLL_PAGE, 10, 30), |
63 ('http://espn.go.com/', 'espn', SCROLL_NEAR), | 68 ('http://espn.go.com/', 'espn', SCROLL_NEAR, 0, 0), |
64 ('https://www.yahoo.com', 'yahoo', SCROLL_NEAR), | 69 ('https://www.yahoo.com', 'yahoo', SCROLL_NEAR, 0, 0), |
65 ('http://techcrunch.tumblr.com/', 'tumblr', SCROLL_FAR), | 70 ('http://techcrunch.tumblr.com/', 'tumblr', SCROLL_FAR, 0, 0), |
66 ('https://www.flickr.com/explore', 'flickr', SCROLL_FAR) | 71 ('https://www.flickr.com/explore', 'flickr', SCROLL_FAR, 0, 0) |
67 ] | 72 ] |
68 for (url, name, scroll_amount) in pages: | 73 for (url, name, scroll_amount, delay, repeat) in pages: |
69 page_class = _CreateInfiniteScrollPageClass(InfiniteScrollPage) | 74 page_class = _CreateInfiniteScrollPageClass(InfiniteScrollPage) |
70 self.AddStory(page_class(url, self, name, scroll_amount)) | 75 self.AddStory(page_class(url, self, name, scroll_amount, delay, repeat)) |
OLD | NEW |