Bug 873054 - Disable FHR prefs checkbox if pref is locked; r=rnewman

This commit is contained in:
Gregory Szorc 2013-07-02 09:55:34 -07:00
parent 4bbbae2ed4
commit b04e74702d
6 changed files with 77 additions and 29 deletions

View File

@ -250,7 +250,7 @@ var gAdvancedPane = {
let checkbox = document.getElementById("submitHealthReportBox");
if (!policy) {
if (!policy || policy.healthReportUploadLocked) {
checkbox.setAttribute("disabled", "true");
return;
}

View File

@ -230,7 +230,7 @@ var gAdvancedPane = {
let checkbox = document.getElementById("submitHealthReportBox");
if (!policy) {
if (!policy || policy.healthReportUploadLocked) {
checkbox.setAttribute("disabled", "true");
return;
}

View File

@ -3,26 +3,32 @@
"use strict";
function runPaneTest(fn) {
open_preferences((win) => {
let doc = win.document;
win.gotoPref("paneAdvanced");
let advancedPrefs = doc.getElementById("advancedPrefs");
let tab = doc.getElementById("dataChoicesTab");
advancedPrefs.selectedTab = tab;
let policy = Components.classes["@mozilla.org/datareporting/service;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject
.policy;
ok(policy, "Policy object is defined.");
fn(win, doc, policy);
});
}
function test() {
waitForExplicitFinish();
resetPreferences();
registerCleanupFunction(resetPreferences);
open_preferences(runTest);
runPaneTest(testBasic);
}
function runTest(win) {
let doc = win.document;
win.gotoPref("paneAdvanced");
let advancedPrefs = doc.getElementById("advancedPrefs");
let dataChoicesTab = doc.getElementById("dataChoicesTab");
advancedPrefs.selectedTab = dataChoicesTab;
let policy = Components.classes["@mozilla.org/datareporting/service;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject
.policy;
ok(policy);
function testBasic(win, doc, policy) {
is(policy.dataSubmissionPolicyAccepted, false, "Data submission policy not accepted.");
is(policy.healthReportUploadEnabled, true, "Health Report upload enabled on app first run.");
@ -38,6 +44,17 @@ function runTest(win) {
checkbox.doCommand();
is(policy.healthReportUploadEnabled, true, "Checking checkbox allows FHR upload.");
win.close();
Services.prefs.lockPref("datareporting.healthreport.uploadEnabled");
runPaneTest(testUploadDisabled);
}
function testUploadDisabled(win, doc, policy) {
ok(policy.healthReportUploadLocked, "Upload enabled flag is locked.");
let checkbox = doc.getElementById("submitHealthReportBox");
is(checkbox.getAttribute("disabled"), "true", "Checkbox is disabled if upload flag is locked.");
policy._healthReportPrefs.unlock("uploadEnabled");
win.close();
finish();
}

View File

@ -3,28 +3,46 @@
"use strict";
function runPaneTest(fn) {
function observer(win, topic, data) {
Services.obs.removeObserver(observer, "advanced-pane-loaded");
let policy = Components.classes["@mozilla.org/datareporting/service;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject
.policy;
ok(policy, "Policy object defined");
fn(win, policy);
}
Services.obs.addObserver(observer, "advanced-pane-loaded", false);
openDialog("chrome://browser/content/preferences/preferences.xul", "Preferences",
"chrome,titlebar,toolbar,centerscreen,dialog=no", "paneAdvanced");
}
function test() {
waitForExplicitFinish();
resetPreferences();
registerCleanupFunction(resetPreferences);
function observer(win, topic, data) {
Services.obs.removeObserver(observer, "advanced-pane-loaded");
runTest(win);
}
Services.obs.addObserver(observer, "advanced-pane-loaded", false);
openDialog("chrome://browser/content/preferences/preferences.xul", "Preferences",
"chrome,titlebar,toolbar,centerscreen,dialog=no", "paneAdvanced");
Services.prefs.lockPref("datareporting.healthreport.uploadEnabled");
runPaneTest(testUploadDisabled);
}
function runTest(win) {
function testUploadDisabled(win, policy) {
ok(policy.healthReportUploadLocked, "Upload enabled flag is locked.");
let checkbox = win.document.getElementById("submitHealthReportBox");
is(checkbox.getAttribute("disabled"), "true", "Checkbox is disabled if upload setting is locked.");
policy._healthReportPrefs.unlock("uploadEnabled");
win.close();
runPaneTest(testBasic);
}
function testBasic(win, policy) {
let doc = win.document;
let policy = Components.classes["@mozilla.org/datareporting/service;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject
.policy;
ok(policy);
is(policy.dataSubmissionPolicyAccepted, false, "Data submission policy not accepted.");
is(policy.healthReportUploadEnabled, true, "Health Report upload enabled on app first run.");

View File

@ -650,6 +650,13 @@ DataReportingPolicy.prototype = Object.freeze({
this._healthReportPrefs.set("uploadEnabled", !!value);
},
/**
* Whether the FHR upload enabled setting is locked and can't be changed.
*/
get healthReportUploadLocked() {
return this._healthReportPrefs.locked("uploadEnabled");
},
/**
* Record user acceptance of data submission policy.
*

View File

@ -120,6 +120,12 @@ add_test(function test_prefs() {
do_check_false(hrPrefs.get("uploadEnabled"));
do_check_false(policy.healthReportUploadEnabled);
do_check_false(policy.healthReportUploadLocked);
hrPrefs.lock("uploadEnabled");
do_check_true(policy.healthReportUploadLocked);
hrPrefs.unlock("uploadEnabled");
do_check_false(policy.healthReportUploadLocked);
run_next_test();
});