browser_revert.js (2085B)
1 // Test reverting the urlbar value with ESC after a tab switch. 2 3 add_task(async function () { 4 registerCleanupFunction(PlacesUtils.history.clear); 5 await BrowserTestUtils.withNewTab( 6 { 7 gBrowser, 8 url: "http://example.com", 9 }, 10 async function () { 11 let originalValue = gURLBar.value; 12 let tab = gBrowser.selectedTab; 13 info("Put a typed value."); 14 gBrowser.userTypedValue = "foobar"; 15 info("Switch tabs."); 16 gBrowser.selectedTab = gBrowser.tabs[0]; 17 gBrowser.selectedTab = tab; 18 Assert.equal( 19 gURLBar.value, 20 "foobar", 21 "location bar displays typed value" 22 ); 23 24 gURLBar.focus(); 25 EventUtils.synthesizeKey("KEY_Escape"); 26 Assert.equal( 27 gURLBar.value, 28 originalValue, 29 "ESC reverted the location bar value" 30 ); 31 } 32 ); 33 }); 34 35 // Tests that pasting a multi-line string into the address bar and reverting 36 // it works as expected. 37 add_task(async function paste_and_revert() { 38 registerCleanupFunction(async () => { 39 SpecialPowers.clipboardCopyString(""); 40 await PlacesUtils.history.clear(); 41 }); 42 await BrowserTestUtils.withNewTab( 43 { 44 gBrowser, 45 url: "https://example.com", 46 }, 47 async function () { 48 gURLBar.value = ""; 49 gURLBar.focus(); 50 51 let input = "https://exam\n"; 52 await SimpleTest.promiseClipboardChange(input, () => { 53 clipboardHelper.copyString(input); 54 }); 55 document.commandDispatcher 56 .getControllerForCommand("cmd_paste") 57 .doCommand("cmd_paste"); 58 59 Assert.equal( 60 gURLBar.value, 61 "https://exam", 62 "Location bar has the pasted value." 63 ); 64 65 gURLBar.focus(); 66 EventUtils.synthesizeKey("KEY_Escape"); 67 EventUtils.synthesizeKey("KEY_Escape"); 68 69 Assert.equal( 70 gURLBar.value, 71 "example.com", 72 "Location bar has the reverted value." 73 ); 74 Assert.equal( 75 gURLBar.getAttribute("pageproxystate"), 76 "valid", 77 "Pageproxystate is valid after revert." 78 ); 79 } 80 ); 81 });