dom/identity/tests/mochitest/test_rpHasValidCallbacks.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/identity/tests/mochitest/test_rpHasValidCallbacks.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     1.4 +<!--
     1.5 +  * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +  * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 + -->
     1.9 +<!DOCTYPE html>
    1.10 +<html>
    1.11 +  <!--
    1.12 +  https://bugzilla.mozilla.org/show_bug.cgi?id=945363
    1.13 +  -->
    1.14 +<head>
    1.15 +  <meta charset="utf-8">
    1.16 +  <title>BrowserID and Firefox Accounts RPs provide requried callbacks - Bug 945363</title>
    1.17 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.18 +  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
    1.19 +</head>
    1.20 +
    1.21 +<body>
    1.22 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=945363">Mozilla Bug 945363</a>
    1.23 +<p id="display"></p>
    1.24 +<div id="content">
    1.25 +
    1.26 +</div>
    1.27 +<pre id="test">
    1.28 +<script type="application/javascript;version=1.7">
    1.29 +
    1.30 +/** Test for Bug 945363 **/
    1.31 +
    1.32 +const BASE_URL = "http://mochi.test:8888/chrome/dom/identity/tests/mochitest/";
    1.33 +
    1.34 +SimpleTest.waitForExplicitFinish();
    1.35 +
    1.36 +// Candidate RPs, and whether we expect them to experience an error.
    1.37 +// Will will load each of these in turn into an iframe.  The candiates
    1.38 +// will invoke navigator.mozId.watch().  If they do not provide the
    1.39 +// correct arguments to watch(), nsDOMIdentity will throw an exception.
    1.40 +let candidates = [
    1.41 +  [BASE_URL + "file_browserid_rp_ok.html",          false],
    1.42 +  [BASE_URL + "file_browserid_rp_noOnlogin.html",   true ],
    1.43 +  [BASE_URL + "file_fxa_rp_ok.html",                false],
    1.44 +  [BASE_URL + "file_fxa_rp_noOnlogin.html",         true ],
    1.45 +  [BASE_URL + "file_fxa_rp_noOnlogout.html",        true ],
    1.46 +  [BASE_URL + "file_fxa_rp_noOnready.html",         true ],
    1.47 +];
    1.48 +
    1.49 +let checkedCount = 0;
    1.50 +let checksTodo = candidates.length;
    1.51 +
    1.52 +// Each iframe will postMessage to us, telling us whether they caught
    1.53 +// an exception or not when calling watch().
    1.54 +window.addEventListener('message', function onMessage(event) {
    1.55 +  let message = JSON.parse(event.data);
    1.56 +  let [uri, expectedError] = candidates[checkedCount];
    1.57 +
    1.58 +  is(message.error, expectedError, "Unexpected error result from " + uri);
    1.59 +
    1.60 +  if (++checkedCount < checksTodo) {
    1.61 +    testRunner.next();
    1.62 +  } else {
    1.63 +    window.removeEventListener('message', onMessage);
    1.64 +    SimpleTest.finish();
    1.65 +  }
    1.66 +}, false);
    1.67 +
    1.68 +let content = document.getElementById('content');
    1.69 +function runTest() {
    1.70 +  for (let [uri, _] of candidates) {
    1.71 +
    1.72 +    let iframe = document.createElement('iframe');
    1.73 +    iframe.setAttribute('mozbrowser', 'true');
    1.74 +    iframe.src = uri;
    1.75 +
    1.76 +    content.appendChild(iframe);
    1.77 +
    1.78 +    yield undefined;
    1.79 +  }
    1.80 +}
    1.81 +
    1.82 +let testRunner = runTest();
    1.83 +
    1.84 +// Enable the identity systems and use verbose logging
    1.85 +SpecialPowers.pushPrefEnv({'set': [
    1.86 +    ['dom.identity.enabled', true],               // navigator.mozId
    1.87 +    ['identity.fxaccounts.enabled', true],        // fx accounts
    1.88 +    ['dom.identity.syntheticEventsOk', true],     // so we can call request()
    1.89 +    ['toolkit.identity.debug', true],             // verbose identity logging
    1.90 +    ['browser.dom.window.dump.enabled', true],
    1.91 +  ]},
    1.92 +  function () { testRunner.next(); }
    1.93 +);
    1.94 +
    1.95 +</script>
    1.96 +</pre>
    1.97 +</body>
    1.98 +</html>

mercurial