[sql] Remove _HAS_EXCEPTIONS=0 from build info.
[chromium-blink-merge.git] / chrome / test / media_router / resources / common.js
blob36e627f2b9278498a2f20e7f3ab7d8033e18f304
1 /**
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
4 * found in the LICENSE file.
6 * @fileoverview Common APIs for presentation integration tests.
8 */
10 var startSessionPromise = null;
11 var startedSession = null;
12 var joinedSession = null;
13 var presentationUrl = "http://www.google.com/#__testprovider__=true";
14 var startSessionRequest = new PresentationRequest(presentationUrl);
16 window.navigator.presentation.defaultRequest = startSessionRequest;
18 /**
19 * Waits until one device is available.
21 function waitUntilDeviceAvailable() {
22 startSessionRequest.getAvailability(presentationUrl).then(
23 function(availability) {
24 console.log('availability ' + availability.value + '\n');
25 if (availability.value) {
26 sendResult(true, '');
27 } else {
28 sendResult(false, 'device unavailable');
30 }).catch(function(){
31 sendResult(false, 'got error');
32 });
35 /**
36 * Starts session.
38 function startSession() {
39 startSessionPromise = startSessionRequest.start();
40 console.log('start session');
41 sendResult(true, '');
44 /**
45 * Checks if the session has been started successfully.
47 function checkSession() {
48 if (!startSessionPromise) {
49 sendResult(false, 'Failed to start session');
50 } else {
51 startSessionPromise.then(function(session) {
52 if(!session) {
53 sendResult(false, 'Failed to start session');
54 } else {
55 // set the new session
56 startedSession = session;
57 sendResult(true, '');
59 }).catch(function() {
60 // close old session if exists
61 startedSession && startedSession.close();
62 sendResult(false, 'Failed to start session');
68 /**
69 * Stops current session.
71 function stopSession() {
72 if (startedSession) {
73 startedSession.close();
75 sendResult(true, '');
79 /**
80 * Joins the started session and verify that it succeeds.
81 * @param {!string} sessionId ID of session to join.
83 function joinSession(sessionId) {
84 var joinSessionRequest = new PresentationRequest(presentationUrl);
85 joinSessionRequest.join(sessionId).then(function(session) {
86 if (!session) {
87 sendResult(false, 'joinSession returned null session');
88 } else {
89 joinedSession = session;
90 sendResult(true, '');
92 }).catch(function(error) {
93 sendResult(false, 'joinSession failed: ' + error.message);
94 });
97 /**
98 * Sends the test result back to browser test.
99 * @param passed true if test passes, otherwise false.
100 * @param errorMessage empty string if test passes, error message if test
101 * fails.
103 function sendResult(passed, errorMessage) {
104 window.domAutomationController.send(JSON.stringify({
105 passed: passed,
106 errorMessage: errorMessage
107 }));