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.

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

mercurial