Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 function runPaneTest(fn) {
7 function observer(win, topic, data) {
8 Services.obs.removeObserver(observer, "advanced-pane-loaded");
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");
16 fn(win, policy);
17 }
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 }
24 function test() {
25 waitForExplicitFinish();
26 resetPreferences();
27 registerCleanupFunction(resetPreferences);
29 Services.prefs.lockPref("datareporting.healthreport.uploadEnabled");
30 runPaneTest(testUploadDisabled);
31 }
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");
39 win.close();
40 runPaneTest(testBasic);
41 }
43 function testBasic(win, policy) {
44 let doc = win.document;
46 is(policy.dataSubmissionPolicyAccepted, false, "Data submission policy not accepted.");
47 is(policy.healthReportUploadEnabled, true, "Health Report upload enabled on app first run.");
49 let checkbox = doc.getElementById("submitHealthReportBox");
50 ok(checkbox);
51 is(checkbox.checked, true, "Health Report checkbox is checked on app first run.");
53 checkbox.checked = false;
54 checkbox.doCommand();
55 is(policy.healthReportUploadEnabled, false, "Unchecking checkbox opts out of FHR upload.");
57 checkbox.checked = true;
58 checkbox.doCommand();
59 is(policy.healthReportUploadEnabled, true, "Checking checkbox allows FHR upload.");
61 win.close();
62 finish();
63 }
65 function resetPreferences() {
66 Services.prefs.clearUserPref("datareporting.healthreport.uploadEnabled");
67 }