dom/media/tests/identity/test_getIdentityAssertion.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/media/tests/identity/test_getIdentityAssertion.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,117 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     1.8 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="application/javascript" src="../mochitest/head.js"></script>
    1.10 +  <script type="application/javascript" src="../mochitest/pc.js"></script>
    1.11 +  <script type="application/javascript" src="../mochitest/templates.js"></script>
    1.12 +</head>
    1.13 +<body>
    1.14 +<pre id="test">
    1.15 +<script type="application/javascript">
    1.16 +  createHTML({
    1.17 +    title: "getIdentityAssertion Tests"
    1.18 +  });
    1.19 +
    1.20 +function checkIdentity(assertion, identity) {
    1.21 +  // here we dig into the payload, which means we need to know something
    1.22 +  // about how the IdP actually works (not good in general, but OK here)
    1.23 +  var assertion = JSON.parse(atob(assertion)).assertion;
    1.24 +  var user = JSON.parse(assertion).username;
    1.25 +  is(user, identity, "id should be '" + identity + "' is '" + user + "'");
    1.26 +}
    1.27 +
    1.28 +var test;
    1.29 +function theTest() {
    1.30 +  test = new PeerConnectionTest();
    1.31 +  test.setMediaConstraints([{audio: true}], [{audio: true}]);
    1.32 +  test.chain.append([
    1.33 +  [
    1.34 +    "GET_IDENTITY_ASSERTION_FAILS_WITHOUT_PROVIDER",
    1.35 +    function(test) {
    1.36 +      test.pcLocal._pc.onidpassertionerror = function(e) {
    1.37 +        ok(e, "getIdentityAssertion must fail without provider");
    1.38 +        test.next();
    1.39 +      };
    1.40 +      test.pcLocal._pc.getIdentityAssertion();
    1.41 +    },
    1.42 +  ],
    1.43 +  [
    1.44 +    "GET_IDENTITY_ASSERTION_FIRES_EVENTUALLY_AND_SUBSEQUENTLY",
    1.45 +    function(test) {
    1.46 +      var fired = 0;
    1.47 +      test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html');
    1.48 +      test.pcLocal._pc.onidentityresult = function(e) {
    1.49 +        fired++;
    1.50 +        if (fired == 1) {
    1.51 +          ok(true, "identityresult fired");
    1.52 +          checkIdentity(e.assertion, 'someone@example.com');
    1.53 +        } else if (fired == 2) {
    1.54 +          ok(true, "identityresult fired 2x");
    1.55 +          checkIdentity(e.assertion, 'someone@example.com');
    1.56 +          test.next();
    1.57 +        }
    1.58 +      };
    1.59 +      test.pcLocal._pc.onidpassertionerror = function(e) {
    1.60 +        ok(false, "error event fired");
    1.61 +        test.next();
    1.62 +      };
    1.63 +      test.pcLocal._pc.getIdentityAssertion();
    1.64 +      test.pcLocal._pc.getIdentityAssertion();
    1.65 +    }
    1.66 +  ],
    1.67 +  [
    1.68 +    "GET_IDENTITY_ASSERTION_FAILS",
    1.69 +    function(test) {
    1.70 +      test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html#error');
    1.71 +      test.pcLocal._pc.onidentityresult = function(e) {
    1.72 +        ok(false, "Should not get an identity result");
    1.73 +        test.next();
    1.74 +      };
    1.75 +      test.pcLocal._pc.onidpassertionerror = function(err) {
    1.76 +        ok(err, "Got error event from getIdentityAssertion");
    1.77 +        test.next();
    1.78 +      };
    1.79 +      test.pcLocal._pc.getIdentityAssertion();
    1.80 +    }
    1.81 +  ],
    1.82 +  [
    1.83 +    "GET_IDENTITY_ASSERTION_IDP_NOT_READY",
    1.84 +    function(test) {
    1.85 +      test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html#error:ready');
    1.86 +      test.pcLocal._pc.onidentityresult = function(e) {
    1.87 +        ok(false, "Should not get an identity result");
    1.88 +        test.next();
    1.89 +      };
    1.90 +      test.pcLocal._pc.onidpassertionerror = function(e) {
    1.91 +        ok(e, "Got error callback from getIdentityAssertion");
    1.92 +        test.next();
    1.93 +      };
    1.94 +      test.pcLocal._pc.getIdentityAssertion();
    1.95 +    }
    1.96 +  ],
    1.97 +  [
    1.98 +    "GET_IDENTITY_ASSERTION_WITH_SPECIFIC_NAME",
    1.99 +    function(test) {
   1.100 +      test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html', 'user@example.com');
   1.101 +      test.pcLocal._pc.onidentityresult = function(e) {
   1.102 +        checkIdentity(e.assertion, 'user@example.com');
   1.103 +        test.next();
   1.104 +      };
   1.105 +      test.pcLocal._pc.onidpassertionerror = function(e) {
   1.106 +        ok(false, "Got error callback from getIdentityAssertion");
   1.107 +        test.next();
   1.108 +      };
   1.109 +      test.pcLocal._pc.getIdentityAssertion();
   1.110 +    }
   1.111 +  ]
   1.112 +  ]);
   1.113 +  test.run();
   1.114 +}
   1.115 +runTest(theTest);
   1.116 +
   1.117 +</script>
   1.118 +</pre>
   1.119 +</body>
   1.120 +</html>

mercurial