Commit c4e34f53 authored by Clifford Cheng's avatar Clifford Cheng Committed by Commit Bot

Use Cast DevTools Protocol for triggering mirroring and flinging telemetry tests.

Bug: 968849
Change-Id: I973dbdc6c6fa37881b97dd837ab021fb2aaedb13
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1639737
Auto-Submit: Clifford Cheng <cliffordcheng@chromium.org>
Reviewed-by: default avatarmark a. foltz <mfoltz@chromium.org>
Commit-Queue: Clifford Cheng <cliffordcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666133}
parent 7f96b354
...@@ -122,6 +122,16 @@ class MediaRouterBasePage(page.Page): ...@@ -122,6 +122,16 @@ class MediaRouterBasePage(page.Page):
'The dialog is not fully loaded within 15s.', 'The dialog is not fully loaded within 15s.',
timeout=15) timeout=15)
def WaitForSink(self, action_runner, target_sink, error_message, timeout=5):
sink_list = action_runner.tab.GetCastSinks()
start_time = time.time()
while target_sink not in sink_list and time.time() - start_time < timeout:
action_runner.tab.EnableCast()
sink_list = action_runner.tab.GetCastSinks()
action_runner.Wait(1)
if target_sink not in sink_list:
raise RuntimeError(error_message)
def _WaitForResult(self, action_runner, verify_func, error_message, def _WaitForResult(self, action_runner, verify_func, error_message,
timeout=5): timeout=5):
"""Waits until the function finishes or timeout.""" """Waits until the function finishes or timeout."""
......
...@@ -32,7 +32,7 @@ class MediaRouterCPUMemoryCast(perf_benchmark.PerfBenchmark): ...@@ -32,7 +32,7 @@ class MediaRouterCPUMemoryCast(perf_benchmark.PerfBenchmark):
[os.path.join(path_util.GetChromiumSrcDir(), 'out', [os.path.join(path_util.GetChromiumSrcDir(), 'out',
'Release', 'mr_extension', 'release'), 'Release', 'mr_extension', 'release'),
os.path.join(path_util.GetChromiumSrcDir(), 'out', os.path.join(path_util.GetChromiumSrcDir(), 'out',
'Release', 'media_router', 'media_router_telemetry_extension')]), 'Release', 'media_router', 'telemetry_extension')]),
'--disable-features=ViewsCastDialog', '--disable-features=ViewsCastDialog',
'--whitelisted-extension-id=enhhojjnijigcajfphajepfemndkmdlo', '--whitelisted-extension-id=enhhojjnijigcajfphajepfemndkmdlo',
'--media-router=1', '--media-router=1',
...@@ -64,7 +64,7 @@ class NoMediaRouterCPUMemory(perf_benchmark.PerfBenchmark): ...@@ -64,7 +64,7 @@ class NoMediaRouterCPUMemory(perf_benchmark.PerfBenchmark):
options.AppendExtraBrowserArgs([ options.AppendExtraBrowserArgs([
'--load-extension=' + '--load-extension=' +
os.path.join(path_util.GetChromiumSrcDir(), 'out', os.path.join(path_util.GetChromiumSrcDir(), 'out',
'Release', 'media_router', 'media_router_telemetry_extension'), 'Release', 'media_router', 'telemetry_extension'),
'--disable-features=ViewsCastDialog', '--disable-features=ViewsCastDialog',
'--media-router=0', '--media-router=0',
'--enable-stats-collection-bindings' '--enable-stats-collection-bindings'
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
from telemetry import story from telemetry import story
from telemetry.page import shared_page_state from telemetry.page import shared_page_state
from telemetry.util import js_template from telemetry.util import js_template
from contrib.media_router_benchmarks.media_router_base_page import MediaRouterBasePage from contrib.media_router_benchmarks.media_router_base_page import MediaRouterBasePage
...@@ -13,9 +14,9 @@ SESSION_TIME = 300 # 5 minutes ...@@ -13,9 +14,9 @@ SESSION_TIME = 300 # 5 minutes
class SharedState(shared_page_state.SharedPageState): class SharedState(shared_page_state.SharedPageState):
"""Shared state that restarts the browser for every single story.""" """Shared state that restarts the browser for every single story."""
def __init__(self, test, finder_options, story_set): def __init__(self, test, finder_options, story_set, possible_browser):
super(SharedState, self).__init__( super(SharedState, self).__init__(
test, finder_options, story_set) test, finder_options, story_set, possible_browser)
def DidRunStory(self, results): def DidRunStory(self, results):
super(SharedState, self).DidRunStory(results) super(SharedState, self).DidRunStory(results)
...@@ -52,30 +53,29 @@ class CastFlingingPage(MediaRouterBasePage): ...@@ -52,30 +53,29 @@ class CastFlingingPage(MediaRouterBasePage):
def RunPageInteractions(self, action_runner): def RunPageInteractions(self, action_runner):
sink_name = self._GetOSEnviron('RECEIVER_NAME') sink_name = self._GetOSEnviron('RECEIVER_NAME')
# Enable Cast and start to discover all sinks.
action_runner.tab.EnableCast()
# Wait for 5s after Chrome is opened in order to get consistent results. # Wait for 5s after Chrome is opened in order to get consistent results.
action_runner.Wait(5) action_runner.Wait(5)
with action_runner.CreateInteraction('flinging'): with action_runner.CreateInteraction('flinging'):
action_runner.tab.StopCasting(sink_name)
self._WaitForResult( self._WaitForResult(
action_runner, action_runner,
lambda: action_runner.EvaluateJavaScript('initialized'), lambda: action_runner.EvaluateJavaScript('initialized'),
'Failed to initialize', 'Failed to initialize',
timeout=30) timeout=30)
self.CloseExistingRoute(action_runner, sink_name)
# Wait for the sinks to appear.
self.WaitForSink(
action_runner, sink_name,
'Targeted receiver "%s" did not showed up. Sink List: %s' % (
sink_name, str(action_runner.tab.GetCastSinks())))
action_runner.tab.SetCastSinkToUse(sink_name)
# Start session # Start session
action_runner.TapElement(selector='#start_session_button') action_runner.TapElement(selector='#start_session_button')
self._WaitForResult(
action_runner,
lambda: len(action_runner.tab.browser.tabs) >= 2,
'MR dialog never showed up.')
for tab in action_runner.tab.browser.tabs:
# Choose sink
if tab.url == 'chrome://media-router/':
self.WaitUntilDialogLoaded(action_runner, tab)
self.ChooseSink(tab, sink_name)
self._WaitForResult( self._WaitForResult(
action_runner, action_runner,
lambda: action_runner.EvaluateJavaScript('currentSession'), lambda: action_runner.EvaluateJavaScript('currentSession'),
...@@ -115,40 +115,29 @@ class CastMirroringPage(MediaRouterBasePage): ...@@ -115,40 +115,29 @@ class CastMirroringPage(MediaRouterBasePage):
def RunPageInteractions(self, action_runner): def RunPageInteractions(self, action_runner):
sink_name = self._GetOSEnviron('RECEIVER_NAME') sink_name = self._GetOSEnviron('RECEIVER_NAME')
# Enable Cast and start to discover all sinks.
action_runner.tab.EnableCast()
# Wait for 5s after Chrome is opened in order to get consistent results. # Wait for 5s after Chrome is opened in order to get consistent results.
action_runner.Wait(5) action_runner.Wait(5)
with action_runner.CreateInteraction('mirroring'): with action_runner.CreateInteraction('mirroring'):
self.CloseExistingRoute(action_runner, sink_name) action_runner.tab.StopCasting(sink_name)
# Start session # Wait for the sinks to appear.
action_runner.TapElement(selector='#start_session_button') self.WaitForSink(
self._WaitForResult( action_runner, sink_name,
action_runner, 'Targeted receiver "%s" did not showed up. Sink List: %s' % (
lambda: len(action_runner.tab.browser.tabs) >= 2, sink_name, str(action_runner.tab.GetCastSinks())))
'MR dialog never showed up.')
for tab in action_runner.tab.browser.tabs: # Start session
# Choose sink action_runner.tab.StartTabMirroring(sink_name)
if tab.url == 'chrome://media-router/':
self.WaitUntilDialogLoaded(action_runner, tab)
self.ChooseSink(tab, sink_name)
# Wait for 5s to make sure the route is created. # Make sure the route is created.
action_runner.Wait(5) if action_runner.tab.GetCastIssue():
action_runner.TapElement(selector='#start_session_button') raise RuntimeError(action_runner.tab.GetCastIssue())
self._WaitForResult(
action_runner,
lambda: len(action_runner.tab.browser.tabs) >= 2,
'MR dialog never showed up.')
for tab in action_runner.tab.browser.tabs:
if tab.url == 'chrome://media-router/':
self.WaitUntilDialogLoaded(action_runner, tab)
if not self.CheckIfExistingRoute(tab, sink_name):
raise RuntimeError('Failed to start mirroring session.')
action_runner.ExecuteJavaScript('collectPerfData();') action_runner.ExecuteJavaScript('collectPerfData();')
action_runner.Wait(SESSION_TIME) action_runner.Wait(SESSION_TIME)
self.CloseExistingRoute(action_runner, sink_name) action_runner.tab.StopCasting(sink_name)
class MediaRouterCPUMemoryPageSet(story.StorySet): class MediaRouterCPUMemoryPageSet(story.StorySet):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment