Bug 1258602 - Part2: Test case changes, r=smaug
authorKershaw Chang <kechang@mozilla.com>
Sun, 29 May 2016 20:00:00 +0200
changeset 338556 e0f15af55efbef722c2a6981203a0d3a06892577
parent 338555 54ca84566554be8fd282e3ffc633e66bc0c39f94
child 338557 3da545fd691fa27d09ab8865b1fa2916418cad7f
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1258602
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1258602 - Part2: Test case changes, r=smaug
dom/presentation/tests/mochitest/file_presentation_1ua_receiver.html
dom/presentation/tests/mochitest/file_presentation_receiver.html
dom/presentation/tests/mochitest/file_presentation_receiver_establish_connection_error.html
--- a/dom/presentation/tests/mochitest/file_presentation_1ua_receiver.html
+++ b/dom/presentation/tests/mochitest/file_presentation_1ua_receiver.html
@@ -37,38 +37,40 @@ function finish() {
 
 var connection;
 
 function testConnectionAvailable() {
   return new Promise(function(aResolve, aReject) {
     info('Receiver: --- testConnectionAvailable ---');
     ok(navigator.presentation, "Receiver: navigator.presentation should be available.");
     ok(navigator.presentation.receiver, "Receiver: navigator.presentation.receiver should be available.");
-    navigator.presentation.receiver.getConnection()
-    .then((aConnection) => {
-      connection = aConnection;
-      ok(connection.id, "Receiver: Connection ID should be set: " + connection.id);
-      is(connection.state, "closed", "Connection state at receiver side should be closed by default.");
+
+    navigator.presentation.receiver.connectionList
+    .then((aList) => {
+      is(aList.connections.length, 1, "Should get one conncetion.");
+      connection = aList.connections[0];
+      ok(connection.id, "Connection ID should be set: " + connection.id);
+      is(connection.state, "connected", "Connection state at receiver side should be connected.");
       aResolve();
     })
     .catch((aError) => {
       ok(false, "Receiver: Error occurred when getting the connection: " + aError);
       finish();
       aReject();
     });
   });
 }
 
 function testConnectionReady() {
   return new Promise(function(aResolve, aReject) {
     info('Receiver: --- testConnectionReady ---');
     connection.onstatechange = function() {
       connection.onstatechange = null;
-      is(connection.state, "connected", "Receiver: Connection state should become connected.");
-      aResolve();
+      ok(false, "Should not get |onstatechange| event.")
+      aReject();
     };
     if (connection.state === "connected") {
       connection.onstatechange = null;
       is(connection.state, "connected", "Receiver: Connection state should become connected.");
       aResolve();
     }
   });
 }
--- a/dom/presentation/tests/mochitest/file_presentation_receiver.html
+++ b/dom/presentation/tests/mochitest/file_presentation_receiver.html
@@ -32,30 +32,31 @@ function finish() {
 
 var connection;
 
 function testConnectionAvailable() {
   return new Promise(function(aResolve, aReject) {
     ok(navigator.presentation, "navigator.presentation should be available in OOP receiving pages.");
     ok(navigator.presentation.receiver, "navigator.presentation.receiver should be available in OOP receiving pages.");
 
-    navigator.presentation.receiver.getConnection().then(
-      function(aConnection) {
-        connection = aConnection;
-
+    navigator.presentation.receiver.connectionList.then(
+      function(aList) {
+        is(aList.connections.length, 1, "Should get one conncetion.");
+        connection = aList.connections[0];
         ok(connection.id, "Connection ID should be set: " + connection.id);
-        is(connection.state, "closed", "Connection state at receiver side should be closed by default.");
+        is(connection.state, "connected", "Connection state at receiver side should be connected.");
         aResolve();
       },
       function(aError) {
-        ok(false, "Error occurred when getting the connection: " + aError);
+        ok(false, "Error occurred when getting the connection list: " + aError);
         finish();
         aReject();
       }
     );
+    command({ name: 'trigger-incoming-offer' });
   });
 }
 
 function testDefauleRequestIsNull() {
   return new Promise(function(aResolve, aReject) {
     navigator.presentation.defaultRequest = new PresentationRequest("http://example.com");
     if (navigator.presentation.defaultRequest === null) {
       ok(true, "defaultRequest should be null.");
@@ -83,25 +84,30 @@ function testConnectionUnavailableDiffOr
     var iframe = document.createElement('iframe');
     iframe.setAttribute('src', 'http://example.com/tests/dom/presentation/tests/mochitest/file_presentation_non_receiver_inner_iframe.html');
     document.body.appendChild(iframe);
 
     aResolve();
   });
 }
 
-function testConnectionReady() {
+function testConnectionListSameObject() {
   return new Promise(function(aResolve, aReject) {
-    connection.onstatechange = function() {
-      connection.onstatechange = null;
-      is(connection.state, "connected", "Connection state should become connected.");
-      aResolve();
-    };
-
-    command({ name: 'trigger-incoming-offer' });
+    is(navigator.presentation.receiver.connectionList, navigator.presentation.receiver.connectionList, "The promise should be the same object.");
+    var promise = navigator.presentation.receiver.connectionList.then(
+      function(aList) {
+        is(connection, aList.connections[0], "The connection from list and the one from |connectionavailable| event should be the same.");
+        aResolve();
+      },
+      function(aError) {
+        ok(false, "Error occurred when getting the connection list: " + aError);
+        finish();
+        aReject();
+      }
+    );
   });
 }
 
 function testIncomingMessage() {
   return new Promise(function(aResolve, aReject) {
     const incomingMessage = "test incoming message";
 
     connection.addEventListener('message', function messageHandler(aEvent) {
@@ -126,16 +132,16 @@ function testTerminateConnection() {
     connection.terminate();
   });
 }
 
 testConnectionAvailable().
 then(testDefauleRequestIsNull).
 then(testConnectionAvailableSameOriginInnerIframe).
 then(testConnectionUnavailableDiffOriginInnerIframe).
-then(testConnectionReady).
+then(testConnectionListSameObject).
 then(testIncomingMessage).
 then(testTerminateConnection).
 then(finish);
 
 </script>
 </body>
 </html>
--- a/dom/presentation/tests/mochitest/file_presentation_receiver_establish_connection_error.html
+++ b/dom/presentation/tests/mochitest/file_presentation_receiver_establish_connection_error.html
@@ -29,50 +29,49 @@ function info(msg) {
 function command(name, data) {
   alert('COMMAND ' + JSON.stringify({name: name, data: data}));
 }
 
 function finish() {
   alert('DONE');
 }
 
-var connection;
-
 function testConnectionAvailable() {
   return new Promise(function(aResolve, aReject) {
     ok(navigator.presentation, "navigator.presentation should be available.");
     ok(navigator.presentation.receiver, "navigator.presentation.receiver should be available.");
-
-    navigator.presentation.receiver.getConnection().then(
-      function(aConnection) {
-        connection = aConnection;
-
-        ok(connection.id, "Connection ID should be set: " + connection.id);
-        is(connection.state, "closed", "Connection state at receiver side should be closed by default.");
-        aResolve();
-      },
-      function(aError) {
-        ok(false, "Error occurred when getting the connection: " + aError);
-        finish();
-        aReject();
-      }
-    );
+    aResolve();
   });
 }
 
 function testUnexpectedControlChannelClose() {
+  // Trigger the control channel to be closed with error code.
+  command({ name: 'trigger-control-channel-close', data: 0x80004004 /* NS_ERROR_ABORT */ });
+
   return new Promise(function(aResolve, aReject) {
-    connection.onstatechange = function() {
-      connection.onstatechange = null;
-      is(connection.state, "terminated", "Connection state should become terminated.");
-      aResolve();
-    };
-
-    // Trigger the control channel to be closed with error code.
-    command('trigger-control-channel-close', 0x80004004 /* NS_ERROR_ABORT */);
+    return Promise.race([
+      navigator.presentation.receiver.connectionList.then(
+        (aList) => {
+          ok(false, "Should not get a connection list.")
+          aReject();
+        },
+        (aError) => {
+          ok(false, "Error occurred when getting the connection list: " + aError);
+          aReject();
+        }
+      ),
+      new Promise(
+        () => {
+          setTimeout(() => {
+            ok(true, "Not getting a conenction list.");
+            aResolve();
+          }, 3000);
+        }
+      ),
+    ]);
   });
 }
 
 testConnectionAvailable().
 then(testUnexpectedControlChannelClose).
 then(finish);
 
 </script>