tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 929fb12c1318659f24965f2908dec6e5fd56d9d9
parent c2446dba1bbbd73f79803707e2d8a9acd8f15cf8
Author: Mark Hammond <mhammond@skippinet.com.au>
Date:   Thu, 18 Dec 2025 03:17:15 +0000

Bug 2006802 - fix sync tabs tests with new app-services. r=skhamis,sync-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D276945

Diffstat:
Mservices/sync/modules/service.sys.mjs | 3++-
Mservices/sync/tests/unit/test_tab_engine.js | 44++++++--------------------------------------
Mservices/sync/tests/unit/test_tab_quickwrite.js | 42++++++++++++++++++++++++++++++------------
3 files changed, 38 insertions(+), 51 deletions(-)

diff --git a/services/sync/modules/service.sys.mjs b/services/sync/modules/service.sys.mjs @@ -797,7 +797,8 @@ Sync11Service.prototype = { "No config or incomplete config in getMaxRecordPayloadSize." + " Are we running tests?" ); - return 256 * 1024; + // should stay in sync with MAX_PAYLOAD_SIZE in the Rust tabs engine. + return 2 * 1024 * 1024; } let payloadMax = config.max_record_payload_bytes; if (config.max_post_bytes && payloadMax <= config.max_post_bytes) { diff --git a/services/sync/tests/unit/test_tab_engine.js b/services/sync/tests/unit/test_tab_engine.js @@ -174,15 +174,12 @@ add_task(async function test_tab_engine_skips_incoming_local_record() { equal(client.name, "Remote client"); equal(client.type, "desktop"); Assert.ok(client.lastModified); // lastModified should be filled in once serverModified is populated from the server - deepEqual(client.tabs, [ - { - title: "title2", - urlHistory: ["http://bar.com/"], - icon: "", - inactive: false, - lastUsed: 3000, - }, - ]); + Assert.equal(client.tabs.length, 1); + let tab = client.tabs[0]; + Assert.equal(tab.title, "title2"); + Assert.deepEqual(tab.urlHistory, ["http://bar.com/"]); + Assert.equal(tab.icon, ""); + Assert.ok(!tab.inactive); await syncFinish.call(engine); resolve(); }; @@ -195,32 +192,3 @@ add_task(async function test_tab_engine_skips_incoming_local_record() { // Bug 1800185 - we don't want the sync scheduler to see these records as incoming. Assert.ok(!Service.scheduler.hasIncomingItems); }); - -// Ensure we trim tabs in the case of going past the max payload size allowed -add_task(async function test_too_many_tabs() { - let a_lot_of_tabs = []; - - for (let i = 0; i < 4000; ++i) { - a_lot_of_tabs.push( - `http://example${i}.com/some-super-long-url-chain-to-help-with-bytes` - ); - } - - TabProvider.getWindowEnumerator = mockGetWindowEnumerator.bind( - this, - a_lot_of_tabs - ); - - let encoder = Utils.utf8Encoder; - // see tryfitItems(..) in util.js - const computeSerializedSize = records => - encoder.encode(JSON.stringify(records)).byteLength; - - const maxPayloadSize = Service.getMaxRecordPayloadSize(); - const maxSerializedSize = (maxPayloadSize / 4) * 3 - 1500; - // We are over max payload size - Assert.greater(computeSerializedSize(a_lot_of_tabs), maxSerializedSize); - let tabs = await engine.getTabsWithinPayloadSize(); - // We are now under max payload size - Assert.less(computeSerializedSize(tabs), maxSerializedSize); -}); diff --git a/services/sync/tests/unit/test_tab_quickwrite.js b/services/sync/tests/unit/test_tab_quickwrite.js @@ -105,10 +105,31 @@ add_task(async function test_tab_quickwrite_keeps_old_tabs() { _("Ensure we don't delete other tabs on quickWrite (bug 1801295)."); let { server, engine } = await prepareServer(); + // The ID of another device. + const id = "fake-guid-99"; + + // The clients engine is always going to tell us there are no other clients, + // but we need other clients, so we trick it. + // (We can't just stick this on the server, because we treat it as stale because it + // doesn't appear in the fxa list - but tricking it this way works) + let observeClientsFinished = (_subject, _topic, data) => { + if (data == "clients") { + engine.service.clientsEngine.fxAccounts.device._deviceListCache = { + devices: [], + }; + // trick the clients engine into thinking it has a remote client with the same guid. + engine.service.clientsEngine._store._remoteClients = {}; + engine.service.clientsEngine._store._remoteClients[id] = { + id, + fxaDeviceId: id, + }; + } + }; + Services.obs.addObserver(observeClientsFinished, "weave:engine:sync:finish"); + // need a first sync to ensure everything is setup correctly. await Service.sync({ engines: ["tabs"] }); - const id = "fake-guid-99"; let remoteRecord = encryptPayload({ id, clientName: "not local", @@ -125,22 +146,14 @@ add_task(async function test_tab_quickwrite_keeps_old_tabs() { let collection = server.getCollection("username", "tabs"); collection.insert(id, remoteRecord); + // This test can be flakey because sometimes we are so fast we think there is nothing to do. + // Resetting the last sync time here ensures we always fetch records from the server. + engine.setLastSync(0); await Service.sync({ engines: ["tabs"] }); // collection should now have 2 records - ours and the pretend remote one we inserted. Assert.equal(collection.count(), 2, "starting with 2 tab records"); - // So fxAccounts.device.recentDeviceList is not null. - engine.service.clientsEngine.fxAccounts.device._deviceListCache = { - devices: [], - }; - // trick the clients engine into thinking it has a remote client with the same guid. - engine.service.clientsEngine._store._remoteClients = {}; - engine.service.clientsEngine._store._remoteClients[id] = { - id, - fxaDeviceId: id, - }; - let clients = await engine.getAllClients(); Assert.equal(clients.length, 1); @@ -154,6 +167,11 @@ add_task(async function test_tab_quickwrite_keeps_old_tabs() { engine.service.clientsEngine._store._remoteClients = {}; + Services.obs.removeObserver( + observeClientsFinished, + "weave:engine:sync:finish" + ); + await promiseStopServer(server); });