Bug 829184 - Update "Data Choices" pref pane with reworked XPCOM service; r=dolske

This commit is contained in:
Gregory Szorc 2013-01-11 15:33:57 -08:00
parent 57f274b2a8
commit 3db9342ace
7 changed files with 63 additions and 94 deletions

View File

@ -235,49 +235,38 @@ var gAdvancedPane = {
* Initialize the health report service reference and checkbox.
*/
initSubmitHealthReport: function () {
this._setupLearnMoreLink("healthreport.infoURL", "FHRLearnMore");
this._setupLearnMoreLink("datareporting.healthreport.infoURL", "FHRLearnMore");
let reporter = Components.classes["@mozilla.org/healthreport/service;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject
.reporter;
let policy = Components.classes["@mozilla.org/datareporting/service;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject
.policy;
let checkbox = document.getElementById("submitHealthReportBox");
if (!reporter) {
if (!policy) {
checkbox.setAttribute("disabled", "true");
return;
}
checkbox.checked = reporter.dataSubmissionPolicyAccepted;
checkbox.checked = policy.healthReportUploadEnabled;
},
/**
* Update the health report policy acceptance with state from checkbox.
*/
updateSubmitHealthReport: function () {
let reporter = Components.classes["@mozilla.org/healthreport/service;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject
.reporter;
let policy = Components.classes["@mozilla.org/datareporting/service;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject
.policy;
if (!reporter) {
if (!policy) {
return;
}
let checkbox = document.getElementById("submitHealthReportBox");
let accepted = reporter.dataSubmissionPolicyAccepted;
if (checkbox.checked && !accepted) {
reporter.recordPolicyAcceptance("pref-checkbox-checked");
return;
}
if (!checkbox.checked && accepted) {
reporter.recordPolicyRejection("pref-checkbox-unchecked");
return;
}
policy.healthReportUploadEnabled = checkbox.checked;
},
#endif

View File

@ -130,7 +130,9 @@
<tabs id="tabsElement">
<tab id="generalTab" label="&generalTab.label;" helpTopic="prefs-advanced-general"/>
#ifdef MOZ_DATA_REPORTING
<tab id="dataChoicesTab" label="&dataChoicesTab.label;" helpTopic="prefs-advanced-data-choices"/>
#endif
<tab id="networkTab" label="&networkTab.label;" helpTopic="prefs-advanced-network"/>
<tab id="updateTab" label="&updateTab.label;" helpTopic="prefs-advanced-update"/>
<tab id="encryptionTab" label="&encryptionTab.label;" helpTopic="prefs-advanced-encryption"/>
@ -204,14 +206,7 @@
#endif
</tabpanel>
#ifndef MOZ_TELEMETRY_REPORTING
#ifndef MOZ_SERVICES_HEALTHREPORT
#ifndef MOZ_CRASHREPORTER
#define HIDE_DATACHOICES
#endif
#endif
#endif
#ifndef HIDE_DATACHOICES
#ifdef MOZ_DATA_REPORTING
<!-- Data Choices -->
<tabpanel id="dataChoicesPanel" orient="vertical">
#ifdef MOZ_TELEMETRY_REPORTING

View File

@ -225,49 +225,38 @@ var gAdvancedPane = {
* Initialize the health report service reference and checkbox.
*/
initSubmitHealthReport: function () {
this._setupLearnMoreLink("healthreport.infoURL", "FHRLearnMore");
this._setupLearnMoreLink("datareporting.healthreport.infoURL", "FHRLearnMore");
let reporter = Components.classes["@mozilla.org/healthreport/service;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject
.reporter;
let policy = Components.classes["@mozilla.org/datareporting/service;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject
.policy;
let checkbox = document.getElementById("submitHealthReportBox");
if (!reporter) {
if (!policy) {
checkbox.setAttribute("disabled", "true");
return;
}
checkbox.checked = reporter.dataSubmissionPolicyAccepted;
checkbox.checked = policy.healthReportUploadEnabled;
},
/**
* Update the health report policy acceptance with state from checkbox.
*/
updateSubmitHealthReport: function () {
let reporter = Components.classes["@mozilla.org/healthreport/service;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject
.reporter;
let policy = Components.classes["@mozilla.org/datareporting/service;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject
.policy;
if (!reporter) {
if (!policy) {
return;
}
let checkbox = document.getElementById("submitHealthReportBox");
let accepted = reporter.dataSubmissionPolicyAccepted;
if (checkbox.checked && !accepted) {
reporter.recordPolicyAcceptance("pref-checkbox-checked");
return;
}
if (!checkbox.checked && accepted) {
reporter.recordPolicyRejection("pref-checkbox-unchecked");
return;
}
policy.healthReportUploadEnabled = checkbox.checked;
},
#endif

View File

@ -152,7 +152,9 @@
<tabs id="tabsElement">
<tab id="generalTab" label="&generalTab.label;" helpTopic="prefs-advanced-general"/>
#ifdef MOZ_DATA_REPORTING
<tab id="dataChoicesTab" label="&dataChoicesTab.label;" helpTopic="prefs-advanced-data-choices"/>
#endif
<tab id="networkTab" label="&networkTab.label;" helpTopic="prefs-advanced-network"/>
<tab id="updateTab" label="&updateTab.label;" helpTopic="prefs-advanced-update"/>
<tab id="encryptionTab" label="&encryptionTab.label;" helpTopic="prefs-advanced-encryption"/>
@ -222,14 +224,7 @@
</groupbox>
#endif
</tabpanel>
#ifndef MOZ_TELEMETRY_REPORTING
#ifndef MOZ_SERVICES_HEALTHREPORT
#ifndef MOZ_CRASHREPORTER
#define HIDE_DATACHOICES
#endif
#endif
#endif
#ifndef HIDE_DATACHOICES
#ifdef MOZ_DATA_REPORTING
<!-- Data Choices -->
<tabpanel id="dataChoicesPanel" orient="vertical">
#ifdef MOZ_TELEMETRY_REPORTING

View File

@ -18,28 +18,31 @@ function runTest(win) {
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);
is(policy.dataSubmissionPolicyAccepted, false, "Data submission policy not accepted.");
is(policy.healthReportUploadEnabled, true, "Health Report upload enabled on app first run.");
let checkbox = doc.getElementById("submitHealthReportBox");
ok(checkbox);
is(checkbox.checked, false, "Health Report checkbox is unchecked on app first run.");
is(checkbox.checked, true, "Health Report checkbox is checked on app first run.");
let reporter = Components.classes["@mozilla.org/healthreport/service;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject
.reporter;
ok(reporter);
is(reporter.dataSubmissionPolicyAccepted, false, "Data submission policy not accepted.");
checkbox.checked = false;
checkbox.doCommand();
is(policy.healthReportUploadEnabled, false, "Unchecking checkbox opts out of FHR upload.");
checkbox.checked = true;
checkbox.doCommand();
is(reporter.dataSubmissionPolicyAccepted, true, "Checking checkbox accepts data submission policy.");
checkbox.checked = false;
checkbox.doCommand();
is(reporter.dataSubmissionPolicyAccepted, false, "Unchecking checkbox opts out of data submission.");
is(policy.healthReportUploadEnabled, true, "Checking checkbox allows FHR upload.");
win.close();
finish();
}
function resetPreferences() {
Services.prefs.clearUserPref("healthreport.policy.dataSubmissionPolicyAccepted");
Services.prefs.clearUserPref("datareporting.healthreport.uploadEnabled");
}

View File

@ -28,8 +28,8 @@ function is_element_hidden(aElement, aMsg) {
function open_preferences(aCallback) {
gBrowser.selectedTab = gBrowser.addTab("about:preferences");
let newTabBrowser = gBrowser.getBrowserForTab(gBrowser.selectedTab);
newTabBrowser.addEventListener("load", function () {
newTabBrowser.removeEventListener("load", arguments.callee, true);
newTabBrowser.addEventListener("Initialized", function () {
newTabBrowser.removeEventListener("Initialized", arguments.callee, true);
aCallback(gBrowser.contentWindow);
}, true);
}

View File

@ -20,33 +20,31 @@ function test() {
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);
is(policy.dataSubmissionPolicyAccepted, false, "Data submission policy not accepted.");
is(policy.healthReportUploadEnabled, true, "Health Report upload enabled on app first run.");
let checkbox = doc.getElementById("submitHealthReportBox");
ok(checkbox);
is(checkbox.checked, false, "Health Report checkbox is unchecked on app first run.");
is(checkbox.checked, true, "Health Report checkbox is checked on app first run.");
let reporter = Components.classes["@mozilla.org/healthreport/service;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject
.reporter;
ok(reporter);
is(reporter.dataSubmissionPolicyAccepted, false, "Data submission policy not accepted.");
checkbox.checked = false;
checkbox.doCommand();
is(policy.healthReportUploadEnabled, false, "Unchecking checkbox opts out of FHR upload.");
checkbox.checked = true;
checkbox.doCommand();
is(reporter.dataSubmissionPolicyAccepted, true, "Checking checkbox accepts data submission policy.");
checkbox.checked = false;
checkbox.doCommand();
is(reporter.dataSubmissionPolicyAccepted, false, "Unchecking checkbox opts out of data submission.");
is(policy.healthReportUploadEnabled, true, "Checking checkbox allows FHR upload.");
win.close();
finish();
}
function resetPreferences() {
Services.prefs.clearUserPref("healthreport.policy.dataSubmissionPolicyAccepted");
Services.prefs.clearUserPref("datareporting.healthreport.uploadEnabled");
}