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 |
index ad079e8d4b515282fcec217d1b9a326dc0bcc3a8..f8f907f5f560a85274d42a90853115e94a95c65c 100644 |
--- a/tools/perf/page_sets/system_health/media_stories.py |
+++ b/tools/perf/page_sets/system_health/media_stories.py |
@@ -114,3 +114,38 @@ class PandoraDesktopStory(_MediaStory): |
def _NavigateToMedia(self, action_runner): |
pass # Audio autoplays on Pandora, no need to search. |
+ |
+ |
+class YoutubeMobileStory(_MediaStory): |
+ NAME = 'play:media:youtube' |
+ URL = 'https://m.youtube.in/watch?v=OnhXkCPMeMc' |
+ |
+ PLAYER_FUNCTION = 'document.getElementById("player")' |
+ STOP_FUNCTION = 'document.getElementsByTagName("video")[0].pause()' |
+ TIME_FUNCTION = 'document.getElementsByTagName("video")[0].currentTime' |
+ |
+ def RunPageInteractions(self, action_runner): |
+ platform = action_runner.tab.browser.platform |
+ package = action_runner.tab.browser.GetBrowserInfo().package_name |
+ action_runner.WaitForElement(element_function=self.PLAYER_FUNCTION) |
+ |
+ # Simulate user click in system ui since youtube play can be initialied only |
+ # by user gesture. |
+ renderer_view = package+':id/compositor_view_holder' |
+ platform.system_ui.WaitForUiNode(resource_id=renderer_view) |
+ content_view = platform.system_ui.GetUiNode(resource_id=renderer_view) |
+ # Click on the top half of the renderer view to start video. |
+ shifted_center = 0.5 * ( |
+ content_view.bounds.center + content_view.bounds.top_left) |
+ content_view.Tap(point=shifted_center) |
+ |
+ self._WaitForPlayTime(action_runner) |
+ action_runner.EvaluateJavaScript(self.STOP_FUNCTION) |
+ |
+ def _GetTimeInSeconds(self, action_runner): |
+ return int(action_runner.EvaluateJavaScript(self.TIME_FUNCTION)) |
+ |
+ def _NavigateToMedia(self, action_runner): |
+ pass # Audio autoplays on Pandora, no need to search. |
+ |
+ SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY |