tor-browser

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

test_360seMigrationUtils.js (4582B)


      1 "use strict";
      2 
      3 const { Qihoo360seMigrationUtils } = ChromeUtils.importESModule(
      4  "resource:///modules/360seMigrationUtils.sys.mjs"
      5 );
      6 
      7 const parentPath = do_get_file("AppData/Roaming/360se6/User Data").path;
      8 const loggedInPath = "0f3ab103a522f4463ecacc36d34eb996";
      9 const loggedInBackup = PathUtils.join(
     10  parentPath,
     11  "Default",
     12  loggedInPath,
     13  "DailyBackup",
     14  "360default_ori_2021_12_02.favdb"
     15 );
     16 const loggedOutBackup = PathUtils.join(
     17  parentPath,
     18  "Default",
     19  "DailyBackup",
     20  "360default_ori_2021_12_02.favdb"
     21 );
     22 
     23 function getSqlitePath(profileId) {
     24  return PathUtils.join(parentPath, profileId, loggedInPath, "360sefav.dat");
     25 }
     26 
     27 add_task(async function test_360se10_logged_in() {
     28  const sqlitePath = getSqlitePath("Default");
     29  await IOUtils.setModificationTime(sqlitePath);
     30  await IOUtils.copy(
     31    PathUtils.join(parentPath, "Default", "360Bookmarks"),
     32    PathUtils.join(parentPath, "Default", loggedInPath)
     33  );
     34  await IOUtils.copy(loggedOutBackup, loggedInBackup);
     35 
     36  const alternativeBookmarks =
     37    await Qihoo360seMigrationUtils.getAlternativeBookmarks({
     38      bookmarksPath: PathUtils.join(parentPath, "Default", "Bookmarks"),
     39      localState: {
     40        sync_login_info: {
     41          filepath: loggedInPath,
     42        },
     43      },
     44    });
     45  Assert.ok(
     46    alternativeBookmarks.resource && alternativeBookmarks.resource.exists,
     47    "Should return the legacy bookmark resource."
     48  );
     49  Assert.strictEqual(
     50    alternativeBookmarks.path,
     51    undefined,
     52    "Should not return any path to plain text bookmarks."
     53  );
     54 });
     55 
     56 add_task(async function test_360se10_logged_in_outdated_sqlite() {
     57  const sqlitePath = getSqlitePath("Default");
     58  await IOUtils.setModificationTime(
     59    sqlitePath,
     60    new Date("2020-08-18").valueOf()
     61  );
     62 
     63  const alternativeBookmarks =
     64    await Qihoo360seMigrationUtils.getAlternativeBookmarks({
     65      bookmarksPath: PathUtils.join(parentPath, "Default", "Bookmarks"),
     66      localState: {
     67        sync_login_info: {
     68          filepath: loggedInPath,
     69        },
     70      },
     71    });
     72  Assert.strictEqual(
     73    alternativeBookmarks.resource,
     74    undefined,
     75    "Should not return the outdated legacy bookmark resource."
     76  );
     77  Assert.strictEqual(
     78    alternativeBookmarks.path,
     79    loggedInBackup,
     80    "Should return path to the most recent plain text bookmarks backup."
     81  );
     82 
     83  await IOUtils.setModificationTime(sqlitePath);
     84 });
     85 
     86 add_task(async function test_360se10_logged_out() {
     87  const alternativeBookmarks =
     88    await Qihoo360seMigrationUtils.getAlternativeBookmarks({
     89      bookmarksPath: PathUtils.join(parentPath, "Default", "Bookmarks"),
     90      localState: {
     91        sync_login_info: {
     92          filepath: "",
     93        },
     94      },
     95    });
     96  Assert.strictEqual(
     97    alternativeBookmarks.resource,
     98    undefined,
     99    "Should not return the legacy bookmark resource."
    100  );
    101  Assert.strictEqual(
    102    alternativeBookmarks.path,
    103    loggedOutBackup,
    104    "Should return path to the most recent plain text bookmarks backup."
    105  );
    106 });
    107 
    108 add_task(async function test_360se9_logged_in_outdated_sqlite() {
    109  const sqlitePath = getSqlitePath("Default4SE9Test");
    110  await IOUtils.setModificationTime(
    111    sqlitePath,
    112    new Date("2020-08-18").valueOf()
    113  );
    114 
    115  const alternativeBookmarks =
    116    await Qihoo360seMigrationUtils.getAlternativeBookmarks({
    117      bookmarksPath: PathUtils.join(parentPath, "Default4SE9Test", "Bookmarks"),
    118      localState: {
    119        sync_login_info: {
    120          filepath: loggedInPath,
    121        },
    122      },
    123    });
    124  Assert.strictEqual(
    125    alternativeBookmarks.resource,
    126    undefined,
    127    "Should not return the legacy bookmark resource."
    128  );
    129  Assert.strictEqual(
    130    alternativeBookmarks.path,
    131    PathUtils.join(
    132      parentPath,
    133      "Default4SE9Test",
    134      loggedInPath,
    135      "DailyBackup",
    136      "360sefav_2020_08_28.favdb"
    137    ),
    138    "Should return path to the most recent plain text bookmarks backup."
    139  );
    140 
    141  await IOUtils.setModificationTime(sqlitePath);
    142 });
    143 
    144 add_task(async function test_360se9_logged_out() {
    145  const alternativeBookmarks =
    146    await Qihoo360seMigrationUtils.getAlternativeBookmarks({
    147      bookmarksPath: PathUtils.join(parentPath, "Default4SE9Test", "Bookmarks"),
    148      localState: {
    149        sync_login_info: {
    150          filepath: "",
    151        },
    152      },
    153    });
    154  Assert.strictEqual(
    155    alternativeBookmarks.resource,
    156    undefined,
    157    "Should not return the legacy bookmark resource."
    158  );
    159  Assert.strictEqual(
    160    alternativeBookmarks.path,
    161    PathUtils.join(parentPath, "Default4SE9Test", "Bookmarks"),
    162    "Should return path to the plain text canonical bookmarks."
    163  );
    164 });