Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: tools/perf/page_sets/browse_media_stories.py

Issue 2124823002: Adding media browsing benchmark. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: format Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
5 import sys
6
7 from telemetry.page import page
8
9 from telemetry.core import discover
10 from telemetry import story
11
12 _ALL_PLATFORMS = frozenset({'desktop', 'mobile'})
13 _DESKTOP_ONLY = frozenset({'desktop'})
14 _MOBILE_ONLY = frozenset({'mobile'})
15 _MEDIA_VIEW_TIME_IN_SECONDS = 3
16
17 class _BrowseMediaStory(page.Page):
18 """Abstract base class for browse media user stories.
19
20 A browse media story emulates browsing a media website:
21 1. Load a media page (image, video, etc.).
22 2. Click on the next item to load the next media page.
23 3. etc.
24 """
25 NAME = NotImplemented
26 URL = NotImplemented
27 SUPPORTED_PLATFORMS = _ALL_PLATFORMS
28 BROWSE_MEDIA_ITEM_SELECTOR = NotImplemented
29 BROWSE_MEDIA_ITEMS_TO_VISIT = 20
30
31 def __init__(self, story_set):
32 super(_BrowseMediaStory, self).__init__(
33 page_set=story_set, name=self.NAME, url=self.URL)
34
35 def _BrowseMediaItem(self, index):
36 return 'document.querySelectorAll(\'%s\')[%d]' % (
37 self.BROWSE_MEDIA_ITEM_SELECTOR, index)
38
39 def _NavigateBack(self, action_runner):
40 action_runner.ExecuteJavaScript('window.history.back()')
41
42 def _Login(self, action_runner):
43 pass
44
45 def _DidLoadDocument(self, action_runner):
46 pass
47
48 def _WaitForNavigationToBrowseMediaItem(self, action_runner):
49 action_runner.WaitForNavigate()
50
51 def _WaitForNavigationFromBrowseMediaItem(self, action_runner):
52 action_runner.WaitForNavigate()
53
54 def RunNavigateSteps(self, action_runner):
55 self._Login(action_runner)
56 super(_BrowseMediaStory, self).RunNavigateSteps(action_runner)
57
58 def RunPageInteractions(self, action_runner):
59 action_runner.tab.WaitForDocumentReadyStateToBeComplete()
60 self._DidLoadDocument(action_runner)
61 for i in xrange(self.BROWSE_MEDIA_ITEMS_TO_VISIT):
62 action_runner.WaitForElement(
63 element_function=self._BrowseMediaItem(self._ItemSelector(i)))
64 action_runner.Wait(_MEDIA_VIEW_TIME_IN_SECONDS)
65 action_runner.ClickElement(
66 element_function=self._BrowseMediaItem(self._ItemSelector(i)))
67
68 def IterAllStoryClasses():
69 # Sort the classes by their names so that their order is stable and
70 # deterministic.
71 for unused_cls_name, cls in sorted(discover.DiscoverClassesInModule(
72 module=sys.modules[__name__],
73 base_class=_BrowseMediaStory,
74 index_by_class_name=True).iteritems()):
75 yield cls
76
77 ################################################################################
78 # Browse media stories.
79 ################################################################################
80
81 class YoutubeBrowseMediaMobileStory(_BrowseMediaStory):
82 NAME = 'youtube-browse-media'
83 URL = 'https://youtube.com/watch?v=b6hoBp7Hk-A'
84 BROWSE_MEDIA_ITEM_SELECTOR = '._mhf > a'
85 SUPPORTED_PLATFORMS = _MOBILE_ONLY
86 def _ItemSelector(self, iteration):
87 return iteration % 3
88
89 class YoutubeBrowseMediaDesktopStory(_BrowseMediaStory):
90 NAME = 'youtube-browse-media'
91 URL = 'https://www.youtube.com/watch?v=Ic07xTJoP34'
92 BROWSE_MEDIA_ITEM_SELECTOR = '.yt-uix-simple-thumb-related'
93 SUPPORTED_PLATFORMS = _DESKTOP_ONLY
94 def _ItemSelector(self, iteration):
95 return iteration % 3
96
97 class FacebookBrowseMediaMobileStory(_BrowseMediaStory):
98 NAME = 'facebook-browse-media'
99 URL = ("https://facebook.com/photo.php?fbid=10154398154450513&"
100 "id=255110695512&set=a.406278500512.172778.255110695512&"
101 "source=54&refid=13")
102 BROWSE_MEDIA_ITEM_SELECTOR = '._57-p > a'
103 SUPPORTED_PLATFORMS = _MOBILE_ONLY
104 def _ItemSelector(self, _):
105 return 1
106
107 class ImgurBrowseMediaMobileStory(_BrowseMediaStory):
108 NAME = 'imgur-browse-media'
109 URL = 'http://imgur.com/gallery/e6gPQ'
110 BROWSE_MEDIA_ITEM_SELECTOR = '.Navbar-customAction'
111 SUPPORTED_PLATFORMS = _MOBILE_ONLY
112 def _ItemSelector(self, _):
113 return 0
114
115 class ImgurBrowseMediaDesktopStory(_BrowseMediaStory):
116 NAME = 'imgur-browse-media'
117 URL = 'http://imgur.com/gallery/e6gPQ'
118 BROWSE_MEDIA_ITEM_SELECTOR = '.navNext'
119 SUPPORTED_PLATFORMS = _DESKTOP_ONLY
120 def _ItemSelector(self, _):
121 return 0
122
123 class FlickrBrowseMediaMobileStory(_BrowseMediaStory):
124 NAME = 'flickr-browse-media'
125 URL = ("https://www.flickr.com/photos/133058989@N03/27995559671/in/"
126 "explore-2016-07-04#")
127 BROWSE_MEDIA_ITEM_SELECTOR = '.next-photo'
128 SUPPORTED_PLATFORMS = _MOBILE_ONLY
129 def _ItemSelector(self, _):
130 return 0
131
132 class FlickrBrowseMediaStory(_BrowseMediaStory):
133 NAME = 'flickr-browse-media'
134 URL = ("https://www.flickr.com/photos/133058989@N03/27995559671/in/"
135 "explore-2016-07-04#")
136 BROWSE_MEDIA_ITEM_SELECTOR = '.navigate-target.navigate-next'
137 SUPPORTED_PLATFORMS = _DESKTOP_ONLY
138 def _ItemSelector(self, _):
139 return 0
140
141 ################################################################################
142 # Browse media story sets.
143 ################################################################################
144
145 class _BrowseMediaStorySet(story.StorySet):
146 PLATFORM = NotImplemented
147
148 def __init__(self):
149 super(_BrowseMediaStorySet, self).__init__(
150 archive_data_file=('../data/browse_media_%s.json' % self.PLATFORM),
151 cloud_storage_bucket=story.PARTNER_BUCKET)
152 for story_class in IterAllStoryClasses():
153 if self.PLATFORM not in story_class.SUPPORTED_PLATFORMS:
154 continue
155 self.AddStory(story_class(self))
156
157 class DesktopBrowseMediaStorySet(_BrowseMediaStorySet):
158 PLATFORM = 'desktop'
159
160 class MobileBrowseMediaStorySet(_BrowseMediaStorySet):
161 PLATFORM = 'mobile'
OLDNEW
« tools/perf/benchmarks/browse_media.py ('K') | « tools/perf/benchmarks/browse_media.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698