Chromium Code Reviews| Index: tools/perf/page_sets/system_health/media_stories.py |
| diff --git a/tools/perf/page_sets/system_health/media_stories.py b/tools/perf/page_sets/system_health/media_stories.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..79f4bb4e5312e7452ffedb3f746fb428993fb4b7 |
| --- /dev/null |
| +++ b/tools/perf/page_sets/system_health/media_stories.py |
| @@ -0,0 +1,124 @@ |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +from page_sets.system_health import platforms |
| +from page_sets.system_health import system_health_story |
| + |
| +from page_sets.login_helpers import google_login |
| +from page_sets.login_helpers import pandora_login |
| + |
| + |
| +class _MediaStory(system_health_story.SystemHealthStory): |
| + """Abstract base class for media System Health user stories.""" |
| + |
| + ABSTRACT_STORY = True |
| + SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY |
| + PLAY_DURATION = 20 |
| + |
| + def RunPageInteractions(self, action_runner): |
| + self._NavigateToMedia(action_runner) |
| + # Play Media. |
| + if self.PLAY_ELEMENT: |
| + self._WaitForAndClickElement(action_runner, self.PLAY_ELEMENT) |
| + self._WaitForPlayTime(action_runner) |
| + # Stop media. |
| + self._WaitForAndClickElement(action_runner, self.STOP_ELEMENT) |
| + |
| + def _NavigateToMedia(self, action_runner): |
| + raise NotImplementedError |
| + |
| + def _WaitForAndClickElement(self, action_runner, element_function): |
| + action_runner.WaitForElement(element_function=element_function) |
| + action_runner.ClickElement(element_function=element_function) |
| + |
| + def _WaitForPlayTime(self, action_runner): |
| + action_runner.Wait(self.PLAY_DURATION) |
| + while self._GetTimeInSeconds(action_runner) < self.PLAY_DURATION: |
| + action_runner.Wait( |
| + self.PLAY_DURATION - self._GetTimeInSeconds(action_runner)) |
| + |
| + def _GetTimeInSeconds(self, action_runner): |
| + minutes, seconds = action_runner.EvaluateJavaScript( |
| + self.TIME_ELEMENT).split(':') |
|
petrcermak
2016/09/22 09:50:56
you should define `TIME_ELEMENT = NotImplemented`
rnephew (Reviews Here)
2016/09/22 16:40:51
Done.
|
| + return int(minutes * 60 + seconds) |
| + |
| + |
| +################################################################################ |
| +# Audio stories. |
| +################################################################################ |
| + |
| + |
| +class GooglePlayMusicDesktopStory(_MediaStory): |
| + NAME = 'play:media:google_play_music' |
| + URL = 'https://music.google.com' |
| + |
| + SEARCH_ELEMENT = 'document.querySelector(".title.fade-out.tooltip")' |
|
petrcermak
2016/09/22 09:50:56
nit: please modify the order of the class constant
rnephew (Reviews Here)
2016/09/22 16:40:51
Done.
|
| + PLAY_ELEMENT = ( |
| + 'document.getElementsByClassName("x-scope paper-fab-0")[0]') |
|
petrcermak
2016/09/22 09:50:56
You use "document.getElementByClassName(SELECTOR)[
rnephew (Reviews Here)
2016/09/22 16:40:51
Done.
|
| + STOP_ELEMENT = ( |
| + 'document.getElementsByClassName("style-scope sj-play-button")[0]') |
| + NAVIGATE_IDENTIFIER = ( |
|
petrcermak
2016/09/22 09:50:56
why is this called "IDENTIFIER" and not "ELEMENT"
rnephew (Reviews Here)
2016/09/22 16:40:51
Missed when switching everything. Fixed.
|
| + 'document.getElementsByClassName("description tooltip fade-out")[0]') |
| + TIME_ELEMENT = 'document.getElementById("time-container-current").innerHTML' |
|
petrcermak
2016/09/22 09:50:56
why don't you use `textContent` instead of `innerH
petrcermak
2016/09/22 09:50:56
All other ELEMENTs refer to the element, but this
rnephew (Reviews Here)
2016/09/22 16:40:51
Didn't know about it, switched to it.
rnephew (Reviews Here)
2016/09/22 16:40:51
Done.
|
| + |
| + |
| + def _Login(self, action_runner): |
| + google_login.LoginGoogleAccount(action_runner, 'googletest', |
| + self.credentials_path) |
| + |
| + def _NavigateToMedia(self, action_runner): |
| + # Clicks on Today's top hits. |
| + self._WaitForAndClickElement(action_runner, self.SEARCH_ELEMENT) |
| + # Clicks on playlist. |
| + self._WaitForAndClickElement(action_runner, self.NAVIGATE_IDENTIFIER) |
| + |
| + def _GetTimeInSeconds(self, action_runner): |
|
petrcermak
2016/09/22 09:50:56
No need to redefine the method again.
rnephew (Reviews Here)
2016/09/22 16:40:52
Done.
|
| + minutes, seconds = action_runner.EvaluateJavaScript( |
| + self.TIME_ELEMENT).split(':') |
| + return int(minutes * 60 + seconds) |
| + |
| + |
| +class SoundCloudDesktopStory(_MediaStory): |
| + NAME = 'play:media:soundcloud' |
| + URL = 'https://soundcloud.com' |
| + |
| + SEARCH_ELEMENT = 'document.getElementsByClassName("headerSearch")[0]' |
| + SEARCH_QUERY = 'SSmooth Jazz' # First S for some reason gets ommited. |
| + PLAY_ELEMENT = ('document.getElementsByClassName("sc-button-play' |
| + ' playButton sc-button sc-button-xlarge")[0]') |
| + STOP_ELEMENT = ('document.getElementsByClassName("playControl ' |
| + 'playControls__icon sc-ir playing")[0]') |
| + TIME_ELEMENT = ('document.getElementsByClassName(' |
| + '"playbackTimeline__timePassed")[0].innerHTML') |
| + |
| + def _NavigateToMedia(self, action_runner): |
| + self._WaitForAndClickElement(action_runner, self.SEARCH_ELEMENT) |
| + action_runner.Wait(1) # Add 1 second wait to make the browsing realistic. |
| + action_runner.EnterText(self.SEARCH_QUERY) |
| + action_runner.PressKey('Return') |
| + |
| + def _GetTimeInSeconds(self, action_runner): |
| + # Format of returned value is: |
|
petrcermak
2016/09/22 09:50:56
Instead of doing this in python, change your TIME_
rnephew (Reviews Here)
2016/09/22 16:40:52
Done.
|
| + # <span class="sc-visuallyhidden">Current time: 19 seconds</span> |
| + # <span aria-hidden="true">0:19</span> |
| + minutes, seconds = action_runner.EvaluateJavaScript( |
| + self.TIME_ELEMENT).split(">")[3].split('<')[0].split(':') |
| + return int(minutes * 60 + seconds) |
| + |
| + |
| +class PandoraDesktopStory(_MediaStory): |
| + NAME = 'play:media:pandora' |
| + URL = 'https://pandora.com' |
| + |
| + SEARCH_ELEMENT = 'document.getElementsByClassName("searchInput")[0]' |
| + SEARCH_QUERY = None |
|
petrcermak
2016/09/22 09:50:56
no need to define SEARCH_QUERY
rnephew (Reviews Here)
2016/09/22 16:40:51
Done.
|
| + PLAY_ELEMENT = None |
| + STOP_ELEMENT = 'document.getElementsByClassName("pauseButton")[0]' |
| + TIME_ELEMENT = 'document.getElementsByClassName("elapsedTime")[0].innerHTML' |
| + |
| + def _Login(self, action_runner): |
| + pandora_login.LoginAccount(action_runner, 'pandora', self.credentials_path) |
| + |
| + def _NavigateToMedia(self, action_runner): |
| + pass # Audio autoplays on Pandora, no need to search. |