Chromium Code Reviews| 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 story_tags | |
| 6 from page_sets.system_health import system_health_story | 7 from page_sets.system_health import system_health_story |
| 7 | 8 |
| 8 from page_sets.login_helpers import google_login | 9 from page_sets.login_helpers import google_login |
| 9 from page_sets.login_helpers import pandora_login | 10 from page_sets.login_helpers import pandora_login |
| 10 | 11 |
| 11 from telemetry import benchmark | 12 from telemetry import benchmark |
| 12 from telemetry import decorators | 13 from telemetry import decorators |
| 13 | 14 |
| 14 | 15 |
| 15 class _MediaStory(system_health_story.SystemHealthStory): | 16 class _PlayMediaStory(system_health_story.SystemHealthStory): |
| 16 """Abstract base class for media System Health user stories.""" | 17 """Abstract base class for media System Health user stories.""" |
| 17 | 18 |
| 18 ABSTRACT_STORY = True | 19 ABSTRACT_STORY = True |
| 19 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | 20 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY |
| 20 PLAY_DURATION = 20 | 21 PLAY_DURATION = 20 |
| 21 PLAY_SELECTOR = NotImplemented | 22 PLAY_SELECTOR = NotImplemented |
| 22 STOP_SELECTOR = NotImplemented | 23 STOP_SELECTOR = NotImplemented |
| 23 TIME_SELECTOR = NotImplemented | 24 TIME_SELECTOR = NotImplemented |
| 24 | 25 |
| 25 def RunPageInteractions(self, action_runner): | 26 def RunPageInteractions(self, action_runner): |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 45 self.PLAY_DURATION - self._GetTimeInSeconds(action_runner)) | 46 self.PLAY_DURATION - self._GetTimeInSeconds(action_runner)) |
| 46 | 47 |
| 47 def _GetTimeInSeconds(self, action_runner): | 48 def _GetTimeInSeconds(self, action_runner): |
| 48 minutes, seconds = action_runner.EvaluateJavaScript( | 49 minutes, seconds = action_runner.EvaluateJavaScript( |
| 49 'document.querySelector({{ selector }}).textContent', | 50 'document.querySelector({{ selector }}).textContent', |
| 50 selector=self.TIME_SELECTOR).split(':') | 51 selector=self.TIME_SELECTOR).split(':') |
| 51 return int(minutes * 60 + seconds) | 52 return int(minutes * 60 + seconds) |
| 52 | 53 |
| 53 | 54 |
| 54 ################################################################################ | 55 ################################################################################ |
| 55 # Audio stories. | 56 # Audio and video stories. |
| 56 ################################################################################ | 57 ################################################################################ |
| 57 | 58 |
| 58 | 59 |
| 59 @benchmark.Disabled('all') # crbug.com/649392 | 60 @benchmark.Disabled('all') # crbug.com/649392 |
| 60 class GooglePlayMusicDesktopStory(_MediaStory): | 61 class GooglePlayMusicDesktopStory(_PlayMediaStory): |
| 61 NAME = 'play:media:google_play_music' | 62 NAME = 'play:media:google_play_music' |
| 62 URL = 'https://music.google.com' | 63 URL = 'https://music.google.com' |
| 63 | 64 |
| 64 PLAY_SELECTOR = '.x-scope.paper-fab-0' | 65 PLAY_SELECTOR = '.x-scope.paper-fab-0' |
| 65 STOP_SELECTOR = '.style-scope.sj-play-button' | 66 STOP_SELECTOR = '.style-scope.sj-play-button' |
| 66 TIME_SELECTOR = '#time-container-current' | 67 TIME_SELECTOR = '#time-container-current' |
| 67 SEARCH_SELECTOR = '.title.fade-out.tooltip' | 68 SEARCH_SELECTOR = '.title.fade-out.tooltip' |
| 68 NAVIGATE_SELECTOR = '.description.tooltip.fade-out' | 69 NAVIGATE_SELECTOR = '.description.tooltip.fade-out' |
| 69 | 70 |
| 70 def _Login(self, action_runner): | 71 def _Login(self, action_runner): |
| 71 google_login.LoginGoogleAccount(action_runner, 'googletest', | 72 google_login.LoginGoogleAccount(action_runner, 'googletest', |
| 72 self.credentials_path) | 73 self.credentials_path) |
| 73 | 74 |
| 74 def _NavigateToMedia(self, action_runner): | 75 def _NavigateToMedia(self, action_runner): |
| 75 # Clicks on Today's top hits. | 76 # Clicks on Today's top hits. |
| 76 action_runner.Wait(1) # Add 1 second wait to make the browsing realistic. | 77 action_runner.Wait(1) # Add 1 second wait to make the browsing realistic. |
| 77 self._WaitForAndClickElementBySelector(action_runner, self.SEARCH_SELECTOR) | 78 self._WaitForAndClickElementBySelector(action_runner, self.SEARCH_SELECTOR) |
| 78 # Clicks on playlist. | 79 # Clicks on playlist. |
| 79 action_runner.Wait(1) # Add 1 second wait to make the browsing realistic. | 80 action_runner.Wait(1) # Add 1 second wait to make the browsing realistic. |
| 80 self._WaitForAndClickElementBySelector(action_runner, | 81 self._WaitForAndClickElementBySelector(action_runner, |
| 81 self.NAVIGATE_SELECTOR) | 82 self.NAVIGATE_SELECTOR) |
| 82 | 83 |
| 83 | 84 |
| 84 @benchmark.Disabled('win') # crbug.com/649392 | 85 @benchmark.Disabled('win') # crbug.com/649392 |
| 85 class SoundCloudDesktopStory(_MediaStory): | 86 class SoundCloudDesktopStory(_PlayMediaStory): |
| 86 NAME = 'play:media:soundcloud' | 87 NAME = 'play:media:soundcloud' |
| 87 URL = 'https://soundcloud.com' | 88 URL = 'https://soundcloud.com' |
| 88 | 89 |
| 89 PLAY_SELECTOR = '.sc-button-play.playButton.sc-button.sc-button-xlarge' | 90 PLAY_SELECTOR = '.sc-button-play.playButton.sc-button.sc-button-xlarge' |
| 90 STOP_SELECTOR = '.playControl.playControls__icon.sc-ir.playing' | 91 STOP_SELECTOR = '.playControl.playControls__icon.sc-ir.playing' |
| 91 TIME_SELECTOR = '.playbackTimeline__timePassed>span[aria-hidden=true]' | 92 TIME_SELECTOR = '.playbackTimeline__timePassed>span[aria-hidden=true]' |
| 92 SEARCH_SELECTOR = '.headerSearch' | 93 SEARCH_SELECTOR = '.headerSearch' |
| 93 SEARCH_QUERY = 'SSmooth Jazz' # First S for some reason gets ommited. | 94 SEARCH_QUERY = 'SSmooth Jazz' # First S for some reason gets ommited. |
| 94 | 95 |
| 95 def _NavigateToMedia(self, action_runner): | 96 def _NavigateToMedia(self, action_runner): |
| 96 self._WaitForAndClickElementBySelector(action_runner, self.SEARCH_SELECTOR) | 97 self._WaitForAndClickElementBySelector(action_runner, self.SEARCH_SELECTOR) |
| 97 action_runner.Wait(1) # Add 1 second wait to make the browsing realistic. | 98 action_runner.Wait(1) # Add 1 second wait to make the browsing realistic. |
| 98 action_runner.EnterText(self.SEARCH_QUERY) | 99 action_runner.EnterText(self.SEARCH_QUERY) |
| 99 action_runner.PressKey('Return') | 100 action_runner.PressKey('Return') |
| 100 | 101 |
| 101 | 102 |
| 102 @decorators.Disabled('all') # crbug.com/649392 | 103 @decorators.Disabled('all') # crbug.com/649392 |
| 103 class PandoraDesktopStory(_MediaStory): | 104 class PandoraDesktopStory(_PlayMediaStory): |
| 104 NAME = 'play:media:pandora' | 105 NAME = 'play:media:pandora' |
| 105 URL = 'https://pandora.com' | 106 URL = 'https://pandora.com' |
| 106 | 107 |
| 107 PLAY_SELECTOR = None | 108 PLAY_SELECTOR = None |
| 108 STOP_SELECTOR = '.pauseButton' | 109 STOP_SELECTOR = '.pauseButton' |
| 109 TIME_SELECTOR = '.elapsedTime' | 110 TIME_SELECTOR = '.elapsedTime' |
| 110 SEARCH_SELECTOR = '.searchInput' | 111 SEARCH_SELECTOR = '.searchInput' |
| 111 | 112 |
| 112 def _Login(self, action_runner): | 113 def _Login(self, action_runner): |
| 113 pandora_login.LoginAccount(action_runner, 'pandora', self.credentials_path) | 114 pandora_login.LoginAccount(action_runner, 'pandora', self.credentials_path) |
| 114 | 115 |
| 115 def _NavigateToMedia(self, action_runner): | 116 def _NavigateToMedia(self, action_runner): |
| 116 pass # Audio autoplays on Pandora, no need to search. | 117 pass # Audio autoplays on Pandora, no need to search. |
| 118 | |
| 119 | |
| 120 class YoutubeMobileStory(_PlayMediaStory): | |
|
nednguyen
2017/04/11 22:24:10
Also add docstring describe what this story is doi
ssid
2017/04/13 21:08:53
removed this story for now.
| |
| 121 NAME = 'browse:media:youtube' | |
| 122 URL = 'https://m.youtube.in/watch?v=OnhXkCPMeMc' | |
| 123 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 124 TAGS = [story_tags.EMERGING_MARKET] | |
| 125 | |
| 126 PLAYER_FUNCTION = 'document.getElementById("player")' | |
| 127 STOP_FUNCTION = 'document.getElementsByTagName("video")[0].pause()' | |
| 128 TIME_FUNCTION = 'document.getElementsByTagName("video")[0].currentTime' | |
| 129 | |
| 130 def RunPageInteractions(self, action_runner): | |
| 131 app_ui = action_runner.tab.browser.app_ui | |
| 132 action_runner.WaitForElement(element_function=self.PLAYER_FUNCTION) | |
| 133 | |
| 134 # Simulate user click in system ui since youtube play can be initialied only | |
| 135 # by user gesture. | |
| 136 renderer_view_id = 'compositor_view_holder' | |
| 137 app_ui.WaitForUiNode(resource_id=renderer_view_id) | |
| 138 renderer_view = app_ui.GetUiNode(resource_id=renderer_view_id) | |
| 139 # Click on the top half of the renderer view to start video. | |
| 140 shifted_center = 0.5 * ( | |
| 141 renderer_view.bounds.center + renderer_view.bounds.top_left) | |
| 142 renderer_view.Tap(point=shifted_center) | |
| 143 | |
| 144 self._WaitForPlayTime(action_runner) | |
| 145 action_runner.EvaluateJavaScript(self.STOP_FUNCTION) | |
| 146 self._Measure(action_runner) | |
| 147 | |
| 148 def _GetTimeInSeconds(self, action_runner): | |
| 149 return int(action_runner.EvaluateJavaScript(self.TIME_FUNCTION)) | |
| 150 | |
| 151 def _NavigateToMedia(self, action_runner): | |
| 152 pass # Users usually open youtube links directly, skip searching. | |
| OLD | NEW |