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

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: tweaks 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
« no previous file with comments | « tools/perf/benchmarks/browse_media.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 = '._mnfb > 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 BROWSE_MEDIA_ITEMS_TO_VISIT = 5
113 def _ItemSelector(self, _):
114 return 0
115
116 class ImgurBrowseMediaDesktopStory(_BrowseMediaStory):
117 NAME = 'imgur-browse-media'
118 URL = 'http://imgur.com/gallery/e6gPQ'
119 BROWSE_MEDIA_ITEM_SELECTOR = '.navNext'
120 SUPPORTED_PLATFORMS = _DESKTOP_ONLY
121 BROWSE_MEDIA_ITEMS_TO_VISIT = 5
122 def _ItemSelector(self, _):
123 return 0
124
125 class FlickrBrowseMediaMobileStory(_BrowseMediaStory):
126 NAME = 'flickr-browse-media'
127 URL = ("https://www.flickr.com/photos/133058989@N03/27995559671/in/"
128 "explore-2016-07-04#")
129 BROWSE_MEDIA_ITEM_SELECTOR = '.next-photo'
130 SUPPORTED_PLATFORMS = _MOBILE_ONLY
131 def _ItemSelector(self, _):
132 return 0
133
134 class FlickrBrowseMediaStory(_BrowseMediaStory):
135 NAME = 'flickr-browse-media'
136 URL = ("https://www.flickr.com/photos/133058989@N03/27995559671/in/"
137 "explore-2016-07-04#")
138 BROWSE_MEDIA_ITEM_SELECTOR = '.navigate-target.navigate-next'
139 SUPPORTED_PLATFORMS = _DESKTOP_ONLY
140 def _ItemSelector(self, _):
141 return 0
142
143 ################################################################################
144 # Browse media story sets.
145 ################################################################################
146
147 class _BrowseMediaStorySet(story.StorySet):
148 PLATFORM = NotImplemented
149
150 def __init__(self):
151 super(_BrowseMediaStorySet, self).__init__(
152 archive_data_file=('../data/browse_media_%s.json' % self.PLATFORM),
153 cloud_storage_bucket=story.PARTNER_BUCKET)
154 for story_class in IterAllStoryClasses():
155 if self.PLATFORM not in story_class.SUPPORTED_PLATFORMS:
156 continue
157 self.AddStory(story_class(self))
158
159 class DesktopBrowseMediaStorySet(_BrowseMediaStorySet):
160 PLATFORM = 'desktop'
161
162 class MobileBrowseMediaStorySet(_BrowseMediaStorySet):
163 PLATFORM = 'mobile'
OLDNEW
« no previous file with comments | « tools/perf/benchmarks/browse_media.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698