Bug 1119593 - Update identity tests, r=drno
☠☠ backed out by a2984f1964f6 ☠ ☠
authorMartin Thomson <martin.thomson@gmail.com>
Tue, 27 Jan 2015 12:35:58 -0800
changeset 239506 2ea753b42366d177d4f6af7abc5484e4819c4951
parent 239505 28d59c42debbf31c459b4a853246a0a2fc5778c3
child 239507 4ccecd0da80ffc40f25a211395d7ca31a8847a9c
push id500
push userjoshua.m.grant@gmail.com
push dateThu, 29 Jan 2015 01:48:36 +0000
reviewersdrno
bugs1119593
milestone38.0a1
Bug 1119593 - Update identity tests, r=drno
dom/media/tests/mochitest/identity/test_getIdentityAssertion.html
dom/media/tests/mochitest/identity/test_peerConnection_peerIdentity.html
dom/media/tests/mochitest/identity/test_setIdentityProvider.html
dom/media/tests/mochitest/identity/test_setIdentityProviderWithErrors.html
--- a/dom/media/tests/mochitest/identity/test_getIdentityAssertion.html
+++ b/dom/media/tests/mochitest/identity/test_getIdentityAssertion.html
@@ -23,95 +23,90 @@ function checkIdentity(assertion, identi
 }
 
 var test;
 function theTest() {
   test = new PeerConnectionTest();
   test.setMediaConstraints([{audio: true}], [{audio: true}]);
   test.chain.removeAfter('PC_REMOTE_CHECK_INITIAL_SIGNALINGSTATE');
   test.chain.append([
-  [
-    "GET_IDENTITY_ASSERTION_FAILS_WITHOUT_PROVIDER",
-    function(test) {
-      test.pcLocal._pc.onidpassertionerror = function(e) {
-        ok(e, "getIdentityAssertion must fail without provider");
-        test.next();
-      };
-      test.pcLocal._pc.getIdentityAssertion();
+    function GET_IDENTITY_ASSERTION_FAILS_WITHOUT_PROVIDER(test) {
+      return new Promise(resolve => {
+        test.pcLocal._pc.onidpassertionerror = function(e) {
+          ok(e, "getIdentityAssertion must fail without provider");
+          resolve();
+        };
+        test.pcLocal._pc.getIdentityAssertion();
+      });
+    },
+    function GET_IDENTITY_ASSERTION_FIRES_EVENTUALLY_AND_SUBSEQUENTLY(test) {
+      return new Promise(resolve => {
+        var fired = 0;
+        test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html');
+        test.pcLocal._pc.onidentityresult = function(e) {
+          fired++;
+          if (fired == 1) {
+            ok(true, "identityresult fired");
+            checkIdentity(e.assertion, 'someone@example.com');
+          } else if (fired == 2) {
+            ok(true, "identityresult fired 2x");
+            checkIdentity(e.assertion, 'someone@example.com');
+            resolve();
+          }
+        };
+        test.pcLocal._pc.onidpassertionerror = function(e) {
+          ok(false, "error event fired");
+          resolve();
+        };
+        test.pcLocal._pc.getIdentityAssertion();
+        test.pcLocal._pc.getIdentityAssertion();
+      });
     },
-  ],
-  [
-    "GET_IDENTITY_ASSERTION_FIRES_EVENTUALLY_AND_SUBSEQUENTLY",
-    function(test) {
-      var fired = 0;
-      test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html');
-      test.pcLocal._pc.onidentityresult = function(e) {
-        fired++;
-        if (fired == 1) {
-          ok(true, "identityresult fired");
-          checkIdentity(e.assertion, 'someone@example.com');
-        } else if (fired == 2) {
-          ok(true, "identityresult fired 2x");
-          checkIdentity(e.assertion, 'someone@example.com');
-          test.next();
-        }
-      };
-      test.pcLocal._pc.onidpassertionerror = function(e) {
-        ok(false, "error event fired");
-        test.next();
-      };
-      test.pcLocal._pc.getIdentityAssertion();
-      test.pcLocal._pc.getIdentityAssertion();
+    function GET_IDENTITY_ASSERTION_FAILS(test) {
+      return new Promise(resolve => {
+        test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html#error');
+        test.pcLocal._pc.onidentityresult = function(e) {
+          ok(false, "Should not get an identity result");
+          resolve();
+        };
+        test.pcLocal._pc.onidpassertionerror = function(err) {
+          ok(err, "Got error event from getIdentityAssertion");
+          resolve();
+        };
+        test.pcLocal._pc.getIdentityAssertion();
+      });
+    },
+    function GET_IDENTITY_ASSERTION_IDP_NOT_READY(test) {
+      return new Promise(resolve => {
+        test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html#error:ready');
+        test.pcLocal._pc.onidentityresult = function(e) {
+          ok(false, "Should not get an identity result");
+          resolve();
+        };
+        test.pcLocal._pc.onidpassertionerror = function(e) {
+          ok(e, "Got error callback from getIdentityAssertion");
+          resolve();
+        };
+        test.pcLocal._pc.getIdentityAssertion();
+      });
+    },
+    function GET_IDENTITY_ASSERTION_WITH_SPECIFIC_NAME(test) {
+      return new Promise(resolve => {
+        test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html', 'user@example.com');
+        test.pcLocal._pc.onidentityresult = function(e) {
+          checkIdentity(e.assertion, 'user@example.com');
+          resolve();
+        };
+        test.pcLocal._pc.onidpassertionerror = function(e) {
+          ok(false, "Got error callback from getIdentityAssertion");
+          resolve();
+        };
+        test.pcLocal._pc.getIdentityAssertion();
+      });
     }
-  ],
-  [
-    "GET_IDENTITY_ASSERTION_FAILS",
-    function(test) {
-      test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html#error');
-      test.pcLocal._pc.onidentityresult = function(e) {
-        ok(false, "Should not get an identity result");
-        test.next();
-      };
-      test.pcLocal._pc.onidpassertionerror = function(err) {
-        ok(err, "Got error event from getIdentityAssertion");
-        test.next();
-      };
-      test.pcLocal._pc.getIdentityAssertion();
-    }
-  ],
-  [
-    "GET_IDENTITY_ASSERTION_IDP_NOT_READY",
-    function(test) {
-      test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html#error:ready');
-      test.pcLocal._pc.onidentityresult = function(e) {
-        ok(false, "Should not get an identity result");
-        test.next();
-      };
-      test.pcLocal._pc.onidpassertionerror = function(e) {
-        ok(e, "Got error callback from getIdentityAssertion");
-        test.next();
-      };
-      test.pcLocal._pc.getIdentityAssertion();
-    }
-  ],
-  [
-    "GET_IDENTITY_ASSERTION_WITH_SPECIFIC_NAME",
-    function(test) {
-      test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html', 'user@example.com');
-      test.pcLocal._pc.onidentityresult = function(e) {
-        checkIdentity(e.assertion, 'user@example.com');
-        test.next();
-      };
-      test.pcLocal._pc.onidpassertionerror = function(e) {
-        ok(false, "Got error callback from getIdentityAssertion");
-        test.next();
-      };
-      test.pcLocal._pc.getIdentityAssertion();
-    }
-  ]
   ]);
   test.run();
 }
 runNetworkTest(theTest);
 
 </script>
 </pre>
 </body>
--- a/dom/media/tests/mochitest/identity/test_peerConnection_peerIdentity.html
+++ b/dom/media/tests/mochitest/identity/test_peerConnection_peerIdentity.html
@@ -43,48 +43,36 @@ function theTest() {
   }, {
     video: true,
     fake: true,
     peerIdentity: id1
   }]);
   test.setIdentityProvider(test.pcLocal, 'test1.example.com', 'idp.html');
   test.setIdentityProvider(test.pcRemote, 'test2.example.com', 'idp.html');
   test.chain.append([
-  [
-    "PEER_IDENTITY_IS_SET_CORRECTLY",
-    function(test) {
+
+    function PEER_IDENTITY_IS_SET_CORRECTLY(test) {
       // no need to wait to check identity in this case,
       // setRemoteDescription should wait for the IdP to complete
       function checkIdentity(pc, pfx, idp, name) {
         is(pc.peerIdentity.idp, idp, pfx + "IdP is correct");
         is(pc.peerIdentity.name, name + "@" + idp, pfx + "identity is correct");
       }
 
       checkIdentity(test.pcLocal._pc, "local: ", "test2.example.com", "someone");
       checkIdentity(test.pcRemote._pc, "remote: ", "test1.example.com", "someone");
-      test.next();
-    }
-  ],
-  [
-    "REMOTE_STREAMS_ARE_RESTRICTED",
-    function(test) {
+    },
+
+    function REMOTE_STREAMS_ARE_RESTRICTED(test) {
       var remoteStream = test.pcLocal._pc.getRemoteStreams()[0];
-      var oneDone = false;
-      function done() {
-        if (!oneDone) {
-          oneDone = true;
-          return;
-        }
-        test.next();
-      }
-
-      audioIsSilence(true, remoteStream, done);
-      videoIsBlack(true, remoteStream, done);
+      return Promise.all([
+        new Promise(done => audioIsSilence(true, remoteStream, done)),
+        new Promise(done => videoIsBlack(true, remoteStream, done))
+      ]);
     }
-  ],
   ]);
   test.run();
 }
 runNetworkTest(theTest);
 
 </script>
 </pre>
 </body>
