summaryrefslogtreecommitdiffstats
path: root/browser/components/migration/tests/unit/test_360seMigrationUtils.js
blob: 3a882b516d2a3b43372e4dd9da9e71897aa3c389 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
"use strict";

const { Qihoo360seMigrationUtils } = ChromeUtils.importESModule(
  "resource:///modules/360seMigrationUtils.sys.mjs"
);

const parentPath = do_get_file("AppData/Roaming/360se6/User Data").path;
const loggedInPath = "0f3ab103a522f4463ecacc36d34eb996";
const loggedInBackup = PathUtils.join(
  parentPath,
  "Default",
  loggedInPath,
  "DailyBackup",
  "360default_ori_2021_12_02.favdb"
);
const loggedOutBackup = PathUtils.join(
  parentPath,
  "Default",
  "DailyBackup",
  "360default_ori_2021_12_02.favdb"
);

function getSqlitePath(profileId) {
  return PathUtils.join(parentPath, profileId, loggedInPath, "360sefav.dat");
}

add_task(async function test_360se10_logged_in() {
  const sqlitePath = getSqlitePath("Default");
  await IOUtils.setModificationTime(sqlitePath);
  await IOUtils.copy(
    PathUtils.join(parentPath, "Default", "360Bookmarks"),
    PathUtils.join(parentPath, "Default", loggedInPath)
  );
  await IOUtils.copy(loggedOutBackup, loggedInBackup);

  const alternativeBookmarks =
    await Qihoo360seMigrationUtils.getAlternativeBookmarks({
      bookmarksPath: PathUtils.join(parentPath, "Default", "Bookmarks"),
      localState: {
        sync_login_info: {
          filepath: loggedInPath,
        },
      },
    });
  Assert.ok(
    alternativeBookmarks.resource && alternativeBookmarks.resource.exists,
    "Should return the legacy bookmark resource."
  );
  Assert.strictEqual(
    alternativeBookmarks.path,
    undefined,
    "Should not return any path to plain text bookmarks."
  );
});

add_task(async function test_360se10_logged_in_outdated_sqlite() {
  const sqlitePath = getSqlitePath("Default");
  await IOUtils.setModificationTime(
    sqlitePath,
    new Date("2020-08-18").valueOf()
  );

  const alternativeBookmarks =
    await Qihoo360seMigrationUtils.getAlternativeBookmarks({
      bookmarksPath: PathUtils.join(parentPath, "Default", "Bookmarks"),
      localState: {
        sync_login_info: {
          filepath: loggedInPath,
        },
      },
    });
  Assert.strictEqual(
    alternativeBookmarks.resource,
    undefined,
    "Should not return the outdated legacy bookmark resource."
  );
  Assert.strictEqual(
    alternativeBookmarks.path,
    loggedInBackup,
    "Should return path to the most recent plain text bookmarks backup."
  );

  await IOUtils.setModificationTime(sqlitePath);
});

add_task(async function test_360se10_logged_out() {
  const alternativeBookmarks =
    await Qihoo360seMigrationUtils.getAlternativeBookmarks({
      bookmarksPath: PathUtils.join(parentPath, "Default", "Bookmarks"),
      localState: {
        sync_login_info: {
          filepath: "",
        },
      },
    });
  Assert.strictEqual(
    alternativeBookmarks.resource,
    undefined,
    "Should not return the legacy bookmark resource."
  );
  Assert.strictEqual(
    alternativeBookmarks.path,
    loggedOutBackup,
    "Should return path to the most recent plain text bookmarks backup."
  );
});

add_task(async function test_360se9_logged_in_outdated_sqlite() {
  const sqlitePath = getSqlitePath("Default4SE9Test");
  await IOUtils.setModificationTime(
    sqlitePath,
    new Date("2020-08-18").valueOf()
  );

  const alternativeBookmarks =
    await Qihoo360seMigrationUtils.getAlternativeBookmarks({
      bookmarksPath: PathUtils.join(parentPath, "Default4SE9Test", "Bookmarks"),
      localState: {
        sync_login_info: {
          filepath: loggedInPath,
        },
      },
    });
  Assert.strictEqual(
    alternativeBookmarks.resource,
    undefined,
    "Should not return the legacy bookmark resource."
  );
  Assert.strictEqual(
    alternativeBookmarks.path,
    PathUtils.join(
      parentPath,
      "Default4SE9Test",
      loggedInPath,
      "DailyBackup",
      "360sefav_2020_08_28.favdb"
    ),
    "Should return path to the most recent plain text bookmarks backup."
  );

  await IOUtils.setModificationTime(sqlitePath);
});

add_task(async function test_360se9_logged_out() {
  const alternativeBookmarks =
    await Qihoo360seMigrationUtils.getAlternativeBookmarks({
      bookmarksPath: PathUtils.join(parentPath, "Default4SE9Test", "Bookmarks"),
      localState: {
        sync_login_info: {
          filepath: "",
        },
      },
    });
  Assert.strictEqual(
    alternativeBookmarks.resource,
    undefined,
    "Should not return the legacy bookmark resource."
  );
  Assert.strictEqual(
    alternativeBookmarks.path,
    PathUtils.join(parentPath, "Default4SE9Test", "Bookmarks"),
    "Should return path to the plain text canonical bookmarks."
  );
});