Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8234)

Unified Diff: chrome/test/media_router/resources/common.js

Issue 2654003002: [MR tests] Assert initial state / state change for reconnect case. (Closed)
Patch Set: rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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') {
+ 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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698