--- a/dom/media/tests/mochitest/identity/test_setIdentityProvider.html
+++ b/dom/media/tests/mochitest/identity/test_setIdentityProvider.html
@@ -22,91 +22,76 @@ function theTest() {
   test.setMediaConstraints([{audio: true}], [{audio: true}]);
   test.setIdentityProvider(test.pcLocal, "test1.example.com", "idp.html", "someone");
   test.setIdentityProvider(test.pcRemote, "test2.example.com", "idp.html", "someone");
 
   var localEvents = trapIdentityEvents(test.pcLocal._pc);
   var remoteEvents = trapIdentityEvents(test.pcRemote._pc);
 
   test.chain.append([
-  [
-    "PEER_IDENTITY_IS_SET_CORRECTLY",
-    function(test) {
+    function PEER_IDENTITY_IS_SET_CORRECTLY(test) {
       var outstanding = 0;
       // we have to wait for the identity result in order to get the actual
       // identity information, since the call will complete before the identity
       // provider has a chance to finish verifying... that's OK, but it makes
       // testing more difficult
 
-      function checkOrSetupCheck(pc, pfx, idp, name) {
+      function checkOrSetupCheck(pc, prefix, idp, name) {
         function checkIdentity() {
-          ok(pc.peerIdentity, pfx + "peerIdentity is set");
-          is(pc.peerIdentity.idp, idp, pfx + "IdP is correct");
-          is(pc.peerIdentity.name, name + "@" + idp, pfx + "identity is correct");
+          ok(pc.peerIdentity, prefix + "peerIdentity is set");
+          is(pc.peerIdentity.idp, idp, prefix + "IdP is correct");
+          is(pc.peerIdentity.name, name + "@" + idp, prefix + "identity is correct");
         }
         if (pc.peerIdentity) {
-          info(pfx + "peerIdentity already set");
+          info(prefix + "peerIdentity already set");
           checkIdentity();
-        } else {
-          ++outstanding;
-          info(pfx + "setting onpeeridentity handler");
-          pc.onpeeridentity = function checkIdentityEvent(e) {
-            info(pfx + "checking peerIdentity");
+          return Promise.resolve();
+        }
+
+        return new Promise(resolve => {
+          info(prefix + "setting onpeeridentity handler");
+          pc.onpeeridentity = e => {
             checkIdentity();
-            --outstanding;
-            if (outstanding <= 0) {
-              test.next();
-            }
+            resolve();
           };
-        }
+        });
       }
 
-      checkOrSetupCheck(test.pcLocal._pc, "local: ", "test2.example.com", "someone");
-      checkOrSetupCheck(test.pcRemote._pc, "remote: ", "test1.example.com", "someone");
-      if (outstanding <= 0) {
-        test.next();
-      }
-    }
-  ],
-  [
-    "CHECK_IDENTITY_EVENTS",
-    function(test) {
+      return Promise.all([
+        checkOrSetupCheck(test.pcLocal._pc, "local: ", "test2.example.com", "someone"),
+        checkOrSetupCheck(test.pcRemote._pc, "remote: ", "test1.example.com", "someone")
+      ]);
+    },
+
+    function CHECK_IDENTITY_EVENTS(test) {
       ok(!localEvents.idpassertionerror , "No assertion generation errors on local");
       ok(!remoteEvents.idpassertionerror, "No assertion generation errors on remote");
       ok(!localEvents.idpvalidationerror, "No assertion validation errors on local");
-      ok( !remoteEvents.idpvalidationerror, "No assertion validation errors on remote");
+      ok(!remoteEvents.idpvalidationerror, "No assertion validation errors on remote");
       ok(localEvents.identityresult, "local acquired identity assertions");
       ok(remoteEvents.identityresult, "remote acquired identity assertions");
       ok(localEvents.peeridentity, "local got peer identity");
       ok(remoteEvents.peeridentity, "remote got peer identity");
-      test.next();
-    }
-  ],
-  [
-    "OFFERS_AND_ANSWERS_INCLUDE_IDENTITY",
-    function(test) {
+    },
+
+    function OFFERS_AND_ANSWERS_INCLUDE_IDENTITY(test) {
       ok(test.originalOffer.sdp.contains("a=identity"), "a=identity is in the offer SDP");
       ok(test.originalAnswer.sdp.contains("a=identity"), "a=identity is in the answer SDP");
-      test.next();
-    }
-  ],
-  [
-    "DESCRIPTIONS_CONTAIN_IDENTITY",
-    function(test) {
+    },
+
+    function DESCRIPTIONS_CONTAIN_IDENTITY(test) {
       ok(test.pcLocal.localDescription.sdp.contains("a=identity"),
-                         "a=identity is in the local copy of the offer");
+         "a=identity is in the local copy of the offer");
       ok(test.pcRemote.localDescription.sdp.contains("a=identity"),
-                         "a=identity is in the remote copy of the offer");
+         "a=identity is in the remote copy of the offer");
       ok(test.pcLocal.remoteDescription.sdp.contains("a=identity"),
-                         "a=identity is in the local copy of the answer");
+         "a=identity is in the local copy of the answer");
       ok(test.pcRemote.remoteDescription.sdp.contains("a=identity"),
-                         "a=identity is in the remote copy of the answer");
-      test.next();
+         "a=identity is in the remote copy of the answer");
     }
-  ]
   ]);
   test.run();
 }
 runNetworkTest(theTest);
 
 
 
 </script>
