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