tor-browser

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

test_browserGlue_migration_osauth.js (3239B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const TOPIC_BROWSERGLUE_TEST = "browser-glue-test";
      7 const TOPICDATA_BROWSERGLUE_TEST = "force-ui-migration";
      8 const gBrowserGlue = Cc["@mozilla.org/browser/browserglue;1"].getService(
      9  Ci.nsIObserver
     10 );
     11 const UI_VERSION = 157;
     12 const NIGHTLY_ONLY_DATA_MIGRATION = 158;
     13 
     14 const { LoginHelper } = ChromeUtils.importESModule(
     15  "resource://gre/modules/LoginHelper.sys.mjs"
     16 );
     17 const { FormAutofillUtils } = ChromeUtils.importESModule(
     18  "resource://gre/modules/shared/FormAutofillUtils.sys.mjs"
     19 );
     20 
     21 const CC_OLD_PREF = "extensions.formautofill.creditCards.reauth.optout";
     22 const CC_NEW_PREF = FormAutofillUtils.AUTOFILL_CREDITCARDS_OS_AUTH_LOCKED_PREF;
     23 
     24 const PASSWORDS_OLD_PREF = "signon.management.page.os-auth.optout";
     25 const PASSWORDS_NEW_PREF = LoginHelper.OS_AUTH_FOR_PASSWORDS_BOOL_PREF;
     26 
     27 function clearPrefs() {
     28  Services.prefs.clearUserPref("browser.migration.version");
     29  Services.prefs.clearUserPref(CC_OLD_PREF);
     30  Services.prefs.clearUserPref(CC_NEW_PREF);
     31  Services.prefs.clearUserPref(PASSWORDS_OLD_PREF);
     32  Services.prefs.clearUserPref(PASSWORDS_NEW_PREF);
     33  Services.prefs.clearUserPref("browser.startup.homepage_override.mstone");
     34 }
     35 
     36 function simulateUIMigration() {
     37  gBrowserGlue.observe(
     38    null,
     39    TOPIC_BROWSERGLUE_TEST,
     40    TOPICDATA_BROWSERGLUE_TEST
     41  );
     42 }
     43 
     44 add_task(async function setup() {
     45  registerCleanupFunction(clearPrefs);
     46 });
     47 
     48 add_task(async function test_pref_migration_old_pref_os_auth_disabled() {
     49  Services.prefs.setIntPref("browser.migration.version", UI_VERSION - 1);
     50  Services.prefs.setStringPref(CC_OLD_PREF, "off");
     51  Services.prefs.setStringPref(PASSWORDS_OLD_PREF, "off");
     52 
     53  simulateUIMigration();
     54 
     55  Assert.ok(
     56    !FormAutofillUtils.getOSAuthEnabled(),
     57    "OS Auth should be disabled for credit cards since it was disabled before migration."
     58  );
     59  Assert.ok(
     60    !LoginHelper.getOSAuthEnabled(),
     61    "OS Auth should be disabled for passwords since it was disabled before migration."
     62  );
     63  clearPrefs();
     64 });
     65 
     66 add_task(async function test_pref_migration_old_pref_os_auth_enabled() {
     67  Services.prefs.setIntPref("browser.migration.version", UI_VERSION - 1);
     68  Services.prefs.setStringPref(CC_OLD_PREF, "");
     69  Services.prefs.setStringPref(PASSWORDS_OLD_PREF, "");
     70 
     71  simulateUIMigration();
     72 
     73  Assert.ok(
     74    FormAutofillUtils.getOSAuthEnabled(),
     75    "OS Auth should be enabled for credit cards since it was enabled before migration."
     76  );
     77  Assert.ok(
     78    LoginHelper.getOSAuthEnabled(),
     79    "OS Auth should be enabled for passwords since it was enabled before migration."
     80  );
     81  clearPrefs();
     82 });
     83 
     84 add_task(async function test_pref_migration_real_pref_os_auth_disabled() {
     85  Services.prefs.setIntPref(
     86    "browser.migration.version",
     87    NIGHTLY_ONLY_DATA_MIGRATION
     88  );
     89  Services.prefs.setCharPref(
     90    "browser.startup.homepage_override.mstone",
     91    "127.0"
     92  );
     93 
     94  simulateUIMigration();
     95 
     96  Assert.ok(
     97    !FormAutofillUtils.getOSAuthEnabled(),
     98    "OS Auth should be disabled for credit cards."
     99  );
    100  Assert.ok(
    101    !LoginHelper.getOSAuthEnabled(),
    102    "OS Auth should be disabled for passwords since it was disabled before migration."
    103  );
    104  clearPrefs();
    105 });