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):
'The dialog is not fully loaded within 15s.',
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,
timeout=5):
"""Waits until the function finishes or timeout."""
......
......@@ -32,7 +32,7 @@ class MediaRouterCPUMemoryCast(perf_benchmark.PerfBenchmark):
[os.path.join(path_util.GetChromiumSrcDir(), 'out',
'Release', 'mr_extension', 'release'),
os.path.join(path_util.GetChromiumSrcDir(), 'out',
'Release', 'media_router', 'media_router_telemetry_extension')]),
'Release', 'media_router', 'telemetry_extension')]),
'--disable-features=ViewsCastDialog',
'--whitelisted-extension-id=enhhojjnijigcajfphajepfemndkmdlo',
'--media-router=1',
......@@ -64,7 +64,7 @@ class NoMediaRouterCPUMemory(perf_benchmark.PerfBenchmark):
options.AppendExtraBrowserArgs([
'--load-extension=' +
os.path.join(path_util.GetChromiumSrcDir(), 'out',
'Release', 'media_router', 'media_router_telemetry_extension'),
'Release', 'media_router', 'telemetry_extension'),
'--disable-features=ViewsCastDialog',
'--media-router=0',
'--enable-stats-collection-bindings'
......
......@@ -5,6 +5,7 @@
from telemetry import story
from telemetry.page import shared_page_state
from telemetry.util import js_template
from contrib.media_router_benchmarks.media_router_base_page import MediaRouterBasePage
......@@ -13,9 +14,9 @@ SESSION_TIME = 300 # 5 minutes
class SharedState(shared_page_state.SharedPageState):
"""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__(
test, finder_options, story_set)
test, finder_options, story_set, possible_browser)
def DidRunStory(self, results):
super(SharedState, self).DidRunStory(results)
......@@ -52,30 +53,29 @@ class CastFlingingPage(MediaRouterBasePage):
def RunPageInteractions(self, action_runner):
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.
action_runner.Wait(5)
with action_runner.CreateInteraction('flinging'):
action_runner.tab.StopCasting(sink_name)
self._WaitForResult(
action_runner,
lambda: action_runner.EvaluateJavaScript('initialized'),
'Failed to initialize',
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
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(
action_runner,
lambda: action_runner.EvaluateJavaScript('currentSession'),
......@@ -115,40 +115,29 @@ class CastMirroringPage(MediaRouterBasePage):
def RunPageInteractions(self, action_runner):
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.
action_runner.Wait(5)
with action_runner.CreateInteraction('mirroring'):
self.CloseExistingRoute(action_runner, sink_name)
action_runner.tab.StopCasting(sink_name)
# Start session
action_runner.TapElement(selector='#start_session_button')
self._WaitForResult(
action_runner,
lambda: len(action_runner.tab.browser.tabs) >= 2,
'MR dialog never showed up.')
# 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())))
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)
# Start session
action_runner.tab.StartTabMirroring(sink_name)
# Wait for 5s to make sure the route is created.
action_runner.Wait(5)
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:
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.')
# Make sure the route is created.
if action_runner.tab.GetCastIssue():
raise RuntimeError(action_runner.tab.GetCastIssue())
action_runner.ExecuteJavaScript('collectPerfData();')
action_runner.Wait(SESSION_TIME)
self.CloseExistingRoute(action_runner, sink_name)
action_runner.tab.StopCasting(sink_name)
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