browser/base/content/test/general/accounts_testRemoteCommands.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <html>
michael@0 2 <head>
michael@0 3 <meta charset="utf-8">
michael@0 4
michael@0 5 <script type="text/javascript;version=1.8">
michael@0 6
michael@0 7 function init() {
michael@0 8 window.addEventListener("message", function process(e) {doTest(e)}, false);
michael@0 9 // unless we relinquish the eventloop,
michael@0 10 // tests will run before the chrome event handlers are ready
michael@0 11 setTimeout(doTest, 0);
michael@0 12 }
michael@0 13
michael@0 14 function checkStatusValue(payload, expectedValue) {
michael@0 15 return payload.status == expectedValue;
michael@0 16 }
michael@0 17
michael@0 18 let tests = [
michael@0 19 {
michael@0 20 info: "Check account log in",
michael@0 21 event: "login",
michael@0 22 data: {
michael@0 23 email: "foo@example.com",
michael@0 24 uid: "1234@lcip.org",
michael@0 25 assertion: "foobar",
michael@0 26 sessionToken: "dead",
michael@0 27 kA: "beef",
michael@0 28 kB: "cafe",
michael@0 29 verified: true
michael@0 30 },
michael@0 31 payloadType: "message",
michael@0 32 validateResponse: function(payload) {
michael@0 33 return checkStatusValue(payload, "login");
michael@0 34 },
michael@0 35 },
michael@0 36 ];
michael@0 37
michael@0 38 let currentTest = -1;
michael@0 39 function doTest(evt) {
michael@0 40 if (evt) {
michael@0 41 if (currentTest < 0 || !evt.data.content)
michael@0 42 return; // not yet testing
michael@0 43
michael@0 44 let test = tests[currentTest];
michael@0 45 if (evt.data.type != test.payloadType)
michael@0 46 return; // skip unrequested events
michael@0 47
michael@0 48 let error = JSON.stringify(evt.data.content);
michael@0 49 let pass = false;
michael@0 50 try {
michael@0 51 pass = test.validateResponse(evt.data.content)
michael@0 52 } catch (e) {}
michael@0 53 reportResult(test.info, pass, error);
michael@0 54 }
michael@0 55 // start the next test if there are any left
michael@0 56 if (tests[++currentTest])
michael@0 57 sendToBrowser(tests[currentTest].event, tests[currentTest].data);
michael@0 58 else
michael@0 59 reportFinished();
michael@0 60 }
michael@0 61
michael@0 62 function reportResult(info, pass, error) {
michael@0 63 let data = {type: "testResult", info: info, pass: pass, error: error};
michael@0 64 window.parent.postMessage(data, "*");
michael@0 65 }
michael@0 66
michael@0 67 function reportFinished(cmd) {
michael@0 68 let data = {type: "testsComplete", count: tests.length};
michael@0 69 window.parent.postMessage(data, "*");
michael@0 70 }
michael@0 71
michael@0 72 function sendToBrowser(type, data) {
michael@0 73 let event = new CustomEvent("FirefoxAccountsCommand", {detail: {command: type, data: data}, bubbles: true});
michael@0 74 document.dispatchEvent(event);
michael@0 75 }
michael@0 76
michael@0 77 </script>
michael@0 78 </head>
michael@0 79 <body onload="init()">
michael@0 80 </body>
michael@0 81 </html>

mercurial