1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/unit/test_419731.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,96 @@ 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 +function run_test() { 1.11 + let uri1 = NetUtil.newURI("http://foo.bar/"); 1.12 + 1.13 + // create 2 bookmarks 1.14 + let bookmark1id = PlacesUtils.bookmarks 1.15 + .insertBookmark(PlacesUtils.bookmarksMenuFolderId, 1.16 + uri1, 1.17 + PlacesUtils.bookmarks.DEFAULT_INDEX, 1.18 + "title 1"); 1.19 + let bookmark2id = PlacesUtils.bookmarks 1.20 + .insertBookmark(PlacesUtils.toolbarFolderId, 1.21 + uri1, 1.22 + PlacesUtils.bookmarks.DEFAULT_INDEX, 1.23 + "title 2"); 1.24 + // add a new tag 1.25 + PlacesUtils.tagging.tagURI(uri1, ["foo"]); 1.26 + 1.27 + // get tag folder id 1.28 + let options = PlacesUtils.history.getNewQueryOptions(); 1.29 + let query = PlacesUtils.history.getNewQuery(); 1.30 + query.setFolders([PlacesUtils.tagsFolderId], 1); 1.31 + let result = PlacesUtils.history.executeQuery(query, options); 1.32 + let tagRoot = result.root; 1.33 + tagRoot.containerOpen = true; 1.34 + let tagNode = tagRoot.getChild(0) 1.35 + .QueryInterface(Ci.nsINavHistoryContainerResultNode); 1.36 + let tagItemId = tagNode.itemId; 1.37 + tagRoot.containerOpen = false; 1.38 + 1.39 + // change bookmark 1 title 1.40 + PlacesUtils.bookmarks.setItemTitle(bookmark1id, "new title 1"); 1.41 + 1.42 + // Workaround timers resolution and time skews. 1.43 + let bookmark2LastMod = PlacesUtils.bookmarks.getItemLastModified(bookmark2id); 1.44 + PlacesUtils.bookmarks.setItemLastModified(bookmark1id, bookmark2LastMod + 1); 1.45 + 1.46 + // Query the tag. 1.47 + options = PlacesUtils.history.getNewQueryOptions(); 1.48 + options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; 1.49 + options.resultType = options.RESULTS_AS_TAG_QUERY; 1.50 + 1.51 + query = PlacesUtils.history.getNewQuery(); 1.52 + result = PlacesUtils.history.executeQuery(query, options); 1.53 + let root = result.root; 1.54 + root.containerOpen = true; 1.55 + do_check_eq(root.childCount, 1); 1.56 + 1.57 + let theTag = root.getChild(0) 1.58 + .QueryInterface(Ci.nsINavHistoryContainerResultNode); 1.59 + // Bug 524219: Check that renaming the tag shows up in the result. 1.60 + do_check_eq(theTag.title, "foo") 1.61 + PlacesUtils.bookmarks.setItemTitle(tagItemId, "bar"); 1.62 + 1.63 + // Check that the item has been replaced 1.64 + do_check_neq(theTag, root.getChild(0)); 1.65 + theTag = root.getChild(0) 1.66 + .QueryInterface(Ci.nsINavHistoryContainerResultNode); 1.67 + do_check_eq(theTag.title, "bar"); 1.68 + 1.69 + // Check that tag container contains new title 1.70 + theTag.containerOpen = true; 1.71 + do_check_eq(theTag.childCount, 1); 1.72 + let node = theTag.getChild(0); 1.73 + do_check_eq(node.title, "new title 1"); 1.74 + theTag.containerOpen = false; 1.75 + root.containerOpen = false; 1.76 + 1.77 + // Change bookmark 2 title. 1.78 + PlacesUtils.bookmarks.setItemTitle(bookmark2id, "new title 2"); 1.79 + 1.80 + // Workaround timers resolution and time skews. 1.81 + let bookmark1LastMod = PlacesUtils.bookmarks.getItemLastModified(bookmark1id); 1.82 + PlacesUtils.bookmarks.setItemLastModified(bookmark2id, bookmark1LastMod + 1); 1.83 + 1.84 + // Check that tag container contains new title 1.85 + options = PlacesUtils.history.getNewQueryOptions(); 1.86 + options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; 1.87 + options.resultType = options.RESULTS_AS_TAG_CONTENTS; 1.88 + 1.89 + query = PlacesUtils.history.getNewQuery(); 1.90 + query.setFolders([tagItemId], 1); 1.91 + result = PlacesUtils.history.executeQuery(query, options); 1.92 + root = result.root; 1.93 + 1.94 + root.containerOpen = true; 1.95 + do_check_eq(root.childCount, 1); 1.96 + node = root.getChild(0); 1.97 + do_check_eq(node.title, "new title 2"); 1.98 + root.containerOpen = false; 1.99 +}