browser/components/preferences/tests/browser_healthreport.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/preferences/tests/browser_healthreport.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,68 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +* http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +"use strict";
     1.8 +
     1.9 +function runPaneTest(fn) {
    1.10 +  function observer(win, topic, data) {
    1.11 +    Services.obs.removeObserver(observer, "advanced-pane-loaded");
    1.12 +
    1.13 +    let policy = Components.classes["@mozilla.org/datareporting/service;1"]
    1.14 +                                   .getService(Components.interfaces.nsISupports)
    1.15 +                                   .wrappedJSObject
    1.16 +                                   .policy;
    1.17 +    ok(policy, "Policy object defined");
    1.18 +
    1.19 +    fn(win, policy);
    1.20 +  }
    1.21 +
    1.22 +  Services.obs.addObserver(observer, "advanced-pane-loaded", false);
    1.23 +  openDialog("chrome://browser/content/preferences/preferences.xul", "Preferences",
    1.24 +             "chrome,titlebar,toolbar,centerscreen,dialog=no", "paneAdvanced");
    1.25 +}
    1.26 +
    1.27 +function test() {
    1.28 +  waitForExplicitFinish();
    1.29 +  resetPreferences();
    1.30 +  registerCleanupFunction(resetPreferences);
    1.31 +
    1.32 +  Services.prefs.lockPref("datareporting.healthreport.uploadEnabled");
    1.33 +  runPaneTest(testUploadDisabled);
    1.34 +}
    1.35 +
    1.36 +function testUploadDisabled(win, policy) {
    1.37 +  ok(policy.healthReportUploadLocked, "Upload enabled flag is locked.");
    1.38 +  let checkbox = win.document.getElementById("submitHealthReportBox");
    1.39 +  is(checkbox.getAttribute("disabled"), "true", "Checkbox is disabled if upload setting is locked.");
    1.40 +  policy._healthReportPrefs.unlock("uploadEnabled");
    1.41 +
    1.42 +  win.close();
    1.43 +  runPaneTest(testBasic);
    1.44 +}
    1.45 +
    1.46 +function testBasic(win, policy) {
    1.47 +  let doc = win.document;
    1.48 +
    1.49 +  is(policy.dataSubmissionPolicyAccepted, false, "Data submission policy not accepted.");
    1.50 +  is(policy.healthReportUploadEnabled, true, "Health Report upload enabled on app first run.");
    1.51 +
    1.52 +  let checkbox = doc.getElementById("submitHealthReportBox");
    1.53 +  ok(checkbox);
    1.54 +  is(checkbox.checked, true, "Health Report checkbox is checked on app first run.");
    1.55 +
    1.56 +  checkbox.checked = false;
    1.57 +  checkbox.doCommand();
    1.58 +  is(policy.healthReportUploadEnabled, false, "Unchecking checkbox opts out of FHR upload.");
    1.59 +
    1.60 +  checkbox.checked = true;
    1.61 +  checkbox.doCommand();
    1.62 +  is(policy.healthReportUploadEnabled, true, "Checking checkbox allows FHR upload.");
    1.63 +
    1.64 +  win.close();
    1.65 +  finish();
    1.66 +}
    1.67 +
    1.68 +function resetPreferences() {
    1.69 +  Services.prefs.clearUserPref("datareporting.healthreport.uploadEnabled");
    1.70 +}
    1.71 +

mercurial