Chromium Code Reviews| Index: chrome/test/media_router/resources/common.js |
| diff --git a/chrome/test/media_router/resources/common.js b/chrome/test/media_router/resources/common.js |
| index d7f4241331d94367880232ccb047ccc163c92080..7cbc77578eda68570f40ab115e064e0da52eebc1 100644 |
| --- a/chrome/test/media_router/resources/common.js |
| +++ b/chrome/test/media_router/resources/common.js |
| @@ -140,6 +140,49 @@ function terminateSessionAndWaitForStateChange() { |
| } |
| } |
| +/** |
| + * Closes |startedConnection| and waits for its onclose event. |
| + */ |
| +function closeSessionAndWaitForStateChange() { |
|
mark a. foltz
2017/02/09 23:29:59
closeConnectionAndWaitForStateChange
takumif
2017/02/14 19:11:48
Done. Should all uses of "session" in this file be
mark a. foltz
2017/02/15 00:41:27
Ideally they should, but don't worry about mass re
takumif
2017/02/18 20:44:05
Acknowledged.
|
| + if (startedConnection) { |
| + if (startedConnection.state == 'closed') { |
| + sendResult(false, 'startedConnection is unexpectedly closed.'); |
| + } |
| + startedConnection.onclose = function() { |
| + sendResult(true, ''); |
| + }; |
| + startedConnection.close(); |
| + } else { |
| + sendResult(false, 'startedConnection does not exist.'); |
| + } |
| +} |
| + |
| +/** |
| + * Sends a message to |startedConnection| and expects InvalidStateError to be |
| + * thrown. Requires |startedConnection.state| to not equal |initialState|. |
| + */ |
| +function checkSendMessageFailed(initialState) { |
| + if (!startedConnection) { |
| + sendResult(false, 'startedConnection does not exist.'); |
| + return; |
| + } |
| + if (startedConnection.state != initialState) { |
| + sendResult(false, 'startedConnection.state is "' + startedConnection.state + |
| + '", but we expected "' + initialState + '".'); |
| + return; |
| + } |
| + |
| + try { |
| + startedConnection.send('test message'); |
| + } catch (e) { |
| + if (e.name == 'InvalidStateError') { |
| + sendResult(true, ''); |
| + } else { |
| + sendResult(false, 'Got an unexpected error: ' + e.name); |
| + } |
| + } |
| + sendResult(false, 'Expected InvalidStateError but it was never thrown.'); |
| +} |
| /** |
| * Sends a message, and expects the connection to close on error. |