Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | function run_test() { |
michael@0 | 8 | let uri1 = NetUtil.newURI("http://foo.bar/"); |
michael@0 | 9 | |
michael@0 | 10 | // create 2 bookmarks |
michael@0 | 11 | let bookmark1id = PlacesUtils.bookmarks |
michael@0 | 12 | .insertBookmark(PlacesUtils.bookmarksMenuFolderId, |
michael@0 | 13 | uri1, |
michael@0 | 14 | PlacesUtils.bookmarks.DEFAULT_INDEX, |
michael@0 | 15 | "title 1"); |
michael@0 | 16 | let bookmark2id = PlacesUtils.bookmarks |
michael@0 | 17 | .insertBookmark(PlacesUtils.toolbarFolderId, |
michael@0 | 18 | uri1, |
michael@0 | 19 | PlacesUtils.bookmarks.DEFAULT_INDEX, |
michael@0 | 20 | "title 2"); |
michael@0 | 21 | // add a new tag |
michael@0 | 22 | PlacesUtils.tagging.tagURI(uri1, ["foo"]); |
michael@0 | 23 | |
michael@0 | 24 | // get tag folder id |
michael@0 | 25 | let options = PlacesUtils.history.getNewQueryOptions(); |
michael@0 | 26 | let query = PlacesUtils.history.getNewQuery(); |
michael@0 | 27 | query.setFolders([PlacesUtils.tagsFolderId], 1); |
michael@0 | 28 | let result = PlacesUtils.history.executeQuery(query, options); |
michael@0 | 29 | let tagRoot = result.root; |
michael@0 | 30 | tagRoot.containerOpen = true; |
michael@0 | 31 | let tagNode = tagRoot.getChild(0) |
michael@0 | 32 | .QueryInterface(Ci.nsINavHistoryContainerResultNode); |
michael@0 | 33 | let tagItemId = tagNode.itemId; |
michael@0 | 34 | tagRoot.containerOpen = false; |
michael@0 | 35 | |
michael@0 | 36 | // change bookmark 1 title |
michael@0 | 37 | PlacesUtils.bookmarks.setItemTitle(bookmark1id, "new title 1"); |
michael@0 | 38 | |
michael@0 | 39 | // Workaround timers resolution and time skews. |
michael@0 | 40 | let bookmark2LastMod = PlacesUtils.bookmarks.getItemLastModified(bookmark2id); |
michael@0 | 41 | PlacesUtils.bookmarks.setItemLastModified(bookmark1id, bookmark2LastMod + 1); |
michael@0 | 42 | |
michael@0 | 43 | // Query the tag. |
michael@0 | 44 | options = PlacesUtils.history.getNewQueryOptions(); |
michael@0 | 45 | options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; |
michael@0 | 46 | options.resultType = options.RESULTS_AS_TAG_QUERY; |
michael@0 | 47 | |
michael@0 | 48 | query = PlacesUtils.history.getNewQuery(); |
michael@0 | 49 | result = PlacesUtils.history.executeQuery(query, options); |
michael@0 | 50 | let root = result.root; |
michael@0 | 51 | root.containerOpen = true; |
michael@0 | 52 | do_check_eq(root.childCount, 1); |
michael@0 | 53 | |
michael@0 | 54 | let theTag = root.getChild(0) |
michael@0 | 55 | .QueryInterface(Ci.nsINavHistoryContainerResultNode); |
michael@0 | 56 | // Bug 524219: Check that renaming the tag shows up in the result. |
michael@0 | 57 | do_check_eq(theTag.title, "foo") |
michael@0 | 58 | PlacesUtils.bookmarks.setItemTitle(tagItemId, "bar"); |
michael@0 | 59 | |
michael@0 | 60 | // Check that the item has been replaced |
michael@0 | 61 | do_check_neq(theTag, root.getChild(0)); |
michael@0 | 62 | theTag = root.getChild(0) |
michael@0 | 63 | .QueryInterface(Ci.nsINavHistoryContainerResultNode); |
michael@0 | 64 | do_check_eq(theTag.title, "bar"); |
michael@0 | 65 | |
michael@0 | 66 | // Check that tag container contains new title |
michael@0 | 67 | theTag.containerOpen = true; |
michael@0 | 68 | do_check_eq(theTag.childCount, 1); |
michael@0 | 69 | let node = theTag.getChild(0); |
michael@0 | 70 | do_check_eq(node.title, "new title 1"); |
michael@0 | 71 | theTag.containerOpen = false; |
michael@0 | 72 | root.containerOpen = false; |
michael@0 | 73 | |
michael@0 | 74 | // Change bookmark 2 title. |
michael@0 | 75 | PlacesUtils.bookmarks.setItemTitle(bookmark2id, "new title 2"); |
michael@0 | 76 | |
michael@0 | 77 | // Workaround timers resolution and time skews. |
michael@0 | 78 | let bookmark1LastMod = PlacesUtils.bookmarks.getItemLastModified(bookmark1id); |
michael@0 | 79 | PlacesUtils.bookmarks.setItemLastModified(bookmark2id, bookmark1LastMod + 1); |
michael@0 | 80 | |
michael@0 | 81 | // Check that tag container contains new title |
michael@0 | 82 | options = PlacesUtils.history.getNewQueryOptions(); |
michael@0 | 83 | options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; |
michael@0 | 84 | options.resultType = options.RESULTS_AS_TAG_CONTENTS; |
michael@0 | 85 | |
michael@0 | 86 | query = PlacesUtils.history.getNewQuery(); |
michael@0 | 87 | query.setFolders([tagItemId], 1); |
michael@0 | 88 | result = PlacesUtils.history.executeQuery(query, options); |
michael@0 | 89 | root = result.root; |
michael@0 | 90 | |
michael@0 | 91 | root.containerOpen = true; |
michael@0 | 92 | do_check_eq(root.childCount, 1); |
michael@0 | 93 | node = root.getChild(0); |
michael@0 | 94 | do_check_eq(node.title, "new title 2"); |
michael@0 | 95 | root.containerOpen = false; |
michael@0 | 96 | } |