Bug 981689 - Show a notice to beta users when we turn telemetry on by default on the beta channel - Firefox Desktop

This commit is contained in:
Asaf Romano 2014-04-07 12:26:58 +03:00
parent a3aa6b9f72
commit 5dbae2896b
3 changed files with 29 additions and 10 deletions

View File

@ -10,3 +10,6 @@ pref("datareporting.policy.dataSubmissionPolicyResponseType", "");
pref("datareporting.policy.dataSubmissionPolicyResponseTime", "0");
pref("datareporting.policy.firstRunTime", "0");
pref("datareporting.policy.minimumPolicyVersion", 1);
pref("datareporting.policy.minimumPolicyVersion.channel-beta", 2);

View File

@ -26,6 +26,7 @@ const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
#endif
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Promise.jsm");
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://services-common/utils.js");
@ -36,6 +37,8 @@ const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000;
// implemented in 2012, so any earlier dates indicate an incorrect clock.
const OLDEST_ALLOWED_YEAR = 2012;
const CURRENT_POLICY_VERSION = 2;
/**
* Represents a request to display data policy.
*
@ -494,6 +497,18 @@ this.DataReportingPolicy.prototype = Object.freeze({
this._prefs.set("dataSubmissionEnabled", !!value);
},
/**
* The minimum policy version which for dataSubmissionPolicyAccepted to
* to be valid.
*/
get minimumPolicyVersion() {
// First check if the current channel has an ove
let channel = Services.appinfo.defaultUpdateChannel;
let channelPref = this._prefs.get("minimumPolicyVersion.channel-" + channel);
return channelPref !== undefined ?
channelPref : this._prefs.get("minimumPolicyVersion", 1);
},
/**
* Whether the user has accepted that data submission can occur.
*
@ -501,15 +516,20 @@ this.DataReportingPolicy.prototype = Object.freeze({
*/
get dataSubmissionPolicyAccepted() {
// Be conservative and default to false.
return this._prefs.get("dataSubmissionPolicyAccepted", false);
let enabled = this._prefs.get("dataSubmissionPolicyAccepted", false);
if (!enabled)
return false;
let acceptedVersion = this._prefs.get("dataSubmissionPolicyAcceptedVersion");
return acceptedVersion >= this.minimumPolicyVersion;
},
set dataSubmissionPolicyAccepted(value) {
this._prefs.set("dataSubmissionPolicyAccepted", !!value);
},
set dataSubmissionPolicyAcceptedVersion(value) {
this._prefs.set("dataSubmissionPolicyAcceptedVersion", value);
if (!!value)
this._prefs.set("dataSubmissionPolicyAcceptedVersion", CURRENT_POLICY_VERSION);
else
this._prefs.reset("dataSubmissionPolicyAcceptedVersion");
},
/**
@ -684,7 +704,6 @@ this.DataReportingPolicy.prototype = Object.freeze({
this.dataSubmissionPolicyResponseDate = this.now();
this.dataSubmissionPolicyResponseType = "accepted-" + reason;
this.dataSubmissionPolicyAccepted = true;
this.dataSubmissionPolicyAcceptedVersion = 1;
},
/**

View File

@ -85,9 +85,6 @@ add_test(function test_prefs() {
do_check_false(policyPrefs.get("dataSubmissionPolicyAccepted", true));
do_check_false(policy.dataSubmissionPolicyAccepted);
policy.dataSubmissionPolicyAcceptedVersion = 2;
do_check_eq(policyPrefs.get("dataSubmissionPolicyAcceptedVersion"), 2);
do_check_false(policy.dataSubmissionPolicyBypassAcceptance);
policyPrefs.set("dataSubmissionPolicyBypassAcceptance", true);
do_check_true(policy.dataSubmissionPolicyBypassAcceptance);
@ -274,7 +271,7 @@ add_test(function test_submission_kill_switch() {
policy.firstRunDate = new Date(Date.now() - 3 * 24 * 60 * 60 * 1000);
policy.nextDataSubmissionDate = new Date(Date.now() - 24 * 60 * 60 * 1000);
policy.recordUserAcceptance("accept-old-ack");
do_check_eq(policyPrefs.get("dataSubmissionPolicyAcceptedVersion"), 1);
do_check_true(policyPrefs.has("dataSubmissionPolicyAcceptedVersion"));
policy.checkStateAndTrigger();
do_check_eq(listener.requestDataUploadCount, 1);