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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { sinon } = ChromeUtils.importESModule(
"resource://testing-common/Sinon.sys.mjs"
);
const { EdgeProfileMigrator } = ChromeUtils.importESModule(
"resource:///modules/EdgeProfileMigrator.sys.mjs"
);
const { MSMigrationUtils } = ChromeUtils.importESModule(
"resource:///modules/MSMigrationUtils.sys.mjs"
);
/**
* Tests that history visits loaded from the registry from Edge (EdgeHTML)
* that have a visit date older than maxAgeInDays days do not get imported.
*/
add_task(async function test_Edge_history_past_max_days() {
let sandbox = sinon.createSandbox();
registerCleanupFunction(() => {
sandbox.restore();
});
Assert.ok(
MigrationUtils.HISTORY_MAX_AGE_IN_DAYS < 300,
"This test expects the current pref to be less than the youngest expired visit."
);
Assert.ok(
MigrationUtils.HISTORY_MAX_AGE_IN_DAYS > 160,
"This test expects the current pref to be greater than the oldest unexpired visit."
);
const EXPIRED_VISITS = [
["https://test1.invalid/", dateDaysAgo(500).getTime() * 1000],
["https://test2.invalid/", dateDaysAgo(450).getTime() * 1000],
["https://test3.invalid/", dateDaysAgo(300).getTime() * 1000],
];
const UNEXPIRED_VISITS = [
["https://test4.invalid/"],
["https://test5.invalid/", dateDaysAgo(160).getTime() * 1000],
["https://test6.invalid/", dateDaysAgo(50).getTime() * 1000],
["https://test7.invalid/", dateDaysAgo(0).getTime() * 1000],
];
const ALL_VISITS = [...EXPIRED_VISITS, ...UNEXPIRED_VISITS];
// Fake out the getResources method of the migrator so that we return
// a single fake MigratorResource per availableResourceType.
sandbox.stub(MSMigrationUtils, "getTypedURLs").callsFake(() => {
return new Map(ALL_VISITS);
});
// Manually create an EdgeProfileMigrator rather than going through
// MigrationUtils.getMigrator to avoid the user data availability check, since
// we're mocking out that stuff.
let migrator = new EdgeProfileMigrator();
let registryTypedHistoryMigrator =
migrator.getHistoryRegistryMigratorForTesting();
await new Promise(resolve => {
registryTypedHistoryMigrator.migrate(resolve);
});
Assert.ok(true, "History from registry migration done!");
for (let expiredEntry of EXPIRED_VISITS) {
let entry = await PlacesUtils.history.fetch(expiredEntry[0], {
includeVisits: true,
});
Assert.equal(entry, null, "Should not have found an entry.");
}
for (let unexpiredEntry of UNEXPIRED_VISITS) {
let entry = await PlacesUtils.history.fetch(unexpiredEntry[0], {
includeVisits: true,
});
Assert.equal(entry.url, unexpiredEntry[0], "Should have the correct URL");
Assert.ok(!!entry.visits.length, "Should have some visits");
}
});
|