dom/media/tests/mochitest/identity/test_getIdentityAssertion.html
author Martin Thomson <martin.thomson@gmail.com>
Sat, 21 Feb 2015 10:15:05 +1300
changeset 249897 02405fe4e525fcf652c4e68ad4819ed5521fd4ab
parent 249892 a983c31d2dcde10f4c4b6c3f34de36b2e2d51b62
child 252193 a75426ed6ab016ed033a2ecc8e7fdf59125446a1
permissions -rw-r--r--
Bug 1119593 - Aggressively removing boilerplate on tests, r=drno, a=testonly Conflicts: dom/media/tests/mochitest/test_getUserMedia_exceptions.html Conflicts: dom/media/tests/mochitest/test_peerConnection_bug825703.html

<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript">var scriptRelativePath = "../";</script>
  <script type="application/javascript" src="../pc.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
  createHTML({
    title: "getIdentityAssertion Tests",
    bug: "942367"
  });

function checkIdentity(assertion, identity) {
  // here we dig into the payload, which means we need to know something
  // about how the IdP actually works (not good in general, but OK here)
  var assertion = JSON.parse(atob(assertion)).assertion;
  var user = JSON.parse(assertion).username;
  is(user, identity, "id should be '" + identity + "' is '" + user + "'");
}

var test;
function theTest() {
  test = new PeerConnectionTest();
  test.setMediaConstraints([{audio: true}], [{audio: true}]);
  test.chain.removeAfter('PC_REMOTE_CHECK_INITIAL_SIGNALINGSTATE');
  test.chain.append([
    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();
      });
    },
    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();
      });
    }
  ]);
  test.run();
}
runNetworkTest(theTest);

</script>
</pre>
</body>
</html>