| |
1 <html> |
| |
2 <head> |
| |
3 <meta charset="utf-8"> |
| |
4 |
| |
5 <script> |
| |
6 |
| |
7 function init() { |
| |
8 window.addEventListener("message", function process(e) {doTest(e)}, false); |
| |
9 doTest(); |
| |
10 } |
| |
11 |
| |
12 function checkSubmissionValue(payload, expectedValue) { |
| |
13 return payload.enabled == expectedValue; |
| |
14 } |
| |
15 |
| |
16 function validatePayload(payload) { |
| |
17 payload = JSON.parse(payload); |
| |
18 |
| |
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; |
| |
22 |
| |
23 return true; |
| |
24 } |
| |
25 |
| |
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 ]; |
| |
84 |
| |
85 var currentTest = -1; |
| |
86 function doTest(evt) { |
| |
87 if (evt) { |
| |
88 if (currentTest < 0 || !evt.data.content) |
| |
89 return; // not yet testing |
| |
90 |
| |
91 var test = tests[currentTest]; |
| |
92 if (evt.data.type != test.payloadType) |
| |
93 return; // skip unrequested events |
| |
94 |
| |
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 } |
| |
108 |
| |
109 function reportResult(info, pass, error) { |
| |
110 var data = {type: "testResult", info: info, pass: pass, error: error}; |
| |
111 window.parent.postMessage(data, "*"); |
| |
112 } |
| |
113 |
| |
114 function reportFinished(cmd) { |
| |
115 var data = {type: "testsComplete", count: tests.length}; |
| |
116 window.parent.postMessage(data, "*"); |
| |
117 } |
| |
118 |
| |
119 function sendToBrowser(type) { |
| |
120 var event = new CustomEvent("RemoteHealthReportCommand", {detail: {command: type}, bubbles: true}); |
| |
121 document.dispatchEvent(event); |
| |
122 } |
| |
123 |
| |
124 </script> |
| |
125 </head> |
| |
126 <body onload="init()"> |
| |
127 </body> |
| |
128 </html> |