Bug 1772956 - only sync after tab changes if the user has more than one client r=markh

Differential Revision: https://phabricator.services.mozilla.com/D148467
This commit is contained in:
Sammy Khamis 2022-06-07 04:32:42 +00:00
Родитель 24801f7209
Коммит 0f37ee0746
2 изменённых файлов: 43 добавлений и 3 удалений

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

@ -429,7 +429,7 @@ TabTracker.prototype = {
callScheduleSync(scoreIncrement) {
this.modified = true;
let { scheduler } = this.engine.service;
const delayInMs = lazy.NimbusFeatures.syncAfterTabChange.getVariable(
"syncDelayAfterTabChange"
);
@ -437,11 +437,14 @@ TabTracker.prototype = {
// If we are part of the experiment don't use score here
// and instead schedule a sync once we detect a tab change
// to ensure the server always has the most up to date tabs
if (delayInMs > 0) {
if (
delayInMs > 0 &&
scheduler.numClients > 1 // Don't constantly schedule syncs for single client users
) {
this._log.debug(
"Detected a tab change: scheduling a sync in " + delayInMs + "ms"
);
this.engine.service.scheduler.scheduleNextSync(delayInMs, {
scheduler.scheduleNextSync(delayInMs, {
why: "tabschanged",
});
} else if (scoreIncrement) {

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

@ -185,6 +185,12 @@ add_task(async function run_sync_on_tab_change_test() {
// This is the fallback pref if we don't have a experiment running
Svc.Prefs.set("syncedTabs.syncDelayAfterTabChange", testExperimentDelay);
// We should only be syncing on tab change if
// the user has > 1 client
Svc.Prefs.set("clients.devices.desktop", 1);
Svc.Prefs.set("clients.devices.mobile", 1);
scheduler.updateClientMode();
Assert.equal(scheduler.numClients, 2);
let doEnrollmentCleanup = await ExperimentFakes.enrollWithFeatureConfig(
{
@ -281,12 +287,43 @@ add_task(async function run_sync_on_tab_change_test() {
scheduler.nextSync - Date.now() <= testExperimentDelay,
"about page should trigger a sync soon after we changed the pref"
);
_("Test no sync after tab change for accounts with <= 1 clients");
// Pretend we just synced
await tracker.clearChangedIDs();
scheduler.nextSync = Date.now() + scheduler.idleInterval;
// Setting clients to only 1 so we don't sync after a tab change
Svc.Prefs.set("clients.devices.desktop", 1);
Svc.Prefs.set("clients.devices.mobile", 0);
scheduler.updateClientMode();
Assert.equal(scheduler.numClients, 1);
tracker.onLocationChange(
{ isTopLevel: true },
undefined,
Services.io.newURI("https://www.mozilla.org"),
Ci.nsIWebProgressListener.LOCATION_CHANGE_RELOAD
);
Assert.ok(
tracker.modified,
"location change for a new top-level document flagged as modified"
);
Assert.ok(
scheduler.nextSync - Date.now() > testExperimentDelay,
"We should NOT be syncing shortly because there is only one client"
);
await doEnrollmentCleanup();
_("If there is no experiment, fallback to the pref");
let delayPref = Svc.Prefs.get("syncedTabs.syncDelayAfterTabChange");
let evttype = "TabOpen";
Assert.equal(delayPref, testExperimentDelay);
// Only have task continuity if we have more than 1 device
Svc.Prefs.set("clients.devices.desktop", 1);
Svc.Prefs.set("clients.devices.mobile", 1);
scheduler.updateClientMode();
Assert.equal(scheduler.numClients, 2);
// Fire ontab event
tracker.onTab({ type: evttype, originalTarget: evttype });