1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/places/tests/unit/test_421483.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 + 1.11 +const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark"; 1.12 +const SMART_BOOKMARKS_PREF = "browser.places.smartBookmarksVersion"; 1.13 + 1.14 +let gluesvc = Cc["@mozilla.org/browser/browserglue;1"]. 1.15 + getService(Ci.nsIBrowserGlue). 1.16 + QueryInterface(Ci.nsIObserver); 1.17 +// Avoid default bookmarks import. 1.18 +gluesvc.observe(null, "initial-migration-will-import-default-bookmarks", ""); 1.19 + 1.20 +function run_test() { 1.21 + run_next_test(); 1.22 +} 1.23 + 1.24 +add_task(function smart_bookmarks_disabled() { 1.25 + Services.prefs.setIntPref("browser.places.smartBookmarksVersion", -1); 1.26 + gluesvc.ensurePlacesDefaultQueriesInitialized(); 1.27 + let smartBookmarkItemIds = 1.28 + PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); 1.29 + do_check_eq(smartBookmarkItemIds.length, 0); 1.30 + do_log_info("check that pref has not been bumped up"); 1.31 + do_check_eq(Services.prefs.getIntPref("browser.places.smartBookmarksVersion"), -1); 1.32 +}); 1.33 + 1.34 +add_task(function create_smart_bookmarks() { 1.35 + Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0); 1.36 + gluesvc.ensurePlacesDefaultQueriesInitialized(); 1.37 + let smartBookmarkItemIds = 1.38 + PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); 1.39 + do_check_neq(smartBookmarkItemIds.length, 0); 1.40 + do_log_info("check that pref has been bumped up"); 1.41 + do_check_true(Services.prefs.getIntPref("browser.places.smartBookmarksVersion") > 0); 1.42 +}); 1.43 + 1.44 +add_task(function remove_smart_bookmark_and_restore() { 1.45 + let smartBookmarkItemIds = 1.46 + PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); 1.47 + let smartBookmarksCount = smartBookmarkItemIds.length; 1.48 + do_log_info("remove one smart bookmark and restore"); 1.49 + PlacesUtils.bookmarks.removeItem(smartBookmarkItemIds[0]); 1.50 + Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0); 1.51 + gluesvc.ensurePlacesDefaultQueriesInitialized(); 1.52 + let smartBookmarkItemIds = 1.53 + PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); 1.54 + do_check_eq(smartBookmarkItemIds.length, smartBookmarksCount); 1.55 + do_log_info("check that pref has been bumped up"); 1.56 + do_check_true(Services.prefs.getIntPref("browser.places.smartBookmarksVersion") > 0); 1.57 +}); 1.58 + 1.59 +add_task(function move_smart_bookmark_rename_and_restore() { 1.60 + let smartBookmarkItemIds = 1.61 + PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); 1.62 + let smartBookmarksCount = smartBookmarkItemIds.length; 1.63 + do_log_info("smart bookmark should be restored in place"); 1.64 + let parent = PlacesUtils.bookmarks.getFolderIdForItem(smartBookmarkItemIds[0]); 1.65 + let oldTitle = PlacesUtils.bookmarks.getItemTitle(smartBookmarkItemIds[0]); 1.66 + // create a subfolder and move inside it 1.67 + let newParent = 1.68 + PlacesUtils.bookmarks.createFolder(parent, "test", 1.69 + PlacesUtils.bookmarks.DEFAULT_INDEX); 1.70 + PlacesUtils.bookmarks.moveItem(smartBookmarkItemIds[0], newParent, 1.71 + PlacesUtils.bookmarks.DEFAULT_INDEX); 1.72 + // change title 1.73 + PlacesUtils.bookmarks.setItemTitle(smartBookmarkItemIds[0], "new title"); 1.74 + // restore 1.75 + Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0); 1.76 + gluesvc.ensurePlacesDefaultQueriesInitialized(); 1.77 + smartBookmarkItemIds = 1.78 + PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); 1.79 + do_check_eq(smartBookmarkItemIds.length, smartBookmarksCount); 1.80 + do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(smartBookmarkItemIds[0]), newParent); 1.81 + do_check_eq(PlacesUtils.bookmarks.getItemTitle(smartBookmarkItemIds[0]), oldTitle); 1.82 + do_log_info("check that pref has been bumped up"); 1.83 + do_check_true(Services.prefs.getIntPref("browser.places.smartBookmarksVersion") > 0); 1.84 +});