browser_bug432599.js (3063B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 function invokeUsingCtrlD(phase) { 5 switch (phase) { 6 case 1: 7 EventUtils.synthesizeKey("d", { accelKey: true }); 8 break; 9 case 2: 10 case 4: 11 EventUtils.synthesizeKey("KEY_Escape"); 12 break; 13 case 3: 14 EventUtils.synthesizeKey("d", { accelKey: true }); 15 EventUtils.synthesizeKey("d", { accelKey: true }); 16 break; 17 } 18 } 19 20 function invokeUsingStarButton(phase) { 21 switch (phase) { 22 case 1: 23 EventUtils.synthesizeMouseAtCenter(BookmarkingUI.star, {}); 24 break; 25 case 2: 26 case 4: 27 EventUtils.synthesizeKey("KEY_Escape"); 28 break; 29 case 3: 30 EventUtils.synthesizeMouseAtCenter(BookmarkingUI.star, { clickCount: 2 }); 31 break; 32 } 33 } 34 35 add_task(async function () { 36 const TEST_URL = "data:text/plain,Content"; 37 38 let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL); 39 registerCleanupFunction(async () => { 40 await BrowserTestUtils.removeTab(tab); 41 await PlacesUtils.bookmarks.eraseEverything(); 42 }); 43 44 // Changing the location causes the star to asynchronously update, thus wait 45 // for it to be in a stable state before proceeding. 46 await TestUtils.waitForCondition( 47 () => BookmarkingUI.status == BookmarkingUI.STATUS_UNSTARRED 48 ); 49 50 await PlacesUtils.bookmarks.insert({ 51 parentGuid: PlacesUtils.bookmarks.unfiledGuid, 52 url: TEST_URL, 53 title: "Bug 432599 Test", 54 }); 55 Assert.equal( 56 BookmarkingUI.status, 57 BookmarkingUI.STATUS_STARRED, 58 "The star state should be starred" 59 ); 60 61 for (let invoker of [invokeUsingStarButton, invokeUsingCtrlD]) { 62 for (let phase = 1; phase < 5; ++phase) { 63 let promise = checkBookmarksPanel(phase); 64 invoker(phase); 65 await promise; 66 Assert.equal( 67 BookmarkingUI.status, 68 BookmarkingUI.STATUS_STARRED, 69 "The star state shouldn't change" 70 ); 71 } 72 } 73 }); 74 75 var initialValue; 76 var initialRemoveHidden; 77 async function checkBookmarksPanel(phase) { 78 StarUI._createPanelIfNeeded(); 79 let popupElement = document.getElementById("editBookmarkPanel"); 80 let titleElement = document.getElementById("editBookmarkPanelTitle"); 81 let removeElement = document.getElementById("editBookmarkPanelRemoveButton"); 82 await document.l10n.translateElements([titleElement]); 83 switch (phase) { 84 case 1: 85 case 3: 86 await promisePopupShown(popupElement); 87 break; 88 case 2: 89 initialValue = titleElement.textContent; 90 initialRemoveHidden = removeElement.hidden; 91 await promisePopupHidden(popupElement); 92 break; 93 case 4: 94 Assert.equal( 95 titleElement.textContent, 96 initialValue, 97 "The bookmark panel's title should be the same" 98 ); 99 Assert.equal( 100 removeElement.hidden, 101 initialRemoveHidden, 102 "The bookmark panel's visibility should not change" 103 ); 104 await promisePopupHidden(popupElement); 105 break; 106 default: 107 throw new Error("Unknown phase"); 108 } 109 }