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