dom/media/tests/identity/test_getIdentityAssertion.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     5   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6   <script type="application/javascript" src="../mochitest/head.js"></script>
     7   <script type="application/javascript" src="../mochitest/pc.js"></script>
     8   <script type="application/javascript" src="../mochitest/templates.js"></script>
     9 </head>
    10 <body>
    11 <pre id="test">
    12 <script type="application/javascript">
    13   createHTML({
    14     title: "getIdentityAssertion Tests"
    15   });
    17 function checkIdentity(assertion, identity) {
    18   // here we dig into the payload, which means we need to know something
    19   // about how the IdP actually works (not good in general, but OK here)
    20   var assertion = JSON.parse(atob(assertion)).assertion;
    21   var user = JSON.parse(assertion).username;
    22   is(user, identity, "id should be '" + identity + "' is '" + user + "'");
    23 }
    25 var test;
    26 function theTest() {
    27   test = new PeerConnectionTest();
    28   test.setMediaConstraints([{audio: true}], [{audio: true}]);
    29   test.chain.append([
    30   [
    31     "GET_IDENTITY_ASSERTION_FAILS_WITHOUT_PROVIDER",
    32     function(test) {
    33       test.pcLocal._pc.onidpassertionerror = function(e) {
    34         ok(e, "getIdentityAssertion must fail without provider");
    35         test.next();
    36       };
    37       test.pcLocal._pc.getIdentityAssertion();
    38     },
    39   ],
    40   [
    41     "GET_IDENTITY_ASSERTION_FIRES_EVENTUALLY_AND_SUBSEQUENTLY",
    42     function(test) {
    43       var fired = 0;
    44       test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html');
    45       test.pcLocal._pc.onidentityresult = function(e) {
    46         fired++;
    47         if (fired == 1) {
    48           ok(true, "identityresult fired");
    49           checkIdentity(e.assertion, 'someone@example.com');
    50         } else if (fired == 2) {
    51           ok(true, "identityresult fired 2x");
    52           checkIdentity(e.assertion, 'someone@example.com');
    53           test.next();
    54         }
    55       };
    56       test.pcLocal._pc.onidpassertionerror = function(e) {
    57         ok(false, "error event fired");
    58         test.next();
    59       };
    60       test.pcLocal._pc.getIdentityAssertion();
    61       test.pcLocal._pc.getIdentityAssertion();
    62     }
    63   ],
    64   [
    65     "GET_IDENTITY_ASSERTION_FAILS",
    66     function(test) {
    67       test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html#error');
    68       test.pcLocal._pc.onidentityresult = function(e) {
    69         ok(false, "Should not get an identity result");
    70         test.next();
    71       };
    72       test.pcLocal._pc.onidpassertionerror = function(err) {
    73         ok(err, "Got error event from getIdentityAssertion");
    74         test.next();
    75       };
    76       test.pcLocal._pc.getIdentityAssertion();
    77     }
    78   ],
    79   [
    80     "GET_IDENTITY_ASSERTION_IDP_NOT_READY",
    81     function(test) {
    82       test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html#error:ready');
    83       test.pcLocal._pc.onidentityresult = function(e) {
    84         ok(false, "Should not get an identity result");
    85         test.next();
    86       };
    87       test.pcLocal._pc.onidpassertionerror = function(e) {
    88         ok(e, "Got error callback from getIdentityAssertion");
    89         test.next();
    90       };
    91       test.pcLocal._pc.getIdentityAssertion();
    92     }
    93   ],
    94   [
    95     "GET_IDENTITY_ASSERTION_WITH_SPECIFIC_NAME",
    96     function(test) {
    97       test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html', 'user@example.com');
    98       test.pcLocal._pc.onidentityresult = function(e) {
    99         checkIdentity(e.assertion, 'user@example.com');
   100         test.next();
   101       };
   102       test.pcLocal._pc.onidpassertionerror = function(e) {
   103         ok(false, "Got error callback from getIdentityAssertion");
   104         test.next();
   105       };
   106       test.pcLocal._pc.getIdentityAssertion();
   107     }
   108   ]
   109   ]);
   110   test.run();
   111 }
   112 runTest(theTest);
   114 </script>
   115 </pre>
   116 </body>
   117 </html>

mercurial