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

Side by Side Diff: chrome/test/media_router/resources/common.js

Issue 2634213002: [Media Router] Add integration browser tests (Closed)
Patch Set: Undo renaming waitUntilDeviceAvailable Created 3 years, 10 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 | « chrome/test/media_router/media_router_integration_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * Copyright 2015 The Chromium Authors. All rights reserved. 2 * Copyright 2015 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 * 5 *
6 * @fileoverview Common APIs for presentation integration tests. 6 * @fileoverview Common APIs for presentation integration tests.
7 * 7 *
8 */ 8 */
9 9
10 var startSessionPromise = null; 10 var startSessionPromise = null;
(...skipping 12 matching lines...) Expand all
23 var lastExecutionResult = null; 23 var lastExecutionResult = null;
24 var useDomAutomationController = !!window.domAutomationController; 24 var useDomAutomationController = !!window.domAutomationController;
25 25
26 window.navigator.presentation.defaultRequest = startSessionRequest; 26 window.navigator.presentation.defaultRequest = startSessionRequest;
27 window.navigator.presentation.defaultRequest.onconnectionavailable = function(e) 27 window.navigator.presentation.defaultRequest.onconnectionavailable = function(e)
28 { 28 {
29 defaultRequestSessionId = e.connection.id; 29 defaultRequestSessionId = e.connection.id;
30 }; 30 };
31 31
32 /** 32 /**
33 * Waits until one device is available. 33 * Waits until one sink is available.
34 */ 34 */
35 function waitUntilDeviceAvailable() { 35 function waitUntilDeviceAvailable() {
36 startSessionRequest.getAvailability(presentationUrl).then( 36 startSessionRequest.getAvailability(presentationUrl).then(
37 function(availability) { 37 function(availability) {
38 console.log('availability ' + availability.value + '\n'); 38 console.log('availability ' + availability.value + '\n');
39 if (availability.value) { 39 if (availability.value) {
40 sendResult(true, ''); 40 sendResult(true, '');
41 } else { 41 } else {
42 availability.onchange = function(newAvailability) { 42 availability.onchange = function(newAvailability) {
43 if (newAvailability) 43 if (newAvailability)
44 sendResult(true, ''); 44 sendResult(true, '');
45 } 45 }
46 } 46 }
47 }).catch(function(){ 47 }).catch(function(e) {
48 sendResult(false, 'got error'); 48 sendResult(false, 'got error: ' + e);
49 }); 49 });
50 } 50 }
51 51
52 /** 52 /**
53 * Starts session. 53 * Starts session.
54 */ 54 */
55 function startSession() { 55 function startSession() {
56 startSessionPromise = startSessionRequest.start(); 56 startSessionPromise = startSessionRequest.start();
57 console.log('start session'); 57 console.log('start session');
58 sendResult(true, ''); 58 sendResult(true, '');
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 if (startedConnection) { 133 if (startedConnection) {
134 startedConnection.onterminate = function() { 134 startedConnection.onterminate = function() {
135 sendResult(true, ''); 135 sendResult(true, '');
136 }; 136 };
137 startedConnection.terminate(); 137 startedConnection.terminate();
138 } else { 138 } else {
139 sendResult(false, 'startedConnection does not exist.'); 139 sendResult(false, 'startedConnection does not exist.');
140 } 140 }
141 } 141 }
142 142
143 /**
144 * Closes |startedConnection| and waits for its onclose event.
145 */
146 function closeConnectionAndWaitForStateChange() {
147 if (startedConnection) {
148 if (startedConnection.state == 'closed') {
149 sendResult(false, 'startedConnection is unexpectedly closed.');
150 }
151 startedConnection.onclose = function() {
152 sendResult(true, '');
153 };
154 startedConnection.close();
155 } else {
156 sendResult(false, 'startedConnection does not exist.');
157 }
158 }
159
160 /**
161 * Sends a message to |startedConnection| and expects InvalidStateError to be
162 * thrown. Requires |startedConnection.state| to not equal |initialState|.
163 */
164 function checkSendMessageFailed(initialState) {
165 if (!startedConnection) {
166 sendResult(false, 'startedConnection does not exist.');
167 return;
168 }
169 if (startedConnection.state != initialState) {
170 sendResult(false, 'startedConnection.state is "' + startedConnection.state +
171 '", but we expected "' + initialState + '".');
172 return;
173 }
174
175 try {
176 startedConnection.send('test message');
177 } catch (e) {
178 if (e.name == 'InvalidStateError') {
179 sendResult(true, '');
180 } else {
181 sendResult(false, 'Got an unexpected error: ' + e.name);
182 }
183 }
184 sendResult(false, 'Expected InvalidStateError but it was never thrown.');
185 }
143 186
144 /** 187 /**
145 * Sends a message, and expects the connection to close on error. 188 * Sends a message, and expects the connection to close on error.
146 */ 189 */
147 function sendMessageAndExpectConnectionCloseOnError() { 190 function sendMessageAndExpectConnectionCloseOnError() {
148 if (!startedConnection) { 191 if (!startedConnection) {
149 sendResult(false, 'startedConnection does not exist.'); 192 sendResult(false, 'startedConnection does not exist.');
150 return; 193 return;
151 } 194 }
152 startedConnection.onclose = function(event) { 195 startedConnection.onclose = function(event) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 passed: passed, 275 passed: passed,
233 errorMessage: errorMessage 276 errorMessage: errorMessage
234 })); 277 }));
235 } else { 278 } else {
236 lastExecutionResult = JSON.stringify({ 279 lastExecutionResult = JSON.stringify({
237 passed: passed, 280 passed: passed,
238 errorMessage: errorMessage 281 errorMessage: errorMessage
239 }); 282 });
240 } 283 }
241 } 284 }
OLDNEW
« no previous file with comments | « chrome/test/media_router/media_router_integration_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698