Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: chrome/test/media_router/telemetry/benchmarks/pagesets/media_router_page.py

Issue 1931553004: Stop the existing session if it exists before start a new session and add mirroring scenario for cp… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update media_router_perf_pages.py Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import logging
5 import os 6 import os
6 import time 7 import time
7 import utils 8 import utils
8 9
9 from telemetry import page 10 from telemetry import page
10 from telemetry import story 11 from telemetry import story
11 from telemetry.core import exceptions 12 from telemetry.core import exceptions
12 13
13 14
14 class CastPage(page.Page): 15 class CastPage(page.Page):
(...skipping 17 matching lines...) Expand all
32 try: 33 try:
33 tab.ExecuteJavaScript( 34 tab.ExecuteJavaScript(
34 'window.document.getElementById("media-router-container").' + 35 'window.document.getElementById("media-router-container").' +
35 'shadowRoot.getElementById("container-header").shadowRoot.' + 36 'shadowRoot.getElementById("container-header").shadowRoot.' +
36 'getElementById("close-button").click();') 37 'getElementById("close-button").click();')
37 except exceptions.DevtoolsTargetCrashException: 38 except exceptions.DevtoolsTargetCrashException:
38 # Ignore the crash exception, this exception is caused by the js 39 # Ignore the crash exception, this exception is caused by the js
39 # code which closes the dialog, it is expected. 40 # code which closes the dialog, it is expected.
40 pass 41 pass
41 42
43 def CloseExistingRoute(self, action_runner, sink_name):
44 """Closes the existing route if it exists, otherwise does nothing."""
45
46 action_runner.TapElement(selector='#start_session_button')
47 action_runner.Wait(5)
48 for tab in action_runner.tab.browser.tabs:
49 if tab.url == 'chrome://media-router/':
50 if self.CheckIfExistingRoute(tab, sink_name):
51 self.ChooseSink(tab, sink_name)
52 tab.ExecuteJavaScript(
53 "window.document.getElementById('media-router-container')."
54 "shadowRoot.getElementById('route-details').shadowRoot."
55 "getElementById('close-route-button').click();")
56 self.CloseDialog(tab)
57 # Wait for 5s to make sure the route is closed.
58 action_runner.Wait(5)
59
60 def CheckIfExistingRoute(self, tab, sink_name):
61 """"Checks if there is existing route for the specific sink."""
62
63 tab.ExecuteJavaScript(
64 "var sinks = window.document.getElementById('media-router-container')."
65 " allSinks;"
66 "var sink_id = null;"
67 "for (var i=0; i<sinks.length; i++) {"
68 " if (sinks[i].name == '%s') {"
69 " 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
70 " 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.
71 " }"
72 "}"
73 "var routes = window.document.getElementById('media-router-container')."
74 " routeList;"
75 "for (var i=0; i<routes.length; i++) {"
76 " if (!!sink_id && routes[i].sinkId == sink_id) {"
77 " window.__telemetry_route_id = routes[i].id;"
78 " }"
79 "}" % sink_name)
80 route = tab.EvaluateJavaScript('!!window.__telemetry_route_id')
81 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.
82 return route
83
42 def ExecuteAsyncJavaScript(self, action_runner, script, verify_func, 84 def ExecuteAsyncJavaScript(self, action_runner, script, verify_func,
43 error_message, timeout=5): 85 error_message, timeout=5):
44 """Executes async javascript function and waits until it finishes.""" 86 """Executes async javascript function and waits until it finishes."""
45 87
46 action_runner.ExecuteJavaScript(script) 88 action_runner.ExecuteJavaScript(script)
47 self._WaitForResult(action_runner, verify_func, error_message, 89 self._WaitForResult(action_runner, verify_func, error_message,
48 timeout=timeout) 90 timeout=timeout)
49 91
50 def _WaitForResult(self, action_runner, verify_func, error_message, 92 def _WaitForResult(self, action_runner, verify_func, error_message,
51 timeout=5): 93 timeout=5):
52 """Waits until the function finishes or timeout.""" 94 """Waits until the function finishes or timeout."""
53 95
54 start_time = time.time() 96 start_time = time.time()
55 while (not verify_func() and 97 while (not verify_func() and
56 time.time() - start_time < timeout): 98 time.time() - start_time < timeout):
57 action_runner.Wait(1) 99 action_runner.Wait(1)
58 if not verify_func(): 100 if not verify_func():
59 raise page.page_test.Failure(error_message) 101 raise page.page_test.Failure(error_message)
60 102
61 def _GetDeviceName(self): 103 def _GetDeviceName(self):
62 """Gets device name from environment variable RECEIVER_NAME.""" 104 """Gets device name from environment variable RECEIVER_NAME."""
63 105
64 if 'RECEIVER_IP' not in os.environ or not os.environ.get('RECEIVER_IP'): 106 if 'RECEIVER_IP' not in os.environ or not os.environ.get('RECEIVER_IP'):
65 raise page.page_test.Failure( 107 raise page.page_test.Failure(
66 'Your test machine is not set up correctly, ' 108 'Your test machine is not set up correctly, '
67 'RECEIVER_IP enviroment variable is missing.') 109 'RECEIVER_IP enviroment variable is missing.')
68 return utils.GetDeviceName(os.environ.get('RECEIVER_IP')) 110 return utils.GetDeviceName(os.environ.get('RECEIVER_IP'))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698