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.
10 var startSessionPromise = null;
11 var currentSession = null;
12 var presentation = window.navigator.presentation;
13 var presUrl = "http://www.google.com/#__testprovider__=true";
16 * Waits until one device is available.
18 function waitUntilDeviceAvailable() {
19 presentation.getAvailability(presUrl).then(function(availability) {
20 console.log('availability ' + availability.value + '\n');
21 if (availability.value) {
24 sendResult(false, 'device unavailable');
27 sendResult(false, 'got error');
34 function startSession() {
35 var presId = Math.random().toFixed(6).substr(2);
36 startSessionPromise = presentation.startSession(presUrl, presId);
37 console.log('start session');
42 * Checks if the session has been started successfully.
44 function checkSession() {
45 if (!startSessionPromise) {
46 sendResult(false, 'Failed to start session');
48 startSessionPromise.then(function (currentSession) {
50 sendResult(false, 'Failed to start session');
52 // set the new session
53 currentSession = currentSession;
57 // close old session if exists
58 currentSession && currentSession.close();
59 sendResult(false, 'Failed to start session');
66 * Stops current session.
68 function stopSession() {
70 currentSession.close();
77 * Sends the test result back to browser test.
78 * @param passed true if test passes, otherwise false.
79 * @param errorMessage empty string if test passes, error message if test
82 function sendResult(passed, errorMessage) {
83 window.domAutomationController.send(JSON.stringify({
85 errorMessage: errorMessage