browser_bug537013.js (4895B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 /* Tests for bug 537013 to ensure proper tab-sequestration of find bar. */ 5 6 var tabs = []; 7 var texts = [ 8 "This side up.", 9 "The world is coming to an end. Please log off.", 10 "Klein bottle for sale. Inquire within.", 11 "To err is human; to forgive is not company policy.", 12 ]; 13 14 var HasFindClipboard = Services.clipboard.isClipboardTypeSupported( 15 Services.clipboard.kFindClipboard 16 ); 17 18 function addTabWithText(aText) { 19 let newTab = BrowserTestUtils.addTab( 20 gBrowser, 21 "data:text/html;charset=utf-8,<h1 id='h1'>" + aText + "</h1>" 22 ); 23 tabs.push(newTab); 24 gBrowser.selectedTab = newTab; 25 } 26 27 function setFindString(aString) { 28 gFindBar.open(); 29 gFindBar._findField.focus(); 30 gFindBar._findField.select(); 31 EventUtils.sendString(aString); 32 is(gFindBar._findField.value, aString, "Set the field correctly!"); 33 } 34 35 var newWindow; 36 37 function test() { 38 waitForExplicitFinish(); 39 registerCleanupFunction(function () { 40 while (tabs.length) { 41 gBrowser.removeTab(tabs.pop()); 42 } 43 }); 44 texts.forEach(aText => addTabWithText(aText)); 45 46 // Set up the first tab 47 gBrowser.selectedTab = tabs[0]; 48 49 gBrowser.getFindBar().then(initialTest); 50 } 51 52 function initialTest() { 53 setFindString(texts[0]); 54 // Turn on highlight for testing bug 891638 55 gFindBar.getElement("highlight").checked = true; 56 57 // Make sure the second tab is correct, then set it up 58 gBrowser.selectedTab = tabs[1]; 59 gBrowser.selectedTab.addEventListener("TabFindInitialized", continueTests1, { 60 once: true, 61 }); 62 // Initialize the findbar 63 gBrowser.getFindBar(); 64 } 65 function continueTests1() { 66 ok(true, "'TabFindInitialized' event properly dispatched!"); 67 ok(gFindBar.hidden, "Second tab doesn't show find bar!"); 68 gFindBar.open(); 69 is( 70 gFindBar._findField.value, 71 texts[0], 72 "Second tab kept old find value for new initialization!" 73 ); 74 setFindString(texts[1]); 75 76 // Confirm the first tab is still correct, ensure re-hiding works as expected 77 gBrowser.selectedTab = tabs[0]; 78 ok(!gFindBar.hidden, "First tab shows find bar!"); 79 // When the Find Clipboard is supported, this test not relevant. 80 if (!HasFindClipboard) { 81 is(gFindBar._findField.value, texts[0], "First tab persists find value!"); 82 } 83 ok( 84 gFindBar.getElement("highlight").checked, 85 "Highlight button state persists!" 86 ); 87 88 // While we're here, let's test bug 253793 89 gBrowser.reload(); 90 gBrowser.addEventListener("DOMContentLoaded", continueTests2, true); 91 } 92 93 function continueTests2() { 94 gBrowser.removeEventListener("DOMContentLoaded", continueTests2, true); 95 ok(gFindBar.getElement("highlight").checked, "Highlight never reset!"); 96 continueTests3(); 97 } 98 99 function continueTests3() { 100 ok(gFindBar.getElement("highlight").checked, "Highlight button reset!"); 101 gFindBar.close(); 102 ok(gFindBar.hidden, "First tab doesn't show find bar!"); 103 gBrowser.selectedTab = tabs[1]; 104 ok(!gFindBar.hidden, "Second tab shows find bar!"); 105 // Test for bug 892384 106 is( 107 gFindBar._findField.getAttribute("focused"), 108 "true", 109 "Open findbar refocused on tab change!" 110 ); 111 gURLBar.focus(); 112 gBrowser.selectedTab = tabs[0]; 113 ok(gFindBar.hidden, "First tab doesn't show find bar!"); 114 115 // Set up a third tab, no tests here 116 gBrowser.selectedTab = tabs[2]; 117 gBrowser.selectedTab.addEventListener("TabFindInitialized", continueTests4, { 118 once: true, 119 }); 120 gBrowser.getFindBar(); 121 } 122 123 function continueTests4() { 124 setFindString(texts[2]); 125 126 // Now we jump to the second, then first, and then fourth 127 gBrowser.selectedTab = tabs[1]; 128 // Test for bug 892384 129 ok( 130 !gFindBar._findField.hasAttribute("focused"), 131 "Open findbar not refocused on tab change!" 132 ); 133 gBrowser.selectedTab = tabs[0]; 134 gBrowser.selectedTab = tabs[3]; 135 ok(gFindBar.hidden, "Fourth tab doesn't show find bar!"); 136 is(gFindBar, gBrowser.getFindBar(), "Find bar is right one!"); 137 gFindBar.open(); 138 // Disabled the following assertion due to intermittent failure on OSX 10.6 Debug. 139 if (!HasFindClipboard) { 140 is( 141 gFindBar._findField.value, 142 texts[1], 143 "Fourth tab has second tab's find value!" 144 ); 145 } 146 147 newWindow = gBrowser.replaceTabWithWindow(tabs.pop()); 148 whenDelayedStartupFinished(newWindow, checkNewWindow); 149 } 150 151 // Test that findbar gets restored when a tab is moved to a new window. 152 function checkNewWindow() { 153 ok(!newWindow.gFindBar.hidden, "New window shows find bar!"); 154 // Disabled the following assertion due to intermittent failure on OSX 10.6 Debug. 155 if (!HasFindClipboard) { 156 is( 157 newWindow.gFindBar._findField.value, 158 texts[1], 159 "New window find bar has correct find value!" 160 ); 161 ok( 162 !newWindow.gFindBar.getElement("find-next").disabled, 163 "New window findbar has enabled buttons!" 164 ); 165 } 166 newWindow.close(); 167 finish(); 168 }