diff options
Diffstat (limited to 'browser/components/places/tests/unit')
19 files changed, 0 insertions, 2261 deletions
diff --git a/browser/components/places/tests/unit/bookmarks.glue.html b/browser/components/places/tests/unit/bookmarks.glue.html deleted file mode 100644 index 07b22e9b3..000000000 --- a/browser/components/places/tests/unit/bookmarks.glue.html +++ /dev/null @@ -1,16 +0,0 @@ -<!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> diff --git a/browser/components/places/tests/unit/bookmarks.glue.json b/browser/components/places/tests/unit/bookmarks.glue.json deleted file mode 100644 index 7f639e462..000000000 --- a/browser/components/places/tests/unit/bookmarks.glue.json +++ /dev/null @@ -1 +0,0 @@ -{"title":"","id":1,"dateAdded":1233157910552624,"lastModified":1233157955206833,"type":"text/x-moz-place-container","root":"placesRoot","children":[{"title":"Bookmarks Menu","id":2,"parent":1,"dateAdded":1233157910552624,"lastModified":1233157993171424,"type":"text/x-moz-place-container","root":"bookmarksMenuFolder","children":[{"title":"examplejson","id":27,"parent":2,"dateAdded":1233157972101126,"lastModified":1233157984999673,"type":"text/x-moz-place","uri":"http://example.com/"}]},{"index":1,"title":"Bookmarks Toolbar","id":3,"parent":1,"dateAdded":1233157910552624,"lastModified":1233157972101126,"annos":[{"name":"bookmarkProperties/description","flags":0,"expires":4,"mimeType":null,"type":3,"value":"Add bookmarks to this folder to see them displayed on the Bookmarks Toolbar"}],"type":"text/x-moz-place-container","root":"toolbarFolder","children":[{"title":"examplejson","id":26,"parent":3,"dateAdded":1233157972101126,"lastModified":1233157984999673,"type":"text/x-moz-place","uri":"http://example.com/"}]},{"index":2,"title":"Tags","id":4,"parent":1,"dateAdded":1233157910552624,"lastModified":1233157910582667,"type":"text/x-moz-place-container","root":"tagsFolder","children":[]},{"index":3,"title":"Unsorted Bookmarks","id":5,"parent":1,"dateAdded":1233157910552624,"lastModified":1233157911033315,"type":"text/x-moz-place-container","root":"unfiledBookmarksFolder","children":[]}]} diff --git a/browser/components/places/tests/unit/corruptDB.sqlite b/browser/components/places/tests/unit/corruptDB.sqlite Binary files differdeleted file mode 100644 index b234246ca..000000000 --- a/browser/components/places/tests/unit/corruptDB.sqlite +++ /dev/null diff --git a/browser/components/places/tests/unit/distribution.ini b/browser/components/places/tests/unit/distribution.ini deleted file mode 100644 index f94a1be3c..000000000 --- a/browser/components/places/tests/unit/distribution.ini +++ /dev/null @@ -1,21 +0,0 @@ -# Distribution Configuration File -# Bug 516444 demo - -[Global] -id=516444 -version=1.0 -about=Test distribution file - -[BookmarksToolbar] -item.1.title=Toolbar Link Before -item.1.link=http://mozilla.com/ -item.2.type=default -item.3.title=Toolbar Link After -item.3.link=http://mozilla.com/ - -[BookmarksMenu] -item.1.title=Menu Link Before -item.1.link=http://mozilla.com/ -item.2.type=default -item.3.title=Menu Link After -item.3.link=http://mozilla.com/
\ No newline at end of file diff --git a/browser/components/places/tests/unit/head_bookmarks.js b/browser/components/places/tests/unit/head_bookmarks.js deleted file mode 100644 index cbe5aa775..000000000 --- a/browser/components/places/tests/unit/head_bookmarks.js +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* 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 Ci = Components.interfaces; -const Cc = Components.classes; -const Cr = Components.results; -const Cu = Components.utils; - -Cu.import("resource://gre/modules/Services.jsm"); - -// Import common head. -let (commonFile = do_get_file("../../../../../toolkit/components/places/tests/head_common.js", false)) { - let uri = Services.io.newFileURI(commonFile); - Services.scriptloader.loadSubScript(uri.spec, this); -} - -// Put any other stuff relative to this test folder below. - - -XPCOMUtils.defineLazyGetter(this, "PlacesUIUtils", function() { - Cu.import("resource:///modules/PlacesUIUtils.jsm"); - return PlacesUIUtils; -}); - - -const ORGANIZER_FOLDER_ANNO = "PlacesOrganizer/OrganizerFolder"; -const ORGANIZER_QUERY_ANNO = "PlacesOrganizer/OrganizerQuery"; - - -// Needed by some test that relies on having an app registered. -let (XULAppInfo = { - vendor: "Mozilla", - name: "PlacesTest", - ID: "{230de50e-4cd1-11dc-8314-0800200c9a66}", - version: "1", - appBuildID: "2007010101", - platformVersion: "", - platformBuildID: "2007010101", - inSafeMode: false, - logConsoleErrors: true, - OS: "XPCShell", - XPCOMABI: "noarch-spidermonkey", - - QueryInterface: XPCOMUtils.generateQI([ - Ci.nsIXULAppInfo, - Ci.nsIXULRuntime, - ]) -}) { - let XULAppInfoFactory = { - createInstance: function (outer, iid) { - if (outer != null) - throw Cr.NS_ERROR_NO_AGGREGATION; - return XULAppInfo.QueryInterface(iid); - } - }; - let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); - registrar.registerFactory(Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}"), - "XULAppInfo", "@mozilla.org/xre/app-info;1", - XULAppInfoFactory); -} - -// Smart bookmarks constants. -const SMART_BOOKMARKS_VERSION = 4; -const SMART_BOOKMARKS_ON_TOOLBAR = 1; -const SMART_BOOKMARKS_ON_MENU = 3; // Takes in count the additional separator. - -// Default bookmarks constants. -const DEFAULT_BOOKMARKS_ON_TOOLBAR = 1; -const DEFAULT_BOOKMARKS_ON_MENU = 1; diff --git a/browser/components/places/tests/unit/test_421483.js b/browser/components/places/tests/unit/test_421483.js deleted file mode 100644 index 46eb5dc55..000000000 --- a/browser/components/places/tests/unit/test_421483.js +++ /dev/null @@ -1,94 +0,0 @@ -/* -*- 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/. */ - -// Get bookmarks service -try { - var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); -} catch(ex) { - do_throw("Could not get Bookmarks service\n"); -} - -// Get annotation service -try { - var annosvc = Cc["@mozilla.org/browser/annotation-service;1"]. - getService(Ci.nsIAnnotationService); -} catch(ex) { - do_throw("Could not get Annotation service\n"); -} - -// Get browser glue -try { - var gluesvc = Cc["@mozilla.org/browser/browserglue;1"]. - getService(Ci.nsIBrowserGlue). - QueryInterface(Ci.nsIObserver); - // Avoid default bookmarks import. - gluesvc.observe(null, "initial-migration-will-import-default-bookmarks", ""); -// gluesvc.observe(null, "initial-migration-did-import-default-bookmarks", ""); -} catch(ex) { - do_throw("Could not get BrowserGlue service\n"); -} - -// Get pref service -try { - var pref = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefBranch); -} catch(ex) { - do_throw("Could not get Preferences service\n"); -} - -const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark"; -const SMART_BOOKMARKS_PREF = "browser.places.smartBookmarksVersion"; - -// main -function run_test() { - // TEST 1: smart bookmarks disabled - pref.setIntPref("browser.places.smartBookmarksVersion", -1); - gluesvc.ensurePlacesDefaultQueriesInitialized(); - var smartBookmarkItemIds = annosvc.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); - do_check_eq(smartBookmarkItemIds.length, 0); - // check that pref has not been bumped up - do_check_eq(pref.getIntPref("browser.places.smartBookmarksVersion"), -1); - - // TEST 2: create smart bookmarks - pref.setIntPref("browser.places.smartBookmarksVersion", 0); - gluesvc.ensurePlacesDefaultQueriesInitialized(); - smartBookmarkItemIds = annosvc.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); - do_check_neq(smartBookmarkItemIds.length, 0); - // check that pref has been bumped up - do_check_true(pref.getIntPref("browser.places.smartBookmarksVersion") > 0); - - var smartBookmarksCount = smartBookmarkItemIds.length; - - // TEST 3: smart bookmarks restore - // remove one smart bookmark and restore - bmsvc.removeItem(smartBookmarkItemIds[0]); - pref.setIntPref("browser.places.smartBookmarksVersion", 0); - gluesvc.ensurePlacesDefaultQueriesInitialized(); - smartBookmarkItemIds = annosvc.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); - do_check_eq(smartBookmarkItemIds.length, smartBookmarksCount); - // check that pref has been bumped up - do_check_true(pref.getIntPref("browser.places.smartBookmarksVersion") > 0); - - // TEST 4: move a smart bookmark, change its title, then restore - // smart bookmark should be restored in place - var parent = bmsvc.getFolderIdForItem(smartBookmarkItemIds[0]); - var oldTitle = bmsvc.getItemTitle(smartBookmarkItemIds[0]); - // create a subfolder and move inside it - var newParent = bmsvc.createFolder(parent, "test", bmsvc.DEFAULT_INDEX); - bmsvc.moveItem(smartBookmarkItemIds[0], newParent, bmsvc.DEFAULT_INDEX); - // change title - bmsvc.setItemTitle(smartBookmarkItemIds[0], "new title"); - // restore - pref.setIntPref("browser.places.smartBookmarksVersion", 0); - gluesvc.ensurePlacesDefaultQueriesInitialized(); - smartBookmarkItemIds = annosvc.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); - do_check_eq(smartBookmarkItemIds.length, smartBookmarksCount); - do_check_eq(bmsvc.getFolderIdForItem(smartBookmarkItemIds[0]), newParent); - do_check_eq(bmsvc.getItemTitle(smartBookmarkItemIds[0]), oldTitle); - // check that pref has been bumped up - do_check_true(pref.getIntPref("browser.places.smartBookmarksVersion") > 0); -} diff --git a/browser/components/places/tests/unit/test_PUIU_makeTransaction.js b/browser/components/places/tests/unit/test_PUIU_makeTransaction.js deleted file mode 100644 index 0a2533e1a..000000000 --- a/browser/components/places/tests/unit/test_PUIU_makeTransaction.js +++ /dev/null @@ -1,351 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -function waitForBookmarkNotification(aNotification, aCallback, aProperty) -{ - PlacesUtils.bookmarks.addObserver({ - validate: function (aMethodName, aData) - { - if (aMethodName == aNotification && - (!aProperty || aProperty == aData.property)) { - PlacesUtils.bookmarks.removeObserver(this); - aCallback(aData); - } - }, - - // nsINavBookmarkObserver - QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]), - onBeginUpdateBatch: function onBeginUpdateBatch() - this.validate(arguments.callee.name, arguments), - onEndUpdateBatch: function onEndUpdateBatch() - this.validate(arguments.callee.name, arguments), - onItemAdded: function onItemAdded(aItemId, aParentId, aIndex, aItemType, - aURI, aTitle) - { - return this.validate(arguments.callee.name, { id: aItemId, - index: aIndex, - type: aItemType, - url: aURI ? aURI.spec : null, - title: aTitle }); - }, - onItemRemoved: function onItemRemoved() - this.validate(arguments.callee.name, arguments), - onItemChanged: function onItemChanged(aItemId, aProperty, aIsAnno, - aNewValue, aLastModified, aItemType) - { - return this.validate(arguments.callee.name, - { id: aItemId, - get index() PlacesUtils.bookmarks.getItemIndex(this.id), - type: aItemType, - property: aProperty, - get url() aItemType == PlacesUtils.bookmarks.TYPE_BOOKMARK ? - PlacesUtils.bookmarks.getBookmarkURI(this.id).spec : - null, - get title() PlacesUtils.bookmarks.getItemTitle(this.id), - }); - }, - onItemVisited: function onItemVisited() - this.validate(arguments.callee.name, arguments), - onItemMoved: function onItemMoved(aItemId, aOldParentId, aOldIndex, - aNewParentId, aNewIndex, aItemType) - { - this.validate(arguments.callee.name, { id: aItemId, - index: aNewIndex, - type: aItemType }); - } - }, false); -} - -function wrapNodeByIdAndParent(aItemId, aParentId) -{ - let wrappedNode; - let root = PlacesUtils.getFolderContents(aParentId, false, false).root; - for (let i = 0; i < root.childCount; ++i) { - let node = root.getChild(i); - if (node.itemId == aItemId) { - let type; - if (PlacesUtils.nodeIsContainer(node)) { - type = PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER; - } - else if (PlacesUtils.nodeIsURI(node)) { - type = PlacesUtils.TYPE_X_MOZ_PLACE; - } - else if (PlacesUtils.nodeIsSeparator(node)) { - type = PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR; - } - else { - do_throw("Unknown node type"); - } - wrappedNode = PlacesUtils.wrapNode(node, type); - } - } - root.containerOpen = false; - return JSON.parse(wrappedNode); -} - -add_test(function test_text_paste() -{ - const TEST_URL = "http://places.moz.org/" - const TEST_TITLE = "Places bookmark" - - waitForBookmarkNotification("onItemAdded", function(aData) - { - do_check_eq(aData.title, TEST_TITLE); - do_check_eq(aData.url, TEST_URL); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_BOOKMARK); - do_check_eq(aData.index, 0); - run_next_test(); - }); - - let txn = PlacesUIUtils.makeTransaction( - { title: TEST_TITLE, uri: TEST_URL }, - PlacesUtils.TYPE_X_MOZ_URL, - PlacesUtils.unfiledBookmarksFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX, - true // Unused for text. - ); - PlacesUtils.transactionManager.doTransaction(txn); -}); - -add_test(function test_container() -{ - const TEST_TITLE = "Places folder" - - waitForBookmarkNotification("onItemChanged", function(aData) - { - do_check_eq(aData.title, TEST_TITLE); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_FOLDER); - do_check_eq(aData.index, 1); - - waitForBookmarkNotification("onItemAdded", function(aData) - { - do_check_eq(aData.title, TEST_TITLE); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_FOLDER); - do_check_eq(aData.index, 2); - let id = aData.id; - - waitForBookmarkNotification("onItemMoved", function(aData) - { - do_check_eq(aData.id, id); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_FOLDER); - do_check_eq(aData.index, 1); - - run_next_test(); - }); - - let txn = PlacesUIUtils.makeTransaction( - wrapNodeByIdAndParent(aData.id, PlacesUtils.unfiledBookmarksFolderId), - 0, // Unused for real nodes. - PlacesUtils.unfiledBookmarksFolderId, - 1, // Move to position 1. - false - ); - PlacesUtils.transactionManager.doTransaction(txn); - }); - - try { - let txn = PlacesUIUtils.makeTransaction( - wrapNodeByIdAndParent(aData.id, PlacesUtils.unfiledBookmarksFolderId), - 0, // Unused for real nodes. - PlacesUtils.unfiledBookmarksFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX, - true - ); - PlacesUtils.transactionManager.doTransaction(txn); - } catch(ex) { - do_throw(ex); - } - }, "random-anno"); - - let id = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, - TEST_TITLE, - PlacesUtils.bookmarks.DEFAULT_INDEX); - PlacesUtils.annotations.setItemAnnotation(id, PlacesUIUtils.DESCRIPTION_ANNO, - "description", 0, - PlacesUtils.annotations.EXPIRE_NEVER); - PlacesUtils.annotations.setItemAnnotation(id, "random-anno", - "random-value", 0, - PlacesUtils.annotations.EXPIRE_NEVER); -}); - - -add_test(function test_separator() -{ - waitForBookmarkNotification("onItemChanged", function(aData) - { - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_SEPARATOR); - do_check_eq(aData.index, 3); - - waitForBookmarkNotification("onItemAdded", function(aData) - { - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_SEPARATOR); - do_check_eq(aData.index, 4); - let id = aData.id; - - waitForBookmarkNotification("onItemMoved", function(aData) - { - do_check_eq(aData.id, id); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_SEPARATOR); - do_check_eq(aData.index, 1); - - run_next_test(); - }); - - let txn = PlacesUIUtils.makeTransaction( - wrapNodeByIdAndParent(aData.id, PlacesUtils.unfiledBookmarksFolderId), - 0, // Unused for real nodes. - PlacesUtils.unfiledBookmarksFolderId, - 1, // Move to position 1. - false - ); - PlacesUtils.transactionManager.doTransaction(txn); - }); - - try { - let txn = PlacesUIUtils.makeTransaction( - wrapNodeByIdAndParent(aData.id, PlacesUtils.unfiledBookmarksFolderId), - 0, // Unused for real nodes. - PlacesUtils.unfiledBookmarksFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX, - true - ); - PlacesUtils.transactionManager.doTransaction(txn); - } catch(ex) { - do_throw(ex); - } - }, "random-anno"); - - let id = PlacesUtils.bookmarks.insertSeparator(PlacesUtils.unfiledBookmarksFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX); - PlacesUtils.annotations.setItemAnnotation(id, "random-anno", - "random-value", 0, - PlacesUtils.annotations.EXPIRE_NEVER); -}); - -add_test(function test_bookmark() -{ - const TEST_URL = "http://places.moz.org/" - const TEST_TITLE = "Places bookmark" - - waitForBookmarkNotification("onItemChanged", function(aData) - { - do_check_eq(aData.title, TEST_TITLE); - do_check_eq(aData.url, TEST_URL); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_BOOKMARK); - do_check_eq(aData.index, 5); - - waitForBookmarkNotification("onItemAdded", function(aData) - { - do_check_eq(aData.title, TEST_TITLE); - do_check_eq(aData.url, TEST_URL); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_BOOKMARK); - do_check_eq(aData.index, 6); - let id = aData.id; - - waitForBookmarkNotification("onItemMoved", function(aData) - { - do_check_eq(aData.id, id); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_BOOKMARK); - do_check_eq(aData.index, 1); - - run_next_test(); - }); - - let txn = PlacesUIUtils.makeTransaction( - wrapNodeByIdAndParent(aData.id, PlacesUtils.unfiledBookmarksFolderId), - 0, // Unused for real nodes. - PlacesUtils.unfiledBookmarksFolderId, - 1, // Move to position 1. - false - ); - PlacesUtils.transactionManager.doTransaction(txn); - }); - - try { - let txn = PlacesUIUtils.makeTransaction( - wrapNodeByIdAndParent(aData.id, PlacesUtils.unfiledBookmarksFolderId), - 0, // Unused for real nodes. - PlacesUtils.unfiledBookmarksFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX, - true - ); - PlacesUtils.transactionManager.doTransaction(txn); - } catch(ex) { - do_throw(ex); - } - }, "random-anno"); - - let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, - NetUtil.newURI(TEST_URL), - PlacesUtils.bookmarks.DEFAULT_INDEX, - TEST_TITLE); - PlacesUtils.annotations.setItemAnnotation(id, PlacesUIUtils.DESCRIPTION_ANNO, - "description", 0, - PlacesUtils.annotations.EXPIRE_NEVER); - PlacesUtils.annotations.setItemAnnotation(id, "random-anno", - "random-value", 0, - PlacesUtils.annotations.EXPIRE_NEVER); -}); - -add_test(function test_visit() -{ - const TEST_URL = "http://places.moz.org/" - const TEST_TITLE = "Places bookmark" - - waitForBookmarkNotification("onItemAdded", function(aData) - { - do_check_eq(aData.title, TEST_TITLE); - do_check_eq(aData.url, TEST_URL); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_BOOKMARK); - do_check_eq(aData.index, 7); - - waitForBookmarkNotification("onItemAdded", function(aData) - { - do_check_eq(aData.title, TEST_TITLE); - do_check_eq(aData.url, TEST_URL); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_BOOKMARK); - do_check_eq(aData.index, 8); - run_next_test(); - }); - - try { - let node = wrapNodeByIdAndParent(aData.id, PlacesUtils.unfiledBookmarksFolderId); - // Simulate a not-bookmarked node, will copy it to a new bookmark. - node.id = -1; - let txn = PlacesUIUtils.makeTransaction( - node, - 0, // Unused for real nodes. - PlacesUtils.unfiledBookmarksFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX, - true - ); - PlacesUtils.transactionManager.doTransaction(txn); - } catch(ex) { - do_throw(ex); - } - }); - - PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, - NetUtil.newURI(TEST_URL), - PlacesUtils.bookmarks.DEFAULT_INDEX, - TEST_TITLE); -}); - -add_test(function check_annotations() { - // As last step check how many items for each annotation exist. - - // Copies should retain the description annotation. - let descriptions = - PlacesUtils.annotations.getItemsWithAnnotation(PlacesUIUtils.DESCRIPTION_ANNO, {}); - do_check_eq(descriptions.length, 4); - - // Only the original bookmarks should have this annotation. - let others = PlacesUtils.annotations.getItemsWithAnnotation("random-anno", {}); - do_check_eq(others.length, 3); - run_next_test(); -}); - -function run_test() -{ - run_next_test(); -} diff --git a/browser/components/places/tests/unit/test_browserGlue_corrupt.js b/browser/components/places/tests/unit/test_browserGlue_corrupt.js deleted file mode 100644 index 55c57add4..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_corrupt.js +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- 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/. */ - -/** - * Tests that nsBrowserGlue correctly restores bookmarks from a JSON backup if - * database is corrupt and one backup is available. - */ - -Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); - -XPCOMUtils.defineLazyServiceGetter(this, "bs", - "@mozilla.org/browser/nav-bookmarks-service;1", - "nsINavBookmarksService"); -XPCOMUtils.defineLazyServiceGetter(this, "anno", - "@mozilla.org/browser/annotation-service;1", - "nsIAnnotationService"); - -let bookmarksObserver = { - onBeginUpdateBatch: function() {}, - onEndUpdateBatch: function() { - let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0); - do_check_neq(itemId, -1); - if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark")) - continue_test(); - }, - onItemAdded: function() {}, - onItemRemoved: function(id, folder, index, itemType) {}, - onItemChanged: function() {}, - onItemVisited: function(id, visitID, time) {}, - onItemMoved: function() {}, - QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]) -}; - -function run_test() { - do_test_pending(); - - // Create our bookmarks.html copying bookmarks.glue.html to the profile - // folder. It should be ignored. - create_bookmarks_html("bookmarks.glue.html"); - - // Create our JSON backup copying bookmarks.glue.json to the profile folder. - create_JSON_backup("bookmarks.glue.json"); - - // Remove current database file. - let db = gProfD.clone(); - db.append("places.sqlite"); - if (db.exists()) { - db.remove(false); - do_check_false(db.exists()); - } - // Create a corrupt database. - let corruptDB = gTestDir.clone(); - corruptDB.append("corruptDB.sqlite"); - corruptDB.copyTo(gProfD, "places.sqlite"); - do_check_true(db.exists()); - - // Initialize nsBrowserGlue before Places. - Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue); - - // Initialize Places through the History Service. - let hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); - // Check the database was corrupt. - // nsBrowserGlue uses databaseStatus to manage initialization. - do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT); - - // The test will continue once restore has finished and smart bookmarks - // have been created. - bs.addObserver(bookmarksObserver, false); -} - -function continue_test() { - // Check that JSON backup has been restored. - // Notice restore from JSON notification is fired before smart bookmarks creation. - let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR); - do_check_eq(bs.getItemTitle(itemId), "examplejson"); - - remove_bookmarks_html(); - remove_all_JSON_backups(); - - do_test_finished(); -} diff --git a/browser/components/places/tests/unit/test_browserGlue_corrupt_nobackup.js b/browser/components/places/tests/unit/test_browserGlue_corrupt_nobackup.js deleted file mode 100644 index e3701f97d..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_corrupt_nobackup.js +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- 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/. */ - -/** - * Tests that nsBrowserGlue correctly imports from bookmarks.html if database - * is corrupt but a JSON backup is not available. - */ - -Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); - -XPCOMUtils.defineLazyServiceGetter(this, "bs", - "@mozilla.org/browser/nav-bookmarks-service;1", - "nsINavBookmarksService"); -XPCOMUtils.defineLazyServiceGetter(this, "anno", - "@mozilla.org/browser/annotation-service;1", - "nsIAnnotationService"); - -let bookmarksObserver = { - onBeginUpdateBatch: function() {}, - onEndUpdateBatch: function() { - let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0); - do_check_neq(itemId, -1); - if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark")) - continue_test(); - }, - onItemAdded: function() {}, - onItemRemoved: function(id, folder, index, itemType) {}, - onItemChanged: function() {}, - onItemVisited: function(id, visitID, time) {}, - onItemMoved: function() {}, - QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]) -}; - -function run_test() { - do_test_pending(); - - // Create bookmarks.html in the profile. - create_bookmarks_html("bookmarks.glue.html"); - // Remove JSON backup from profile. - remove_all_JSON_backups(); - - // Remove current database file. - let db = gProfD.clone(); - db.append("places.sqlite"); - if (db.exists()) { - db.remove(false); - do_check_false(db.exists()); - } - // Create a corrupt database. - let corruptDB = gTestDir.clone(); - corruptDB.append("corruptDB.sqlite"); - corruptDB.copyTo(gProfD, "places.sqlite"); - do_check_true(db.exists()); - - // Initialize nsBrowserGlue before Places. - Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue); - - // Initialize Places through the History Service. - let hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); - // Check the database was corrupt. - // nsBrowserGlue uses databaseStatus to manage initialization. - do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT); - - // The test will continue once import has finished and smart bookmarks - // have been created. - bs.addObserver(bookmarksObserver, false); -} - -function continue_test() { - // Check that bookmarks html has been restored. - let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR); - do_check_eq(bs.getItemTitle(itemId), "example"); - - remove_bookmarks_html(); - - do_test_finished(); -} diff --git a/browser/components/places/tests/unit/test_browserGlue_corrupt_nobackup_default.js b/browser/components/places/tests/unit/test_browserGlue_corrupt_nobackup_default.js deleted file mode 100644 index 3d554ce98..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_corrupt_nobackup_default.js +++ /dev/null @@ -1,80 +0,0 @@ -/* -*- 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/. */ - -/** - * Tests that nsBrowserGlue correctly restores default bookmarks if database is - * corrupt, nor a JSON backup nor bookmarks.html are available. - */ - -Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); - -XPCOMUtils.defineLazyServiceGetter(this, "bs", - "@mozilla.org/browser/nav-bookmarks-service;1", - "nsINavBookmarksService"); -XPCOMUtils.defineLazyServiceGetter(this, "anno", - "@mozilla.org/browser/annotation-service;1", - "nsIAnnotationService"); - -let bookmarksObserver = { - onBeginUpdateBatch: function() {}, - onEndUpdateBatch: function() { - let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0); - do_check_neq(itemId, -1); - if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark")) - continue_test(); - }, - onItemAdded: function() {}, - onItemRemoved: function(id, folder, index, itemType) {}, - onItemChanged: function() {}, - onItemVisited: function(id, visitID, time) {}, - onItemMoved: function() {}, - QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]) -}; - -function run_test() { - do_test_pending(); - - // Remove bookmarks.html from profile. - remove_bookmarks_html(); - // Remove JSON backup from profile. - remove_all_JSON_backups(); - - // Remove current database file. - let db = gProfD.clone(); - db.append("places.sqlite"); - if (db.exists()) { - db.remove(false); - do_check_false(db.exists()); - } - // Create a corrupt database. - let corruptDB = gTestDir.clone(); - corruptDB.append("corruptDB.sqlite"); - corruptDB.copyTo(gProfD, "places.sqlite"); - do_check_true(db.exists()); - - // Initialize nsBrowserGlue before Places. - Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue); - - // Initialize Places through the History Service. - let hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); - // Check the database was corrupt. - // nsBrowserGlue uses databaseStatus to manage initialization. - do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT); - - // The test will continue once import has finished and smart bookmarks - // have been created. - bs.addObserver(bookmarksObserver, false); -} - -function continue_test() { - // Check that default bookmarks have been restored. - let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR); - do_check_true(itemId > 0); - do_check_eq(bs.getItemTitle(itemId), "Getting Started"); - - do_test_finished(); -} diff --git a/browser/components/places/tests/unit/test_browserGlue_distribution.js b/browser/components/places/tests/unit/test_browserGlue_distribution.js deleted file mode 100644 index 49839ef7a..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_distribution.js +++ /dev/null @@ -1,103 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -/** - * Tests that nsBrowserGlue correctly imports bookmarks from distribution.ini. - */ - -const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion"; -const PREF_BMPROCESSED = "distribution.516444.bookmarksProcessed"; -const PREF_DISTRIBUTION_ID = "distribution.id"; - -const TOPICDATA_DISTRIBUTION_CUSTOMIZATION = "force-distribution-customization"; -const TOPIC_CUSTOMIZATION_COMPLETE = "distribution-customization-complete"; -const TOPIC_BROWSERGLUE_TEST = "browser-glue-test"; - -function run_test() -{ - do_test_pending(); - - // Copy distribution.ini file to our app dir. - let distroDir = Services.dirsvc.get("XREExeF", Ci.nsIFile); - distroDir.leafName = "distribution"; - let iniFile = distroDir.clone(); - iniFile.append("distribution.ini"); - if (iniFile.exists()) { - iniFile.remove(false); - print("distribution.ini already exists, did some test forget to cleanup?"); - } - let testDistributionFile = gTestDir.clone(); - testDistributionFile.append("distribution.ini"); - testDistributionFile.copyTo(distroDir, "distribution.ini"); - do_check_true(testDistributionFile.exists()); - - // Disable Smart Bookmarks creation. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1); - - // Initialize Places through the History Service and check that a new - // database has been created. - do_check_eq(PlacesUtils.history.databaseStatus, - PlacesUtils.history.DATABASE_STATUS_CREATE); - - // Force distribution. - Cc["@mozilla.org/browser/browserglue;1"]. - getService(Ci.nsIObserver).observe(null, - TOPIC_BROWSERGLUE_TEST, - TOPICDATA_DISTRIBUTION_CUSTOMIZATION); - - // Test will continue on customization complete notification. - Services.obs.addObserver(function(aSubject, aTopic, aData) { - Services.obs.removeObserver(arguments.callee, - TOPIC_CUSTOMIZATION_COMPLETE, - false); - do_execute_soon(onCustomizationComplete); - }, TOPIC_CUSTOMIZATION_COMPLETE, false); -} - -function onCustomizationComplete() -{ - // Check the custom bookmarks exist on menu. - let menuItemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0); - do_check_neq(menuItemId, -1); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(menuItemId), - "Menu Link Before"); - menuItemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, - 1 + DEFAULT_BOOKMARKS_ON_MENU); - do_check_neq(menuItemId, -1); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(menuItemId), - "Menu Link After"); - - // Check the custom bookmarks exist on toolbar. - let toolbarItemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_neq(toolbarItemId, -1); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(toolbarItemId), - "Toolbar Link Before"); - toolbarItemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, - 1 + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_neq(toolbarItemId, -1); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(toolbarItemId), - "Toolbar Link After"); - - // Check the bmprocessed pref has been created. - do_check_true(Services.prefs.getBoolPref(PREF_BMPROCESSED)); - - // Check distribution prefs have been created. - do_check_eq(Services.prefs.getCharPref(PREF_DISTRIBUTION_ID), "516444"); - - do_test_finished(); -} - -do_register_cleanup(function() { - // Remove the distribution file, even if the test failed, otherwise all - // next tests will import it. - let iniFile = Services.dirsvc.get("XREExeF", Ci.nsIFile); - iniFile.leafName = "distribution"; - iniFile.append("distribution.ini"); - if (iniFile.exists()) - iniFile.remove(false); - do_check_false(iniFile.exists()); -}); diff --git a/browser/components/places/tests/unit/test_browserGlue_migrate.js b/browser/components/places/tests/unit/test_browserGlue_migrate.js deleted file mode 100644 index 001f066d3..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_migrate.js +++ /dev/null @@ -1,88 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -/** - * Tests that nsBrowserGlue does not overwrite bookmarks imported from the - * migrators. They usually run before nsBrowserGlue, so if we find any - * bookmark on init, we should not try to import. - */ - -const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion"; - -function run_test() { - do_test_pending(); - - // Create our bookmarks.html copying bookmarks.glue.html to the profile - // folder. It should be ignored. - create_bookmarks_html("bookmarks.glue.html"); - - // Remove current database file. - let db = gProfD.clone(); - db.append("places.sqlite"); - if (db.exists()) { - db.remove(false); - do_check_false(db.exists()); - } - - // Initialize Places through the History Service and check that a new - // database has been created. - do_check_eq(PlacesUtils.history.databaseStatus, - PlacesUtils.history.DATABASE_STATUS_CREATE); - - // A migrator would run before nsBrowserGlue Places initialization, so mimic - // that behavior adding a bookmark and notifying the migration. - let bg = Cc["@mozilla.org/browser/browserglue;1"]. - getService(Ci.nsIObserver); - - bg.observe(null, "initial-migration-will-import-default-bookmarks", null); - - PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarks.bookmarksMenuFolder, uri("http://mozilla.org/"), - PlacesUtils.bookmarks.DEFAULT_INDEX, "migrated"); - - let bookmarksObserver = { - onBeginUpdateBatch: function() {}, - onEndUpdateBatch: function() { - // Check if the currently finished batch created the smart bookmarks. - let itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_neq(itemId, -1); - if (PlacesUtils.annotations - .itemHasAnnotation(itemId, "Places/SmartBookmark")) { - do_execute_soon(onSmartBookmarksCreation); - } - }, - onItemAdded: function() {}, - onItemRemoved: function(id, folder, index, itemType) {}, - onItemChanged: function() {}, - onItemVisited: function(id, visitID, time) {}, - onItemMoved: function() {}, - QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]) - }; - // The test will continue once import has finished and smart bookmarks - // have been created. - PlacesUtils.bookmarks.addObserver(bookmarksObserver, false); - - bg.observe(null, "initial-migration-did-import-default-bookmarks", null); -} - -function onSmartBookmarksCreation() { - // Check the created bookmarks still exist. - let itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, - SMART_BOOKMARKS_ON_MENU); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "migrated"); - - // Check that we have not imported any new bookmark. - itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, - SMART_BOOKMARKS_ON_MENU + 1) - do_check_eq(itemId, -1); - itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, - SMART_BOOKMARKS_ON_MENU) - do_check_eq(itemId, -1); - - remove_bookmarks_html(); - - do_test_finished(); -} diff --git a/browser/components/places/tests/unit/test_browserGlue_prefs.js b/browser/components/places/tests/unit/test_browserGlue_prefs.js deleted file mode 100644 index e8366a614..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_prefs.js +++ /dev/null @@ -1,282 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -/** - * Tests that nsBrowserGlue is correctly interpreting the preferences settable - * by the user or by other components. - */ - -const PREF_IMPORT_BOOKMARKS_HTML = "browser.places.importBookmarksHTML"; -const PREF_RESTORE_DEFAULT_BOOKMARKS = "browser.bookmarks.restore_default_bookmarks"; -const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion"; -const PREF_AUTO_EXPORT_HTML = "browser.bookmarks.autoExportHTML"; - -const TOPIC_BROWSERGLUE_TEST = "browser-glue-test"; -const TOPICDATA_FORCE_PLACES_INIT = "force-places-init"; - -let bg = Cc["@mozilla.org/browser/browserglue;1"]. - getService(Ci.nsIBrowserGlue); - -function waitForImportAndSmartBookmarks(aCallback) { - Services.obs.addObserver(function waitImport() { - Services.obs.removeObserver(waitImport, "bookmarks-restore-success"); - // Delay to test eventual smart bookmarks creation. - do_execute_soon(function () { - promiseAsyncUpdates().then(aCallback); - }); - }, "bookmarks-restore-success", false); -} - -[ - - // This test must be the first one. - function test_checkPreferences() { - // Initialize Places through the History Service and check that a new - // database has been created. - do_check_eq(PlacesUtils.history.databaseStatus, - PlacesUtils.history.DATABASE_STATUS_CREATE); - - // Wait for Places init notification. - Services.obs.addObserver(function(aSubject, aTopic, aData) { - Services.obs.removeObserver(arguments.callee, - "places-browser-init-complete"); - do_execute_soon(function () { - // Ensure preferences status. - do_check_false(Services.prefs.getBoolPref(PREF_AUTO_EXPORT_HTML)); - - try { - do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML)); - do_throw("importBookmarksHTML pref should not exist"); - } - catch(ex) {} - - try { - do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS)); - do_throw("importBookmarksHTML pref should not exist"); - } - catch(ex) {} - - run_next_test(); - }); - }, "places-browser-init-complete", false); - }, - - function test_import() - { - do_log_info("Import from bookmarks.html if importBookmarksHTML is true."); - - remove_all_bookmarks(); - // Sanity check: we should not have any bookmark on the toolbar. - let itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_eq(itemId, -1); - - // Set preferences. - Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true); - - waitForImportAndSmartBookmarks(function () { - // Check bookmarks.html has been imported, and a smart bookmark has been - // created. - itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, - SMART_BOOKMARKS_ON_TOOLBAR); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "example"); - // Check preferences have been reverted. - do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML)); - - run_next_test(); - }); - // Force nsBrowserGlue::_initPlaces(). - do_log_info("Simulate Places init"); - bg.QueryInterface(Ci.nsIObserver).observe(null, - TOPIC_BROWSERGLUE_TEST, - TOPICDATA_FORCE_PLACES_INIT); - }, - - function test_import_noSmartBookmarks() - { - do_log_info("import from bookmarks.html, but don't create smart bookmarks \ - if they are disabled"); - - remove_all_bookmarks(); - // Sanity check: we should not have any bookmark on the toolbar. - let itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_eq(itemId, -1); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1); - Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true); - - waitForImportAndSmartBookmarks(function () { - // Check bookmarks.html has been imported, but smart bookmarks have not - // been created. - itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "example"); - // Check preferences have been reverted. - do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML)); - - run_next_test(); - }); - // Force nsBrowserGlue::_initPlaces(). - do_log_info("Simulate Places init"); - bg.QueryInterface(Ci.nsIObserver).observe(null, - TOPIC_BROWSERGLUE_TEST, - TOPICDATA_FORCE_PLACES_INIT); - }, - - function test_import_autoExport_updatedSmartBookmarks() - { - do_log_info("Import from bookmarks.html, but don't create smart bookmarks \ - if autoExportHTML is true and they are at latest version"); - - remove_all_bookmarks(); - // Sanity check: we should not have any bookmark on the toolbar. - let itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_eq(itemId, -1); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 999); - Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, true); - Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true); - - waitForImportAndSmartBookmarks(function () { - // Check bookmarks.html has been imported, but smart bookmarks have not - // been created. - itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "example"); - do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML)); - // Check preferences have been reverted. - Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, false); - - run_next_test(); - }); - // Force nsBrowserGlue::_initPlaces() - do_log_info("Simulate Places init"); - bg.QueryInterface(Ci.nsIObserver).observe(null, - TOPIC_BROWSERGLUE_TEST, - TOPICDATA_FORCE_PLACES_INIT); - }, - - function test_import_autoExport_oldSmartBookmarks() - { - do_log_info("Import from bookmarks.html, and create smart bookmarks if \ - autoExportHTML is true and they are not at latest version."); - - remove_all_bookmarks(); - // Sanity check: we should not have any bookmark on the toolbar. - let itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_eq(itemId, -1); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0); - Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, true); - Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true); - - waitForImportAndSmartBookmarks(function () { - // Check bookmarks.html has been imported, but smart bookmarks have not - // been created. - itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, - SMART_BOOKMARKS_ON_TOOLBAR); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "example"); - do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML)); - // Check preferences have been reverted. - Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, false); - - run_next_test(); - }); - // Force nsBrowserGlue::_initPlaces() - do_log_info("Simulate Places init"); - bg.QueryInterface(Ci.nsIObserver).observe(null, - TOPIC_BROWSERGLUE_TEST, - TOPICDATA_FORCE_PLACES_INIT); - }, - - function test_restore() - { - do_log_info("restore from default bookmarks.html if \ - restore_default_bookmarks is true."); - - remove_all_bookmarks(); - // Sanity check: we should not have any bookmark on the toolbar. - let itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_eq(itemId, -1); - - // Set preferences. - Services.prefs.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true); - - waitForImportAndSmartBookmarks(function () { - // Check bookmarks.html has been restored. - itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, - SMART_BOOKMARKS_ON_TOOLBAR); - do_check_true(itemId > 0); - // Check preferences have been reverted. - do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS)); - - run_next_test(); - }); - // Force nsBrowserGlue::_initPlaces() - do_log_info("Simulate Places init"); - bg.QueryInterface(Ci.nsIObserver).observe(null, - TOPIC_BROWSERGLUE_TEST, - TOPICDATA_FORCE_PLACES_INIT); - - }, - - function test_restore_import() - { - do_log_info("setting both importBookmarksHTML and \ - restore_default_bookmarks should restore defaults."); - - remove_all_bookmarks(); - // Sanity check: we should not have any bookmark on the toolbar. - let itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_eq(itemId, -1); - - // Set preferences. - Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true); - Services.prefs.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true); - - waitForImportAndSmartBookmarks(function () { - // Check bookmarks.html has been restored. - itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, - SMART_BOOKMARKS_ON_TOOLBAR); - do_check_true(itemId > 0); - // Check preferences have been reverted. - do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS)); - do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML)); - - run_next_test(); - }); - // Force nsBrowserGlue::_initPlaces() - do_log_info("Simulate Places init"); - bg.QueryInterface(Ci.nsIObserver).observe(null, - TOPIC_BROWSERGLUE_TEST, - TOPICDATA_FORCE_PLACES_INIT); - } - -].forEach(add_test); - -do_register_cleanup(function () { - remove_all_bookmarks(); - remove_bookmarks_html(); - remove_all_JSON_backups(); -}); - -function run_test() -{ - // Create our bookmarks.html from bookmarks.glue.html. - create_bookmarks_html("bookmarks.glue.html"); - // Create our JSON backup from bookmarks.glue.json. - create_JSON_backup("bookmarks.glue.json"); - - run_next_test(); -} diff --git a/browser/components/places/tests/unit/test_browserGlue_restore.js b/browser/components/places/tests/unit/test_browserGlue_restore.js deleted file mode 100644 index eb7320617..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_restore.js +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- 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/. */ - -/** - * Tests that nsBrowserGlue correctly restores bookmarks from a JSON backup if - * database has been created and one backup is available. - */ - -Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); - -XPCOMUtils.defineLazyServiceGetter(this, "bs", - "@mozilla.org/browser/nav-bookmarks-service;1", - "nsINavBookmarksService"); -XPCOMUtils.defineLazyServiceGetter(this, "anno", - "@mozilla.org/browser/annotation-service;1", - "nsIAnnotationService"); - -let bookmarksObserver = { - onBeginUpdateBatch: function() {}, - onEndUpdateBatch: function() { - let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0); - do_check_neq(itemId, -1); - if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark")) - continue_test(); - }, - onItemAdded: function() {}, - onItemRemoved: function(id, folder, index, itemType) {}, - onItemChanged: function() {}, - onItemVisited: function(id, visitID, time) {}, - onItemMoved: function() {}, - QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]) -}; - -function run_test() { - do_test_pending(); - - // Create our bookmarks.html copying bookmarks.glue.html to the profile - // folder. It will be ignored. - create_bookmarks_html("bookmarks.glue.html"); - - // Create our JSON backup copying bookmarks.glue.json to the profile - // folder. It will be ignored. - create_JSON_backup("bookmarks.glue.json"); - - // Remove current database file. - let db = gProfD.clone(); - db.append("places.sqlite"); - if (db.exists()) { - db.remove(false); - do_check_false(db.exists()); - } - - // Initialize nsBrowserGlue before Places. - Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue); - - // Initialize Places through the History Service. - let hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); - // Check a new database has been created. - // nsBrowserGlue uses databaseStatus to manage initialization. - do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CREATE); - - // The test will continue once restore has finished and smart bookmarks - // have been created. - bs.addObserver(bookmarksObserver, false); -} - -function continue_test() { - // Check that JSON backup has been restored. - // Notice restore from JSON notification is fired before smart bookmarks creation. - let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR); - do_check_eq(bs.getItemTitle(itemId), "examplejson"); - - remove_bookmarks_html(); - remove_all_JSON_backups(); - - do_test_finished(); -} diff --git a/browser/components/places/tests/unit/test_browserGlue_shutdown.js b/browser/components/places/tests/unit/test_browserGlue_shutdown.js deleted file mode 100644 index 83e5fd32f..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_shutdown.js +++ /dev/null @@ -1,162 +0,0 @@ -/* -*- 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/. */ - -/** - * Tests that nsBrowserGlue is correctly exporting based on preferences values, - * and creating bookmarks backup if one does not exist for today. - */ - -// Initialize nsBrowserGlue after Places. -let bg = Cc["@mozilla.org/browser/browserglue;1"]. - getService(Ci.nsIBrowserGlue); - -// Initialize Places through Bookmarks Service. -let bs = PlacesUtils.bookmarks; - -// Get other services. -let ps = Services.prefs; -let os = Services.obs; - -const PREF_AUTO_EXPORT_HTML = "browser.bookmarks.autoExportHTML"; - -let tests = []; - -//------------------------------------------------------------------------------ - -tests.push({ - description: "Export to bookmarks.html if autoExportHTML is true.", - exec: function() { - // Sanity check: we should have bookmarks on the toolbar. - do_check_true(bs.getIdForItemAt(bs.toolbarFolder, 0) > 0); - - // Set preferences. - ps.setBoolPref(PREF_AUTO_EXPORT_HTML, true); - - // Force nsBrowserGlue::_shutdownPlaces(). - bg.QueryInterface(Ci.nsIObserver).observe(null, - PlacesUtils.TOPIC_SHUTDOWN, - null); - - // Check bookmarks.html has been created. - check_bookmarks_html(); - // Check JSON backup has been created. - check_JSON_backup(); - - // Check preferences have not been reverted. - do_check_true(ps.getBoolPref(PREF_AUTO_EXPORT_HTML)); - // Reset preferences. - ps.setBoolPref(PREF_AUTO_EXPORT_HTML, false); - - next_test(); - } -}); - -//------------------------------------------------------------------------------ - -tests.push({ - description: "Export to bookmarks.html if autoExportHTML is true and a bookmarks.html exists.", - exec: function() { - // Sanity check: we should have bookmarks on the toolbar. - do_check_true(bs.getIdForItemAt(bs.toolbarFolder, 0) > 0); - - // Set preferences. - ps.setBoolPref(PREF_AUTO_EXPORT_HTML, true); - - // Create a bookmarks.html in the profile. - let profileBookmarksHTMLFile = create_bookmarks_html("bookmarks.glue.html"); - // Get file lastModified and size. - let lastMod = profileBookmarksHTMLFile.lastModifiedTime; - let fileSize = profileBookmarksHTMLFile.fileSize; - - // Force nsBrowserGlue::_shutdownPlaces(). - bg.QueryInterface(Ci.nsIObserver).observe(null, - PlacesUtils.TOPIC_SHUTDOWN, - null); - - // Check a new bookmarks.html has been created. - let profileBookmarksHTMLFile = check_bookmarks_html(); - //XXX not working on Linux unit boxes. Could be filestats caching issue. - let isLinux = ("@mozilla.org/gnome-gconf-service;1" in Cc); - if (!isLinux) { - //XXX this test does not working on Mac boxes as well. - let isOSX = ("nsILocalFileMac" in Ci); - if (!isOSX) { - do_check_true(profileBookmarksHTMLFile.lastModifiedTime > lastMod); - } - do_check_neq(profileBookmarksHTMLFile.fileSize, fileSize); - } - - // Check preferences have not been reverted. - do_check_true(ps.getBoolPref(PREF_AUTO_EXPORT_HTML)); - // Reset preferences. - ps.setBoolPref(PREF_AUTO_EXPORT_HTML, false); - - next_test(); - } -}); - -//------------------------------------------------------------------------------ - -tests.push({ - description: "Backup to JSON should be a no-op if a backup for today already exists.", - exec: function() { - // Sanity check: we should have bookmarks on the toolbar. - do_check_true(bs.getIdForItemAt(bs.toolbarFolder, 0) > 0); - - // Create a JSON backup in the profile. - let profileBookmarksJSONFile = create_JSON_backup("bookmarks.glue.json"); - // Get file lastModified and size. - let lastMod = profileBookmarksJSONFile.lastModifiedTime; - let fileSize = profileBookmarksJSONFile.fileSize; - - // Force nsBrowserGlue::_shutdownPlaces(). - bg.QueryInterface(Ci.nsIObserver).observe(null, - PlacesUtils.TOPIC_SHUTDOWN, - null); - - // Check a new JSON backup has not been created. - do_check_true(profileBookmarksJSONFile.exists()); - do_check_eq(profileBookmarksJSONFile.lastModifiedTime, lastMod); - do_check_eq(profileBookmarksJSONFile.fileSize, fileSize); - - do_test_finished(); - } -}); - -//------------------------------------------------------------------------------ - -function finish_test() { - do_test_finished(); -} - -var testIndex = 0; -function next_test() { - // Remove bookmarks.html from profile. - remove_bookmarks_html(); - // Remove JSON backups from profile. - remove_all_JSON_backups(); - - // Execute next test. - let test = tests.shift(); - dump("\nTEST " + (++testIndex) + ": " + test.description); - test.exec(); -} - -function run_test() { - do_test_pending(); - - // Clean up bookmarks. - remove_all_bookmarks(); - - // Create some bookmarks. - bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://mozilla.org/"), - bs.DEFAULT_INDEX, "bookmark-on-menu"); - bs.insertBookmark(bs.toolbarFolder, uri("http://mozilla.org/"), - bs.DEFAULT_INDEX, "bookmark-on-toolbar"); - - // Kick-off tests. - next_test(); -} diff --git a/browser/components/places/tests/unit/test_browserGlue_smartBookmarks.js b/browser/components/places/tests/unit/test_browserGlue_smartBookmarks.js deleted file mode 100644 index 8fdfca29c..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_smartBookmarks.js +++ /dev/null @@ -1,346 +0,0 @@ -/* -*- 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/. */ - -/** - * Tests that nsBrowserGlue is correctly interpreting the preferences settable - * by the user or by other components. - */ - -const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion"; -const PREF_AUTO_EXPORT_HTML = "browser.bookmarks.autoExportHTML"; -const PREF_IMPORT_BOOKMARKS_HTML = "browser.places.importBookmarksHTML"; -const PREF_RESTORE_DEFAULT_BOOKMARKS = "browser.bookmarks.restore_default_bookmarks"; - -const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark"; - -/** - * Rebuilds smart bookmarks listening to console output to report any message or - * exception generated when calling ensurePlacesDefaultQueriesInitialized(). - */ -function rebuildSmartBookmarks() { - let consoleListener = { - observe: function(aMsg) { - print("Got console message: " + aMsg.message); - }, - - QueryInterface: XPCOMUtils.generateQI([ - Ci.nsIConsoleListener - ]), - }; - Services.console.reset(); - Services.console.registerListener(consoleListener); - Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue) - .ensurePlacesDefaultQueriesInitialized(); - Services.console.unregisterListener(consoleListener); -} - - -let tests = []; -//------------------------------------------------------------------------------ - -tests.push({ - description: "All smart bookmarks are created if smart bookmarks version is 0.", - exec: function() { - // Sanity check: we should have default bookmark. - do_check_neq(PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0), -1); - do_check_neq(PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0), -1); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0); - - rebuildSmartBookmarks(); - - // Count items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Check version has been updated. - do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION), - SMART_BOOKMARKS_VERSION); - - next_test(); - } -}); - -//------------------------------------------------------------------------------ - -tests.push({ - description: "An existing smart bookmark is replaced when version changes.", - exec: function() { - // Sanity check: we have a smart bookmark on the toolbar. - let itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_neq(itemId, -1); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO)); - // Change its title. - PlacesUtils.bookmarks.setItemTitle(itemId, "new title"); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "new title"); - - // Sanity check items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1); - - rebuildSmartBookmarks(); - - // Count items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Check smart bookmark has been replaced, itemId has changed. - itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_neq(itemId, -1); - do_check_neq(PlacesUtils.bookmarks.getItemTitle(itemId), "new title"); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO)); - - // Check version has been updated. - do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION), - SMART_BOOKMARKS_VERSION); - - next_test(); - } -}); - -//------------------------------------------------------------------------------ - -tests.push({ - description: "bookmarks position is retained when version changes.", - exec: function() { - // Sanity check items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - let itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO)); - let firstItemTitle = PlacesUtils.bookmarks.getItemTitle(itemId); - - itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 1); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO)); - let secondItemTitle = PlacesUtils.bookmarks.getItemTitle(itemId); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1); - - rebuildSmartBookmarks(); - - // Count items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Check smart bookmarks are still in correct position. - itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO)); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), firstItemTitle); - - itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 1); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO)); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), secondItemTitle); - - // Check version has been updated. - do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION), - SMART_BOOKMARKS_VERSION); - - next_test(); - } -}); - -//------------------------------------------------------------------------------ - -tests.push({ - description: "moved bookmarks position is retained when version changes.", - exec: function() { - // Sanity check items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - let itemId1 = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId1, SMART_BOOKMARKS_ANNO)); - let firstItemTitle = PlacesUtils.bookmarks.getItemTitle(itemId1); - - let itemId2 = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 1); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId2, SMART_BOOKMARKS_ANNO)); - let secondItemTitle = PlacesUtils.bookmarks.getItemTitle(itemId2); - - // Move the first smart bookmark to the end of the menu. - PlacesUtils.bookmarks.moveItem(itemId1, PlacesUtils.bookmarksMenuFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX); - - do_check_eq(itemId1, PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX)); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1); - - rebuildSmartBookmarks(); - - // Count items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Check smart bookmarks are still in correct position. - itemId2 = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId2, SMART_BOOKMARKS_ANNO)); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId2), secondItemTitle); - - itemId1 = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId1, SMART_BOOKMARKS_ANNO)); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId1), firstItemTitle); - - // Move back the smart bookmark to the original position. - PlacesUtils.bookmarks.moveItem(itemId1, PlacesUtils.bookmarksMenuFolderId, 1); - - // Check version has been updated. - do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION), - SMART_BOOKMARKS_VERSION); - - next_test(); - } -}); - -//------------------------------------------------------------------------------ - -tests.push({ - description: "An explicitly removed smart bookmark should not be recreated.", - exec: function() { - // Remove toolbar's smart bookmarks - PlacesUtils.bookmarks.removeItem(PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0)); - - // Sanity check items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1); - - rebuildSmartBookmarks(); - - // Count items. - // We should not have recreated the smart bookmark on toolbar. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Check version has been updated. - do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION), - SMART_BOOKMARKS_VERSION); - - next_test(); - } -}); - -//------------------------------------------------------------------------------ - -tests.push({ - description: "Even if a smart bookmark has been removed recreate it if version is 0.", - exec: function() { - // Sanity check items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0); - - rebuildSmartBookmarks(); - - // Count items. - // We should not have recreated the smart bookmark on toolbar. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Check version has been updated. - do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION), - SMART_BOOKMARKS_VERSION); - - next_test(); - } -}); -//------------------------------------------------------------------------------ - -function countFolderChildren(aFolderItemId) { - let rootNode = PlacesUtils.getFolderContents(aFolderItemId).root; - let cc = rootNode.childCount; - // Dump contents. - for (let i = 0; i < cc ; i++) { - let node = rootNode.getChild(i); - let title = PlacesUtils.nodeIsSeparator(node) ? "---" : node.title; - print("Found child(" + i + "): " + title); - } - rootNode.containerOpen = false; - return cc; -} - -function next_test() { - if (tests.length) { - // Execute next test. - let test = tests.shift(); - print("\nTEST: " + test.description); - test.exec(); - } - else { - // Clean up database from all bookmarks. - remove_all_bookmarks(); - do_test_finished(); - } -} - -function run_test() { - do_test_pending(); - - remove_bookmarks_html(); - remove_all_JSON_backups(); - - // Initialize browserGlue, but remove it's listener to places-init-complete. - let bg = Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIObserver); - // Initialize Places. - PlacesUtils.history; - // Usually places init would async notify to glue, but we want to avoid - // randomness here, thus we fire the notification synchronously. - bg.observe(null, "places-init-complete", null); - - // Ensure preferences status. - do_check_false(Services.prefs.getBoolPref(PREF_AUTO_EXPORT_HTML)); - do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS)); - try { - do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML)); - do_throw("importBookmarksHTML pref should not exist"); - } - catch(ex) {} - - waitForImportAndSmartBookmarks(next_test); -} - -function waitForImportAndSmartBookmarks(aCallback) { - Services.obs.addObserver(function waitImport() { - Services.obs.removeObserver(waitImport, "bookmarks-restore-success"); - // Delay to test eventual smart bookmarks creation. - do_execute_soon(function () { - promiseAsyncUpdates().then(aCallback); - }); - }, "bookmarks-restore-success", false); -} diff --git a/browser/components/places/tests/unit/test_clearHistory_shutdown.js b/browser/components/places/tests/unit/test_clearHistory_shutdown.js deleted file mode 100644 index a3b198008..000000000 --- a/browser/components/places/tests/unit/test_clearHistory_shutdown.js +++ /dev/null @@ -1,183 +0,0 @@ -/* -*- 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/. */ - -/** - * Tests that requesting clear history at shutdown will really clear history. - */ - -const URIS = [ - "http://a.example1.com/" -, "http://b.example1.com/" -, "http://b.example2.com/" -, "http://c.example3.com/" -]; - -const TOPIC_CONNECTION_CLOSED = "places-connection-closed"; - -let EXPECTED_NOTIFICATIONS = [ - "places-shutdown" -, "places-will-close-connection" -, "places-expiration-finished" -, "places-connection-closed" -]; - -const UNEXPECTED_NOTIFICATIONS = [ - "xpcom-shutdown" -]; - -const URL = "ftp://localhost/clearHistoryOnShutdown/"; - -// Send the profile-after-change notification to the form history component to ensure -// that it has been initialized. -var formHistoryStartup = Cc["@mozilla.org/satchel/form-history-startup;1"]. - getService(Ci.nsIObserver); -formHistoryStartup.observe(null, "profile-after-change", null); - -let notificationIndex = 0; - -let notificationsObserver = { - observe: function observe(aSubject, aTopic, aData) { - print("Received notification: " + aTopic); - - // Note that some of these notifications could arrive multiple times, for - // example in case of sync, we allow that. - if (EXPECTED_NOTIFICATIONS[notificationIndex] != aTopic) - notificationIndex++; - do_check_eq(EXPECTED_NOTIFICATIONS[notificationIndex], aTopic); - - if (aTopic != TOPIC_CONNECTION_CLOSED) - return; - - getDistinctNotifications().forEach( - function (topic) Services.obs.removeObserver(notificationsObserver, topic) - ); - - print("Looking for uncleared stuff."); - - let stmt = DBConn().createStatement( - "SELECT id FROM moz_places WHERE url = :page_url " - ); - - try { - URIS.forEach(function(aUrl) { - stmt.params.page_url = aUrl; - do_check_false(stmt.executeStep()); - stmt.reset(); - }); - } finally { - stmt.finalize(); - } - - // Check cache. - checkCache(URL); - } -} - -let timeInMicroseconds = Date.now() * 1000; - -function run_test() { - run_next_test(); -} - -add_task(function test_execute() { - do_test_pending(); - - print("Initialize browserglue before Places"); - - // Avoid default bookmarks import. - let glue = Cc["@mozilla.org/browser/browserglue;1"]. - getService(Ci.nsIObserver); - glue.observe(null, "initial-migration-will-import-default-bookmarks", null); - - Services.prefs.setBoolPref("privacy.clearOnShutdown.cache", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.cookies", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.offlineApps", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.history", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.downloads", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.cookies", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.formData", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.passwords", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.sessions", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.siteSettings", true); - - Services.prefs.setBoolPref("privacy.sanitize.sanitizeOnShutdown", true); - - print("Add visits."); - for (let aUrl of URIS) { - yield promiseAddVisits({uri: uri(aUrl), visitDate: timeInMicroseconds++, - transition: PlacesUtils.history.TRANSITION_TYPED}) - } - print("Add cache."); - storeCache(URL, "testData"); -}); - -function run_test_continue() -{ - print("Simulate and wait shutdown."); - getDistinctNotifications().forEach( - function (topic) - Services.obs.addObserver(notificationsObserver, topic, false) - ); - - shutdownPlaces(); - - // Shutdown the download manager. - Services.obs.notifyObservers(null, "quit-application", null); -} - -function getDistinctNotifications() { - let ar = EXPECTED_NOTIFICATIONS.concat(UNEXPECTED_NOTIFICATIONS); - return [ar[i] for (i in ar) if (ar.slice(0, i).indexOf(ar[i]) == -1)]; -} - -function storeCache(aURL, aContent) { - let cache = Cc["@mozilla.org/network/cache-service;1"]. - getService(Ci.nsICacheService); - let session = cache.createSession("FTP", Ci.nsICache.STORE_ANYWHERE, - Ci.nsICache.STREAM_BASED); - - var storeCacheListener = { - onCacheEntryAvailable: function (entry, access, status) { - do_check_eq(status, Cr.NS_OK); - - entry.setMetaDataElement("servertype", "0"); - var os = entry.openOutputStream(0); - - var written = os.write(aContent, aContent.length); - if (written != aContent.length) { - do_throw("os.write has not written all data!\n" + - " Expected: " + written + "\n" + - " Actual: " + aContent.length + "\n"); - } - os.close(); - entry.close(); - do_execute_soon(run_test_continue); - } - }; - - session.asyncOpenCacheEntry(aURL, - Ci.nsICache.ACCESS_READ_WRITE, - storeCacheListener); -} - - -function checkCache(aURL) { - let cache = Cc["@mozilla.org/network/cache-service;1"]. - getService(Ci.nsICacheService); - let session = cache.createSession("FTP", Ci.nsICache.STORE_ANYWHERE, - Ci.nsICache.STREAM_BASED); - - var checkCacheListener = { - onCacheEntryAvailable: function (entry, access, status) { - do_check_eq(status, Cr.NS_ERROR_CACHE_KEY_NOT_FOUND); - do_test_finished(); - } - }; - - session.asyncOpenCacheEntry(aURL, - Ci.nsICache.ACCESS_READ, - checkCacheListener); -} diff --git a/browser/components/places/tests/unit/test_leftpane_corruption_handling.js b/browser/components/places/tests/unit/test_leftpane_corruption_handling.js deleted file mode 100644 index a88c2b6d2..000000000 --- a/browser/components/places/tests/unit/test_leftpane_corruption_handling.js +++ /dev/null @@ -1,198 +0,0 @@ -/* -*- 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/. */ - -/** - * Tests that we build a working leftpane in various corruption situations. - */ - -// Used to store the original leftPaneFolderId getter. -let gLeftPaneFolderIdGetter; -let gAllBookmarksFolderIdGetter; -// Used to store the original left Pane status as a JSON string. -let gReferenceJSON; -let gLeftPaneFolderId; -// Third party annotated folder. -let gFolderId; - -// Corruption cases. -let gTests = [ - - function test1() { - print("1. Do nothing, checks test calibration."); - }, - - function test2() { - print("2. Delete the left pane folder."); - PlacesUtils.bookmarks.removeItem(gLeftPaneFolderId); - }, - - function test3() { - print("3. Delete a child of the left pane folder."); - let id = PlacesUtils.bookmarks.getIdForItemAt(gLeftPaneFolderId, 0); - PlacesUtils.bookmarks.removeItem(id); - }, - - function test4() { - print("4. Delete AllBookmarks."); - PlacesUtils.bookmarks.removeItem(PlacesUIUtils.allBookmarksFolderId); - }, - - function test5() { - print("5. Create a duplicated left pane folder."); - let id = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, - "PlacesRoot", - PlacesUtils.bookmarks.DEFAULT_INDEX); - PlacesUtils.annotations.setItemAnnotation(id, ORGANIZER_FOLDER_ANNO, - "PlacesRoot", 0, - PlacesUtils.annotations.EXPIRE_NEVER); - }, - - function test6() { - print("6. Create a duplicated left pane query."); - let id = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, - "AllBookmarks", - PlacesUtils.bookmarks.DEFAULT_INDEX); - PlacesUtils.annotations.setItemAnnotation(id, ORGANIZER_QUERY_ANNO, - "AllBookmarks", 0, - PlacesUtils.annotations.EXPIRE_NEVER); - }, - - function test7() { - print("7. Remove the left pane folder annotation."); - PlacesUtils.annotations.removeItemAnnotation(gLeftPaneFolderId, - ORGANIZER_FOLDER_ANNO); - }, - - function test8() { - print("8. Remove a left pane query annotation."); - PlacesUtils.annotations.removeItemAnnotation(PlacesUIUtils.allBookmarksFolderId, - ORGANIZER_QUERY_ANNO); - }, - - function test9() { - print("9. Remove a child of AllBookmarks."); - let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUIUtils.allBookmarksFolderId, 0); - PlacesUtils.bookmarks.removeItem(id); - }, - -]; - -function run_test() { - // We want empty roots. - remove_all_bookmarks(); - - // Sanity check. - do_check_true(!!PlacesUIUtils); - - // Check getters. - gLeftPaneFolderIdGetter = PlacesUIUtils.__lookupGetter__("leftPaneFolderId"); - do_check_eq(typeof(gLeftPaneFolderIdGetter), "function"); - gAllBookmarksFolderIdGetter = PlacesUIUtils.__lookupGetter__("allBookmarksFolderId"); - do_check_eq(typeof(gAllBookmarksFolderIdGetter), "function"); - - // Add a third party bogus annotated item. Should not be removed. - gFolderId = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, - "test", - PlacesUtils.bookmarks.DEFAULT_INDEX); - PlacesUtils.annotations.setItemAnnotation(gFolderId, ORGANIZER_QUERY_ANNO, - "test", 0, - PlacesUtils.annotations.EXPIRE_NEVER); - - // Create the left pane, and store its current status, it will be used - // as reference value. - gLeftPaneFolderId = PlacesUIUtils.leftPaneFolderId; - - do_test_pending(); - - Task.spawn(function() { - gReferenceJSON = yield folderToJSON(gLeftPaneFolderId); - - // Kick-off tests. - do_timeout(0, run_next_test); - }); -} - -function run_next_test() { - if (gTests.length) { - // Create corruption. - let test = gTests.shift(); - test(); - // Regenerate getters. - PlacesUIUtils.__defineGetter__("leftPaneFolderId", gLeftPaneFolderIdGetter); - gLeftPaneFolderId = PlacesUIUtils.leftPaneFolderId; - PlacesUIUtils.__defineGetter__("allBookmarksFolderId", gAllBookmarksFolderIdGetter); - // Check the new left pane folder. - Task.spawn(function() { - let leftPaneJSON = yield folderToJSON(gLeftPaneFolderId); - do_check_true(compareJSON(gReferenceJSON, leftPaneJSON)); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(gFolderId), "test"); - // Go to next test. - do_timeout(0, run_next_test); - }); - } - else { - // All tests finished. - remove_all_bookmarks(); - do_test_finished(); - } -} - -/** - * Convert a folder item id to a JSON representation of it and its contents. - */ -function folderToJSON(aItemId) { - return Task.spawn(function() { - let query = PlacesUtils.history.getNewQuery(); - query.setFolders([aItemId], 1); - let options = PlacesUtils.history.getNewQueryOptions(); - options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; - let root = PlacesUtils.history.executeQuery(query, options).root; - let writer = { - value: "", - write: function PU_wrapNode__write(aStr, aLen) { - this.value += aStr; - } - }; - yield BookmarkJSONUtils.serializeNodeAsJSONToOutputStream(root, writer, - false, false); - do_check_true(writer.value.length > 0); - throw new Task.Result(writer.value); - }); -} - -/** - * Compare the JSON representation of 2 nodes, skipping everchanging properties - * like dates. - */ -function compareJSON(aNodeJSON_1, aNodeJSON_2) { - let node1 = JSON.parse(aNodeJSON_1); - let node2 = JSON.parse(aNodeJSON_2); - - // List of properties we should not compare (expected to be different). - const SKIP_PROPS = ["dateAdded", "lastModified", "id"]; - - function compareObjects(obj1, obj2) { - function count(o) { var n = 0; for (let p in o) n++; return n; } - do_check_eq(count(obj1), count(obj2)); - for (let prop in obj1) { - // Skip everchanging values. - if (SKIP_PROPS.indexOf(prop) != -1) - continue; - // Skip undefined objects, otherwise we hang on them. - if (!obj1[prop]) - continue; - if (typeof(obj1[prop]) == "object") - return compareObjects(obj1[prop], obj2[prop]); - if (obj1[prop] !== obj2[prop]) { - print(prop + ": " + obj1[prop] + "!=" + obj2[prop]); - return false; - } - } - return true; - } - - return compareObjects(node1, node2); -} diff --git a/browser/components/places/tests/unit/xpcshell.ini b/browser/components/places/tests/unit/xpcshell.ini deleted file mode 100644 index e8b2576f6..000000000 --- a/browser/components/places/tests/unit/xpcshell.ini +++ /dev/null @@ -1,18 +0,0 @@ -[DEFAULT] -head = head_bookmarks.js -tail = -firefox-appdir = browser - -[test_421483.js] -[test_browserGlue_corrupt.js] -[test_browserGlue_corrupt_nobackup.js] -[test_browserGlue_corrupt_nobackup_default.js] -[test_browserGlue_distribution.js] -[test_browserGlue_migrate.js] -[test_browserGlue_prefs.js] -[test_browserGlue_restore.js] -[test_browserGlue_shutdown.js] -[test_browserGlue_smartBookmarks.js] -[test_clearHistory_shutdown.js] -[test_leftpane_corruption_handling.js] -[test_PUIU_makeTransaction.js] |