1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/migration/tests/unit/test_IE_bookmarks.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +function run_test() { 1.9 + do_test_pending(); 1.10 + 1.11 + let migrator = MigrationUtils.getMigrator("ie"); 1.12 + 1.13 + // Sanity check for the source. 1.14 + do_check_true(migrator.sourceExists); 1.15 + 1.16 + // Ensure bookmarks migration is available. 1.17 + let availableSources = migrator.getMigrateData("FieldOfFlowers", false); 1.18 + do_check_true((availableSources & MigrationUtils.resourceTypes.BOOKMARKS) > 0); 1.19 + 1.20 + // Wait for the imported bookmarks. Check that "From Internet Explorer" 1.21 + // folders are created in the menu and on the toolbar. 1.22 + let source = MigrationUtils.getLocalizedString("sourceNameIE"); 1.23 + let label = MigrationUtils.getLocalizedString("importedBookmarksFolder", [source]); 1.24 + 1.25 + let expectedParents = [ PlacesUtils.bookmarksMenuFolderId, 1.26 + PlacesUtils.toolbarFolderId ]; 1.27 + 1.28 + PlacesUtils.bookmarks.addObserver({ 1.29 + onItemAdded: function onItemAdded(aItemId, aParentId, aIndex, aItemType, 1.30 + aURI, aTitle) { 1.31 + if (aTitle == label) { 1.32 + let index = expectedParents.indexOf(aParentId); 1.33 + do_check_neq(index, -1); 1.34 + expectedParents.splice(index, 1); 1.35 + if (expectedParents.length == 0) 1.36 + PlacesUtils.bookmarks.removeObserver(this); 1.37 + } 1.38 + }, 1.39 + onBeginUpdateBatch: function () {}, 1.40 + onEndUpdateBatch: function () {}, 1.41 + onItemRemoved: function () {}, 1.42 + onItemChanged: function () {}, 1.43 + onItemVisited: function () {}, 1.44 + onItemMoved: function () {}, 1.45 + }, false); 1.46 + 1.47 + // Wait for migration. 1.48 + Services.obs.addObserver(function onMigrationEnded() { 1.49 + Services.obs.removeObserver(onMigrationEnded, "Migration:Ended"); 1.50 + 1.51 + // Check the bookmarks have been imported to all the expected parents. 1.52 + do_check_eq(expectedParents.length, 0); 1.53 + 1.54 + do_test_finished(); 1.55 + }, "Migration:Ended", false); 1.56 + 1.57 + migrator.migrate(MigrationUtils.resourceTypes.BOOKMARKS, null, 1.58 + "FieldOfFlowers"); 1.59 +}