browser/components/preferences/in-content/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/in-content/tests/browser_healthreport.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,65 @@
     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 +  open_preferences((win) => {
    1.11 +    let doc = win.document;
    1.12 +    win.gotoPref("paneAdvanced");
    1.13 +    let advancedPrefs = doc.getElementById("advancedPrefs");
    1.14 +    let tab = doc.getElementById("dataChoicesTab");
    1.15 +    advancedPrefs.selectedTab = tab;
    1.16 +
    1.17 +    let policy = Components.classes["@mozilla.org/datareporting/service;1"]
    1.18 +                                   .getService(Components.interfaces.nsISupports)
    1.19 +                                   .wrappedJSObject
    1.20 +                                   .policy;
    1.21 +
    1.22 +    ok(policy, "Policy object is defined.");
    1.23 +    fn(win, doc, policy);
    1.24 +  });
    1.25 +}
    1.26 +
    1.27 +function test() {
    1.28 +  waitForExplicitFinish();
    1.29 +  resetPreferences();
    1.30 +  registerCleanupFunction(resetPreferences);
    1.31 +  runPaneTest(testBasic);
    1.32 +}
    1.33 +
    1.34 +function testBasic(win, doc, policy) {
    1.35 +  is(policy.dataSubmissionPolicyAccepted, false, "Data submission policy not accepted.");
    1.36 +  is(policy.healthReportUploadEnabled, true, "Health Report upload enabled on app first run.");
    1.37 +
    1.38 +  let checkbox = doc.getElementById("submitHealthReportBox");
    1.39 +  ok(checkbox);
    1.40 +  is(checkbox.checked, true, "Health Report checkbox is checked on app first run.");
    1.41 +
    1.42 +  checkbox.checked = false;
    1.43 +  checkbox.doCommand();
    1.44 +  is(policy.healthReportUploadEnabled, false, "Unchecking checkbox opts out of FHR upload.");
    1.45 +
    1.46 +  checkbox.checked = true;
    1.47 +  checkbox.doCommand();
    1.48 +  is(policy.healthReportUploadEnabled, true, "Checking checkbox allows FHR upload.");
    1.49 +
    1.50 +  win.close();
    1.51 +  Services.prefs.lockPref("datareporting.healthreport.uploadEnabled");
    1.52 +  runPaneTest(testUploadDisabled);
    1.53 +}
    1.54 +
    1.55 +function testUploadDisabled(win, doc, policy) {
    1.56 +  ok(policy.healthReportUploadLocked, "Upload enabled flag is locked.");
    1.57 +  let checkbox = doc.getElementById("submitHealthReportBox");
    1.58 +  is(checkbox.getAttribute("disabled"), "true", "Checkbox is disabled if upload flag is locked.");
    1.59 +  policy._healthReportPrefs.unlock("uploadEnabled");
    1.60 +
    1.61 +  win.close();
    1.62 +  finish();
    1.63 +}
    1.64 +
    1.65 +function resetPreferences() {
    1.66 +  Services.prefs.clearUserPref("datareporting.healthreport.uploadEnabled");
    1.67 +}
    1.68 +

mercurial