Bug 981689 - Show a notice to beta users when we turn telemetry on by default on the beta channel - Firefox Desktop (very final fix). r=bsmedberg.

This commit is contained in:
Asaf Romano 2014-05-06 10:15:20 +03:00
Родитель 217586bb12
Коммит 64ea68b6be
4 изменённых файлов: 108 добавлений и 16 удалений

Просмотреть файл

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

Просмотреть файл

@ -38,8 +38,6 @@ 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.
*
@ -292,8 +290,19 @@ this.DataReportingPolicy = function (prefs, healthReportPrefs, listener) {
this._healthReportPrefs = healthReportPrefs;
this._listener = listener;
// If we've never run before, record the current time.
if (!this.firstRunDate.getTime()) {
// If the policy version has changed, reset all preferences, so that
// the notification reappears.
let acceptedVersion = this._prefs.get("dataSubmissionPolicyAcceptedVersion");
if (typeof(acceptedVersion) == "number" &&
acceptedVersion < this.minimumPolicyVersion) {
this._log.info("policy version has changed - resetting all prefs");
// We don't want to delay the notification in this case.
let firstRunToRestore = this.firstRunDate;
this._prefs.resetBranch();
this.firstRunDate = firstRunToRestore.getTime() ?
firstRunToRestore : this.now();
} else if (!this.firstRunDate.getTime()) {
// If we've never run before, record the current time.
this.firstRunDate = this.now();
}
@ -517,20 +526,17 @@ this.DataReportingPolicy.prototype = Object.freeze({
*/
get dataSubmissionPolicyAccepted() {
// Be conservative and default to false.
let enabled = this._prefs.get("dataSubmissionPolicyAccepted", false);
if (!enabled)
return false;
let acceptedVersion = this._prefs.get("dataSubmissionPolicyAcceptedVersion");
return acceptedVersion >= this.minimumPolicyVersion;
return this._prefs.get("dataSubmissionPolicyAccepted", false);
},
set dataSubmissionPolicyAccepted(value) {
this._prefs.set("dataSubmissionPolicyAccepted", !!value);
if (!!value)
this._prefs.set("dataSubmissionPolicyAcceptedVersion", CURRENT_POLICY_VERSION);
else
if (!!value) {
let currentPolicyVersion = this._prefs.get("currentPolicyVersion");
this._prefs.set("dataSubmissionPolicyAcceptedVersion", currentPolicyVersion);
} else {
this._prefs.reset("dataSubmissionPolicyAcceptedVersion");
}
},
/**

Просмотреть файл

@ -8,10 +8,26 @@ const {utils: Cu} = Components;
Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://gre/modules/services/datareporting/policy.jsm");
Cu.import("resource://testing-common/services/datareporting/mocks.jsm");
Cu.import("resource://gre/modules/UpdateChannel.jsm");
function getPolicy(name) {
function getPolicy(name,
aCurrentPolicyVersion = 1,
aMinimumPolicyVersion = 1,
aBranchMinimumVersionOverride) {
let branch = "testing.datareporting." + name;
// The version prefs should not be removed on reset, so set them in the
// default branch.
let defaultPolicyPrefs = new Preferences({ branch: branch + ".policy."
, defaultBranch: true });
defaultPolicyPrefs.set("currentPolicyVersion", aCurrentPolicyVersion);
defaultPolicyPrefs.set("minimumPolicyVersion", aMinimumPolicyVersion);
let branchOverridePrefName = "minimumPolicyVersion.channel-" + UpdateChannel.get(false);
if (aBranchMinimumVersionOverride !== undefined)
defaultPolicyPrefs.set(branchOverridePrefName, aBranchMinimumVersionOverride);
else
defaultPolicyPrefs.reset(branchOverridePrefName);
let policyPrefs = new Preferences(branch + ".policy.");
let healthReportPrefs = new Preferences(branch + ".healthreport.");
@ -776,3 +792,72 @@ add_test(function test_pref_change_initiates_deletion() {
hrPrefs.set("uploadEnabled", false);
});
add_task(function* test_policy_version() {
let policy, policyPrefs, hrPrefs, listener, now, firstRunTime;
function createPolicy(shouldBeAccepted = false,
currentPolicyVersion = 1, minimumPolicyVersion = 1,
branchMinimumVersionOverride) {
[policy, policyPrefs, hrPrefs, listener] =
getPolicy("policy_version_test", currentPolicyVersion,
minimumPolicyVersion, branchMinimumVersionOverride);
let firstRun = now === undefined;
if (firstRun) {
firstRunTime = policy.firstRunDate.getTime();
do_check_true(firstRunTime > 0);
now = new Date(policy.firstRunDate.getTime() +
policy.SUBMISSION_NOTIFY_INTERVAL_MSEC);
}
else {
// The first-run time should not be reset even after policy-version
// upgrades.
do_check_eq(policy.firstRunDate.getTime(), firstRunTime);
}
defineNow(policy, now);
do_check_eq(policy.dataSubmissionPolicyAccepted, shouldBeAccepted);
}
function* triggerPolicyCheckAndEnsureNotified(notified = true, accept = true) {
policy.checkStateAndTrigger();
do_check_eq(listener.notifyUserCount, Number(notified));
if (notified) {
yield listener.lastNotifyRequest.onUserNotifyComplete();
if (accept) {
listener.lastNotifyRequest.onUserAccept("because,");
do_check_true(policy.dataSubmissionPolicyAccepted);
do_check_eq(policyPrefs.get("dataSubmissionPolicyAcceptedVersion"),
policyPrefs.get("currentPolicyVersion"));
}
else {
do_check_false(policyPrefs.has("dataSubmissionPolicyAcceptedVersion"));
}
}
}
createPolicy();
yield triggerPolicyCheckAndEnsureNotified();
// We shouldn't be notified again if the current version is still valid;
createPolicy(true);
yield triggerPolicyCheckAndEnsureNotified(false);
// Just increasing the current version isn't enough. The minimum
// version must be changed.
let currentPolicyVersion = policyPrefs.get("currentPolicyVersion");
let minimumPolicyVersion = policyPrefs.get("minimumPolicyVersion");
createPolicy(true, ++currentPolicyVersion, minimumPolicyVersion);
yield triggerPolicyCheckAndEnsureNotified(false);
do_check_true(policy.dataSubmissionPolicyAccepted);
do_check_eq(policyPrefs.get("dataSubmissionPolicyAcceptedVersion"),
minimumPolicyVersion);
// Increase the minimum policy version and check if we're notified.
createPolicy(false, currentPolicyVersion, ++minimumPolicyVersion);
do_check_false(policyPrefs.has("dataSubmissionPolicyAcceptedVersion"));
yield triggerPolicyCheckAndEnsureNotified();
// Test increasing the minimum version just on the current channel.
createPolicy(true, currentPolicyVersion, minimumPolicyVersion);
yield triggerPolicyCheckAndEnsureNotified(false);
createPolicy(false, ++currentPolicyVersion, minimumPolicyVersion, minimumPolicyVersion + 1);
yield triggerPolicyCheckAndEnsureNotified(true);
});

Просмотреть файл

@ -322,7 +322,7 @@ Preferences.prototype = {
}
},
resetBranch: function(prefBranch) {
resetBranch: function(prefBranch = "") {
try {
this._prefSvc.resetBranch(prefBranch);
}