gecko-dev/browser/base/content/test/general/accounts_testRemoteCommands.html
Masatoshi Kimura 1b484b57d6 Bug 1342144 - Fix ESLint errors in browser/. r=Paolo
MozReview-Commit-ID: ByMEEcTQQtd

--HG--
extra : rebase_source : af62eeccdc22b63022ac18e46023c153798caa94
2017-02-24 23:25:45 +09:00

83 lines
2 KiB
HTML

<html>
<head>
<meta charset="utf-8">
<script type="text/javascript">
function init() {
window.addEventListener("message", function process(e) { doTest(e) });
// unless we relinquish the eventloop,
// tests will run before the chrome event handlers are ready
setTimeout(doTest, 0);
}
function checkStatusValue(payload, expectedValue) {
return payload.status == expectedValue;
}
let tests = [
{
info: "Check account log in",
event: "login",
data: {
email: "foo@example.com",
uid: "1234@lcip.org",
assertion: "foobar",
sessionToken: "dead",
kA: "beef",
kB: "cafe",
verified: true
},
payloadType: "message",
validateResponse(payload) {
return checkStatusValue(payload, "login");
},
},
];
let currentTest = -1;
function doTest(evt) {
if (evt) {
if (currentTest < 0 || !evt.data.content)
return; // not yet testing
let test = tests[currentTest];
if (evt.data.type != test.payloadType)
return; // skip unrequested events
let error = JSON.stringify(evt.data.content);
let pass = false;
try {
pass = test.validateResponse(evt.data.content)
} catch (e) {}
reportResult(test.info, pass, error);
}
// start the next test if there are any left
if (tests[++currentTest])
sendToBrowser(tests[currentTest].event, tests[currentTest].data);
else
reportFinished();
}
function reportResult(info, pass, error) {
let data = {type: "testResult", info, pass, error};
let event = new CustomEvent("FirefoxAccountsTestResponse", {detail: {data}, bubbles: true});
document.dispatchEvent(event);
}
function reportFinished(cmd) {
let data = {type: "testsComplete", count: tests.length};
let event = new CustomEvent("FirefoxAccountsTestResponse", {detail: {data}, bubbles: true});
document.dispatchEvent(event);
}
function sendToBrowser(type, data) {
let event = new CustomEvent("FirefoxAccountsCommand", {detail: {command: type, data}, bubbles: true});
document.dispatchEvent(event);
}
</script>
</head>
<body onload="init()">
</body>
</html>