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 | |
|
petrcermak
2016/07/12 12:53:19
Sorry to keep changing my mind. Now that I look at
ulan
2016/07/12 14:05:47
I extracted _ClinkLink.
Item related code in _Bro
petrcermak
2016/07/12 15:30:54
I see. In that case I'm fine either way (extracted
ulan
2016/07/12 17:14:48
Acknowledged.
| |
| 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 action_runner.WaitForElement(element_function=item_selector) | |
| 37 action_runner.ClickElement(element_function=item_selector) | |
| 38 self._WaitForNavigation(action_runner) | |
| 39 | |
| 40 def _NavigateBack(self, action_runner): | |
| 41 action_runner.ExecuteJavaScript('window.history.back()') | |
| 42 self._WaitForNavigation(action_runner) | |
| 43 | |
| 44 | |
| 45 class _NewsBrowsingStory(_BrowsingStory): | |
| 46 """Abstract base class for news user stories. | |
| 47 | |
| 48 A news story imitates browsing a news website: | |
| 49 1. Load the main page. | |
| 50 2. Open and scroll the first news item. | |
| 51 3. Go back to the main page and scroll it. | |
| 52 4. Open and scroll the second news item. | |
| 53 5. Go back to the main page and scroll it. | |
| 54 6. etc. | |
| 55 """ | |
| 56 | |
| 57 ITEM_READ_TIME_IN_SECONDS = 3 | |
| 58 ITEM_SCROLL_REPEAT = 2 | |
| 59 MAIN_PAGE_SCROLL_REPEAT = 0 | |
| 60 | |
| 61 def _DidLoadDocument(self, action_runner): | |
| 62 for i in xrange(self.ITEMS_TO_VISIT): | |
| 63 self._NavigateToItem(action_runner, i) | |
| 64 self._ReadNewsItem(action_runner) | |
| 65 self._NavigateBack(action_runner) | |
| 66 self._ScrollMainPage(action_runner) | |
| 67 | |
| 68 def _ReadNewsItem(self, action_runner): | |
| 69 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | |
| 70 action_runner.Wait(self.ITEM_READ_TIME_IN_SECONDS) | |
| 71 action_runner.RepeatableBrowserDrivenScroll( | |
| 72 repeat_count=self.ITEM_SCROLL_REPEAT) | |
| 73 | |
| 74 def _ScrollMainPage(self, action_runner): | |
| 75 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | |
| 76 action_runner.RepeatableBrowserDrivenScroll( | |
| 77 repeat_count=self.MAIN_PAGE_SCROLL_REPEAT) | |
| 78 | |
| 79 | |
| 80 ############################################################################## | |
| 81 # News browsing stories. | |
| 82 ############################################################################## | |
| 83 | |
| 84 | |
| 85 class RedditDesktopStory(_NewsBrowsingStory): | |
| 86 """The top website in http://www.alexa.com/topsites/category/News""" | |
| 87 NAME = 'browse:news:reddit' | |
| 88 URL = 'https://www.reddit.com/top/?sort=top&t=week' | |
| 89 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 90 ITEM_SELECTOR = '.thing .title > a' | |
| 91 | |
| 92 | |
| 93 class RedditMobileStory(_NewsBrowsingStory): | |
| 94 """The top website in http://www.alexa.com/topsites/category/News""" | |
| 95 NAME = 'browse:news:reddit' | |
| 96 URL = 'https://m.reddit.com/?sort=top&time=week' | |
| 97 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 98 ITEM_SELECTOR = '.PostHeader__post-title-line' | |
| 99 IS_SINGLE_PAGE_APP = True | |
| 100 | |
| 101 | |
| 102 class CnnStory(_NewsBrowsingStory): | |
| 103 """The second top website in http://www.alexa.com/topsites/category/News""" | |
| 104 NAME = 'browse:news:cnn' | |
| 105 URL = 'http://edition.cnn.com/' | |
| 106 ITEM_SELECTOR = '.cd__content > h3 > a' | |
| 107 # TODO(ulan): Enable this story on mobile once it uses less memory and | |
| 108 # does not crash with OOM. | |
| 109 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 110 | |
| 111 | |
| 112 class NytimesMobileStory(_NewsBrowsingStory): | |
| 113 """The third top website in http://www.alexa.com/topsites/category/News""" | |
| 114 NAME = 'browse:news:nytimes' | |
| 115 URL = 'http://mobile.nytimes.com' | |
| 116 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 117 ITEM_SELECTOR = '.sfgAsset-link' | |
| 118 # Visiting more items causes OOM. | |
| 119 ITEMS_TO_VISIT = 2 | |
| 120 | |
| 121 | |
| 122 class NytimesDesktopStory(_NewsBrowsingStory): | |
| 123 """The third top website in http://www.alexa.com/topsites/category/News""" | |
| 124 NAME = 'browse:news:nytimes' | |
| 125 URL = 'http://www.nytimes.com' | |
| 126 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 127 ITEM_SELECTOR = '.story-heading > a' | |
| 128 | |
| 129 | |
| 130 class HackerNewsStory(_NewsBrowsingStory): | |
| 131 NAME = 'browse:news:hackernews' | |
| 132 URL = 'https://news.ycombinator.com' | |
| 133 ITEM_SELECTOR = '.athing .title > a' | |
| 134 | |
| 135 | |
| 136 # Facebook on desktop is not interesting because it embeds post comments | |
| 137 # directly in the main timeline. | |
| 138 class FacebookMobileStory(_NewsBrowsingStory): | |
| 139 NAME = 'browse:social:facebook' | |
| 140 URL = 'https://facebook.com/natgeo' | |
| 141 ITEM_SELECTOR = 'article ._5msj' | |
| 142 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 143 | |
| 144 | |
| 145 class TwitterMobileStory(_NewsBrowsingStory): | |
| 146 NAME = 'browse:social:twitter' | |
| 147 URL = 'https://mobile.twitter.com/cnnbrk' | |
| 148 ITEM_SELECTOR = '.Tweet-text' | |
| 149 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 150 | |
| 151 | |
| 152 class TwitterDesktopStory(_NewsBrowsingStory): | |
| 153 NAME = 'browse:social:twitter' | |
| 154 URL = 'https://twitter.com/cnnbrk' | |
| 155 ITEM_SELECTOR = '.tweet-text' | |
| 156 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 157 IS_SINGLE_PAGE_APP = True | |
| 158 | |
| 159 | |
| 160 class WashingtonPostMobileStory(_NewsBrowsingStory): | |
| 161 """Progressive website""" | |
| 162 NAME = 'browse:news:washingtonpost' | |
| 163 URL = 'https://www.washingtonpost.com/pwa' | |
| 164 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 165 ITEM_SELECTOR = '.hed > a' | |
| 166 IS_SINGLE_PAGE_APP = True | |
| 167 | |
| 168 def _DidLoadDocument(self, action_runner): | |
| 169 # Close the popup window. | |
| 170 action_runner.ClickElement(selector='.close') | |
| 171 self._DidLoadDocument(action_runner) | |
| 172 | |
| 173 | |
| 174 class QqMobileStory(_NewsBrowsingStory): | |
| 175 NAME = 'browse:news:qq' | |
| 176 URL = 'http://news.qq.com' | |
| 177 # qq.com on desktop opens a news item in a separate tab, for which the back | |
| 178 # button does not work. | |
| 179 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 180 ITEM_SELECTOR = '.list .full a' | |
| 181 | |
| 182 | |
| 183 ############################################################################## | |
| 184 # Browsing story sets. | |
| 185 ############################################################################## | |
| 186 | |
| 187 | |
| 188 def _IterAllNewsBrowsingStoryClasses(): | |
| 189 return system_health_story.IterAllStoryClasses( | |
| 190 sys.modules[__name__], _NewsBrowsingStory) | |
| 191 | |
| 192 | |
| 193 class _NewsBrowsingStorySet(story.StorySet): | |
| 194 PLATFORM = NotImplemented | |
| 195 | |
| 196 def __init__(self): | |
| 197 super(_NewsBrowsingStorySet, self).__init__( | |
| 198 archive_data_file=('../data/news_%s.json' % self.PLATFORM), | |
| 199 cloud_storage_bucket=story.PARTNER_BUCKET) | |
| 200 for story_class in _IterAllNewsBrowsingStoryClasses(): | |
| 201 if self.PLATFORM not in story_class.SUPPORTED_PLATFORMS: | |
| 202 continue | |
| 203 self.AddStory(story_class(self)) | |
| 204 | |
| 205 | |
| 206 class DesktopNewsStorySet(_NewsBrowsingStorySet): | |
| 207 PLATFORM = platforms.DESKTOP | |
| 208 | |
| 209 | |
| 210 class MobileNewsStorySet(_NewsBrowsingStorySet): | |
| 211 PLATFORM = platforms.MOBILE | |
| OLD | NEW |