Bug 591884 - Make IE importer fallback to the default Links folder to support toolbar favorites in versions >= 7
authorMarco Bonardo <mbonardo@mozilla.com>
Fri, 09 Mar 2012 11:13:14 +0100
changeset 88559 06a1c1a9dd386792a81b6e843c36e720e956dc91
parent 88558 8f4aeb506495c7dab52161886c3385cc3dbaaa30
child 88560 9ba6560332ee7899433f2ec4114885710cf75117
push idunknown
push userunknown
push dateunknown
bugs591884
milestone12.0a2
Bug 591884 - Make IE importer fallback to the default Links folder to support toolbar favorites in versions >= 7 r=felipe a=akeybl
browser/components/migration/Makefile.in
browser/components/migration/src/nsIEProfileMigrator.cpp
browser/components/migration/tests/Makefile.in
browser/components/migration/tests/unit/bookmarks.html
browser/components/migration/tests/unit/head_migration.js
browser/components/migration/tests/unit/test_IE_bookmarks.js
browser/components/migration/tests/unit/xpcshell.ini
browser/makefiles.sh
testing/xpcshell/xpcshell.ini
--- a/browser/components/migration/Makefile.in
+++ b/browser/components/migration/Makefile.in
@@ -38,16 +38,18 @@ DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS		= public src
 
+TEST_DIRS += tests
+
 include $(topsrcdir)/config/rules.mk
 
 # Needed for preprocessor removal of IE Profile Migrator label - bug 236901
 ifeq ($(OS_ARCH),WINNT)
 ifdef GNU_CXX
 DEFINES += -DNO_IE_MIGRATOR=1
 endif
 endif
--- a/browser/components/migration/src/nsIEProfileMigrator.cpp
+++ b/browser/components/migration/src/nsIEProfileMigrator.cpp
@@ -1407,28 +1407,36 @@ nsIEProfileMigrator::CopyFavoritesBatche
     // Initialize the default bookmarks
     nsCOMPtr<nsIFile> profile;
     GetProfilePath(nsnull, profile);
     rv = InitializeBookmarks(profile);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // Locate the Links toolbar folder, we want to replace the Personal Toolbar
     // content with Favorites in this folder.
+    // On versions minor or equal to IE6 the folder name is stored in the
+    // LinksFolderName registry key, but in newer versions it may be just a
+    // Links subfolder inside the default Favorites folder.
     nsCOMPtr<nsIWindowsRegKey> regKey =
       do_CreateInstance("@mozilla.org/windows-registry-key;1");
     if (regKey &&
         NS_SUCCEEDED(regKey->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
                                   REGISTRY_IE_TOOLBAR_KEY,
                                   nsIWindowsRegKey::ACCESS_READ))) {
       nsAutoString linksFolderName;
       if (NS_SUCCEEDED(regKey->ReadStringValue(
                          NS_LITERAL_STRING("LinksFolderName"),
-                         linksFolderName)))
+                         linksFolderName))) {
         personalToolbarFolderName = linksFolderName;
+      }
+      else {
+        personalToolbarFolderName.AssignLiteral("Links");
+      }
     }
