test_Edge_registry_migration.js (2882B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const { sinon } = ChromeUtils.importESModule( 7 "resource://testing-common/Sinon.sys.mjs" 8 ); 9 const { EdgeProfileMigrator } = ChromeUtils.importESModule( 10 "resource:///modules/EdgeProfileMigrator.sys.mjs" 11 ); 12 const { MSMigrationUtils } = ChromeUtils.importESModule( 13 "resource:///modules/MSMigrationUtils.sys.mjs" 14 ); 15 16 /** 17 * Tests that history visits loaded from the registry from Edge (EdgeHTML) 18 * that have a visit date older than maxAgeInDays days do not get imported. 19 */ 20 add_task(async function test_Edge_history_past_max_days() { 21 let sandbox = sinon.createSandbox(); 22 registerCleanupFunction(() => { 23 sandbox.restore(); 24 }); 25 26 Assert.less( 27 MigrationUtils.HISTORY_MAX_AGE_IN_DAYS, 28 300, 29 "This test expects the current pref to be less than the youngest expired visit." 30 ); 31 Assert.greater( 32 MigrationUtils.HISTORY_MAX_AGE_IN_DAYS, 33 160, 34 "This test expects the current pref to be greater than the oldest unexpired visit." 35 ); 36 37 const EXPIRED_VISITS = [ 38 ["https://test1.invalid/", dateDaysAgo(500).getTime() * 1000], 39 ["https://test2.invalid/", dateDaysAgo(450).getTime() * 1000], 40 ["https://test3.invalid/", dateDaysAgo(300).getTime() * 1000], 41 ]; 42 43 const UNEXPIRED_VISITS = [ 44 ["https://test4.invalid/"], 45 ["https://test5.invalid/", dateDaysAgo(160).getTime() * 1000], 46 ["https://test6.invalid/", dateDaysAgo(50).getTime() * 1000], 47 ["https://test7.invalid/", dateDaysAgo(0).getTime() * 1000], 48 ]; 49 50 const ALL_VISITS = [...EXPIRED_VISITS, ...UNEXPIRED_VISITS]; 51 52 // Fake out the getResources method of the migrator so that we return 53 // a single fake MigratorResource per availableResourceType. 54 sandbox.stub(MSMigrationUtils, "getTypedURLs").callsFake(() => { 55 return new Map(ALL_VISITS); 56 }); 57 58 // Manually create an EdgeProfileMigrator rather than going through 59 // MigrationUtils.getMigrator to avoid the user data availability check, since 60 // we're mocking out that stuff. 61 let migrator = new EdgeProfileMigrator(); 62 let registryTypedHistoryMigrator = 63 migrator.getHistoryRegistryMigratorForTesting(); 64 await new Promise(resolve => { 65 registryTypedHistoryMigrator.migrate(resolve); 66 }); 67 Assert.ok(true, "History from registry migration done!"); 68 69 for (let expiredEntry of EXPIRED_VISITS) { 70 let entry = await PlacesUtils.history.fetch(expiredEntry[0], { 71 includeVisits: true, 72 }); 73 Assert.equal(entry, null, "Should not have found an entry."); 74 } 75 76 for (let unexpiredEntry of UNEXPIRED_VISITS) { 77 let entry = await PlacesUtils.history.fetch(unexpiredEntry[0], { 78 includeVisits: true, 79 }); 80 Assert.equal(entry.url, unexpiredEntry[0], "Should have the correct URL"); 81 Assert.ok(!!entry.visits.length, "Should have some visits"); 82 } 83 });