Chromium Code Reviews| Index: chrome/test/media_router/telemetry/benchmarks/pagesets/media_router_page.py |
| diff --git a/chrome/test/media_router/telemetry/benchmarks/pagesets/media_router_page.py b/chrome/test/media_router/telemetry/benchmarks/pagesets/media_router_page.py |
| index 538d99b22ea165f7d70d8263921b1be46f2ff82f..2cbd67989d55eb459e9a13d141926e09ee9f854f 100644 |
| --- a/chrome/test/media_router/telemetry/benchmarks/pagesets/media_router_page.py |
| +++ b/chrome/test/media_router/telemetry/benchmarks/pagesets/media_router_page.py |
| @@ -2,6 +2,7 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| +import logging |
| import os |
| import time |
| import utils |
| @@ -39,6 +40,47 @@ class CastPage(page.Page): |
| # code which closes the dialog, it is expected. |
| pass |
| + def CloseExistingRoute(self, action_runner, sink_name): |
| + """Closes the existing route if it exists, otherwise does nothing.""" |
| + |
| + action_runner.TapElement(selector='#start_session_button') |
| + action_runner.Wait(5) |
| + for tab in action_runner.tab.browser.tabs: |
| + if tab.url == 'chrome://media-router/': |
| + if self.CheckIfExistingRoute(tab, sink_name): |
| + self.ChooseSink(tab, sink_name) |
| + tab.ExecuteJavaScript( |
| + "window.document.getElementById('media-router-container')." |
| + "shadowRoot.getElementById('route-details').shadowRoot." |
| + "getElementById('close-route-button').click();") |
| + self.CloseDialog(tab) |
| + # Wait for 5s to make sure the route is closed. |
| + action_runner.Wait(5) |
| + |
| + def CheckIfExistingRoute(self, tab, sink_name): |
| + """"Checks if there is existing route for the specific sink.""" |
| + |
| + tab.ExecuteJavaScript( |
| + "var sinks = window.document.getElementById('media-router-container')." |
| + " allSinks;" |
| + "var sink_id = null;" |
| + "for (var i=0; i<sinks.length; i++) {" |
| + " if (sinks[i].name == '%s') {" |
| + " console.info('sink id: ' + sinks[i].id); " |
|
apacible
2016/04/28 20:39:55
Do we need to print out all of the sink ids for th
Lei Lei
2016/04/28 23:11:06
No, this is just for debug purpose. I would like t
|
| + " sink_id = sinks[i].id;" |
|
apacible
2016/04/28 20:39:55
Break early in this loop and below loop if the sin
Lei Lei
2016/04/28 23:11:06
Done.
|
| + " }" |
| + "}" |
| + "var routes = window.document.getElementById('media-router-container')." |
| + " routeList;" |
| + "for (var i=0; i<routes.length; i++) {" |
| + " if (!!sink_id && routes[i].sinkId == sink_id) {" |
| + " window.__telemetry_route_id = routes[i].id;" |
| + " }" |
| + "}" % sink_name) |
| + route = tab.EvaluateJavaScript('!!window.__telemetry_route_id') |
| + logging.info('Is there existing router? ' + str(route)) |
|
imcheng
2016/04/28 18:28:36
s/router/route
Lei Lei
2016/04/28 23:11:05
Done.
|
| + return route |
| + |
| def ExecuteAsyncJavaScript(self, action_runner, script, verify_func, |
| error_message, timeout=5): |
| """Executes async javascript function and waits until it finishes.""" |