Chromium Code Reviews| Index: tools/perf/page_sets/system_health/browsing_stories.py |
| diff --git a/tools/perf/page_sets/system_health/browsing_stories.py b/tools/perf/page_sets/system_health/browsing_stories.py |
| index 7d57323c571b0be838d877b1b4a9455e89b8c330..3f4f864be6f70a9ad0c33880ce720eab46cf6df5 100644 |
| --- a/tools/perf/page_sets/system_health/browsing_stories.py |
| +++ b/tools/perf/page_sets/system_health/browsing_stories.py |
| @@ -7,6 +7,7 @@ from page_sets.system_health import platforms |
| from page_sets.system_health import story_tags |
| from page_sets.system_health import system_health_story |
| +from page_sets.login_helpers import facebook_login |
| from page_sets.login_helpers import pinterest_login |
| from telemetry import decorators |
| @@ -783,3 +784,131 @@ class GoogleEarthStory(_BrowsingStory): |
| action_runner.RepeatableBrowserDrivenScroll( |
| x_scroll_distance_ratio = 1, y_scroll_distance_ratio = 0, |
| repeat_count=3, speed=500, timeout=120) |
| + |
| + |
| +############################################################################## |
| +# Browsing stories with infinite scrolling |
| +############################################################################## |
| + |
| + |
| +class _InfiniteScrollStory(system_health_story.SystemHealthStory): |
| + SUPPORTED_PLATFORMS = platforms.ALL_PLATFORMS |
| + |
| + SCROLL_DISTANCE = 25000 |
| + SCROLL_STEP = 1000 |
| + MAX_SCROLL_RETRIES = 3 |
| + TIME_BEFORE_SCROLL_RETRY_IN_SECONDS = 1 |
| + TIME_TO_WAIT_BEFORE_STARTING_IN_SECONDS = 5 |
| + |
| + def __init__(self, story_set, take_memory_measurement): |
| + super(_InfiniteScrollStory, self).__init__(story_set, |
| + take_memory_measurement) |
| + self.script_to_evaluate_on_commit = ''' |
| + window.WebSocket = undefined; |
| + window.Worker = undefined; |
| + window.performance = undefined;''' |
| + |
| + def _DidLoadDocument(self, action_runner): |
| + action_runner.WaitForJavaScriptCondition( |
| + 'document.body != null && ' |
| + 'document.body.scrollHeight > window.innerHeight && ' |
| + '!document.body.addEventListener("touchstart", function() {})') |
| + action_runner.Wait(self.TIME_TO_WAIT_BEFORE_STARTING_IN_SECONDS) |
| + self._Scroll(action_runner, self.SCROLL_DISTANCE, self.SCROLL_STEP) |
| + |
| + |
| + def _Scroll(self, action_runner, distance, step_size): |
| + """ This function scrolls the webpage by the given scroll distance in |
| + multiple steps, where each step (except the last one) has the given size. |
| + |
| + If scrolling gets stuck, the functions retries scrolling MAX_SCROLL_RETRIES |
| + times waiting TIME_BEFORE_SCROLL_RETRY_IN_SECONDS seconds between retries. |
| + """ |
| + remaining = distance - action_runner.EvaluateJavaScript('window.scrollY') |
| + retry_count = 0 |
| + # Scroll until the window.scrollY is within 1 pixel of the target distance. |
| + while remaining > 1: |
| + action_runner.ScrollPage(distance=min(remaining, step_size) + 1) |
| + new_remaining = (distance - |
| + action_runner.EvaluateJavaScript('window.scrollY')) |
| + if remaining >= new_remaining: |
| + # Scrolling is stuck. This can happen if the page is loading |
| + # resources. Give the page some time and retry scrolling. |
| + if retry_count == self.MAX_SCROLL_RETRIES: |
| + raise Exception('Scrolling stuck at %d' % remaining) |
| + retry_count += 1 |
| + action_runner.Wait(self.TIME_BEFORE_SCROLL_RETRY_IN_SECONDS) |
| + else: |
| + retry_count = 0 |
| + remaining = new_remaining |
| + |
| + @classmethod |
| + def GenerateStoryDescription(cls): |
| + return 'Load %s then make a very long scroll.' % cls.URL |
| + |
| + |
| +class DiscourseDesktopStory(_InfiniteScrollStory): |
| + NAME = 'browse:tech:discourse_infinite_scroll' |
| + URL = ('https://meta.discourse.org/t/the-official-discourse-tags-plugin-discourse-tagging/26482') |
|
perezju
2017/05/25 08:27:42
nit: no need for parenthesis anymore :)
|
| + SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY |
| + TAGS = [story_tags.INFINITE_SCROLL] |
| + |
| + |
| +class DiscourseMobileStory(_InfiniteScrollStory): |
| + NAME = 'browse:tech:discourse_infinite_scroll' |
| + URL = ('https://meta.discourse.org/t/the-official-discourse-tags-plugin-discourse-tagging/26482') |
| + SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY |
| + SCROLL_DISTANCE = 15000 |
| + TAGS = [story_tags.INFINITE_SCROLL] |
| + |
| + |
| +class FacebookScrollDesktopStory(_InfiniteScrollStory): |
| + NAME = 'browse:social:facebook_infinite_scroll' |
| + URL = 'https://www.facebook.com/shakira' |
| + SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY |
| + TAGS = [story_tags.INFINITE_SCROLL] |
| + |
| + |
| +class FacebookScrollMobileStory(_InfiniteScrollStory): |
| + NAME = 'browse:social:facebook_infinite_scroll' |
| + URL = 'https://m.facebook.com/shakira' |
| + SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY |
|
perezju
2017/05/25 08:27:42
missing TAGS, probably by mistake
|
| + |
| + def _Login(self, action_runner): |
| + facebook_login.LoginWithMobileSite( |
| + action_runner, 'facebook3', self.credentials_path) |
| + |
| + |
| +class FlickrDesktopStory(_InfiniteScrollStory): |
| + NAME = 'browse:media:flickr_infinite_scroll' |
| + URL = 'https://www.flickr.com/explore' |
| + SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY |
| + TAGS = [story_tags.INFINITE_SCROLL] |
| + |
| + |
| +class FlickrMobileStory(_InfiniteScrollStory): |
| + NAME = 'browse:media:flickr_infinite_scroll' |
| + URL = 'https://www.flickr.com/explore' |
| + SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY |
| + SCROLL_DISTANCE = 10000 |
| + TAGS = [story_tags.INFINITE_SCROLL] |
| + |
| + |
| +class PinterestMobileStory(_InfiniteScrollStory): |
| + NAME = 'browse:social:pinterest_infinite_scroll' |
| + URL = 'https://www.pinterest.com/all' |
| + SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY |
| + TAGS = [story_tags.INFINITE_SCROLL] |
| + |
| + |
| +class TumblrStory(_InfiniteScrollStory): |
| + NAME = 'browse:social:tumblr_infinite_scroll' |
| + URL = 'http://techcrunch.tumblr.com/' # This page doesn't support HTTPS. |
| + TAGS = [story_tags.INFINITE_SCROLL] |
| + |
| + |
| +class TwitterScrollDesktopStory(_InfiniteScrollStory): |
| + NAME = 'browse:social:twitter_infinite_scroll' |
| + URL = 'https://twitter.com/taylorswift13' |
| + SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY |
| + TAGS = [story_tags.INFINITE_SCROLL] |