gecko/dom/identity/tests/mochitest/test_rpHasValidCallbacks.html

98 lines
3.1 KiB
HTML

<!--
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-->
<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=945363
-->
<head>
<meta charset="utf-8">
<title>BrowserID and Firefox Accounts RPs provide requried callbacks - Bug 945363</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=945363">Mozilla Bug 945363</a>
<p id="display"></p>
<div id="content">
</div>
<pre id="test">
<script type="application/javascript;version=1.7">
/** Test for Bug 945363 **/
const BASE_URL = "http://mochi.test:8888/chrome/dom/identity/tests/mochitest/";
SimpleTest.waitForExplicitFinish();
// Candidate RPs, and whether we expect them to experience an error.
// Will will load each of these in turn into an iframe. The candiates
// will invoke navigator.mozId.watch(). If they do not provide the
// correct arguments to watch(), nsDOMIdentity will throw an exception.
let candidates = [
[BASE_URL + "file_browserid_rp_ok.html", false],
[BASE_URL + "file_browserid_rp_noOnlogin.html", true ],
[BASE_URL + "file_fxa_rp_ok.html", false],
[BASE_URL + "file_fxa_rp_noOnlogin.html", true ],
[BASE_URL + "file_fxa_rp_noOnlogout.html", true ],
[BASE_URL + "file_fxa_rp_noOnready.html", true ],
];
let checkedCount = 0;
let checksTodo = candidates.length;
// Each iframe will postMessage to us, telling us whether they caught
// an exception or not when calling watch().
window.addEventListener('message', function onMessage(event) {
let message = JSON.parse(event.data);
let [uri, expectedError] = candidates[checkedCount];
is(message.error, expectedError, "Unexpected error result from " + uri);
if (++checkedCount < checksTodo) {
testRunner.next();
} else {
window.removeEventListener('message', onMessage);
SimpleTest.finish();
}
}, false);
let content = document.getElementById('content');
function runTest() {
for (let [uri, _] of candidates) {
let iframe = document.createElement('iframe');
iframe.setAttribute('mozbrowser', 'true');
iframe.src = uri;
content.appendChild(iframe);
yield undefined;
}
}
let testRunner = runTest();
// Enable the identity systems and use verbose logging
SpecialPowers.pushPrefEnv({'set': [
['dom.identity.enabled', true], // navigator.mozId
['identity.fxaccounts.enabled', true], // fx accounts
['dom.identity.syntheticEventsOk', true], // so we can call request()
['toolkit.identity.debug', true], // verbose identity logging
['browser.dom.window.dump.enabled', true],
["security.apps.privileged.CSP.default", "'inline-script';"],
["security.apps.certified.CSP.default", "'inline-script';"],
]},
function () { testRunner.next(); }
);
</script>
</pre>
</body>
</html>