From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../tests/browser/browser_do_migration.js | 195 +++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 browser/components/migration/tests/browser/browser_do_migration.js (limited to 'browser/components/migration/tests/browser/browser_do_migration.js') diff --git a/browser/components/migration/tests/browser/browser_do_migration.js b/browser/components/migration/tests/browser/browser_do_migration.js new file mode 100644 index 0000000000..b1a5e9ad60 --- /dev/null +++ b/browser/components/migration/tests/browser/browser_do_migration.js @@ -0,0 +1,195 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * Tests that the MigrationWizard can be used to successfully migrate + * using the InternalTestingProfileMigrator in a few scenarios. + */ +add_task(async function test_successful_migrations() { + // Scenario 1: A single resource type is available. + let migration = waitForTestMigration( + [MigrationUtils.resourceTypes.BOOKMARKS], + [MigrationUtils.resourceTypes.BOOKMARKS], + InternalTestingProfileMigrator.testProfile + ); + + await withMigrationWizardDialog(async prefsWin => { + let dialogBody = prefsWin.document.body; + let wizard = dialogBody.querySelector("migration-wizard"); + let shadow = wizard.openOrClosedShadowRoot; + let selector = shadow.querySelector("#browser-profile-selector"); + + await new Promise(resolve => prefsWin.requestAnimationFrame(resolve)); + Assert.equal(shadow.activeElement, selector, "Selector should be focused."); + + let wizardDone = BrowserTestUtils.waitForEvent( + wizard, + "MigrationWizard:DoneMigration" + ); + selectResourceTypesAndStartMigration(wizard, [ + MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.BOOKMARKS, + ]); + await migration; + await wizardDone; + + let dialog = prefsWin.document.querySelector("#migrationWizardDialog"); + let doneButton = shadow.querySelector( + "div[name='page-progress'] .done-button" + ); + + await new Promise(resolve => prefsWin.requestAnimationFrame(resolve)); + Assert.equal( + shadow.activeElement, + doneButton, + "Done button should be focused." + ); + + let dialogClosed = BrowserTestUtils.waitForEvent(dialog, "close"); + doneButton.click(); + await dialogClosed; + assertQuantitiesShown(wizard, [ + MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.BOOKMARKS, + ]); + }); + + // Scenario 2: Several resource types are available, but only 1 + // is checked / expected. + migration = waitForTestMigration( + [ + MigrationUtils.resourceTypes.BOOKMARKS, + MigrationUtils.resourceTypes.PASSWORDS, + ], + [MigrationUtils.resourceTypes.PASSWORDS], + InternalTestingProfileMigrator.testProfile + ); + + await withMigrationWizardDialog(async prefsWin => { + let dialogBody = prefsWin.document.body; + let wizard = dialogBody.querySelector("migration-wizard"); + let shadow = wizard.openOrClosedShadowRoot; + let selector = shadow.querySelector("#browser-profile-selector"); + + await new Promise(resolve => prefsWin.requestAnimationFrame(resolve)); + Assert.equal(shadow.activeElement, selector, "Selector should be focused."); + + let wizardDone = BrowserTestUtils.waitForEvent( + wizard, + "MigrationWizard:DoneMigration" + ); + selectResourceTypesAndStartMigration(wizard, [ + MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.PASSWORDS, + ]); + await migration; + await wizardDone; + + let dialog = prefsWin.document.querySelector("#migrationWizardDialog"); + let doneButton = shadow.querySelector( + "div[name='page-progress'] .done-button" + ); + + await new Promise(resolve => prefsWin.requestAnimationFrame(resolve)); + Assert.equal( + shadow.activeElement, + doneButton, + "Done button should be focused." + ); + + let dialogClosed = BrowserTestUtils.waitForEvent(dialog, "close"); + doneButton.click(); + await dialogClosed; + assertQuantitiesShown(wizard, [ + MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.PASSWORDS, + ]); + }); + + // Scenario 3: Several resource types are available, all are checked. + let allResourceTypeStrs = Object.values( + MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES + ); + let allResourceTypes = allResourceTypeStrs.map(resourceTypeStr => { + return MigrationUtils.resourceTypes[resourceTypeStr]; + }); + + migration = waitForTestMigration( + allResourceTypes, + allResourceTypes, + InternalTestingProfileMigrator.testProfile + ); + + await withMigrationWizardDialog(async prefsWin => { + let dialogBody = prefsWin.document.body; + let wizard = dialogBody.querySelector("migration-wizard"); + let shadow = wizard.openOrClosedShadowRoot; + let selector = shadow.querySelector("#browser-profile-selector"); + + await new Promise(resolve => prefsWin.requestAnimationFrame(resolve)); + Assert.equal(shadow.activeElement, selector, "Selector should be focused."); + + let wizardDone = BrowserTestUtils.waitForEvent( + wizard, + "MigrationWizard:DoneMigration" + ); + selectResourceTypesAndStartMigration(wizard, allResourceTypeStrs); + await migration; + await wizardDone; + assertQuantitiesShown(wizard, allResourceTypeStrs); + }); +}); + +/** + * Tests that if somehow the Migration Wizard requests to import a + * resource type that the migrator doesn't have the ability to import, + * that it's ignored and the migration completes normally. + */ +add_task(async function test_invalid_resource_type() { + let migration = waitForTestMigration( + [MigrationUtils.resourceTypes.BOOKMARKS], + [MigrationUtils.resourceTypes.BOOKMARKS], + InternalTestingProfileMigrator.testProfile + ); + + await withMigrationWizardDialog(async prefsWin => { + let dialogBody = prefsWin.document.body; + let wizard = dialogBody.querySelector("migration-wizard"); + let wizardDone = BrowserTestUtils.waitForEvent( + wizard, + "MigrationWizard:DoneMigration" + ); + + // The Migration Wizard _shouldn't_ display anything except BOOKMARKS, + // since that's the only resource type that the selected migrator is + // supposed to currently support, but we'll check the other checkboxes + // even though they're hidden just to see what happens. + selectResourceTypesAndStartMigration(wizard, [ + MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.BOOKMARKS, + MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.PASSWORDS, + MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.HISTORY, + MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.FORMDATA, + ]); + await migration; + await wizardDone; + + let dialog = prefsWin.document.querySelector("#migrationWizardDialog"); + let shadow = wizard.openOrClosedShadowRoot; + let doneButton = shadow.querySelector( + "div[name='page-progress'] .done-button" + ); + + await new Promise(resolve => prefsWin.requestAnimationFrame(resolve)); + Assert.equal( + shadow.activeElement, + doneButton, + "Done button should be focused." + ); + + assertQuantitiesShown(wizard, [ + MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.BOOKMARKS, + ]); + + let dialogClosed = BrowserTestUtils.waitForEvent(dialog, "close"); + doneButton.click(); + await dialogClosed; + }); +}); -- cgit v1.2.3