Bug 801450 - Can't import bookmarks from Safari-created HTML files. r=mak
authorVirgil Dupras <hsoft@hardcoded.net>
Mon, 03 Dec 2012 20:26:15 -0500
changeset 114862 eb2757708863
parent 114861 82982ebe08cd
child 114863 10a3208b7a9d
push id23947
push useremorley@mozilla.com
push dateTue, 04 Dec 2012 14:54:11 +0000
treeherdermozilla-central@0035f77045bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs801450
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 801450 - Can't import bookmarks from Safari-created HTML files. r=mak
toolkit/components/places/BookmarkHTMLUtils.jsm
toolkit/components/places/tests/unit/bookmarks_html_singleframe.html
toolkit/components/places/tests/unit/test_bookmarks_html_singleframe.js
toolkit/components/places/tests/unit/xpcshell.ini
--- a/toolkit/components/places/BookmarkHTMLUtils.jsm
+++ b/toolkit/components/places/BookmarkHTMLUtils.jsm
@@ -249,17 +249,20 @@ BookmarkImporter.prototype = {
     //   <h3>FOO</h3>
     //   <h3>BAR</h3>
     //   <dl>...content 1...</dl>
     //   <dl>...content 2...</dl>
     // we'll pop the stack when we find the h3 for BAR, treating that as an
     // implicit ending of the FOO container. The output will be FOO and BAR as
     // siblings. If there's another <dl> following (as in "content 2"), those
     // items will be treated as further siblings of FOO and BAR
-    if (frame.containerNesting == 0) {
+    // This special frame popping business, of course, only happens when our
+    // frame array has more than one element so we can avoid situations where
+    // we don't have a frame to parse into anymore.
+    if (frame.containerNesting == 0 && this._frames.length > 1) {
       this._frames.pop();
     }
 
     // We have to check for some attributes to see if this is a "special"
     // folder, which will have different creation rules when the end tag is
     // processed.
     if (aElt.hasAttribute("personal_toolbar_folder")) {
       if (this._isImportDefaults) {
new file mode 100644
--- /dev/null
+++ b/toolkit/components/places/tests/unit/bookmarks_html_singleframe.html
@@ -0,0 +1,10 @@
+<!DOCTYPE NETSCAPE-Bookmark-file-1>
+	<HTML>
+	<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
+	<Title>Bookmarks</Title>
+	<H1>Bookmarks</H1>
+    <DT><H3>Subtitle</H3>
+	<DL><p>
+		<DT><A HREF="http://www.mozilla.org/">Mozilla</A>
+    </DL><p>
+</HTML>
new file mode 100644
--- /dev/null
+++ b/toolkit/components/places/tests/unit/test_bookmarks_html_singleframe.js
@@ -0,0 +1,31 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* 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/. */
+
+// Test for bug #801450
+
+// Get Services
+Cu.import("resource://gre/modules/BookmarkHTMLUtils.jsm");
+
+function run_test() {
+  do_test_pending();
+  let bookmarksFile = do_get_file("bookmarks_html_singleframe.html");
+  BookmarkHTMLUtils.importFromFile(bookmarksFile, true, after_import);
+}
+
+function after_import(success) {
+  do_check_true(success);
+  let root = PlacesUtils.getFolderContents(PlacesUtils.bookmarksMenuFolderId).root;
+  do_check_eq(root.childCount, 1);
+  let folder = root.getChild(0);
+  PlacesUtils.asContainer(folder).containerOpen = true;
+  do_check_eq(folder.title, "Subtitle");
+  do_check_eq(folder.childCount, 1);
+  let bookmark = folder.getChild(0);
+  do_check_eq(bookmark.uri, "http://www.mozilla.org/");
+  do_check_eq(bookmark.title, "Mozilla");
+  folder.containerOpen = false;
+  do_test_finished();
+}
\ No newline at end of file
--- a/toolkit/components/places/tests/unit/xpcshell.ini
+++ b/toolkit/components/places/tests/unit/xpcshell.ini
@@ -53,16 +53,17 @@ skip-if = os == "android"
 [test_asyncExecuteLegacyQueries.js]
 # Bug 676989: test hangs consistently on Android
 skip-if = os == "android"
 [test_async_history_api.js]
 [test_autocomplete_stopSearch_no_throw.js]
 [test_bookmark_catobs.js]
 [test_bookmarks_html.js]
 [test_bookmarks_html_corrupt.js]
+[test_bookmarks_html_singleframe.js]
 [test_bookmarks_restore_notification.js]
 [test_bookmarks_setNullTitle.js]
 [test_broken_folderShortcut_result.js]
 [test_browserhistory.js]
 [test_bug636917_isLivemark.js]
 [test_childlessTags.js]
 [test_crash_476292.js]
 [test_database_replaceOnStartup.js]