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.login_helpers import facebook_login | |
5 from page_sets.system_health import platforms | 6 from page_sets.system_health import platforms |
6 from page_sets.system_health import system_health_story | 7 from page_sets.system_health import system_health_story |
7 | 8 |
8 | 9 |
9 class _BrowsingStory(system_health_story.SystemHealthStory): | 10 class _BrowsingStory(system_health_story.SystemHealthStory): |
10 """Abstract base class for browsing stories. | 11 """Abstract base class for browsing stories. |
11 | 12 |
12 A browsing story visits items on the main page. Subclasses provide | 13 A browsing story visits items on the main page. Subclasses provide |
13 CSS selector to identify the items and implement interaction using | 14 CSS selector to identify the items and implement interaction using |
14 the helper methods of this class. | 15 the helper methods of this class. |
15 """ | 16 """ |
16 | 17 |
17 IS_SINGLE_PAGE_APP = False | 18 IS_SINGLE_PAGE_APP = False |
18 ITEM_SELECTOR = NotImplemented | 19 ITEM_SELECTOR = NotImplemented |
19 ITEMS_TO_VISIT = 4 | 20 ITEMS_TO_VISIT = 4 |
petrcermak
2016/08/01 11:22:30
This field is currently not used anywhere in the b
Hannes Payer (out of office)
2016/08/04 11:38:01
Moved it to the _NewsBrowsingStory.
| |
20 ABSTRACT_STORY = True | 21 ABSTRACT_STORY = True |
21 | 22 |
22 def _WaitForNavigation(self, action_runner): | 23 def _WaitForNavigation(self, action_runner): |
23 if not self.IS_SINGLE_PAGE_APP: | 24 if not self.IS_SINGLE_PAGE_APP: |
24 action_runner.WaitForNavigate() | 25 action_runner.WaitForNavigate() |
25 | 26 |
26 def _NavigateToItem(self, action_runner, index): | 27 def _NavigateToItem(self, action_runner, index): |
27 item_selector = 'document.querySelectorAll("%s")[%d]' % ( | 28 item_selector = 'document.querySelectorAll("%s")[%d]' % ( |
28 self.ITEM_SELECTOR, index) | 29 self.ITEM_SELECTOR, index) |
29 self._ClickLink(action_runner, item_selector) | 30 self._ClickLink(action_runner, item_selector) |
30 | 31 |
31 def _ClickLink(self, action_runner, element_function): | 32 def _ClickLink(self, action_runner, element_function): |
32 action_runner.WaitForElement(element_function=element_function) | 33 action_runner.WaitForElement(element_function=element_function) |
33 action_runner.ClickElement(element_function=element_function) | 34 action_runner.ClickElement(element_function=element_function) |
34 self._WaitForNavigation(action_runner) | 35 self._WaitForNavigation(action_runner) |
35 | 36 |
36 def _NavigateBack(self, action_runner): | 37 def _NavigateBack(self, action_runner): |
37 action_runner.ExecuteJavaScript('window.history.back()') | 38 action_runner.ExecuteJavaScript('window.history.back()') |
38 self._WaitForNavigation(action_runner) | 39 self._WaitForNavigation(action_runner) |
39 | 40 |
40 | 41 |
42 ############################################################################## | |
43 # News browsing stories. | |
44 ############################################################################## | |
45 | |
46 | |
41 class _NewsBrowsingStory(_BrowsingStory): | 47 class _NewsBrowsingStory(_BrowsingStory): |
42 """Abstract base class for news user stories. | 48 """Abstract base class for news user stories. |
43 | 49 |
44 A news story imitates browsing a news website: | 50 A news story imitates browsing a news website: |
45 1. Load the main page. | 51 1. Load the main page. |
46 2. Open and scroll the first news item. | 52 2. Open and scroll the first news item. |
47 3. Go back to the main page and scroll it. | 53 3. Go back to the main page and scroll it. |
48 4. Open and scroll the second news item. | 54 4. Open and scroll the second news item. |
49 5. Go back to the main page and scroll it. | 55 5. Go back to the main page and scroll it. |
50 6. etc. | 56 6. etc. |
(...skipping 16 matching lines...) Expand all Loading... | |
67 action_runner.Wait(self.ITEM_READ_TIME_IN_SECONDS) | 73 action_runner.Wait(self.ITEM_READ_TIME_IN_SECONDS) |
68 action_runner.RepeatableBrowserDrivenScroll( | 74 action_runner.RepeatableBrowserDrivenScroll( |
69 repeat_count=self.ITEM_SCROLL_REPEAT) | 75 repeat_count=self.ITEM_SCROLL_REPEAT) |
70 | 76 |
71 def _ScrollMainPage(self, action_runner): | 77 def _ScrollMainPage(self, action_runner): |
72 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | 78 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
73 action_runner.RepeatableBrowserDrivenScroll( | 79 action_runner.RepeatableBrowserDrivenScroll( |
74 repeat_count=self.MAIN_PAGE_SCROLL_REPEAT) | 80 repeat_count=self.MAIN_PAGE_SCROLL_REPEAT) |
75 | 81 |
76 | 82 |
77 ############################################################################## | |
78 # News browsing stories. | |
79 ############################################################################## | |
80 | |
81 | |
82 class CnnStory(_NewsBrowsingStory): | 83 class CnnStory(_NewsBrowsingStory): |
83 """The second top website in http://www.alexa.com/topsites/category/News""" | 84 """The second top website in http://www.alexa.com/topsites/category/News""" |
84 NAME = 'browse:news:cnn' | 85 NAME = 'browse:news:cnn' |
85 URL = 'http://edition.cnn.com/' | 86 URL = 'http://edition.cnn.com/' |
86 ITEM_SELECTOR = '.cd__content > h3 > a' | 87 ITEM_SELECTOR = '.cd__content > h3 > a' |
87 ITEMS_TO_VISIT = 2 | 88 ITEMS_TO_VISIT = 2 |
88 # TODO(ulan): Enable this story on mobile once it uses less memory and | 89 # TODO(ulan): Enable this story on mobile once it uses less memory and |
89 # does not crash with OOM. | 90 # does not crash with OOM. |
90 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | 91 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY |
91 | 92 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 def _DidLoadDocument(self, action_runner): | 206 def _DidLoadDocument(self, action_runner): |
206 # Close the popup window. On Nexus 9 (and probably other tables) the popup | 207 # 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 | 208 # 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 | 209 # 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. | 210 # popup is transparent, so this is mostly an aesthetical issue. |
210 has_button = action_runner.EvaluateJavaScript( | 211 has_button = action_runner.EvaluateJavaScript( |
211 '!!document.querySelector("%s")' % self._CLOSE_BUTTON_SELECTOR) | 212 '!!document.querySelector("%s")' % self._CLOSE_BUTTON_SELECTOR) |
212 if has_button: | 213 if has_button: |
213 action_runner.ClickElement(selector=self._CLOSE_BUTTON_SELECTOR) | 214 action_runner.ClickElement(selector=self._CLOSE_BUTTON_SELECTOR) |
214 super(WashingtonPostMobileStory, self)._DidLoadDocument(action_runner) | 215 super(WashingtonPostMobileStory, self)._DidLoadDocument(action_runner) |
216 | |
217 | |
218 ############################################################################## | |
219 # Media browsing stories. | |
petrcermak
2016/08/01 11:22:30
Can you please update the corresponding loading st
Hannes Payer (out of office)
2016/08/04 11:38:01
Added imgur to the load stories.
Changed the links
| |
220 ############################################################################## | |
221 | |
222 | |
223 class _MediaBrowsingStory(_BrowsingStory): | |
224 """ Abstract base class for media user stories | |
petrcermak
2016/08/01 11:22:30
nit: remove space before "Abstract"
Hannes Payer (out of office)
2016/08/04 11:38:01
Done.
| |
225 | |
226 A media story imitates browsing a website with photo or video content: | |
227 1. Load a page showing a media item | |
228 2. Click on the next link to go to the next media item | |
229 3. etc. | |
230 """ | |
231 | |
232 ABSTRACT_STORY = True | |
233 ITEM_VIEW_TIME_IN_SECONDS = 1 | |
234 ITEMS_TO_VISIT = 30 | |
235 ITEM_SELECTOR_INDEX = 0 | |
236 | |
237 def _DidLoadDocument(self, action_runner): | |
238 for _ in xrange(self.ITEMS_TO_VISIT): | |
239 self._NavigateToItem(action_runner, self.ITEM_SELECTOR_INDEX) | |
240 self._ViewMediaItem(action_runner) | |
241 | |
242 def _ViewMediaItem(self, action_runner): | |
243 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | |
244 action_runner.Wait(self.ITEM_VIEW_TIME_IN_SECONDS) | |
245 | |
246 | |
247 class ImgurMobileStory(_MediaBrowsingStory): | |
248 NAME = 'browse:media:imgur' | |
249 URL = 'http://imgur.com/gallery/5UlBN' | |
250 ITEM_SELECTOR = '.Navbar-customAction' | |
251 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
252 IS_SINGLE_PAGE_APP = True | |
253 | |
254 | |
255 class ImgurDesktopStory(_MediaBrowsingStory): | |
256 NAME = 'browse:media:imgur' | |
257 URL = 'http://imgur.com/gallery/5UlBN' | |
258 ITEM_SELECTOR = '.navNext' | |
259 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
260 IS_SINGLE_PAGE_APP = True | |
261 | |
262 | |
263 class YoutubeMobileStory(_MediaBrowsingStory): | |
264 NAME = 'browse:media:youtube' | |
265 URL = 'https://m.youtube.com/watch?v=njCDZWTI-xg' | |
266 ITEM_SELECTOR = '._mpfb > a' | |
267 IS_SINGLE_PAGE_APP = True | |
268 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
269 ITEM_VIEW_TIME_IN_SECONDS = 2 | |
270 ITEMS_TO_VISIT = 15 | |
271 ITEM_SELECTOR_INDEX = 3 | |
272 | |
273 | |
274 class YoutubeDesktopStory(_MediaBrowsingStory): | |
275 NAME = 'browse:media:youtube' | |
276 URL = 'https://www.youtube.com/watch?v=Ic07xTJoP34' | |
277 ITEM_SELECTOR = '.yt-uix-simple-thumb-related' | |
278 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
279 IS_SINGLE_PAGE_APP = True | |
280 ITEM_VIEW_TIME_IN_SECONDS = 2 | |
charliea (OOO until 10-5)
2016/07/29 20:10:01
IMO this (and the corresponding mobile story time)
Hannes Payer (out of office)
2016/08/04 11:38:01
Done.
| |
281 ITEMS_TO_VISIT = 15 | |
282 | |
283 | |
284 class FacebookMobileStory(_MediaBrowsingStory): | |
285 NAME = 'browse:media:facebookphotos' | |
286 URL = ( | |
287 'https://facebook.com/photo.php?fbid=10154398154450513&id=255110695512&set =a.406278500512.172778.255110695512&source=54&refid=13') | |
288 ITEM_SELECTOR = '._57-p > a' | |
289 IS_SINGLE_PAGE_APP = True | |
290 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
291 ITEM_VIEW_TIME_IN_SECONDS = 2 | |
292 ITEMS_TO_VISIT = 20 | |
293 ITEM_SELECTOR_INDEX = 1 | |
294 | |
295 | |
296 class FacebookDesktopStory(_MediaBrowsingStory): | |
297 NAME = 'browse:media:facebookphotos' | |
298 URL = ( | |
299 'https://www.facebook.com/NASA/photos/a.67899501771.69169.54971236771/1015 4267233981772/?type=3&theater') | |
300 ITEM_SELECTOR = '.snowliftPager.next' | |
301 IS_SINGLE_PAGE_APP = True | |
302 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
303 ITEM_VIEW_TIME_IN_SECONDS = 2 | |
304 ITEMS_TO_VISIT = 20 | |
305 | |
306 def _Login(self, action_runner): | |
307 facebook_login.LoginWithDesktopSite(action_runner, 'facebook3', | |
308 self.credentials_path) | |
petrcermak
2016/08/01 11:22:30
nit: invalid indentation. The two basic options ar
| |
OLD | NEW |