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 import sys | |
6 | |
7 from page_sets.system_health import platforms | 5 from page_sets.system_health import platforms |
8 from page_sets.system_health import system_health_story | 6 from page_sets.system_health import system_health_story |
9 | 7 |
10 from telemetry import story | |
11 | |
12 | 8 |
13 class _BrowsingStory(system_health_story.SystemHealthStory): | 9 class _BrowsingStory(system_health_story.SystemHealthStory): |
14 """Abstract base class for browsing stories. | 10 """Abstract base class for browsing stories. |
15 | 11 |
16 A browsing story visits items on the main page. Subclasses provide | 12 A browsing story visits items on the main page. Subclasses provide |
17 CSS selector to identify the items and implement interaction using | 13 CSS selector to identify the items and implement interaction using |
18 the helper methods of this class. | 14 the helper methods of this class. |
19 """ | 15 """ |
20 | 16 |
21 IS_SINGLE_PAGE_APP = False | 17 IS_SINGLE_PAGE_APP = False |
22 ITEM_SELECTOR = NotImplemented | 18 ITEM_SELECTOR = NotImplemented |
23 ITEMS_TO_VISIT = 4 | 19 ITEMS_TO_VISIT = 4 |
24 | 20 ABSTRACT_STORY = True |
25 def __init__(self, story_set): | |
26 super(_BrowsingStory, self).__init__( | |
27 story_set, take_memory_measurement=False) | |
28 | 21 |
29 def _WaitForNavigation(self, action_runner): | 22 def _WaitForNavigation(self, action_runner): |
30 if not self.IS_SINGLE_PAGE_APP: | 23 if not self.IS_SINGLE_PAGE_APP: |
31 action_runner.WaitForNavigate() | 24 action_runner.WaitForNavigate() |
32 | 25 |
33 def _NavigateToItem(self, action_runner, index): | 26 def _NavigateToItem(self, action_runner, index): |
34 item_selector = 'document.querySelectorAll("%s")[%d]' % ( | 27 item_selector = 'document.querySelectorAll("%s")[%d]' % ( |
35 self.ITEM_SELECTOR, index) | 28 self.ITEM_SELECTOR, index) |
36 self._ClickLink(action_runner, item_selector) | 29 self._ClickLink(action_runner, item_selector) |
37 | 30 |
(...skipping 15 matching lines...) Expand all Loading... |
53 2. Open and scroll the first news item. | 46 2. Open and scroll the first news item. |
54 3. Go back to the main page and scroll it. | 47 3. Go back to the main page and scroll it. |
55 4. Open and scroll the second news item. | 48 4. Open and scroll the second news item. |
56 5. Go back to the main page and scroll it. | 49 5. Go back to the main page and scroll it. |
57 6. etc. | 50 6. etc. |
58 """ | 51 """ |
59 | 52 |
60 ITEM_READ_TIME_IN_SECONDS = 3 | 53 ITEM_READ_TIME_IN_SECONDS = 3 |
61 ITEM_SCROLL_REPEAT = 2 | 54 ITEM_SCROLL_REPEAT = 2 |
62 MAIN_PAGE_SCROLL_REPEAT = 0 | 55 MAIN_PAGE_SCROLL_REPEAT = 0 |
| 56 ABSTRACT_STORY = True |
63 | 57 |
64 def _DidLoadDocument(self, action_runner): | 58 def _DidLoadDocument(self, action_runner): |
65 for i in xrange(self.ITEMS_TO_VISIT): | 59 for i in xrange(self.ITEMS_TO_VISIT): |
66 self._NavigateToItem(action_runner, i) | 60 self._NavigateToItem(action_runner, i) |
67 self._ReadNewsItem(action_runner) | 61 self._ReadNewsItem(action_runner) |
68 self._NavigateBack(action_runner) | 62 self._NavigateBack(action_runner) |
69 self._ScrollMainPage(action_runner) | 63 self._ScrollMainPage(action_runner) |
70 | 64 |
71 def _ReadNewsItem(self, action_runner): | 65 def _ReadNewsItem(self, action_runner): |
72 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | 66 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 NAME = 'browse:news:washingtonpost' | 170 NAME = 'browse:news:washingtonpost' |
177 URL = 'https://www.washingtonpost.com/pwa' | 171 URL = 'https://www.washingtonpost.com/pwa' |
178 IS_SINGLE_PAGE_APP = True | 172 IS_SINGLE_PAGE_APP = True |
179 ITEM_SELECTOR = '.hed > a' | 173 ITEM_SELECTOR = '.hed > a' |
180 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | 174 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY |
181 | 175 |
182 def _DidLoadDocument(self, action_runner): | 176 def _DidLoadDocument(self, action_runner): |
183 # Close the popup window. | 177 # Close the popup window. |
184 action_runner.ClickElement(selector='.close') | 178 action_runner.ClickElement(selector='.close') |
185 super(WashingtonPostMobileStory, self)._DidLoadDocument(action_runner) | 179 super(WashingtonPostMobileStory, self)._DidLoadDocument(action_runner) |
186 | |
187 | |
188 ############################################################################## | |
189 # Browsing story sets. | |
190 ############################################################################## | |
191 | |
192 | |
193 def _IterAllNewsBrowsingStoryClasses(): | |
194 return system_health_story.IterAllStoryClasses( | |
195 sys.modules[__name__], _NewsBrowsingStory) | |
196 | |
197 | |
198 class _BrowsingSystemHealthStorySet(story.StorySet): | |
199 PLATFORM = NotImplemented | |
200 | |
201 def __init__(self): | |
202 super(_BrowsingSystemHealthStorySet, self).__init__( | |
203 archive_data_file=('../data/browsing_%s.json' % self.PLATFORM), | |
204 cloud_storage_bucket=story.PARTNER_BUCKET) | |
205 for story_class in _IterAllNewsBrowsingStoryClasses(): | |
206 if self.PLATFORM not in story_class.SUPPORTED_PLATFORMS: | |
207 continue | |
208 self.AddStory(story_class(self)) | |
209 | |
210 | |
211 class DesktopBrowsingSystemHealthStorySet(_BrowsingSystemHealthStorySet): | |
212 PLATFORM = platforms.DESKTOP | |
213 | |
214 | |
215 class MobileBrowsingSystemHealthStorySet(_BrowsingSystemHealthStorySet): | |
216 PLATFORM = platforms.MOBILE | |
OLD | NEW |