| Index: tools/perf/page_sets/browse_media_stories.py
|
| diff --git a/tools/perf/page_sets/browse_media_stories.py b/tools/perf/page_sets/browse_media_stories.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..41d5a12a60e11fc5be9dd01b411db6be53479dee
|
| --- /dev/null
|
| +++ b/tools/perf/page_sets/browse_media_stories.py
|
| @@ -0,0 +1,161 @@
|
| +# Copyright 2016 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 sys
|
| +
|
| +from telemetry.page import page
|
| +
|
| +from telemetry.core import discover
|
| +from telemetry import story
|
| +
|
| +_ALL_PLATFORMS = frozenset({'desktop', 'mobile'})
|
| +_DESKTOP_ONLY = frozenset({'desktop'})
|
| +_MOBILE_ONLY = frozenset({'mobile'})
|
| +_MEDIA_VIEW_TIME_IN_SECONDS = 3
|
| +
|
| +class _BrowseMediaStory(page.Page):
|
| + """Abstract base class for browse media user stories.
|
| +
|
| + A browse media story emulates browsing a media website:
|
| + 1. Load a media page (image, video, etc.).
|
| + 2. Click on the next item to load the next media page.
|
| + 3. etc.
|
| + """
|
| + NAME = NotImplemented
|
| + URL = NotImplemented
|
| + SUPPORTED_PLATFORMS = _ALL_PLATFORMS
|
| + BROWSE_MEDIA_ITEM_SELECTOR = NotImplemented
|
| + BROWSE_MEDIA_ITEMS_TO_VISIT = 20
|
| +
|
| + def __init__(self, story_set):
|
| + super(_BrowseMediaStory, self).__init__(
|
| + page_set=story_set, name=self.NAME, url=self.URL)
|
| +
|
| + def _BrowseMediaItem(self, index):
|
| + return 'document.querySelectorAll(\'%s\')[%d]' % (
|
| + self.BROWSE_MEDIA_ITEM_SELECTOR, index)
|
| +
|
| + def _NavigateBack(self, action_runner):
|
| + action_runner.ExecuteJavaScript('window.history.back()')
|
| +
|
| + def _Login(self, action_runner):
|
| + pass
|
| +
|
| + def _DidLoadDocument(self, action_runner):
|
| + pass
|
| +
|
| + def _WaitForNavigationToBrowseMediaItem(self, action_runner):
|
| + action_runner.WaitForNavigate()
|
| +
|
| + def _WaitForNavigationFromBrowseMediaItem(self, action_runner):
|
| + action_runner.WaitForNavigate()
|
| +
|
| + def RunNavigateSteps(self, action_runner):
|
| + self._Login(action_runner)
|
| + super(_BrowseMediaStory, self).RunNavigateSteps(action_runner)
|
| +
|
| + def RunPageInteractions(self, action_runner):
|
| + action_runner.tab.WaitForDocumentReadyStateToBeComplete()
|
| + self._DidLoadDocument(action_runner)
|
| + for i in xrange(self.BROWSE_MEDIA_ITEMS_TO_VISIT):
|
| + action_runner.WaitForElement(
|
| + element_function=self._BrowseMediaItem(self._ItemSelector(i)))
|
| + action_runner.Wait(_MEDIA_VIEW_TIME_IN_SECONDS)
|
| + action_runner.ClickElement(
|
| + element_function=self._BrowseMediaItem(self._ItemSelector(i)))
|
| +
|
| +def IterAllStoryClasses():
|
| + # Sort the classes by their names so that their order is stable and
|
| + # deterministic.
|
| + for unused_cls_name, cls in sorted(discover.DiscoverClassesInModule(
|
| + module=sys.modules[__name__],
|
| + base_class=_BrowseMediaStory,
|
| + index_by_class_name=True).iteritems()):
|
| + yield cls
|
| +
|
| +################################################################################
|
| +# Browse media stories.
|
| +################################################################################
|
| +
|
| +class YoutubeBrowseMediaMobileStory(_BrowseMediaStory):
|
| + NAME = 'youtube-browse-media'
|
| + URL = 'https://youtube.com/watch?v=b6hoBp7Hk-A'
|
| + BROWSE_MEDIA_ITEM_SELECTOR = '._mhf > a'
|
| + SUPPORTED_PLATFORMS = _MOBILE_ONLY
|
| + def _ItemSelector(self, iteration):
|
| + return iteration % 3
|
| +
|
| +class YoutubeBrowseMediaDesktopStory(_BrowseMediaStory):
|
| + NAME = 'youtube-browse-media'
|
| + URL = 'https://www.youtube.com/watch?v=Ic07xTJoP34'
|
| + BROWSE_MEDIA_ITEM_SELECTOR = '.yt-uix-simple-thumb-related'
|
| + SUPPORTED_PLATFORMS = _DESKTOP_ONLY
|
| + def _ItemSelector(self, iteration):
|
| + return iteration % 3
|
| +
|
| +class FacebookBrowseMediaMobileStory(_BrowseMediaStory):
|
| + NAME = 'facebook-browse-media'
|
| + URL = ("https://facebook.com/photo.php?fbid=10154398154450513&"
|
| + "id=255110695512&set=a.406278500512.172778.255110695512&"
|
| + "source=54&refid=13")
|
| + BROWSE_MEDIA_ITEM_SELECTOR = '._57-p > a'
|
| + SUPPORTED_PLATFORMS = _MOBILE_ONLY
|
| + def _ItemSelector(self, _):
|
| + return 1
|
| +
|
| +class ImgurBrowseMediaMobileStory(_BrowseMediaStory):
|
| + NAME = 'imgur-browse-media'
|
| + URL = 'http://imgur.com/gallery/e6gPQ'
|
| + BROWSE_MEDIA_ITEM_SELECTOR = '.Navbar-customAction'
|
| + SUPPORTED_PLATFORMS = _MOBILE_ONLY
|
| + def _ItemSelector(self, _):
|
| + return 0
|
| +
|
| +class ImgurBrowseMediaDesktopStory(_BrowseMediaStory):
|
| + NAME = 'imgur-browse-media'
|
| + URL = 'http://imgur.com/gallery/e6gPQ'
|
| + BROWSE_MEDIA_ITEM_SELECTOR = '.navNext'
|
| + SUPPORTED_PLATFORMS = _DESKTOP_ONLY
|
| + def _ItemSelector(self, _):
|
| + return 0
|
| +
|
| +class FlickrBrowseMediaMobileStory(_BrowseMediaStory):
|
| + NAME = 'flickr-browse-media'
|
| + URL = ("https://www.flickr.com/photos/133058989@N03/27995559671/in/"
|
| + "explore-2016-07-04#")
|
| + BROWSE_MEDIA_ITEM_SELECTOR = '.next-photo'
|
| + SUPPORTED_PLATFORMS = _MOBILE_ONLY
|
| + def _ItemSelector(self, _):
|
| + return 0
|
| +
|
| +class FlickrBrowseMediaStory(_BrowseMediaStory):
|
| + NAME = 'flickr-browse-media'
|
| + URL = ("https://www.flickr.com/photos/133058989@N03/27995559671/in/"
|
| + "explore-2016-07-04#")
|
| + BROWSE_MEDIA_ITEM_SELECTOR = '.navigate-target.navigate-next'
|
| + SUPPORTED_PLATFORMS = _DESKTOP_ONLY
|
| + def _ItemSelector(self, _):
|
| + return 0
|
| +
|
| +################################################################################
|
| +# Browse media story sets.
|
| +################################################################################
|
| +
|
| +class _BrowseMediaStorySet(story.StorySet):
|
| + PLATFORM = NotImplemented
|
| +
|
| + def __init__(self):
|
| + super(_BrowseMediaStorySet, self).__init__(
|
| + archive_data_file=('../data/browse_media_%s.json' % self.PLATFORM),
|
| + cloud_storage_bucket=story.PARTNER_BUCKET)
|
| + for story_class in IterAllStoryClasses():
|
| + if self.PLATFORM not in story_class.SUPPORTED_PLATFORMS:
|
| + continue
|
| + self.AddStory(story_class(self))
|
| +
|
| +class DesktopBrowseMediaStorySet(_BrowseMediaStorySet):
|
| + PLATFORM = 'desktop'
|
| +
|
| +class MobileBrowseMediaStorySet(_BrowseMediaStorySet):
|
| + PLATFORM = 'mobile'
|
|
|