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 | |
| 5 import sys | |
| 6 | |
| 7 from page_sets.system_health import platforms | |
| 8 from page_sets.system_health import system_health_story | |
| 9 | |
| 10 from telemetry import story | |
| 11 | |
| 12 | |
| 13 class _BrowsingStory(system_health_story.SystemHealthStory): | |
| 14 """Abstract base class for browsing stories. | |
| 15 | |
| 16 A browsing story visits items on the main page. Subclasses provide | |
| 17 CSS selector to identify the items and implement interaction using | |
| 18 the helper methods of this class. | |
| 19 """ | |
| 20 | |
| 21 IS_SINGLE_PAGE_APP = False | |
| 22 ITEM_SELECTOR = NotImplemented | |
| 23 ITEMS_TO_VISIT = 4 | |
| 24 | |
| 25 def __init__(self, story_set): | |
| 26 super(_BrowsingStory, self).__init__( | |
| 27 story_set, take_memory_measurement=False) | |
| 28 | |
| 29 def _WaitForNavigation(self, action_runner): | |
| 30 if not self.IS_SINGLE_PAGE_APP: | |
| 31 action_runner.WaitForNavigate() | |
| 32 | |
| 33 def _NavigateToItem(self, action_runner, index): | |
| 34 item_selector = 'document.querySelectorAll("%s")[%d]' % ( | |
| 35 self.ITEM_SELECTOR, index) | |
| 36 self._ClickLink(action_runner, item_selector) | |
| 37 | |
| 38 def _ClickLink(self, action_runner, element_function): | |
| 39 action_runner.WaitForElement(element_function=element_function) | |
| 40 action_runner.ClickElement(element_function=element_function) | |
| 41 self._WaitForNavigation(action_runner) | |
| 42 | |
| 43 def _NavigateBack(self, action_runner): | |
| 44 action_runner.ExecuteJavaScript('window.history.back()') | |
| 45 self._WaitForNavigation(action_runner) | |
| 46 | |
| 47 | |
| 48 class _NewsBrowsingStory(_BrowsingStory): | |
| 49 """Abstract base class for news user stories. | |
| 50 | |
| 51 A news story imitates browsing a news website: | |
| 52 1. Load the main page. | |
| 53 2. Open and scroll the first news item. | |
| 54 3. Go back to the main page and scroll it. | |
| 55 4. Open and scroll the second news item. | |
| 56 5. Go back to the main page and scroll it. | |
| 57 6. etc. | |
| 58 """ | |
| 59 | |
| 60 ITEM_READ_TIME_IN_SECONDS = 3 | |
| 61 ITEM_SCROLL_REPEAT = 2 | |
| 62 MAIN_PAGE_SCROLL_REPEAT = 0 | |
| 63 | |
| 64 def _DidLoadDocument(self, action_runner): | |
| 65 for i in xrange(self.ITEMS_TO_VISIT): | |
| 66 self._NavigateToItem(action_runner, i) | |
| 67 self._ReadNewsItem(action_runner) | |
| 68 self._NavigateBack(action_runner) | |
| 69 self._ScrollMainPage(action_runner) | |
| 70 | |
| 71 def _ReadNewsItem(self, action_runner): | |
| 72 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | |
| 73 action_runner.Wait(self.ITEM_READ_TIME_IN_SECONDS) | |
| 74 action_runner.RepeatableBrowserDrivenScroll( | |
| 75 repeat_count=self.ITEM_SCROLL_REPEAT) | |
| 76 | |
| 77 def _ScrollMainPage(self, action_runner): | |
| 78 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | |
| 79 action_runner.RepeatableBrowserDrivenScroll( | |
| 80 repeat_count=self.MAIN_PAGE_SCROLL_REPEAT) | |
| 81 | |
| 82 | |
| 83 ############################################################################## | |
| 84 # News browsing stories. | |
| 85 ############################################################################## | |
| 86 | |
| 87 | |
| 88 class CnnStory(_NewsBrowsingStory): | |
| 89 """The second top website in http://www.alexa.com/topsites/category/News""" | |
| 90 NAME = 'browse:news:cnn' | |
| 91 URL = 'http://edition.cnn.com/' | |
| 92 ITEM_SELECTOR = '.cd__content > h3 > a' | |
| 93 # TODO(ulan): Enable this story on mobile once it uses less memory and | |
| 94 # does not crash with OOM. | |
| 95 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 96 | |
| 97 | |
| 98 class FacebookMobileStory(_NewsBrowsingStory): | |
| 99 NAME = 'browse:social:facebook' | |
| 100 URL = 'https://www.facebook.com/rihanna' | |
| 101 ITEM_SELECTOR = 'article ._5msj' | |
| 102 # Facebook on desktop is not interesting because it embeds post comments | |
| 103 # directly in the main timeline. | |
| 104 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 105 | |
| 106 | |
| 107 class HackerNewsStory(_NewsBrowsingStory): | |
| 108 NAME = 'browse:news:hackernews' | |
| 109 URL = 'https://news.ycombinator.com' | |
| 110 ITEM_SELECTOR = '.athing .title > a' | |
| 111 | |
| 112 | |
| 113 class NytimesMobileStory(_NewsBrowsingStory): | |
| 114 """The third top website in http://www.alexa.com/topsites/category/News""" | |
| 115 NAME = 'browse:news:nytimes' | |
| 116 URL = 'http://mobile.nytimes.com' | |
| 117 ITEM_SELECTOR = '.sfgAsset-link' | |
| 118 # Visiting more items causes OOM. | |
| 119 ITEMS_TO_VISIT = 2 | |
| 120 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 121 | |
| 122 | |
| 123 class NytimesDesktopStory(_NewsBrowsingStory): | |
| 124 """The third top website in http://www.alexa.com/topsites/category/News""" | |
| 125 NAME = 'browse:news:nytimes' | |
| 126 URL = 'http://www.nytimes.com' | |
| 127 ITEM_SELECTOR = '.story-heading > a' | |
| 128 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 129 | |
| 130 | |
| 131 class QqMobileStory(_NewsBrowsingStory): | |
| 132 NAME = 'browse:news:qq' | |
| 133 URL = 'http://news.qq.com' | |
| 134 # Desktop qq.com opens a news item in a separate tab, for which the back | |
| 135 # button does not work. | |
| 136 # Mobile qq.com is disabled due to crbug.com/627166 | |
| 137 ITEM_SELECTOR = '.list .full a' | |
| 138 SUPPORTED_PLATFORMS = platforms.NO_PLATFORMS | |
| 139 | |
| 140 | |
| 141 class RedditDesktopStory(_NewsBrowsingStory): | |
| 142 """The top website in http://www.alexa.com/topsites/category/News""" | |
| 143 NAME = 'browse:news:reddit' | |
| 144 URL = 'https://www.reddit.com/top/?sort=top&t=week' | |
| 145 ITEM_SELECTOR = '.thing .title > a' | |
| 146 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 147 | |
| 148 | |
| 149 class RedditMobileStory(_NewsBrowsingStory): | |
| 150 """The top website in http://www.alexa.com/topsites/category/News""" | |
| 151 NAME = 'browse:news:reddit' | |
| 152 URL = 'https://m.reddit.com/?sort=top&time=week' | |
| 153 IS_SINGLE_PAGE_APP = True | |
| 154 ITEM_SELECTOR = '.PostHeader__post-title-line' | |
| 155 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 156 | |
| 157 | |
| 158 class TwitterMobileStory(_NewsBrowsingStory): | |
| 159 NAME = 'browse:social:twitter' | |
| 160 URL = 'https://www.twitter.com/justinbieber?skip_interstitial=true' | |
| 161 ITEM_SELECTOR = '.Tweet-text' | |
| 162 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 163 | |
| 164 | |
| 165 class TwitterDesktopStory(_NewsBrowsingStory): | |
| 166 NAME = 'browse:social:twitter' | |
| 167 URL = 'https://www.twitter.com/justinbieber?skip_interstitial=true' | |
| 168 IS_SINGLE_PAGE_APP = True | |
| 169 ITEM_SELECTOR = '.tweet-text' | |
| 170 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 171 | |
| 172 | |
| 173 class WashingtonPostMobileStory(_NewsBrowsingStory): | |
| 174 """Progressive website""" | |
| 175 NAME = 'browse:news:washingtonpost' | |
| 176 URL = 'https://www.washingtonpost.com/pwa' | |
| 177 IS_SINGLE_PAGE_APP = True | |
| 178 ITEM_SELECTOR = '.hed > a' | |
| 179 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 180 | |
| 181 def _DidLoadDocument(self, action_runner): | |
| 182 # Close the popup window. | |
| 183 action_runner.ClickElement(selector='.close') | |
| 184 super(WashingtonPostMobileStory, self)._DidLoadDocument(action_runner) | |
| 185 | |
| 186 | |
| 187 ############################################################################## | |
| 188 # Browsing story sets. | |
| 189 ############################################################################## | |
| 190 | |
| 191 | |
| 192 def _IterAllNewsBrowsingStoryClasses(): | |
| 193 return system_health_story.IterAllStoryClasses( | |
| 194 sys.modules[__name__], _NewsBrowsingStory) | |
| 195 | |
| 196 | |
| 197 class _NewsBrowsingStorySet(story.StorySet): | |
|
petrcermak
2016/07/12 15:30:55
Could this be called _BrowsingSystemHealthStorySet
ulan
2016/07/12 17:14:48
I renamed it to _NewsBrowsingSystemHealthStorySet.
nednguyen
2016/07/12 17:19:15
More benchmarks will make it more confusing for us
petrcermak
2016/07/12 17:23:24
I agree with Ned. Let's have a single _BrowsingSys
| |
| 198 PLATFORM = NotImplemented | |
| 199 | |
| 200 def __init__(self): | |
| 201 super(_NewsBrowsingStorySet, self).__init__( | |
| 202 archive_data_file=('../data/news_%s.json' % self.PLATFORM), | |
| 203 cloud_storage_bucket=story.PARTNER_BUCKET) | |
| 204 for story_class in _IterAllNewsBrowsingStoryClasses(): | |
| 205 if self.PLATFORM not in story_class.SUPPORTED_PLATFORMS: | |
| 206 continue | |
| 207 self.AddStory(story_class(self)) | |
| 208 | |
| 209 | |
| 210 class DesktopNewsStorySet(_NewsBrowsingStorySet): | |
| 211 PLATFORM = platforms.DESKTOP | |
| 212 | |
| 213 | |
| 214 class MobileNewsStorySet(_NewsBrowsingStorySet): | |
| 215 PLATFORM = platforms.MOBILE | |
| OLD | NEW |