tor-browser

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

test_disconnect_shutdown.js (3153B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const { SyncDisconnect, SyncDisconnectInternal } = ChromeUtils.importESModule(
      7  "resource://services-sync/SyncDisconnect.sys.mjs"
      8 );
      9 const { AsyncShutdown } = ChromeUtils.importESModule(
     10  "resource://gre/modules/AsyncShutdown.sys.mjs"
     11 );
     12 const { PREF_LAST_FXA_USER_UID } = ChromeUtils.importESModule(
     13  "resource://gre/modules/FxAccountsCommon.sys.mjs"
     14 );
     15 
     16 add_task(async function test_shutdown_blocker() {
     17  let spySignout = sinon.stub(
     18    SyncDisconnectInternal,
     19    "doSyncAndAccountDisconnect"
     20  );
     21 
     22  // We don't need to check for the lock regularly as we end up aborting the wait.
     23  SyncDisconnectInternal.lockRetryInterval = 1000;
     24  // Force the retry count to a very large value - this test should never
     25  // abort due to the retry count and we want the test to fail (aka timeout)
     26  // should our abort code not work.
     27  SyncDisconnectInternal.lockRetryCount = 10000;
     28  // mock the "browser" sanitize function - it should not be called by
     29  // this test.
     30  let spyBrowser = sinon.stub(SyncDisconnectInternal, "doSanitizeBrowserData");
     31  // mock Sync
     32  let mockEngine1 = {
     33    enabled: true,
     34    name: "Test Engine 1",
     35    wipeClient: sinon.spy(),
     36  };
     37  let mockEngine2 = {
     38    enabled: false,
     39    name: "Test Engine 2",
     40    wipeClient: sinon.spy(),
     41  };
     42 
     43  // This weave mock never gives up the lock.
     44  let Weave = {
     45    Service: {
     46      enabled: true,
     47      lock: () => false, // so we never get the lock.
     48      unlock: sinon.spy(),
     49 
     50      engineManager: {
     51        getAll: sinon.stub().returns([mockEngine1, mockEngine2]),
     52      },
     53      errorHandler: {
     54        resetFileLog: sinon.spy(),
     55      },
     56    },
     57  };
     58  let weaveStub = sinon.stub(SyncDisconnectInternal, "getWeave");
     59  weaveStub.returns(Weave);
     60 
     61  Services.prefs.setStringPref(
     62    PREF_LAST_FXA_USER_UID,
     63    "dGVzdEBleGFtcGxlLmNvbQ=="
     64  );
     65 
     66  let promiseDisconnected = SyncDisconnect.disconnect(true);
     67 
     68  // Pretend we hit the shutdown blocker.
     69  info("simulating appShutdownConfirmed");
     70  Services.prefs.setBoolPref("toolkit.asyncshutdown.testing", true);
     71  AsyncShutdown.appShutdownConfirmed._trigger();
     72  Services.prefs.clearUserPref("toolkit.asyncshutdown.testing");
     73 
     74  info("waiting for disconnect to complete");
     75  await promiseDisconnected;
     76 
     77  Assert.ok(
     78    !Services.prefs.prefHasUserValue(PREF_LAST_FXA_USER_UID),
     79    "Should have reset different user warning pref"
     80  );
     81  Assert.equal(
     82    Weave.Service.unlock.callCount,
     83    0,
     84    "should not have unlocked at the end"
     85  );
     86  Assert.ok(!Weave.Service.enabled, "Weave should be and remain disabled");
     87  Assert.equal(
     88    Weave.Service.errorHandler.resetFileLog.callCount,
     89    1,
     90    "should have reset the log"
     91  );
     92  Assert.equal(
     93    mockEngine1.wipeClient.callCount,
     94    1,
     95    "enabled engine should have been wiped"
     96  );
     97  Assert.equal(
     98    mockEngine2.wipeClient.callCount,
     99    0,
    100    "disabled engine should not have been wiped"
    101  );
    102  Assert.equal(spyBrowser.callCount, 1, "should not sanitize the browser");
    103  Assert.equal(spySignout.callCount, 1, "should have signed out of FxA");
    104 });