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