2014-03-11 19:35:24 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=971379
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>Certified/packaged apps may use synthetic events with FXA -- Bug 971379</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=971379">Mozilla Bug 971379</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script type="application/javascript;version=1.8">
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
Components.utils.import("resource://gre/modules/Promise.jsm");
|
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
|
|
Components.utils.import("resource://gre/modules/DOMIdentity.jsm");
|
|
|
|
Components.utils.import("resource://gre/modules/identity/jwcrypto.jsm");
|
|
|
|
Components.utils.import("resource://gre/modules/identity/FirefoxAccounts.jsm");
|
|
|
|
|
|
|
|
// Mock the Firefox Accounts manager to give a dummy assertion, just to confirm
|
|
|
|
// that we're making the trip through the dom/identity and toolkit/identity
|
|
|
|
// plumbing.
|
|
|
|
function MockFXAManager() {}
|
|
|
|
MockFXAManager.prototype = {
|
2014-03-11 17:49:26 -07:00
|
|
|
getAssertion: function(audience, options) {
|
|
|
|
if (options.silent) {
|
|
|
|
return Promise.resolve(null);
|
|
|
|
}
|
2014-03-11 19:35:24 -07:00
|
|
|
return Promise.resolve("here~you.go.dude");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let originalManager = FirefoxAccounts.fxAccountsManager;
|
|
|
|
FirefoxAccounts.fxAccountsManager = new MockFXAManager();
|
|
|
|
|
|
|
|
// Mock IdentityService (Persona) so we can test request() while not handling
|
|
|
|
// user input on an installed app. Since in this test suite, we have only this
|
|
|
|
// one test for Persona, we additionally cause request() to throw if invoked, as
|
|
|
|
// added security that nsDOMIdentity did not emit a request message.
|
|
|
|
let MockIdentityService = function() {
|
|
|
|
this.RP = this;
|
|
|
|
this.contexts = {};
|
|
|
|
}
|
|
|
|
MockIdentityService.prototype = {
|
|
|
|
watch: function(context) {
|
|
|
|
this.contexts[context.id] = context;
|
|
|
|
context.doReady();
|
|
|
|
},
|
|
|
|
|
|
|
|
request: function(message) {
|
|
|
|
ok(false, "nsDOMIdentity should block Persona request() in this test suite");
|
|
|
|
},
|
|
|
|
};
|
|
|
|
DOMIdentity._mockIdentityService = new MockIdentityService();
|
|
|
|
|
|
|
|
// The manifests for these apps are all declared in
|
|
|
|
// /testing/profiles/webapps_mochitest.json. They are injected into the profile
|
|
|
|
// by /testing/mochitest/runtests.py with the appropriate appStatus. So we don't
|
|
|
|
// have to manually install any apps.
|
|
|
|
let apps = [
|
|
|
|
{
|
|
|
|
title: "an installed app, which must request() in a native event",
|
|
|
|
manifest: "https://example.com/manifest.webapp",
|
|
|
|
origin: "https://example.com",
|
|
|
|
uri: "https://example.com/chrome/dom/identity/tests/mochitest/file_syntheticEvents.html",
|
|
|
|
wantIssuer: "", // default to persona
|
|
|
|
expected: {
|
|
|
|
success: false,
|
|
|
|
errors: [
|
|
|
|
"ERROR_REQUEST_WHILE_NOT_HANDLING_USER_INPUT",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "an installed app, which must may not use firefox accounts",
|
|
|
|
manifest: "https://example.com/manifest.webapp",
|
|
|
|
origin: "https://example.com",
|
|
|
|
uri: "https://example.com/chrome/dom/identity/tests/mochitest/file_syntheticEvents.html",
|
|
|
|
wantIssuer: "firefox-accounts",
|
|
|
|
expected: {
|
|
|
|
success: false,
|
|
|
|
errors: [
|
|
|
|
"ERROR_NOT_AUTHORIZED_FOR_FIREFOX_ACCOUNTS",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "a privileged app, which may not use synthetic events (until bug 982460 lands)",
|
|
|
|
manifest: "https://example.com/manifest_priv.webapp",
|
|
|
|
origin: "https://example.com",
|
|
|
|
uri: "https://example.com/chrome/dom/identity/tests/mochitest/file_syntheticEvents.html",
|
|
|
|
wantIssuer: "firefox-accounts",
|
|
|
|
expected: {
|
|
|
|
success: false,
|
|
|
|
errors: [
|
|
|
|
"ERROR_REQUEST_WHILE_NOT_HANDLING_USER_INPUT",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "a certified app, which may use synthetic events",
|
|
|
|
manifest: "https://example.com/manifest_cert.webapp",
|
|
|
|
origin: "https://example.com",
|
|
|
|
uri: "https://example.com/chrome/dom/identity/tests/mochitest/file_syntheticEvents.html",
|
|
|
|
wantIssuer: "firefox-accounts",
|
|
|
|
expected: {
|
|
|
|
success: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
let appIndex = 0;
|
|
|
|
let testRunner = runTest();
|
|
|
|
let receivedErrors = [];
|
|
|
|
|
|
|
|
function receiveMessage(event) {
|
|
|
|
dump("** Received response: " + event.data + "\n");
|
|
|
|
let result = JSON.parse(event.data);
|
|
|
|
let app = apps[appIndex];
|
|
|
|
let expected = app.expected;
|
|
|
|
|
|
|
|
is(result.success, expected.success,
|
|
|
|
"Assertion request " + (expected.success ? "succeeds" : "fails"));
|
|
|
|
|
|
|
|
if (result.error) {
|
|
|
|
receivedErrors.push(result.error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (receivedErrors.length === (expected.errors || []).length) {
|
|
|
|
receivedErrors.forEach((error) => {
|
|
|
|
ok(expected.errors.indexOf(error) > -1,
|
|
|
|
"Received " + error + ". " +
|
|
|
|
"Expected errors are: " + JSON.stringify(expected.errors));
|
|
|
|
});
|
|
|
|
|
|
|
|
appIndex += 1;
|
|
|
|
|
|
|
|
if (appIndex === apps.length) {
|
|
|
|
window.removeEventListener("message", receiveMessage);
|
|
|
|
|
|
|
|
// Remove mock from DOMIdentity
|
|
|
|
DOMIdentity._mockIdentityService = null;
|
|
|
|
|
|
|
|
// Restore original fxa manager
|
|
|
|
FirefoxAccounts.fxAccountsManager = originalManager;
|
|
|
|
|
|
|
|
SimpleTest.finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
testRunner.next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("message", receiveMessage, false, true);
|
|
|
|
|
|
|
|
function runTest() {
|
|
|
|
for (let app of apps) {
|
|
|
|
dump("** Testing " + app.title + "\n");
|
|
|
|
|
|
|
|
receivedErrors = [];
|
|
|
|
|
|
|
|
let iframe = document.createElement("iframe");
|
|
|
|
|
|
|
|
iframe.setAttribute("mozapp", app.manifest);
|
|
|
|
iframe.setAttribute("mozbrowser", "true");
|
|
|
|
iframe.src = app.uri;
|
|
|
|
|
|
|
|
document.getElementById("content").appendChild(iframe);
|
|
|
|
|
|
|
|
iframe.addEventListener("load", function onLoad() {
|
|
|
|
iframe.removeEventListener("load", onLoad);
|
|
|
|
|
|
|
|
// Because the <iframe mozapp> can't parent its way back to us, we
|
|
|
|
// provide this handle to our window so it can postMessage to us.
|
|
|
|
iframe.contentWindow.wrappedJSObject.realParent = window;
|
|
|
|
iframe.contentWindow.postMessage({wantIssuer: app.wantIssuer}, "*");
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
yield undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpecialPowers.pushPrefEnv({"set":
|
|
|
|
[
|
|
|
|
["dom.mozBrowserFramesEnabled", true],
|
|
|
|
["dom.identity.enabled", true],
|
|
|
|
["identity.fxaccounts.enabled", true],
|
|
|
|
["toolkit.identity.debug", true],
|
|
|
|
|
|
|
|
["security.apps.privileged.CSP.default", ""],
|
|
|
|
["security.apps.certified.CSP.default", ""],
|
|
|
|
]},
|
|
|
|
function() {
|
|
|
|
testRunner.next();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|