Chromium Code Reviews| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 if (startedConnection) { | 124 if (startedConnection) { |
| 125 startedConnection.onterminate = function() { | 125 startedConnection.onterminate = function() { |
| 126 sendResult(true, ''); | 126 sendResult(true, ''); |
| 127 }; | 127 }; |
| 128 startedConnection.terminate(); | 128 startedConnection.terminate(); |
| 129 } else { | 129 } else { |
| 130 sendResult(false, 'startedConnection does not exist.'); | 130 sendResult(false, 'startedConnection does not exist.'); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 /** | |
| 135 * Closes |startedConnection| and waits for its onclose event. | |
| 136 */ | |
| 137 function closeSessionAndWaitForStateChange() { | |
| 138 if (startedConnection) { | |
| 139 startedConnection.onclose = function() { | |
| 140 sendResult(true, ''); | |
| 141 }; | |
| 142 startedConnection.close(); | |
| 143 } else { | |
| 144 sendResult(false, 'startedConnection does not exist.'); | |
| 145 } | |
| 146 } | |
| 147 | |
| 148 /** | |
| 149 * Reconnects to |startedConnection| and waits for its state to change to | |
| 150 * "connected." Requires |startedConnection| to be closed initially. | |
| 151 */ | |
| 152 function reconnectToClosedSessionAndWaitForStateChange() { | |
| 153 if (startedConnection) { | |
| 154 if (startedConnection.state != 'closed') { | |
| 155 sendResult(false, 'startedConnection is not closed.'); | |
| 156 return; | |
| 157 } | |
| 158 startSessionRequest.reconnect(startedConnection.id).then(function(session) { | |
| 159 if(session !== startedConnection) { | |
| 160 sendResult(false, 'Failed to reconnect to the closed session'); | |
| 161 } else { | |
| 162 console.log('connection state is "' + startedConnection.state + '"'); | |
| 163 if (startedConnection.state == 'connected') { | |
| 164 sendResult(true, ''); | |
| 165 } else if (startedConnection.state == 'connecting') { | |
| 166 startedConnection.onconnect = () => { | |
| 167 sendResult(true, ''); | |
| 168 }; | |
| 169 } else { | |
| 170 sendResult(false, | |
| 171 'Expect connection state to be "connecting" or "connected", ' + | |
| 172 'actual "' + startedConnection.state + '"'); | |
| 173 } | |
| 174 } | |
| 175 }).catch(function(e) { | |
| 176 // terminate old session if exists | |
| 177 startedConnection && startedConnection.terminate(); | |
| 178 sendResult(false, 'Failed to start session: encountered exception ' + e); | |
| 179 }); | |
| 180 } else { | |
| 181 sendResult(false, 'startedConnection does not exist.'); | |
| 182 } | |
| 183 } | |
| 184 | |
| 185 /** | |
| 186 * Sends a message to |startedConnection| and expects InvalidStateError to be | |
| 187 * thrown. Requires |startedConnection.state| to not be "connected." | |
|
mark a. foltz
2017/01/20 19:00:09
Can you pass in an expectation of the connection s
takumif
2017/02/07 22:17:36
Done.
| |
| 188 */ | |
| 189 function checkSendMessageFailed() { | |
| 190 if (!startedConnection) { | |
| 191 sendResult(false, 'startedConnection does not exist.'); | |
| 192 return; | |
| 193 } | |
| 194 if (startedConnection.state == 'connected') { | |
| 195 sendResult(false, 'startedConnection is connected, which is not expected.'); | |
| 196 return; | |
| 197 } | |
| 198 | |
| 199 try { | |
| 200 startedConnection.send('test message'); | |
| 201 } catch (e) { | |
| 202 if (e.name == 'InvalidStateError') { | |
| 203 sendResult(true, ''); | |
| 204 } else { | |
| 205 sendResult(false, 'Got an unexpected error: ' + e.name); | |
| 206 } | |
| 207 } | |
| 208 sendResult(false, 'Expected InvalidStateError but it was never thrown.'); | |
| 209 } | |
| 134 | 210 |
| 135 /** | 211 /** |
| 136 * Sends a message, and expects the connection to close on error. | 212 * Sends a message, and expects the connection to close on error. |
| 137 */ | 213 */ |
| 138 function sendMessageAndExpectConnectionCloseOnError() { | 214 function sendMessageAndExpectConnectionCloseOnError() { |
| 139 if (!startedConnection) { | 215 if (!startedConnection) { |
| 140 sendResult(false, 'startedConnection does not exist.'); | 216 sendResult(false, 'startedConnection does not exist.'); |
| 141 return; | 217 return; |
| 142 } | 218 } |
| 143 startedConnection.onclose = function(event) { | 219 startedConnection.onclose = function(event) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 passed: passed, | 299 passed: passed, |
| 224 errorMessage: errorMessage | 300 errorMessage: errorMessage |
| 225 })); | 301 })); |
| 226 } else { | 302 } else { |
| 227 lastExecutionResult = JSON.stringify({ | 303 lastExecutionResult = JSON.stringify({ |
| 228 passed: passed, | 304 passed: passed, |
| 229 errorMessage: errorMessage | 305 errorMessage: errorMessage |
| 230 }); | 306 }); |
| 231 } | 307 } |
| 232 } | 308 } |
| OLD | NEW |