Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
7 let observer = {
8 __proto__: NavBookmarkObserver.prototype,
10 onItemAdded: function (id, folder, index) {
11 this._itemAddedId = id;
12 this._itemAddedParent = folder;
13 this._itemAddedIndex = index;
14 },
15 onItemChanged: function (id, property, isAnnotationProperty, value) {
16 this._itemChangedId = id;
17 this._itemChangedProperty = property;
18 this._itemChanged_isAnnotationProperty = isAnnotationProperty;
19 this._itemChangedValue = value;
20 }
21 };
22 PlacesUtils.bookmarks.addObserver(observer, false);
24 do_register_cleanup(function () {
25 PlacesUtils.bookmarks.removeObserver(observer);
26 });
28 function run_test() {
29 // We set times in the past to workaround a timing bug due to virtual
30 // machines and the skew between PR_Now() and Date.now(), see bug 427142 and
31 // bug 858377 for details.
32 const PAST_PRTIME = (Date.now() - 86400000) * 1000;
34 // Insert a new bookmark.
35 let testFolder = PlacesUtils.bookmarks.createFolder(
36 PlacesUtils.placesRootId, "test Folder",
37 PlacesUtils.bookmarks.DEFAULT_INDEX);
38 let bookmarkId = PlacesUtils.bookmarks.insertBookmark(
39 testFolder, uri("http://google.com/"),
40 PlacesUtils.bookmarks.DEFAULT_INDEX, "");
42 // Sanity check.
43 do_check_true(observer.itemChangedProperty === undefined);
45 // Set dateAdded in the past and verify the bookmarks cache.
46 PlacesUtils.bookmarks.setItemDateAdded(bookmarkId, PAST_PRTIME);
47 do_check_eq(observer._itemChangedProperty, "dateAdded");
48 do_check_eq(observer._itemChangedValue, PAST_PRTIME);
49 let dateAdded = PlacesUtils.bookmarks.getItemDateAdded(bookmarkId);
50 do_check_eq(dateAdded, PAST_PRTIME);
52 // After just inserting, modified should be the same as dateAdded.
53 do_check_eq(PlacesUtils.bookmarks.getItemLastModified(bookmarkId), dateAdded);
55 // Set lastModified in the past and verify the bookmarks cache.
56 PlacesUtils.bookmarks.setItemLastModified(bookmarkId, PAST_PRTIME);
57 do_check_eq(observer._itemChangedProperty, "lastModified");
58 do_check_eq(observer._itemChangedValue, PAST_PRTIME);
59 do_check_eq(PlacesUtils.bookmarks.getItemLastModified(bookmarkId),
60 PAST_PRTIME);
62 // Set bookmark title
63 PlacesUtils.bookmarks.setItemTitle(bookmarkId, "Google");
65 // Test notifications.
66 do_check_eq(observer._itemChangedId, bookmarkId);
67 do_check_eq(observer._itemChangedProperty, "title");
68 do_check_eq(observer._itemChangedValue, "Google");
70 // Check lastModified has been updated.
71 is_time_ordered(PAST_PRTIME,
72 PlacesUtils.bookmarks.getItemLastModified(bookmarkId));
74 // Check that node properties are updated.
75 let root = PlacesUtils.getFolderContents(testFolder).root;
76 do_check_eq(root.childCount, 1);
77 let childNode = root.getChild(0);
79 // confirm current dates match node properties
80 do_check_eq(PlacesUtils.bookmarks.getItemDateAdded(bookmarkId),
81 childNode.dateAdded);
82 do_check_eq(PlacesUtils.bookmarks.getItemLastModified(bookmarkId),
83 childNode.lastModified);
85 // Test live update of lastModified when setting title.
86 PlacesUtils.bookmarks.setItemLastModified(bookmarkId, PAST_PRTIME);
87 PlacesUtils.bookmarks.setItemTitle(bookmarkId, "Google");
89 // Check lastModified has been updated.
90 is_time_ordered(PAST_PRTIME, childNode.lastModified);
91 // Test that node value matches db value.
92 do_check_eq(PlacesUtils.bookmarks.getItemLastModified(bookmarkId),
93 childNode.lastModified);
95 // Test live update of the exposed date apis.
96 PlacesUtils.bookmarks.setItemDateAdded(bookmarkId, PAST_PRTIME);
97 do_check_eq(childNode.dateAdded, PAST_PRTIME);
98 PlacesUtils.bookmarks.setItemLastModified(bookmarkId, PAST_PRTIME);
99 do_check_eq(childNode.lastModified, PAST_PRTIME);
101 root.containerOpen = false;
102 }