browser/components/preferences/tests/browser_healthreport.js

branch
TOR_BUG_9701
changeset 14
925c144e1f1f
equal deleted inserted replaced
-1:000000000000 0:c0f8dbec329e
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 "use strict";
5
6 function runPaneTest(fn) {
7 function observer(win, topic, data) {
8 Services.obs.removeObserver(observer, "advanced-pane-loaded");
9
10 let policy = Components.classes["@mozilla.org/datareporting/service;1"]
11 .getService(Components.interfaces.nsISupports)
12 .wrappedJSObject
13 .policy;
14 ok(policy, "Policy object defined");
15
16 fn(win, policy);
17 }
18
19 Services.obs.addObserver(observer, "advanced-pane-loaded", false);
20 openDialog("chrome://browser/content/preferences/preferences.xul", "Preferences",
21 "chrome,titlebar,toolbar,centerscreen,dialog=no", "paneAdvanced");
22 }
23
24 function test() {
25 waitForExplicitFinish();
26 resetPreferences();
27 registerCleanupFunction(resetPreferences);
28
29 Services.prefs.lockPref("datareporting.healthreport.uploadEnabled");
30 runPaneTest(testUploadDisabled);
31 }
32
33 function testUploadDisabled(win, policy) {
34 ok(policy.healthReportUploadLocked, "Upload enabled flag is locked.");
35 let checkbox = win.document.getElementById("submitHealthReportBox");
36 is(checkbox.getAttribute("disabled"), "true", "Checkbox is disabled if upload setting is locked.");
37 policy._healthReportPrefs.unlock("uploadEnabled");
38
39 win.close();
40 runPaneTest(testBasic);
41 }
42
43 function testBasic(win, policy) {
44 let doc = win.document;
45
46 is(policy.dataSubmissionPolicyAccepted, false, "Data submission policy not accepted.");
47 is(policy.healthReportUploadEnabled, true, "Health Report upload enabled on app first run.");
48
49 let checkbox = doc.getElementById("submitHealthReportBox");
50 ok(checkbox);
51 is(checkbox.checked, true, "Health Report checkbox is checked on app first run.");
52
53 checkbox.checked = false;
54 checkbox.doCommand();
55 is(policy.healthReportUploadEnabled, false, "Unchecking checkbox opts out of FHR upload.");
56
57 checkbox.checked = true;
58 checkbox.doCommand();
59 is(policy.healthReportUploadEnabled, true, "Checking checkbox allows FHR upload.");
60
61 win.close();
62 finish();
63 }
64
65 function resetPreferences() {
66 Services.prefs.clearUserPref("datareporting.healthreport.uploadEnabled");
67 }
68

mercurial