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 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
5 let testURL = "data:text/plain,nothing but plain text";
6 let testTag = "581253_tag";
7 let timerID = -1;
9 function test() {
10 registerCleanupFunction(function() {
11 PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
12 if (timerID > 0) {
13 clearTimeout(timerID);
14 }
15 });
16 waitForExplicitFinish();
18 let tab = gBrowser.selectedTab = gBrowser.addTab();
19 tab.linkedBrowser.addEventListener("load", (function(event) {
20 tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
22 let uri = makeURI(testURL);
23 let bmTxn =
24 new PlacesCreateBookmarkTransaction(uri,
25 PlacesUtils.unfiledBookmarksFolderId,
26 -1, "", null, []);
27 PlacesUtils.transactionManager.doTransaction(bmTxn);
29 ok(PlacesUtils.bookmarks.isBookmarked(uri), "the test url is bookmarked");
30 waitForStarChange(true, onStarred);
31 }), true);
33 content.location = testURL;
34 }
36 function waitForStarChange(aValue, aCallback) {
37 let expectedStatus = aValue ? BookmarkingUI.STATUS_STARRED
38 : BookmarkingUI.STATUS_UNSTARRED;
39 if (BookmarkingUI.status == BookmarkingUI.STATUS_UPDATING ||
40 BookmarkingUI.status != expectedStatus) {
41 info("Waiting for star button change.");
42 setTimeout(waitForStarChange, 50, aValue, aCallback);
43 return;
44 }
45 aCallback();
46 }
48 function onStarred() {
49 is(BookmarkingUI.status, BookmarkingUI.STATUS_STARRED,
50 "star button indicates that the page is bookmarked");
52 let uri = makeURI(testURL);
53 let tagTxn = new PlacesTagURITransaction(uri, [testTag]);
54 PlacesUtils.transactionManager.doTransaction(tagTxn);
56 StarUI.panel.addEventListener("popupshown", onPanelShown, false);
57 BookmarkingUI.star.click();
58 }
60 function onPanelShown(aEvent) {
61 if (aEvent.target == StarUI.panel) {
62 StarUI.panel.removeEventListener("popupshown", arguments.callee, false);
63 let tagsField = document.getElementById("editBMPanel_tagsField");
64 ok(tagsField.value == testTag, "tags field value was set");
65 tagsField.focus();
67 StarUI.panel.addEventListener("popuphidden", onPanelHidden, false);
68 let removeButton = document.getElementById("editBookmarkPanelRemoveButton");
69 removeButton.click();
70 }
71 }
73 /**
74 * Clears history invoking callback when done.
75 */
76 function waitForClearHistory(aCallback)
77 {
78 let observer = {
79 observe: function(aSubject, aTopic, aData)
80 {
81 Services.obs.removeObserver(this, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
82 aCallback(aSubject, aTopic, aData);
83 }
84 };
85 Services.obs.addObserver(observer, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false);
86 PlacesUtils.bhistory.removeAllPages();
87 }
89 function onPanelHidden(aEvent) {
90 if (aEvent.target == StarUI.panel) {
91 StarUI.panel.removeEventListener("popuphidden", arguments.callee, false);
93 executeSoon(function() {
94 ok(!PlacesUtils.bookmarks.isBookmarked(makeURI(testURL)),
95 "the bookmark for the test url has been removed");
96 is(BookmarkingUI.status, BookmarkingUI.STATUS_UNSTARRED,
97 "star button indicates that the bookmark has been removed");
98 gBrowser.removeCurrentTab();
99 waitForClearHistory(finish);
100 });
101 }
102 }