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

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

Issue 2724903005: Updates exception and adds rety to ExecuteAsyncJavaScript (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | chrome/test/media_router/telemetry/benchmarks/pagesets/media_router_perf_pages.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 logging
6 import os 6 import os
7 import time 7 import time
8 import utils 8 import utils
9 9
10 from telemetry import page 10 from telemetry import page
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 window.__telemetry_route_id = routes[i].id; 80 window.__telemetry_route_id = routes[i].id;
81 break; 81 break;
82 } 82 }
83 }""", 83 }""",
84 sink_name=sink_name) 84 sink_name=sink_name)
85 route = tab.EvaluateJavaScript('!!window.__telemetry_route_id') 85 route = tab.EvaluateJavaScript('!!window.__telemetry_route_id')
86 logging.info('Is there existing route? ' + str(route)) 86 logging.info('Is there existing route? ' + str(route))
87 return route 87 return route
88 88
89 def ExecuteAsyncJavaScript(self, action_runner, script, verify_func, 89 def ExecuteAsyncJavaScript(self, action_runner, script, verify_func,
90 error_message, timeout=5): 90 error_message, timeout=5, retry=1):
91 """Executes async javascript function and waits until it finishes.""" 91 """Executes async javascript function and waits until it finishes."""
92 92 exception = None
93 action_runner.ExecuteJavaScript(script) 93 for _ in xrange(retry):
94 self._WaitForResult(action_runner, verify_func, error_message, 94 try:
95 timeout=timeout) 95 action_runner.ExecuteJavaScript(script)
96 self._WaitForResult(
97 action_runner, verify_func, error_message, timeout=timeout)
98 exception = None
99 break
100 except RuntimeError as e:
101 exception = e
102 if exception:
103 raise exception
96 104
97 def WaitUntilDialogLoaded(self, action_runner, tab): 105 def WaitUntilDialogLoaded(self, action_runner, tab):
98 """Waits until dialog is fully loaded.""" 106 """Waits until dialog is fully loaded."""
99 107
100 self._WaitForResult( 108 self._WaitForResult(
101 action_runner, 109 action_runner,
102 lambda: tab.EvaluateJavaScript( 110 lambda: tab.EvaluateJavaScript(
103 '!!window.document.getElementById(' 111 '!!window.document.getElementById('
104 '"media-router-container") &&' 112 '"media-router-container") &&'
105 'window.document.getElementById(' 113 'window.document.getElementById('
106 '"media-router-container").sinksToShow_ &&' 114 '"media-router-container").sinksToShow_ &&'
107 'window.document.getElementById(' 115 'window.document.getElementById('
108 '"media-router-container").sinksToShow_.length'), 116 '"media-router-container").sinksToShow_.length'),
109 'The dialog is not fully loaded within 15s.', 117 'The dialog is not fully loaded within 15s.',
110 timeout=15) 118 timeout=15)
111 119
112 def _WaitForResult(self, action_runner, verify_func, error_message, 120 def _WaitForResult(self, action_runner, verify_func, error_message,
113 timeout=5): 121 timeout=5):
114 """Waits until the function finishes or timeout.""" 122 """Waits until the function finishes or timeout."""
115 123
116 start_time = time.time() 124 start_time = time.time()
117 while (not verify_func() and 125 while (not verify_func() and
118 time.time() - start_time < timeout): 126 time.time() - start_time < timeout):
119 action_runner.Wait(1) 127 action_runner.Wait(1)
120 if not verify_func(): 128 if not verify_func():
121 raise page.page_test.Failure(error_message) 129 raise RuntimeError(error_message)
122 130
123 def _GetDeviceName(self): 131 def _GetDeviceName(self):
124 """Gets device name from environment variable RECEIVER_NAME.""" 132 """Gets device name from environment variable RECEIVER_NAME."""
125 133
126 if 'RECEIVER_IP' not in os.environ or not os.environ.get('RECEIVER_IP'): 134 if 'RECEIVER_IP' not in os.environ or not os.environ.get('RECEIVER_IP'):
127 raise page.page_test.Failure( 135 raise RuntimeError(
128 'Your test machine is not set up correctly, ' 136 'Your test machine is not set up correctly, '
129 'RECEIVER_IP enviroment variable is missing.') 137 'RECEIVER_IP enviroment variable is missing.')
130 return utils.GetDeviceName(os.environ.get('RECEIVER_IP')) 138 return utils.GetDeviceName(os.environ.get('RECEIVER_IP'))
OLDNEW
« no previous file with comments | « no previous file | chrome/test/media_router/telemetry/benchmarks/pagesets/media_router_perf_pages.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698