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 function invokeUsingCtrlD(phase) {
2 switch (phase) {
3 case 1:
4 EventUtils.synthesizeKey("d", { accelKey: true });
5 break;
6 case 2:
7 case 4:
8 EventUtils.synthesizeKey("VK_ESCAPE", {});
9 break;
10 case 3:
11 EventUtils.synthesizeKey("d", { accelKey: true });
12 EventUtils.synthesizeKey("d", { accelKey: true });
13 break;
14 }
15 }
17 function invokeUsingStarButton(phase) {
18 switch (phase) {
19 case 1:
20 EventUtils.synthesizeMouseAtCenter(BookmarkingUI.star, {});
21 break;
22 case 2:
23 case 4:
24 EventUtils.synthesizeKey("VK_ESCAPE", {});
25 break;
26 case 3:
27 EventUtils.synthesizeMouseAtCenter(BookmarkingUI.star,
28 { clickCount: 2 });
29 break;
30 }
31 }
33 var testURL = "data:text/plain,Content";
34 var bookmarkId;
36 function add_bookmark(aURI, aTitle) {
37 return PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
38 aURI, PlacesUtils.bookmarks.DEFAULT_INDEX,
39 aTitle);
40 }
42 // test bug 432599
43 function test() {
44 waitForExplicitFinish();
46 gBrowser.selectedTab = gBrowser.addTab();
47 gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
48 gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
49 waitForStarChange(false, initTest);
50 }, true);
52 content.location = testURL;
53 }
55 function initTest() {
56 // First, bookmark the page.
57 bookmarkId = add_bookmark(makeURI(testURL), "Bug 432599 Test");
59 checkBookmarksPanel(invokers[currentInvoker], 1);
60 }
62 function waitForStarChange(aValue, aCallback) {
63 let expectedStatus = aValue ? BookmarkingUI.STATUS_STARRED
64 : BookmarkingUI.STATUS_UNSTARRED;
65 if (BookmarkingUI.status == BookmarkingUI.STATUS_UPDATING ||
66 BookmarkingUI.status != expectedStatus) {
67 info("Waiting for star button change.");
68 setTimeout(waitForStarChange, 50, aValue, aCallback);
69 return;
70 }
71 aCallback();
72 }
74 let invokers = [invokeUsingStarButton, invokeUsingCtrlD];
75 let currentInvoker = 0;
77 let initialValue;
78 let initialRemoveHidden;
80 let popupElement = document.getElementById("editBookmarkPanel");
81 let titleElement = document.getElementById("editBookmarkPanelTitle");
82 let removeElement = document.getElementById("editBookmarkPanelRemoveButton");
84 function checkBookmarksPanel(invoker, phase)
85 {
86 let onPopupShown = function(aEvent) {
87 if (aEvent.originalTarget == popupElement) {
88 popupElement.removeEventListener("popupshown", arguments.callee, false);
89 checkBookmarksPanel(invoker, phase + 1);
90 }
91 };
92 let onPopupHidden = function(aEvent) {
93 if (aEvent.originalTarget == popupElement) {
94 popupElement.removeEventListener("popuphidden", arguments.callee, false);
95 if (phase < 4) {
96 checkBookmarksPanel(invoker, phase + 1);
97 } else {
98 ++currentInvoker;
99 if (currentInvoker < invokers.length) {
100 checkBookmarksPanel(invokers[currentInvoker], 1);
101 } else {
102 gBrowser.removeCurrentTab();
103 PlacesUtils.bookmarks.removeItem(bookmarkId);
104 executeSoon(finish);
105 }
106 }
107 }
108 };
110 switch (phase) {
111 case 1:
112 case 3:
113 popupElement.addEventListener("popupshown", onPopupShown, false);
114 break;
115 case 2:
116 popupElement.addEventListener("popuphidden", onPopupHidden, false);
117 initialValue = titleElement.value;
118 initialRemoveHidden = removeElement.hidden;
119 break;
120 case 4:
121 popupElement.addEventListener("popuphidden", onPopupHidden, false);
122 is(titleElement.value, initialValue, "The bookmark panel's title should be the same");
123 is(removeElement.hidden, initialRemoveHidden, "The bookmark panel's visibility should not change");
124 break;
125 }
126 invoker(phase);
127 }