OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from page_sets.system_health import platforms | 5 from page_sets.system_health import platforms |
6 from page_sets.system_health import system_health_story | 6 from page_sets.system_health import system_health_story |
7 | 7 |
8 | 8 |
9 class _BrowsingStory(system_health_story.SystemHealthStory): | 9 class _BrowsingStory(system_health_story.SystemHealthStory): |
10 """Abstract base class for browsing stories. | 10 """Abstract base class for browsing stories. |
11 | 11 |
12 A browsing story visits items on the main page. Subclasses provide | 12 A browsing story visits items on the main page. Subclasses provide |
13 CSS selector to identify the items and implement interaction using | 13 CSS selector to identify the items and implement interaction using |
14 the helper methods of this class. | 14 the helper methods of this class. |
15 """ | 15 """ |
16 | 16 |
17 IS_SINGLE_PAGE_APP = False | 17 IS_SINGLE_PAGE_APP = False |
18 ITEM_SELECTOR = NotImplemented | 18 ITEM_SELECTOR = NotImplemented |
19 ITEMS_TO_VISIT = 4 | |
20 ABSTRACT_STORY = True | 19 ABSTRACT_STORY = True |
21 | 20 |
22 def _WaitForNavigation(self, action_runner): | 21 def _WaitForNavigation(self, action_runner): |
23 if not self.IS_SINGLE_PAGE_APP: | 22 if not self.IS_SINGLE_PAGE_APP: |
24 action_runner.WaitForNavigate() | 23 action_runner.WaitForNavigate() |
25 | 24 |
26 def _NavigateToItem(self, action_runner, index): | 25 def _NavigateToItem(self, action_runner, index): |
27 item_selector = 'document.querySelectorAll("%s")[%d]' % ( | 26 item_selector = 'document.querySelectorAll("%s")[%d]' % ( |
28 self.ITEM_SELECTOR, index) | 27 self.ITEM_SELECTOR, index) |
29 self._ClickLink(action_runner, item_selector) | 28 self._ClickLink(action_runner, item_selector) |
30 | 29 |
31 def _ClickLink(self, action_runner, element_function): | 30 def _ClickLink(self, action_runner, element_function): |
32 action_runner.WaitForElement(element_function=element_function) | 31 action_runner.WaitForElement(element_function=element_function) |
33 action_runner.ClickElement(element_function=element_function) | 32 action_runner.ClickElement(element_function=element_function) |
34 self._WaitForNavigation(action_runner) | 33 self._WaitForNavigation(action_runner) |
35 | 34 |
36 def _NavigateBack(self, action_runner): | 35 def _NavigateBack(self, action_runner): |
37 action_runner.ExecuteJavaScript('window.history.back()') | 36 action_runner.ExecuteJavaScript('window.history.back()') |
38 self._WaitForNavigation(action_runner) | 37 self._WaitForNavigation(action_runner) |
39 | 38 |
40 | 39 |
| 40 ############################################################################## |
| 41 # News browsing stories. |
| 42 ############################################################################## |
| 43 |
| 44 |
41 class _NewsBrowsingStory(_BrowsingStory): | 45 class _NewsBrowsingStory(_BrowsingStory): |
42 """Abstract base class for news user stories. | 46 """Abstract base class for news user stories. |
43 | 47 |
44 A news story imitates browsing a news website: | 48 A news story imitates browsing a news website: |
45 1. Load the main page. | 49 1. Load the main page. |
46 2. Open and scroll the first news item. | 50 2. Open and scroll the first news item. |
47 3. Go back to the main page and scroll it. | 51 3. Go back to the main page and scroll it. |
48 4. Open and scroll the second news item. | 52 4. Open and scroll the second news item. |
49 5. Go back to the main page and scroll it. | 53 5. Go back to the main page and scroll it. |
50 6. etc. | 54 6. etc. |
51 """ | 55 """ |
52 | 56 |
53 ITEM_READ_TIME_IN_SECONDS = 3 | 57 ITEM_READ_TIME_IN_SECONDS = 3 |
54 ITEM_SCROLL_REPEAT = 2 | 58 ITEM_SCROLL_REPEAT = 2 |
| 59 ITEMS_TO_VISIT = 4 |
55 MAIN_PAGE_SCROLL_REPEAT = 0 | 60 MAIN_PAGE_SCROLL_REPEAT = 0 |
56 ABSTRACT_STORY = True | 61 ABSTRACT_STORY = True |
57 | 62 |
58 def _DidLoadDocument(self, action_runner): | 63 def _DidLoadDocument(self, action_runner): |
59 for i in xrange(self.ITEMS_TO_VISIT): | 64 for i in xrange(self.ITEMS_TO_VISIT): |
60 self._NavigateToItem(action_runner, i) | 65 self._NavigateToItem(action_runner, i) |
61 self._ReadNewsItem(action_runner) | 66 self._ReadNewsItem(action_runner) |
62 self._NavigateBack(action_runner) | 67 self._NavigateBack(action_runner) |
63 self._ScrollMainPage(action_runner) | 68 self._ScrollMainPage(action_runner) |
64 | 69 |
65 def _ReadNewsItem(self, action_runner): | 70 def _ReadNewsItem(self, action_runner): |
66 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | 71 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
67 action_runner.Wait(self.ITEM_READ_TIME_IN_SECONDS) | 72 action_runner.Wait(self.ITEM_READ_TIME_IN_SECONDS) |
68 action_runner.RepeatableBrowserDrivenScroll( | 73 action_runner.RepeatableBrowserDrivenScroll( |
69 repeat_count=self.ITEM_SCROLL_REPEAT) | 74 repeat_count=self.ITEM_SCROLL_REPEAT) |
70 | 75 |
71 def _ScrollMainPage(self, action_runner): | 76 def _ScrollMainPage(self, action_runner): |
72 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | 77 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
73 action_runner.RepeatableBrowserDrivenScroll( | 78 action_runner.RepeatableBrowserDrivenScroll( |
74 repeat_count=self.MAIN_PAGE_SCROLL_REPEAT) | 79 repeat_count=self.MAIN_PAGE_SCROLL_REPEAT) |
75 | 80 |
76 | 81 |
77 ############################################################################## | |
78 # News browsing stories. | |
79 ############################################################################## | |
80 | |
81 | |
82 class CnnStory(_NewsBrowsingStory): | 82 class CnnStory(_NewsBrowsingStory): |
83 """The second top website in http://www.alexa.com/topsites/category/News""" | 83 """The second top website in http://www.alexa.com/topsites/category/News""" |
84 NAME = 'browse:news:cnn' | 84 NAME = 'browse:news:cnn' |
85 URL = 'http://edition.cnn.com/' | 85 URL = 'http://edition.cnn.com/' |
86 ITEM_SELECTOR = '.cd__content > h3 > a' | 86 ITEM_SELECTOR = '.cd__content > h3 > a' |
87 ITEMS_TO_VISIT = 2 | 87 ITEMS_TO_VISIT = 2 |
88 # TODO(ulan): Enable this story on mobile once it uses less memory and | 88 # TODO(ulan): Enable this story on mobile once it uses less memory and |
89 # does not crash with OOM. | 89 # does not crash with OOM. |
90 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | 90 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY |
91 | 91 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 def _DidLoadDocument(self, action_runner): | 205 def _DidLoadDocument(self, action_runner): |
206 # Close the popup window. On Nexus 9 (and probably other tables) the popup | 206 # Close the popup window. On Nexus 9 (and probably other tables) the popup |
207 # window does not have a "Close" button, instead it has only a "Send link | 207 # window does not have a "Close" button, instead it has only a "Send link |
208 # to phone" button. So on tablets we run with the popup window open. The | 208 # to phone" button. So on tablets we run with the popup window open. The |
209 # popup is transparent, so this is mostly an aesthetical issue. | 209 # popup is transparent, so this is mostly an aesthetical issue. |
210 has_button = action_runner.EvaluateJavaScript( | 210 has_button = action_runner.EvaluateJavaScript( |
211 '!!document.querySelector("%s")' % self._CLOSE_BUTTON_SELECTOR) | 211 '!!document.querySelector("%s")' % self._CLOSE_BUTTON_SELECTOR) |
212 if has_button: | 212 if has_button: |
213 action_runner.ClickElement(selector=self._CLOSE_BUTTON_SELECTOR) | 213 action_runner.ClickElement(selector=self._CLOSE_BUTTON_SELECTOR) |
214 super(WashingtonPostMobileStory, self)._DidLoadDocument(action_runner) | 214 super(WashingtonPostMobileStory, self)._DidLoadDocument(action_runner) |
| 215 |
| 216 |
| 217 ############################################################################## |
| 218 # Media browsing stories. |
| 219 ############################################################################## |
| 220 |
| 221 |
| 222 class _MediaBrowsingStory(_BrowsingStory): |
| 223 """Abstract base class for media user stories |
| 224 |
| 225 A media story imitates browsing a website with photo or video content: |
| 226 1. Load a page showing a media item |
| 227 2. Click on the next link to go to the next media item |
| 228 3. etc. |
| 229 """ |
| 230 |
| 231 ABSTRACT_STORY = True |
| 232 ITEM_VIEW_TIME_IN_SECONDS = 3 |
| 233 ITEMS_TO_VISIT = 15 |
| 234 ITEM_SELECTOR_INDEX = 0 |
| 235 |
| 236 def _DidLoadDocument(self, action_runner): |
| 237 for _ in xrange(self.ITEMS_TO_VISIT): |
| 238 self._NavigateToItem(action_runner, self.ITEM_SELECTOR_INDEX) |
| 239 self._ViewMediaItem(action_runner) |
| 240 |
| 241 def _ViewMediaItem(self, action_runner): |
| 242 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
| 243 action_runner.Wait(self.ITEM_VIEW_TIME_IN_SECONDS) |
| 244 |
| 245 |
| 246 class ImgurMobileStory(_MediaBrowsingStory): |
| 247 NAME = 'browse:media:imgur' |
| 248 URL = 'http://imgur.com/gallery/5UlBN' |
| 249 ITEM_SELECTOR = '.Navbar-customAction' |
| 250 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY |
| 251 IS_SINGLE_PAGE_APP = True |
| 252 |
| 253 |
| 254 class ImgurDesktopStory(_MediaBrowsingStory): |
| 255 NAME = 'browse:media:imgur' |
| 256 URL = 'http://imgur.com/gallery/5UlBN' |
| 257 ITEM_SELECTOR = '.navNext' |
| 258 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY |
| 259 IS_SINGLE_PAGE_APP = True |
| 260 |
| 261 |
| 262 class YouTubeMobileStory(_MediaBrowsingStory): |
| 263 NAME = 'browse:media:youtube' |
| 264 URL = 'https://m.youtube.com/watch?v=QGfhS1hfTWw&autoplay=false' |
| 265 ITEM_SELECTOR = '._mhgb > a' |
| 266 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY |
| 267 IS_SINGLE_PAGE_APP = True |
| 268 ITEM_SELECTOR_INDEX = 3 |
| 269 |
| 270 |
| 271 class YouTubeDesktopStory(_MediaBrowsingStory): |
| 272 NAME = 'browse:media:youtube' |
| 273 URL = 'https://www.youtube.com/watch?v=QGfhS1hfTWw&autoplay=false' |
| 274 ITEM_SELECTOR = '.yt-uix-simple-thumb-related' |
| 275 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY |
| 276 IS_SINGLE_PAGE_APP = True |
| 277 # A longer view time allows videos to load and play. |
| 278 ITEM_VIEW_TIME_IN_SECONDS = 5 |
| 279 ITEMS_TO_VISIT = 8 |
| 280 ITEM_SELECTOR_INDEX = 3 |
| 281 |
| 282 |
| 283 class FacebookMobileStory(_MediaBrowsingStory): |
| 284 NAME = 'browse:media:facebook' |
| 285 URL = ( |
| 286 'https://m.facebook.com/rihanna/photos/a.207477806675.138795.10092511675/1
0153911739606676/?type=3&source=54&ref=page_internal') |
| 287 ITEM_SELECTOR = '._57-r.touchable' |
| 288 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY |
| 289 IS_SINGLE_PAGE_APP = True |
| 290 ITEM_SELECTOR_INDEX = 0 |
| 291 |
| 292 def _Login(self, action_runner): |
| 293 action_runner.Navigate('https://m.facebook.com/rihanna') |
| 294 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
| 295 |
| 296 |
| 297 class FacebookDesktopStory(_MediaBrowsingStory): |
| 298 NAME = 'browse:media:facebook' |
| 299 URL = ( |
| 300 'https://www.facebook.com/rihanna/photos/a.207477806675.138795.10092511675
/10153911739606676/?type=3&theater') |
| 301 ITEM_SELECTOR = '.snowliftPager.next' |
| 302 # Recording currently does not work. The page gets stuck in the |
| 303 # theater viewer. |
| 304 SUPPORTED_PLATFORMS = platforms.NO_PLATFORMS |
| 305 IS_SINGLE_PAGE_APP = True |
| 306 |
| 307 def _Login(self, action_runner): |
| 308 action_runner.Navigate('https://www.facebook.com/rihanna') |
| 309 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
OLD | NEW |