Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 from page_sets import mobile_facebook_page | |
| 5 from telemetry.page import page as page_module | |
| 6 from telemetry.page import shared_page_state | |
| 7 from telemetry import story | |
| 8 | |
| 9 TIME_TO_WAIT_BEFORE_STARTING_IN_SECONDS = 5 | |
| 10 SCROLL_TIMEOUT_IN_SECONDS = 120 | |
| 11 | |
| 12 # TODO(ulan): Remove this once crbug.com/541508 is fixed. | |
| 13 STARTUP_SCRIPT = ''' | |
| 14 window.WebSocket = undefined; | |
| 15 window.Worker = undefined; | |
| 16 window.performance = undefined;''' | |
| 17 | |
| 18 def _ScrollAction(action_runner, scroll_amount, delay, repeat): | |
| 19 # with action_runner.CreateInteraction('Begin'): | |
|
eakuefner
2016/03/09 17:49:08
Please remove these comments
ulan
2016/03/10 11:41:23
Done.
| |
| 20 # action_runner.tab.browser.DumpMemory() | |
| 21 with action_runner.CreateInteraction('Scrolling'): | |
| 22 action_runner.RepeatableBrowserDrivenScroll( | |
| 23 y_scroll_distance_ratio=scroll_amount, | |
| 24 repeat_delay_ms=delay, | |
| 25 repeat_count=repeat, | |
| 26 timeout=SCROLL_TIMEOUT_IN_SECONDS) | |
| 27 # with action_runner.CreateInteraction('End'): | |
|
eakuefner
2016/03/09 17:49:08
And here
ulan
2016/03/10 11:41:23
Done.
| |
| 28 # action_runner.tab.browser.DumpMemory() | |
| 29 | |
| 30 def _WaitAction(action_runner): | |
| 31 with action_runner.CreateInteraction('Load'): | |
| 32 action_runner.WaitForJavaScriptCondition( | |
| 33 'document.body != null && ' | |
| 34 'document.body.scrollHeight > window.innerHeight && ' | |
| 35 '!document.body.addEventListener("touchstart", function() {})') | |
| 36 with action_runner.CreateInteraction('Wait'): | |
| 37 action_runner.Wait(TIME_TO_WAIT_BEFORE_STARTING_IN_SECONDS) | |
| 38 with action_runner.CreateInteraction('GC'): | |
| 39 action_runner.ForceGarbageCollection() | |
| 40 | |
| 41 class MobileInfiniteScrollPage(page_module.Page): | |
| 42 def __init__(self, url, page_set, name, scroll_amount, delay, repeat, | |
| 43 credentials=None): | |
| 44 super(MobileInfiniteScrollPage, self).__init__( | |
| 45 url=url, page_set=page_set, name=name, | |
| 46 shared_page_state_class=shared_page_state.SharedPageState, | |
| 47 credentials_path='data/credentials.json') | |
| 48 self.credentials = credentials | |
| 49 self.script_to_evaluate_on_commit = STARTUP_SCRIPT | |
| 50 self.scroll_amount = scroll_amount | |
| 51 self.delay = delay | |
| 52 self.repeat = repeat | |
| 53 | |
| 54 def RunPageInteractions(self, action_runner): | |
| 55 _WaitAction(action_runner) | |
| 56 _ScrollAction(action_runner, self.scroll_amount, self.delay, | |
| 57 self.repeat) | |
| 58 | |
| 59 class MobileInfiniteScrollFacebookPage(mobile_facebook_page.MobileFacebookPage): | |
| 60 def __init__(self, url, page_set, name, scroll_amount, delay, repeat): | |
| 61 super(MobileInfiniteScrollFacebookPage, self).__init__( | |
| 62 url=url, page_set=page_set, | |
| 63 shared_page_state_class=shared_page_state.SharedPageState, | |
| 64 name=name) | |
| 65 self.script_to_evaluate_on_commit = STARTUP_SCRIPT | |
| 66 self.scroll_amount = scroll_amount | |
| 67 self.delay = delay | |
| 68 self.repeat = repeat | |
| 69 | |
| 70 def RunPageInteractions(self, action_runner): | |
| 71 _WaitAction(action_runner) | |
| 72 _ScrollAction(action_runner, self.scroll_amount, self.delay, | |
| 73 self.repeat) | |
| 74 | |
| 75 class MobileInfiniteScrollPageSet(story.StorySet): | |
| 76 """ Top mobile pages that can be scrolled for many pages. """ | |
| 77 def __init__(self): | |
| 78 super(MobileInfiniteScrollPageSet, self).__init__( | |
| 79 archive_data_file='data/mobile_infinite_scroll.json', | |
| 80 cloud_storage_bucket=story.PARTNER_BUCKET) | |
| 81 # The scroll distance is chosen such that the page can be scrolled | |
| 82 # continuously through the test without hitting the end of the page. | |
| 83 SCROLL_FAR = 60 | |
| 84 SCROLL_PAGE = 1 | |
| 85 pages = [ | |
| 86 ('https://m.facebook.com/shakira', 'facebook', SCROLL_FAR, 0, 0), | |
| 87 ('https://mobile.twitter.com/taylorswift13', 'twitter', SCROLL_PAGE, 10, 30), | |
| 88 ('http://techcrunch.tumblr.com/', 'tumblr', SCROLL_FAR, 0, 0), | |
| 89 ('https://www.flickr.com/explore', 'flickr', SCROLL_FAR, 0, 0), | |
| 90 ('https://meta.discourse.org/t/the-official-discourse-tags-plugin-discou rse-tagging/26482', | |
| 91 'discourse', SCROLL_PAGE, 10, 30) | |
| 92 ] | |
| 93 self.AddStory( | |
| 94 MobileInfiniteScrollFacebookPage(pages[0][0], self, pages[0][1], | |
| 95 pages[0][2], pages[0][3], pages[0][4])) | |
| 96 for (url, name, scroll_amount, delay, repeat) in pages[1:]: | |
| 97 self.AddStory( | |
| 98 MobileInfiniteScrollPage(url, self, name, scroll_amount, delay, repeat)) | |
| OLD | NEW |