Wed, 31 Dec 2014 06:09:35 +0100
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> |
michael@0 | 6 | |
michael@0 | 7 | function init() { |
michael@0 | 8 | window.addEventListener("message", function process(e) {doTest(e)}, false); |
michael@0 | 9 | doTest(); |
michael@0 | 10 | } |
michael@0 | 11 | |
michael@0 | 12 | function checkSubmissionValue(payload, expectedValue) { |
michael@0 | 13 | return payload.enabled == expectedValue; |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | function validatePayload(payload) { |
michael@0 | 17 | payload = JSON.parse(payload); |
michael@0 | 18 | |
michael@0 | 19 | // xxxmpc - this is some pretty low-bar validation, but we have plenty of tests of that API elsewhere |
michael@0 | 20 | if (!payload.thisPingDate) |
michael@0 | 21 | return false; |
michael@0 | 22 | |
michael@0 | 23 | return true; |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | var tests = [ |
michael@0 | 27 | { |
michael@0 | 28 | info: "Checking initial value is enabled", |
michael@0 | 29 | event: "RequestCurrentPrefs", |
michael@0 | 30 | payloadType: "prefs", |
michael@0 | 31 | validateResponse: function(payload) { |
michael@0 | 32 | return checkSubmissionValue(payload, true); |
michael@0 | 33 | }, |
michael@0 | 34 | }, |
michael@0 | 35 | { |
michael@0 | 36 | info: "Verifying disabling works", |
michael@0 | 37 | event: "DisableDataSubmission", |
michael@0 | 38 | payloadType: "prefs", |
michael@0 | 39 | validateResponse: function(payload) { |
michael@0 | 40 | return checkSubmissionValue(payload, false); |
michael@0 | 41 | }, |
michael@0 | 42 | }, |
michael@0 | 43 | { |
michael@0 | 44 | info: "Verifying we're still disabled", |
michael@0 | 45 | event: "RequestCurrentPrefs", |
michael@0 | 46 | payloadType: "prefs", |
michael@0 | 47 | validateResponse: function(payload) { |
michael@0 | 48 | return checkSubmissionValue(payload, false); |
michael@0 | 49 | }, |
michael@0 | 50 | }, |
michael@0 | 51 | { |
michael@0 | 52 | info: "Verifying we can get a payload while submission is disabled", |
michael@0 | 53 | event: "RequestCurrentPayload", |
michael@0 | 54 | payloadType: "payload", |
michael@0 | 55 | validateResponse: function(payload) { |
michael@0 | 56 | return validatePayload(payload); |
michael@0 | 57 | }, |
michael@0 | 58 | }, |
michael@0 | 59 | { |
michael@0 | 60 | info: "Verifying enabling works", |
michael@0 | 61 | event: "EnableDataSubmission", |
michael@0 | 62 | payloadType: "prefs", |
michael@0 | 63 | validateResponse: function(payload) { |
michael@0 | 64 | return checkSubmissionValue(payload, true); |
michael@0 | 65 | }, |
michael@0 | 66 | }, |
michael@0 | 67 | { |
michael@0 | 68 | info: "Verifying we're still re-enabled", |
michael@0 | 69 | event: "RequestCurrentPrefs", |
michael@0 | 70 | payloadType: "prefs", |
michael@0 | 71 | validateResponse: function(payload) { |
michael@0 | 72 | return checkSubmissionValue(payload, true); |
michael@0 | 73 | }, |
michael@0 | 74 | }, |
michael@0 | 75 | { |
michael@0 | 76 | info: "Verifying we can get a payload after re-enabling", |
michael@0 | 77 | event: "RequestCurrentPayload", |
michael@0 | 78 | payloadType: "payload", |
michael@0 | 79 | validateResponse: function(payload) { |
michael@0 | 80 | return validatePayload(payload); |
michael@0 | 81 | }, |
michael@0 | 82 | }, |
michael@0 | 83 | ]; |
michael@0 | 84 | |
michael@0 | 85 | var currentTest = -1; |
michael@0 | 86 | function doTest(evt) { |
michael@0 | 87 | if (evt) { |
michael@0 | 88 | if (currentTest < 0 || !evt.data.content) |
michael@0 | 89 | return; // not yet testing |
michael@0 | 90 | |
michael@0 | 91 | var test = tests[currentTest]; |
michael@0 | 92 | if (evt.data.type != test.payloadType) |
michael@0 | 93 | return; // skip unrequested events |
michael@0 | 94 | |
michael@0 | 95 | var error = JSON.stringify(evt.data.content); |
michael@0 | 96 | var pass = false; |
michael@0 | 97 | try { |
michael@0 | 98 | pass = test.validateResponse(evt.data.content) |
michael@0 | 99 | } catch (e) {} |
michael@0 | 100 | reportResult(test.info, pass, error); |
michael@0 | 101 | } |
michael@0 | 102 | // start the next test if there are any left |
michael@0 | 103 | if (tests[++currentTest]) |
michael@0 | 104 | sendToBrowser(tests[currentTest].event); |
michael@0 | 105 | else |
michael@0 | 106 | reportFinished(); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | function reportResult(info, pass, error) { |
michael@0 | 110 | var data = {type: "testResult", info: info, pass: pass, error: error}; |
michael@0 | 111 | window.parent.postMessage(data, "*"); |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | function reportFinished(cmd) { |
michael@0 | 115 | var data = {type: "testsComplete", count: tests.length}; |
michael@0 | 116 | window.parent.postMessage(data, "*"); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | function sendToBrowser(type) { |
michael@0 | 120 | var event = new CustomEvent("RemoteHealthReportCommand", {detail: {command: type}, bubbles: true}); |
michael@0 | 121 | document.dispatchEvent(event); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | </script> |
michael@0 | 125 | </head> |
michael@0 | 126 | <body onload="init()"> |
michael@0 | 127 | </body> |
michael@0 | 128 | </html> |