+
     folder = bookmarksMenuFolderId;
   }
 
   nsCOMPtr<nsIProperties> fileLocator =
     do_GetService("@mozilla.org/file/directory_service;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIFile> favoritesDirectory;
   (void)fileLocator->Get(NS_WIN_FAVORITES_DIR, NS_GET_IID(nsIFile),
new file mode 100644
--- /dev/null
+++ b/browser/components/migration/tests/Makefile.in
@@ -0,0 +1,15 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+DEPTH		  = ../../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		  = @srcdir@
+relativesrcdir = browser/components/migration/tests
+
+include $(DEPTH)/config/autoconf.mk
+
+XPCSHELL_TESTS = unit
+
+include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/browser/components/migration/tests/unit/bookmarks.html
@@ -0,0 +1,16 @@
+<!DOCTYPE NETSCAPE-Bookmark-file-1>
+<!-- This is an automatically generated file.
+     It will be read and overwritten.
+     DO NOT EDIT! -->
+<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
+<TITLE>Bookmarks</TITLE>
+<H1>Bookmarks Menu</H1>
+
+<DL><p>
+    <DT><A HREF="http://example.com/" ADD_DATE="1233157972" LAST_MODIFIED="1233157984">example</A>
+    <DT><H3 ADD_DATE="1233157910" LAST_MODIFIED="1233157972" PERSONAL_TOOLBAR_FOLDER="true">Bookmarks Toolbar</H3>
+<DD>Add bookmarks to this folder to see them displayed on the Bookmarks Toolbar
+    <DL><p>
+        <DT><A HREF="http://example.com/" ADD_DATE="1233157972" LAST_MODIFIED="1233157984">example</A>
+    </DL><p>
+</DL><p>
new file mode 100644
--- /dev/null
+++ b/browser/components/migration/tests/unit/head_migration.js
@@ -0,0 +1,28 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cu = Components.utils;
+
+const IMIGRATOR = Ci.nsIBrowserProfileMigrator;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
+                                  "resource://gre/modules/PlacesUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
+                                  "resource://gre/modules/FileUtils.jsm");
+
+// Initialize profile.
+let gProfD = do_get_profile();
+
+function newMigratorFor(aKey) {
+  let cid = "@mozilla.org/profile/migrator;1?app=browser&type=" + aKey;
+  return Cc[cid].createInstance(Ci.nsIBrowserProfileMigrator);
+}
+
+let (bookmarkshtml = do_get_file("bookmarks.html")) {
+  bookmarkshtml.copyTo(gProfD, "bookmarks.html");
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/migration/tests/unit/test_IE_bookmarks.js
@@ -0,0 +1,28 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+function run_test() {
+  let migrator = newMigratorFor("ie");
+
+  // Sanity check for the source.
+  do_check_true(migrator.sourceExists);
+
+  // Ensure bookmarks migration is available.
+  let availableSources = migrator.getMigrateData("FieldOfFlowers", false);
+  do_check_true((availableSources & IMIGRATOR.BOOKMARKS) > 0);
+
+  // Needed to enforce bookmarks replacing.
+  let startup = {
+    doStartup: function () {},
+    get directory() do_get_profile()
+  }
+  migrator.migrate(IMIGRATOR.BOOKMARKS, startup, "FieldOfFlowers");
+
+  // Check that at least two bookmark have been added to the menu and the
+  // toolbar.  The first one comes from bookmarks.html, the others from IE.
+  do_check_true(PlacesUtils.bookmarks
+                           .getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 1) > 0);
+  do_check_true(PlacesUtils.bookmarks
+                           .getIdForItemAt(PlacesUtils.toolbarFolderId, 1) > 0);
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/migration/tests/unit/xpcshell.ini
@@ -0,0 +1,6 @@
+[DEFAULT]
+head = head_migration.js
+tail =
+
+[test_IE_bookmarks.js]
+skip-if = os != "win"
--- a/browser/makefiles.sh
+++ b/browser/makefiles.sh
@@ -124,16 +124,17 @@ if [ "$ENABLE_TESTS" ]; then
     browser/components/certerror/test/Makefile
     browser/components/dirprovider/tests/Makefile
     browser/components/preferences/tests/Makefile
     browser/components/search/test/Makefile
     browser/components/sessionstore/test/Makefile
     browser/components/shell/test/Makefile
     browser/components/feeds/test/Makefile
     browser/components/feeds/test/chrome/Makefile
+    browser/components/migration/tests/Makefile
     browser/components/places/tests/Makefile
     browser/components/places/tests/chrome/Makefile
     browser/components/places/tests/browser/Makefile
     browser/components/privatebrowsing/test/Makefile
     browser/components/privatebrowsing/test/browser/Makefile
     browser/components/tabview/test/Makefile
     browser/components/test/Makefile
     browser/devtools/highlighter/test/Makefile
--- a/testing/xpcshell/xpcshell.ini
+++ b/testing/xpcshell/xpcshell.ini
@@ -64,16 +64,17 @@ skip-if = os == "android"
 [include:toolkit/components/url-classifier/tests/unit/xpcshell.ini]
 [include:services/crypto/tests/unit/xpcshell.ini]
 [include:services/crypto/components/tests/unit/xpcshell.ini]
 [include:services/sync/tests/unit/xpcshell.ini]
 # Bug 676978: tests hang on Android 
 skip-if = os == "android"
 [include:browser/components/dirprovider/tests/unit/xpcshell.ini]
 [include:browser/components/feeds/test/unit/xpcshell.ini]
+[include:browser/components/migration/tests/unit/xpcshell.ini]
 [include:browser/components/places/tests/unit/xpcshell.ini]
 [include:browser/components/privatebrowsing/test/unit/xpcshell.ini]
 [include:browser/components/shell/test/unit/xpcshell.ini]
 [include:extensions/spellcheck/hunspell/tests/unit/xpcshell.ini]
 [include:toolkit/components/search/tests/xpcshell/xpcshell.ini]
 [include:toolkit/mozapps/shared/test/unit/xpcshell.ini]
 [include:services/crypto/component/tests/unit/xpcshell.ini]
 [include:layout/tools/layout-debug/tests/unit/xpcshell.ini]