1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_bug432599.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,127 @@ 1.4 +function invokeUsingCtrlD(phase) { 1.5 + switch (phase) { 1.6 + case 1: 1.7 + EventUtils.synthesizeKey("d", { accelKey: true }); 1.8 + break; 1.9 + case 2: 1.10 + case 4: 1.11 + EventUtils.synthesizeKey("VK_ESCAPE", {}); 1.12 + break; 1.13 + case 3: 1.14 + EventUtils.synthesizeKey("d", { accelKey: true }); 1.15 + EventUtils.synthesizeKey("d", { accelKey: true }); 1.16 + break; 1.17 + } 1.18 +} 1.19 + 1.20 +function invokeUsingStarButton(phase) { 1.21 + switch (phase) { 1.22 + case 1: 1.23 + EventUtils.synthesizeMouseAtCenter(BookmarkingUI.star, {}); 1.24 + break; 1.25 + case 2: 1.26 + case 4: 1.27 + EventUtils.synthesizeKey("VK_ESCAPE", {}); 1.28 + break; 1.29 + case 3: 1.30 + EventUtils.synthesizeMouseAtCenter(BookmarkingUI.star, 1.31 + { clickCount: 2 }); 1.32 + break; 1.33 + } 1.34 +} 1.35 + 1.36 +var testURL = "data:text/plain,Content"; 1.37 +var bookmarkId; 1.38 + 1.39 +function add_bookmark(aURI, aTitle) { 1.40 + return PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, 1.41 + aURI, PlacesUtils.bookmarks.DEFAULT_INDEX, 1.42 + aTitle); 1.43 +} 1.44 + 1.45 +// test bug 432599 1.46 +function test() { 1.47 + waitForExplicitFinish(); 1.48 + 1.49 + gBrowser.selectedTab = gBrowser.addTab(); 1.50 + gBrowser.selectedBrowser.addEventListener("load", function onLoad() { 1.51 + gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); 1.52 + waitForStarChange(false, initTest); 1.53 + }, true); 1.54 + 1.55 + content.location = testURL; 1.56 +} 1.57 + 1.58 +function initTest() { 1.59 + // First, bookmark the page. 1.60 + bookmarkId = add_bookmark(makeURI(testURL), "Bug 432599 Test"); 1.61 + 1.62 + checkBookmarksPanel(invokers[currentInvoker], 1); 1.63 +} 1.64 + 1.65 +function waitForStarChange(aValue, aCallback) { 1.66 + let expectedStatus = aValue ? BookmarkingUI.STATUS_STARRED 1.67 + : BookmarkingUI.STATUS_UNSTARRED; 1.68 + if (BookmarkingUI.status == BookmarkingUI.STATUS_UPDATING || 1.69 + BookmarkingUI.status != expectedStatus) { 1.70 + info("Waiting for star button change."); 1.71 + setTimeout(waitForStarChange, 50, aValue, aCallback); 1.72 + return; 1.73 + } 1.74 + aCallback(); 1.75 +} 1.76 + 1.77 +let invokers = [invokeUsingStarButton, invokeUsingCtrlD]; 1.78 +let currentInvoker = 0; 1.79 + 1.80 +let initialValue; 1.81 +let initialRemoveHidden; 1.82 + 1.83 +let popupElement = document.getElementById("editBookmarkPanel"); 1.84 +let titleElement = document.getElementById("editBookmarkPanelTitle"); 1.85 +let removeElement = document.getElementById("editBookmarkPanelRemoveButton"); 1.86 + 1.87 +function checkBookmarksPanel(invoker, phase) 1.88 +{ 1.89 + let onPopupShown = function(aEvent) { 1.90 + if (aEvent.originalTarget == popupElement) { 1.91 + popupElement.removeEventListener("popupshown", arguments.callee, false); 1.92 + checkBookmarksPanel(invoker, phase + 1); 1.93 + } 1.94 + }; 1.95 + let onPopupHidden = function(aEvent) { 1.96 + if (aEvent.originalTarget == popupElement) { 1.97 + popupElement.removeEventListener("popuphidden", arguments.callee, false); 1.98 + if (phase < 4) { 1.99 + checkBookmarksPanel(invoker, phase + 1); 1.100 + } else { 1.101 + ++currentInvoker; 1.102 + if (currentInvoker < invokers.length) { 1.103 + checkBookmarksPanel(invokers[currentInvoker], 1); 1.104 + } else { 1.105 + gBrowser.removeCurrentTab(); 1.106 + PlacesUtils.bookmarks.removeItem(bookmarkId); 1.107 + executeSoon(finish); 1.108 + } 1.109 + } 1.110 + } 1.111 + }; 1.112 + 1.113 + switch (phase) { 1.114 + case 1: 1.115 + case 3: 1.116 + popupElement.addEventListener("popupshown", onPopupShown, false); 1.117 + break; 1.118 + case 2: 1.119 + popupElement.addEventListener("popuphidden", onPopupHidden, false); 1.120 + initialValue = titleElement.value; 1.121 + initialRemoveHidden = removeElement.hidden; 1.122 + break; 1.123 + case 4: 1.124 + popupElement.addEventListener("popuphidden", onPopupHidden, false); 1.125 + is(titleElement.value, initialValue, "The bookmark panel's title should be the same"); 1.126 + is(removeElement.hidden, initialRemoveHidden, "The bookmark panel's visibility should not change"); 1.127 + break; 1.128 + } 1.129 + invoker(phase); 1.130 +}