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

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

Issue 2634213002: [Media Router] Add integration browser tests (Closed)
Patch Set: Undo renaming waitUntilDeviceAvailable Created 3 years, 10 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 | « chrome/test/media_router/media_router_integration_browsertest.cc ('k') | 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 d7f4241331d94367880232ccb047ccc163c92080..9e69d91a62379ffd824128fc7e2f96760ca34590 100644
--- a/chrome/test/media_router/resources/common.js
+++ b/chrome/test/media_router/resources/common.js
@@ -30,7 +30,7 @@ window.navigator.presentation.defaultRequest.onconnectionavailable = function(e)
};
/**
- * Waits until one device is available.
+ * Waits until one sink is available.
*/
function waitUntilDeviceAvailable() {
startSessionRequest.getAvailability(presentationUrl).then(
@@ -44,8 +44,8 @@ function waitUntilDeviceAvailable() {
sendResult(true, '');
}
}
- }).catch(function(){
- sendResult(false, 'got error');
+ }).catch(function(e) {
+ sendResult(false, 'got error: ' + e);
});
}
@@ -140,6 +140,49 @@ function terminateSessionAndWaitForStateChange() {
}
}
+/**
+ * Closes |startedConnection| and waits for its onclose event.
+ */
+function closeConnectionAndWaitForStateChange() {
+ 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.
« no previous file with comments | « chrome/test/media_router/media_router_integration_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698