| 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 from page_sets.login_helpers import pinterest_login |
| 9 |
| 8 from telemetry import decorators | 10 from telemetry import decorators |
| 9 | 11 |
| 10 | 12 |
| 11 class _BrowsingStory(system_health_story.SystemHealthStory): | 13 class _BrowsingStory(system_health_story.SystemHealthStory): |
| 12 """Abstract base class for browsing stories. | 14 """Abstract base class for browsing stories. |
| 13 | 15 |
| 14 A browsing story visits items on the main page. Subclasses provide | 16 A browsing story visits items on the main page. Subclasses provide |
| 15 CSS selector to identify the items and implement interaction using | 17 CSS selector to identify the items and implement interaction using |
| 16 the helper methods of this class. | 18 the helper methods of this class. |
| 17 """ | 19 """ |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 A media story imitates browsing a website with photo or video content: | 229 A media story imitates browsing a website with photo or video content: |
| 228 1. Load a page showing a media item | 230 1. Load a page showing a media item |
| 229 2. Click on the next link to go to the next media item | 231 2. Click on the next link to go to the next media item |
| 230 3. etc. | 232 3. etc. |
| 231 """ | 233 """ |
| 232 | 234 |
| 233 ABSTRACT_STORY = True | 235 ABSTRACT_STORY = True |
| 234 ITEM_VIEW_TIME_IN_SECONDS = 3 | 236 ITEM_VIEW_TIME_IN_SECONDS = 3 |
| 235 ITEMS_TO_VISIT = 15 | 237 ITEMS_TO_VISIT = 15 |
| 236 ITEM_SELECTOR_INDEX = 0 | 238 ITEM_SELECTOR_INDEX = 0 |
| 239 INCREMENT_INDEX_AFTER_EACH_ITEM = False |
| 237 | 240 |
| 238 def _DidLoadDocument(self, action_runner): | 241 def _DidLoadDocument(self, action_runner): |
| 242 index = self.ITEM_SELECTOR_INDEX |
| 239 for _ in xrange(self.ITEMS_TO_VISIT): | 243 for _ in xrange(self.ITEMS_TO_VISIT): |
| 240 self._NavigateToItem(action_runner, self.ITEM_SELECTOR_INDEX) | 244 self._NavigateToItem(action_runner, index) |
| 241 self._ViewMediaItem(action_runner) | 245 self._ViewMediaItem(action_runner, index) |
| 246 if self.INCREMENT_INDEX_AFTER_EACH_ITEM: |
| 247 index += 1 |
| 242 | 248 |
| 243 def _ViewMediaItem(self, action_runner): | 249 |
| 250 def _ViewMediaItem(self, action_runner, index): |
| 251 del index # Unused. |
| 244 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | 252 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
| 245 action_runner.Wait(self.ITEM_VIEW_TIME_IN_SECONDS) | 253 action_runner.Wait(self.ITEM_VIEW_TIME_IN_SECONDS) |
| 246 | 254 |
| 247 | 255 |
| 248 class ImgurMobileStory(_MediaBrowsingStory): | 256 class ImgurMobileStory(_MediaBrowsingStory): |
| 249 NAME = 'browse:media:imgur' | 257 NAME = 'browse:media:imgur' |
| 250 URL = 'http://imgur.com/gallery/5UlBN' | 258 URL = 'http://imgur.com/gallery/5UlBN' |
| 251 ITEM_SELECTOR = '.Navbar-customAction' | 259 ITEM_SELECTOR = '.Navbar-customAction' |
| 252 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | 260 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY |
| 253 IS_SINGLE_PAGE_APP = True | 261 IS_SINGLE_PAGE_APP = True |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 302 |
| 295 class FacebookPhotosDesktopStory(_MediaBrowsingStory): | 303 class FacebookPhotosDesktopStory(_MediaBrowsingStory): |
| 296 NAME = 'browse:media:facebook_photos' | 304 NAME = 'browse:media:facebook_photos' |
| 297 URL = ( | 305 URL = ( |
| 298 'https://www.facebook.com/rihanna/photos/a.207477806675.138795.10092511675
/10153911739606676/?type=3&theater') | 306 'https://www.facebook.com/rihanna/photos/a.207477806675.138795.10092511675
/10153911739606676/?type=3&theater') |
| 299 ITEM_SELECTOR = '.snowliftPager.next' | 307 ITEM_SELECTOR = '.snowliftPager.next' |
| 300 # Recording currently does not work. The page gets stuck in the | 308 # Recording currently does not work. The page gets stuck in the |
| 301 # theater viewer. | 309 # theater viewer. |
| 302 SUPPORTED_PLATFORMS = platforms.NO_PLATFORMS | 310 SUPPORTED_PLATFORMS = platforms.NO_PLATFORMS |
| 303 IS_SINGLE_PAGE_APP = True | 311 IS_SINGLE_PAGE_APP = True |
| 312 |
| 313 |
| 314 class TumblrDesktopStory(_MediaBrowsingStory): |
| 315 NAME = 'browse:media:tumblr' |
| 316 URL = 'https://tumblr.com/search/gifs' |
| 317 ITEM_SELECTOR = '.photo' |
| 318 IS_SINGLE_PAGE_APP = True |
| 319 ITEMS_TO_VISIT = 2 # Increase when crbug.com/651909 is implemented. |
| 320 ITEM_VIEW_TIME_IN_SECONDS = 5 |
| 321 INCREMENT_INDEX_AFTER_EACH_ITEM = True |
| 322 SUPPORTED_PLATFORMS = platforms.NO_PLATFORMS # crbug.com/651909. |
| 323 |
| 324 def _ViewMediaItem(self, action_runner, index): |
| 325 super(TumblrDesktopStory, self)._ViewMediaItem(action_runner, index) |
| 326 action_runner.MouseClick(selector='#tumblr_lightbox_center_image') |
| 327 |
| 328 |
| 329 class PinterestDesktopStory(_MediaBrowsingStory): |
| 330 NAME = 'browse:media:pinterest' |
| 331 URL = 'https://pinterest.com' |
| 332 ITEM_SELECTOR = '.pinImageDim' |
| 333 IS_SINGLE_PAGE_APP = True |
| 334 ITEMS_TO_VISIT = 5 # Increase when crbug.com/651909 is implemented. |
| 335 ITEM_VIEW_TIME_IN_SECONDS = 5 |
| 336 INCREMENT_INDEX_AFTER_EACH_ITEM = True |
| 337 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY |
| 338 |
| 339 def _Login(self, action_runner): |
| 340 pinterest_login.LoginDesktopAccount(action_runner, 'googletest', |
| 341 self.credentials_path) |
| 342 |
| 343 def _ViewMediaItem(self, action_runner, index): |
| 344 super(PinterestDesktopStory, self)._ViewMediaItem(action_runner, index) |
| 345 # To imitate real user interaction, we do not want to pin every post. |
| 346 # We will only pin every other post. |
| 347 if index % 2 == 0: |
| 348 # Pin the selection. |
| 349 save_function = ('document.querySelector(' |
| 350 '".Button.Module.ShowModalButton.btn.hasIcon.hasText.' |
| 351 'isBrioFlat.medium.primary.primaryOnHover.repin.' |
| 352 'pinActionBarButton.isBrioFlat.rounded")') |
| 353 action_runner.ClickElement(element_function=save_function) |
| 354 action_runner.Wait(1) # Wait to make navigation realistic. |
| 355 # Select which board to pin to. |
| 356 inner_save_function = 'document.querySelector(".nameAndIcons")' |
| 357 action_runner.WaitForElement(element_function=inner_save_function) |
| 358 action_runner.ClickElement(element_function=inner_save_function) |
| 359 action_runner.Wait(1) # Wait to make navigation realistic. |
| 360 |
| 361 # Close selection. |
| 362 x_element_function = ('document.querySelector(' |
| 363 '".Button.borderless.close.visible")') |
| 364 action_runner.ClickElement(element_function=x_element_function) |
| 365 action_runner.Wait(1) # Wait to make navigation realistic. |
| OLD | NEW |