1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/accounts_testRemoteCommands.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +<html> 1.5 + <head> 1.6 + <meta charset="utf-8"> 1.7 + 1.8 +<script type="text/javascript;version=1.8"> 1.9 + 1.10 +function init() { 1.11 + window.addEventListener("message", function process(e) {doTest(e)}, false); 1.12 + // unless we relinquish the eventloop, 1.13 + // tests will run before the chrome event handlers are ready 1.14 + setTimeout(doTest, 0); 1.15 +} 1.16 + 1.17 +function checkStatusValue(payload, expectedValue) { 1.18 + return payload.status == expectedValue; 1.19 +} 1.20 + 1.21 +let tests = [ 1.22 +{ 1.23 + info: "Check account log in", 1.24 + event: "login", 1.25 + data: { 1.26 + email: "foo@example.com", 1.27 + uid: "1234@lcip.org", 1.28 + assertion: "foobar", 1.29 + sessionToken: "dead", 1.30 + kA: "beef", 1.31 + kB: "cafe", 1.32 + verified: true 1.33 + }, 1.34 + payloadType: "message", 1.35 + validateResponse: function(payload) { 1.36 + return checkStatusValue(payload, "login"); 1.37 + }, 1.38 +}, 1.39 +]; 1.40 + 1.41 +let currentTest = -1; 1.42 +function doTest(evt) { 1.43 + if (evt) { 1.44 + if (currentTest < 0 || !evt.data.content) 1.45 + return; // not yet testing 1.46 + 1.47 + let test = tests[currentTest]; 1.48 + if (evt.data.type != test.payloadType) 1.49 + return; // skip unrequested events 1.50 + 1.51 + let error = JSON.stringify(evt.data.content); 1.52 + let pass = false; 1.53 + try { 1.54 + pass = test.validateResponse(evt.data.content) 1.55 + } catch (e) {} 1.56 + reportResult(test.info, pass, error); 1.57 + } 1.58 + // start the next test if there are any left 1.59 + if (tests[++currentTest]) 1.60 + sendToBrowser(tests[currentTest].event, tests[currentTest].data); 1.61 + else 1.62 + reportFinished(); 1.63 +} 1.64 + 1.65 +function reportResult(info, pass, error) { 1.66 + let data = {type: "testResult", info: info, pass: pass, error: error}; 1.67 + window.parent.postMessage(data, "*"); 1.68 +} 1.69 + 1.70 +function reportFinished(cmd) { 1.71 + let data = {type: "testsComplete", count: tests.length}; 1.72 + window.parent.postMessage(data, "*"); 1.73 +} 1.74 + 1.75 +function sendToBrowser(type, data) { 1.76 + let event = new CustomEvent("FirefoxAccountsCommand", {detail: {command: type, data: data}, bubbles: true}); 1.77 + document.dispatchEvent(event); 1.78 +} 1.79 + 1.80 +</script> 1.81 + </head> 1.82 + <body onload="init()"> 1.83 + </body> 1.84 +</html>