michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark"; michael@0: const SMART_BOOKMARKS_PREF = "browser.places.smartBookmarksVersion"; michael@0: michael@0: let gluesvc = Cc["@mozilla.org/browser/browserglue;1"]. michael@0: getService(Ci.nsIBrowserGlue). michael@0: QueryInterface(Ci.nsIObserver); michael@0: // Avoid default bookmarks import. michael@0: gluesvc.observe(null, "initial-migration-will-import-default-bookmarks", ""); michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function smart_bookmarks_disabled() { michael@0: Services.prefs.setIntPref("browser.places.smartBookmarksVersion", -1); michael@0: gluesvc.ensurePlacesDefaultQueriesInitialized(); michael@0: let smartBookmarkItemIds = michael@0: PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); michael@0: do_check_eq(smartBookmarkItemIds.length, 0); michael@0: do_log_info("check that pref has not been bumped up"); michael@0: do_check_eq(Services.prefs.getIntPref("browser.places.smartBookmarksVersion"), -1); michael@0: }); michael@0: michael@0: add_task(function create_smart_bookmarks() { michael@0: Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0); michael@0: gluesvc.ensurePlacesDefaultQueriesInitialized(); michael@0: let smartBookmarkItemIds = michael@0: PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); michael@0: do_check_neq(smartBookmarkItemIds.length, 0); michael@0: do_log_info("check that pref has been bumped up"); michael@0: do_check_true(Services.prefs.getIntPref("browser.places.smartBookmarksVersion") > 0); michael@0: }); michael@0: michael@0: add_task(function remove_smart_bookmark_and_restore() { michael@0: let smartBookmarkItemIds = michael@0: PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); michael@0: let smartBookmarksCount = smartBookmarkItemIds.length; michael@0: do_log_info("remove one smart bookmark and restore"); michael@0: PlacesUtils.bookmarks.removeItem(smartBookmarkItemIds[0]); michael@0: Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0); michael@0: gluesvc.ensurePlacesDefaultQueriesInitialized(); michael@0: let smartBookmarkItemIds = michael@0: PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); michael@0: do_check_eq(smartBookmarkItemIds.length, smartBookmarksCount); michael@0: do_log_info("check that pref has been bumped up"); michael@0: do_check_true(Services.prefs.getIntPref("browser.places.smartBookmarksVersion") > 0); michael@0: }); michael@0: michael@0: add_task(function move_smart_bookmark_rename_and_restore() { michael@0: let smartBookmarkItemIds = michael@0: PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); michael@0: let smartBookmarksCount = smartBookmarkItemIds.length; michael@0: do_log_info("smart bookmark should be restored in place"); michael@0: let parent = PlacesUtils.bookmarks.getFolderIdForItem(smartBookmarkItemIds[0]); michael@0: let oldTitle = PlacesUtils.bookmarks.getItemTitle(smartBookmarkItemIds[0]); michael@0: // create a subfolder and move inside it michael@0: let newParent = michael@0: PlacesUtils.bookmarks.createFolder(parent, "test", michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX); michael@0: PlacesUtils.bookmarks.moveItem(smartBookmarkItemIds[0], newParent, michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX); michael@0: // change title michael@0: PlacesUtils.bookmarks.setItemTitle(smartBookmarkItemIds[0], "new title"); michael@0: // restore michael@0: Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0); michael@0: gluesvc.ensurePlacesDefaultQueriesInitialized(); michael@0: smartBookmarkItemIds = michael@0: PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); michael@0: do_check_eq(smartBookmarkItemIds.length, smartBookmarksCount); michael@0: do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(smartBookmarkItemIds[0]), newParent); michael@0: do_check_eq(PlacesUtils.bookmarks.getItemTitle(smartBookmarkItemIds[0]), oldTitle); michael@0: do_log_info("check that pref has been bumped up"); michael@0: do_check_true(Services.prefs.getIntPref("browser.places.smartBookmarksVersion") > 0); michael@0: });