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: function run_test() { michael@0: let uri1 = NetUtil.newURI("http://foo.bar/"); michael@0: michael@0: // create 2 bookmarks michael@0: let bookmark1id = PlacesUtils.bookmarks michael@0: .insertBookmark(PlacesUtils.bookmarksMenuFolderId, michael@0: uri1, michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, michael@0: "title 1"); michael@0: let bookmark2id = PlacesUtils.bookmarks michael@0: .insertBookmark(PlacesUtils.toolbarFolderId, michael@0: uri1, michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, michael@0: "title 2"); michael@0: // add a new tag michael@0: PlacesUtils.tagging.tagURI(uri1, ["foo"]); michael@0: michael@0: // get tag folder id michael@0: let options = PlacesUtils.history.getNewQueryOptions(); michael@0: let query = PlacesUtils.history.getNewQuery(); michael@0: query.setFolders([PlacesUtils.tagsFolderId], 1); michael@0: let result = PlacesUtils.history.executeQuery(query, options); michael@0: let tagRoot = result.root; michael@0: tagRoot.containerOpen = true; michael@0: let tagNode = tagRoot.getChild(0) michael@0: .QueryInterface(Ci.nsINavHistoryContainerResultNode); michael@0: let tagItemId = tagNode.itemId; michael@0: tagRoot.containerOpen = false; michael@0: michael@0: // change bookmark 1 title michael@0: PlacesUtils.bookmarks.setItemTitle(bookmark1id, "new title 1"); michael@0: michael@0: // Workaround timers resolution and time skews. michael@0: let bookmark2LastMod = PlacesUtils.bookmarks.getItemLastModified(bookmark2id); michael@0: PlacesUtils.bookmarks.setItemLastModified(bookmark1id, bookmark2LastMod + 1); michael@0: michael@0: // Query the tag. michael@0: options = PlacesUtils.history.getNewQueryOptions(); michael@0: options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; michael@0: options.resultType = options.RESULTS_AS_TAG_QUERY; michael@0: michael@0: query = PlacesUtils.history.getNewQuery(); michael@0: result = PlacesUtils.history.executeQuery(query, options); michael@0: let root = result.root; michael@0: root.containerOpen = true; michael@0: do_check_eq(root.childCount, 1); michael@0: michael@0: let theTag = root.getChild(0) michael@0: .QueryInterface(Ci.nsINavHistoryContainerResultNode); michael@0: // Bug 524219: Check that renaming the tag shows up in the result. michael@0: do_check_eq(theTag.title, "foo") michael@0: PlacesUtils.bookmarks.setItemTitle(tagItemId, "bar"); michael@0: michael@0: // Check that the item has been replaced michael@0: do_check_neq(theTag, root.getChild(0)); michael@0: theTag = root.getChild(0) michael@0: .QueryInterface(Ci.nsINavHistoryContainerResultNode); michael@0: do_check_eq(theTag.title, "bar"); michael@0: michael@0: // Check that tag container contains new title michael@0: theTag.containerOpen = true; michael@0: do_check_eq(theTag.childCount, 1); michael@0: let node = theTag.getChild(0); michael@0: do_check_eq(node.title, "new title 1"); michael@0: theTag.containerOpen = false; michael@0: root.containerOpen = false; michael@0: michael@0: // Change bookmark 2 title. michael@0: PlacesUtils.bookmarks.setItemTitle(bookmark2id, "new title 2"); michael@0: michael@0: // Workaround timers resolution and time skews. michael@0: let bookmark1LastMod = PlacesUtils.bookmarks.getItemLastModified(bookmark1id); michael@0: PlacesUtils.bookmarks.setItemLastModified(bookmark2id, bookmark1LastMod + 1); michael@0: michael@0: // Check that tag container contains new title michael@0: options = PlacesUtils.history.getNewQueryOptions(); michael@0: options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; michael@0: options.resultType = options.RESULTS_AS_TAG_CONTENTS; michael@0: michael@0: query = PlacesUtils.history.getNewQuery(); michael@0: query.setFolders([tagItemId], 1); michael@0: result = PlacesUtils.history.executeQuery(query, options); michael@0: root = result.root; michael@0: michael@0: root.containerOpen = true; michael@0: do_check_eq(root.childCount, 1); michael@0: node = root.getChild(0); michael@0: do_check_eq(node.title, "new title 2"); michael@0: root.containerOpen = false; michael@0: }