| OLD | NEW |
| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 function checkSession() { | 64 function checkSession() { |
| 65 if (!startSessionPromise) { | 65 if (!startSessionPromise) { |
| 66 sendResult(false, 'Did not attempt to start session'); | 66 sendResult(false, 'Did not attempt to start session'); |
| 67 } else { | 67 } else { |
| 68 startSessionPromise.then(function(session) { | 68 startSessionPromise.then(function(session) { |
| 69 if(!session) { | 69 if(!session) { |
| 70 sendResult(false, 'Failed to start session: connection is null'); | 70 sendResult(false, 'Failed to start session: connection is null'); |
| 71 } else { | 71 } else { |
| 72 // set the new session | 72 // set the new session |
| 73 startedConnection = session; | 73 startedConnection = session; |
| 74 console.log('connection state is "' + startedConnection.state + '"'); | 74 waitForConnectedStateAndSendResult(startedConnection); |
| 75 if (startedConnection.state == "connected") { | |
| 76 sendResult(true, ''); | |
| 77 } else if (startedConnection.state == "connecting") { | |
| 78 startedConnection.onconnect = () => { | |
| 79 sendResult(true, ''); | |
| 80 }; | |
| 81 } else { | |
| 82 sendResult(false, | |
| 83 'Expect connection state to be "connecting" or "connected", ' + | |
| 84 'actual "' + startedConnection.state + '"'); | |
| 85 } | |
| 86 } | 75 } |
| 87 }).catch(function(e) { | 76 }).catch(function(e) { |
| 88 // terminate old session if exists | 77 // terminate old session if exists |
| 89 startedConnection && startedConnection.terminate(); | 78 startedConnection && startedConnection.terminate(); |
| 90 sendResult(false, 'Failed to start session: encountered exception ' + e); | 79 sendResult(false, 'Failed to start session: encountered exception ' + e); |
| 91 }) | 80 }) |
| 92 } | 81 } |
| 93 } | 82 } |
| 94 | 83 |
| 95 /** | 84 /** |
| 85 * Asserts the current state of the connection is 'connected' or 'connecting'. |
| 86 * If the current state is connecting, waits for it to become 'connected'. |
| 87 * @param {!PresentationConnection} connection |
| 88 */ |
| 89 function waitForConnectedStateAndSendResult(connection) { |
| 90 console.log(`connection state is "${connection.state}"`); |
| 91 if (connection.state == 'connected') { |
| 92 sendResult(true, ''); |
| 93 } else if (connection.state == 'connecting') { |
| 94 connection.onconnect = () => { |
| 95 sendResult(true, ''); |
| 96 }; |
| 97 } else { |
| 98 sendResult(false, |
| 99 `Expect connection state to be "connecting" or "connected", actual: \ |
| 100 "${connection.state}"`); |
| 101 } |
| 102 } |
| 103 |
| 104 /** |
| 96 * Checks the start() request fails with expected error and message substring. | 105 * Checks the start() request fails with expected error and message substring. |
| 97 * @param {!string} expectedErrorName | 106 * @param {!string} expectedErrorName |
| 98 * @param {!string} expectedErrorMessageSubstring | 107 * @param {!string} expectedErrorMessageSubstring |
| 99 */ | 108 */ |
| 100 function checkStartFailed(expectedErrorName, expectedErrorMessageSubstring) { | 109 function checkStartFailed(expectedErrorName, expectedErrorMessageSubstring) { |
| 101 if (!startSessionPromise) { | 110 if (!startSessionPromise) { |
| 102 sendResult(false, 'Did not attempt to start session'); | 111 sendResult(false, 'Did not attempt to start session'); |
| 103 } else { | 112 } else { |
| 104 startSessionPromise.then(function(session) { | 113 startSessionPromise.then(function(session) { |
| 105 sendResult(false, 'start() unexpectedly succeeded.'); | 114 sendResult(false, 'start() unexpectedly succeeded.'); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 * Reconnects to |sessionId| and verifies that it succeeds. | 186 * Reconnects to |sessionId| and verifies that it succeeds. |
| 178 * @param {!string} sessionId ID of session to reconnect. | 187 * @param {!string} sessionId ID of session to reconnect. |
| 179 */ | 188 */ |
| 180 function reconnectSession(sessionId) { | 189 function reconnectSession(sessionId) { |
| 181 var reconnectSessionRequest = new PresentationRequest(presentationUrl); | 190 var reconnectSessionRequest = new PresentationRequest(presentationUrl); |
| 182 reconnectSessionRequest.reconnect(sessionId).then(function(session) { | 191 reconnectSessionRequest.reconnect(sessionId).then(function(session) { |
| 183 if (!session) { | 192 if (!session) { |
| 184 sendResult(false, 'reconnectSession returned null session'); | 193 sendResult(false, 'reconnectSession returned null session'); |
| 185 } else { | 194 } else { |
| 186 reconnectedSession = session; | 195 reconnectedSession = session; |
| 187 sendResult(true, ''); | 196 waitForConnectedStateAndSendResult(reconnectedSession); |
| 188 } | 197 } |
| 189 }).catch(function(error) { | 198 }).catch(function(error) { |
| 190 sendResult(false, 'reconnectSession failed: ' + error.message); | 199 sendResult(false, 'reconnectSession failed: ' + error.message); |
| 191 }); | 200 }); |
| 192 } | 201 } |
| 193 | 202 |
| 194 /** | 203 /** |
| 195 * Calls reconnect(sessionId) and verifies that it fails. | 204 * Calls reconnect(sessionId) and verifies that it fails. |
| 196 * @param {!string} sessionId ID of session to reconnect. | 205 * @param {!string} sessionId ID of session to reconnect. |
| 197 * @param {!string} expectedErrorMessage | 206 * @param {!string} expectedErrorMessage |
| (...skipping 25 matching lines...) Expand all Loading... |
| 223 passed: passed, | 232 passed: passed, |
| 224 errorMessage: errorMessage | 233 errorMessage: errorMessage |
| 225 })); | 234 })); |
| 226 } else { | 235 } else { |
| 227 lastExecutionResult = JSON.stringify({ | 236 lastExecutionResult = JSON.stringify({ |
| 228 passed: passed, | 237 passed: passed, |
| 229 errorMessage: errorMessage | 238 errorMessage: errorMessage |
| 230 }); | 239 }); |
| 231 } | 240 } |
| 232 } | 241 } |
| OLD | NEW |