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

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

Issue 2820433003: [Presentation API] Add browser tests for 1-UA mode (Closed)
Patch Set: resolve code review comments from Derek Created 3 years, 8 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 /** 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;
11 var startedConnection = null; 11 var startedConnection = null;
12 var reconnectedSession = null; 12 var reconnectedSession = null;
13 var presentationUrl = null; 13 var presentationUrl = null;
14 if (window.location.href.indexOf('__is_android__=true') >= 0) { 14 var pageUrl = window.location.href;
15
16 if (pageUrl.indexOf('__is_android__=true') >= 0) {
mark a. foltz 2017/04/18 01:03:44 Can you use URL.searchParams to parse the URL inst
zhaobin 2017/04/18 03:17:10 Done.
15 // For android, "google.com/cast" is required in presentation URL. 17 // For android, "google.com/cast" is required in presentation URL.
16 // TODO(zqzhang): this requirement may be removed in the future. 18 // TODO(zqzhang): this requirement may be removed in the future.
17 presentationUrl = "https://google.com/cast#__castAppId__=CCCCCCCC/"; 19 presentationUrl = "https://google.com/cast#__castAppId__=CCCCCCCC/";
20 } else if (pageUrl.indexOf('__oneUA__=true') >= 0) {
21 presentationUrl =
22 "presentation_receiver.html#__testprovider__=true&__oneUA__=true";
23 } else if (pageUrl.indexOf('__oneUANoReceiver__=true') >= 0) {
24 presentationUrl = "https://www.google.com#__testprovider__=true&__oneUA__=true ";
18 } else { 25 } else {
19 presentationUrl = "http://www.google.com/#__testprovider__=true"; 26 presentationUrl = "http://www.google.com/#__testprovider__=true";
20 } 27 }
28
21 var startSessionRequest = new PresentationRequest([presentationUrl]); 29 var startSessionRequest = new PresentationRequest([presentationUrl]);
22 var defaultRequestSessionId = null; 30 var defaultRequestSessionId = null;
23 var lastExecutionResult = null; 31 var lastExecutionResult = null;
24 var useDomAutomationController = !!window.domAutomationController; 32 var useDomAutomationController = !!window.domAutomationController;
25 33
26 window.navigator.presentation.defaultRequest = startSessionRequest; 34 window.navigator.presentation.defaultRequest = startSessionRequest;
27 window.navigator.presentation.defaultRequest.onconnectionavailable = function(e) 35 window.navigator.presentation.defaultRequest.onconnectionavailable = function(e)
28 { 36 {
29 defaultRequestSessionId = e.connection.id; 37 defaultRequestSessionId = e.connection.id;
30 }; 38 };
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 sendResult(false, 'Expected message: ' + expectedResponse + 227 sendResult(false, 'Expected message: ' + expectedResponse +
220 ', but got: ' + actualResponse); 228 ', but got: ' + actualResponse);
221 return; 229 return;
222 } 230 }
223 sendResult(true, ''); 231 sendResult(true, '');
224 }; 232 };
225 startedConnection.send(message); 233 startedConnection.send(message);
226 } 234 }
227 235
228 /** 236 /**
237 * Sends 'close' to receiver page, and expects receiver page closing
238 * the connection.
239 */
240 function initiateCloseFromReceiverPage() {
241 if (!startedConnection) {
242 sendResult(false, 'startedConnection does not exist.');
243 return;
244 }
245 startedConnection.onclose = function(event) {
mark a. foltz 2017/04/18 01:03:44 Slight preference for arrow function syntax: (even
zhaobin 2017/04/18 03:17:10 Done.
246 var reason = event.reason;
mark a. foltz 2017/04/18 01:03:44 s/var/const/
zhaobin 2017/04/18 03:17:10 Done.
247 if (reason != 'closed') {
248 sendResult(false, 'Unexpected close reason: ' + reason);
249 return;
250 }
251 sendResult(true, '');
252 };
253 startedConnection.send('close');
254 }
255
256 /**
229 * Reconnects to |sessionId| and verifies that it succeeds. 257 * Reconnects to |sessionId| and verifies that it succeeds.
230 * @param {!string} sessionId ID of session to reconnect. 258 * @param {!string} sessionId ID of session to reconnect.
231 */ 259 */
232 function reconnectSession(sessionId) { 260 function reconnectSession(sessionId) {
233 var reconnectSessionRequest = new PresentationRequest(presentationUrl); 261 var reconnectSessionRequest = new PresentationRequest(presentationUrl);
234 reconnectSessionRequest.reconnect(sessionId).then(function(session) { 262 reconnectSessionRequest.reconnect(sessionId).then(function(session) {
235 if (!session) { 263 if (!session) {
236 sendResult(false, 'reconnectSession returned null session'); 264 sendResult(false, 'reconnectSession returned null session');
237 } else { 265 } else {
238 reconnectedSession = session; 266 reconnectedSession = session;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 passed: passed, 303 passed: passed,
276 errorMessage: errorMessage 304 errorMessage: errorMessage
277 })); 305 }));
278 } else { 306 } else {
279 lastExecutionResult = JSON.stringify({ 307 lastExecutionResult = JSON.stringify({
280 passed: passed, 308 passed: passed,
281 errorMessage: errorMessage 309 errorMessage: errorMessage
282 }); 310 });
283 } 311 }
284 } 312 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698