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 3f61ae4d1bdc5c49b87202f7b5458b748a55299c..d7f4241331d94367880232ccb047ccc163c92080 100644 |
| --- a/chrome/test/media_router/resources/common.js |
| +++ b/chrome/test/media_router/resources/common.js |
| @@ -71,18 +71,7 @@ function checkSession() { |
| } else { |
| // set the new session |
| startedConnection = session; |
| - console.log('connection state is "' + startedConnection.state + '"'); |
| - if (startedConnection.state == "connected") { |
| - sendResult(true, ''); |
| - } else if (startedConnection.state == "connecting") { |
| - startedConnection.onconnect = () => { |
| - sendResult(true, ''); |
| - }; |
| - } else { |
| - sendResult(false, |
| - 'Expect connection state to be "connecting" or "connected", ' + |
| - 'actual "' + startedConnection.state + '"'); |
| - } |
| + waitForConnectedStateAndSendResult(startedConnection); |
| } |
| }).catch(function(e) { |
| // terminate old session if exists |
| @@ -93,6 +82,26 @@ function checkSession() { |
| } |
| /** |
| + * Asserts the current state of the connection is 'connected' or 'connecting'. |
| + * If the current state is connecting, waits for it to become 'connected'. |
| + * @param {!PresentationConnection} connection |
| + */ |
| +function waitForConnectedStateAndSendResult(connection) { |
| + console.log(`connection state is "${connection.state}"`); |
| + if (connection.state == 'connected') { |
|
mark a. foltz
2017/01/26 19:32:23
When would this be 'connected'? The state must be
takumif
2017/01/26 21:28:29
In checkSession() we're passing in a resolver func
mark a. foltz
2017/01/26 22:27:24
Yes, if the Promise is already settled the connect
|
| + sendResult(true, ''); |
| + } else if (connection.state == 'connecting') { |
| + connection.onconnect = () => { |
| + sendResult(true, ''); |
| + }; |
| + } else { |
| + sendResult(false, |
| + `Expect connection state to be "connecting" or "connected", actual: \ |
| + "${connection.state}"`); |
| + } |
| +} |
| + |
| +/** |
| * Checks the start() request fails with expected error and message substring. |
| * @param {!string} expectedErrorName |
| * @param {!string} expectedErrorMessageSubstring |
| @@ -184,7 +193,7 @@ function reconnectSession(sessionId) { |
| sendResult(false, 'reconnectSession returned null session'); |
| } else { |
| reconnectedSession = session; |
| - sendResult(true, ''); |
| + waitForConnectedStateAndSendResult(reconnectedSession); |
| } |
| }).catch(function(error) { |
| sendResult(false, 'reconnectSession failed: ' + error.message); |