--- a/dom/media/tests/mochitest/identity/test_setIdentityProviderWithErrors.html
+++ b/dom/media/tests/mochitest/identity/test_setIdentityProviderWithErrors.html
@@ -23,63 +23,55 @@ runNetworkTest(function () {
   test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html#error', 'nobody');
   // second generates a bad assertion; which fails to validate
   test.setIdentityProvider(test.pcRemote, 'example.com', 'idp.html#bad', 'nobody');
 
   var localEvents = trapIdentityEvents(test.pcLocal._pc);
   var remoteEvents = trapIdentityEvents(test.pcRemote._pc);
 
   test.chain.append([
-    [
-      'CHECK_IDENTITY_EVENTS',
-      function(test) {
-        function checkEvents() {
-          ok(localEvents.idpassertionerror, 'local assertion generation should fail (idpassertionerror)');
-          is(localEvents.idpassertionerror.idp, 'example.com', 'event IdP is correct');
-          is(localEvents.idpassertionerror.protocol, 'idp.html#error', 'event IdP protocol is #error');
-          ok(!remoteEvents.idpassertionerror, 'remote assertion generation should succeed (idpassertionerror)');
-          ok(!localEvents.identityresult, 'local assertion generation should fail (identityresult)');
-          ok(remoteEvents.identityresult, 'remote assertion generation should succeed (identityresult)');
+    function CHECK_IDENTITY_EVENTS(test) {
+      function checkEvents() {
+        ok(localEvents.idpassertionerror, 'local assertion generation should fail (idpassertionerror)');
+        is(localEvents.idpassertionerror.idp, 'example.com', 'event IdP is correct');
+        is(localEvents.idpassertionerror.protocol, 'idp.html#error', 'event IdP protocol is #error');
+        ok(!remoteEvents.idpassertionerror, 'remote assertion generation should succeed (idpassertionerror)');
+        ok(!localEvents.identityresult, 'local assertion generation should fail (identityresult)');
+        ok(remoteEvents.identityresult, 'remote assertion generation should succeed (identityresult)');
 
-          ok(!localEvents.peeridentity, 'no peer identity event for local peer');
-          ok(!remoteEvents.peeridentity, 'no peer identity event for remote peer');
-          ok(localEvents.idpvalidationerror, 'local fails to validate');
-          is(localEvents.idpvalidationerror.idp, 'example.com', 'event IdP is correct');
-          is(localEvents.idpvalidationerror.protocol, 'idp.html#bad', 'event IdP protocol is #bad');
-          ok(!remoteEvents.idpvalidationerror, 'remote doesn\'t even see an assertion');
+        ok(!localEvents.peeridentity, 'no peer identity event for local peer');
+        ok(!remoteEvents.peeridentity, 'no peer identity event for remote peer');
+        ok(localEvents.idpvalidationerror, 'local fails to validate');
+        is(localEvents.idpvalidationerror.idp, 'example.com', 'event IdP is correct');
+        is(localEvents.idpvalidationerror.protocol, 'idp.html#bad', 'event IdP protocol is #bad');
+        ok(!remoteEvents.idpvalidationerror, 'remote doesn\'t even see an assertion');
 
-          test.next();
-        }
+      }
 
-        // we actually have to wait on this because IdP validation happens asynchronously
-        if (localEvents.idpvalidationerror) {
-          checkEvents();
-        } else {
-          // have to let the other event handler have a chance to record success
-          // before we run the checks that rely on that recording
-          test.pcLocal._pc.onidpvalidationerror = setTimeout.bind(window, checkEvents, 1);
-        }
+      // we actually have to wait on this because IdP validation happens asynchronously
+      if (localEvents.idpvalidationerror) {
+        checkEvents();
+        return Promise.resolve();
       }
-    ],
-    [
-      'PEER_IDENTITY_IS_EMPTY',
-      function(test) {
-        ok(!test.pcLocal._pc.peerIdentity, 'local peerIdentity is not set');
-        ok(!test.pcRemote._pc.peerIdentity, 'remote peerIdentity is not set');
-        test.next();
-      }
-    ],
-    [
-      'ONLY_REMOTE_SDP_INCLUDES_IDENTITY_ASSERTION',
-      function(test) {
-        ok(!test.originalOffer.sdp.contains('a=identity'), 'a=identity not contained in the offer SDP');
-        ok(test.originalAnswer.sdp.contains('a=identity'), 'a=identity is contained in the answer SDP');
-        test.next();
-      }
-    ]
+      // have to let the other event handler have a chance to record success
+      // before we run the checks that rely on that recording
+      return new Promise(resolve => {
+        test.pcLocal._pc.onidpvalidationerror = resolve;
+      }).then(checkEvents);
+    },
+
+    function PEER_IDENTITY_IS_EMPTY(test) {
+      ok(!test.pcLocal._pc.peerIdentity, 'local peerIdentity is not set');
+      ok(!test.pcRemote._pc.peerIdentity, 'remote peerIdentity is not set');
+    },
+
+    function ONLY_REMOTE_SDP_INCLUDES_IDENTITY_ASSERTION(test) {
+      ok(!test.originalOffer.sdp.contains('a=identity'), 'a=identity not contained in the offer SDP');
+      ok(test.originalAnswer.sdp.contains('a=identity'), 'a=identity is contained in the answer SDP');
+    }
   ]);
   test.run();
 });
 
 </script>
 </pre>
 </body>
 </html>