michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /* Tests for bug 537013 to ensure proper tab-sequestration of find bar. */ michael@0: michael@0: let tabs = []; michael@0: let texts = [ michael@0: "This side up.", michael@0: "The world is coming to an end. Please log off.", michael@0: "Klein bottle for sale. Inquire within.", michael@0: "To err is human; to forgive is not company policy." michael@0: ]; michael@0: michael@0: let Clipboard = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard); michael@0: let HasFindClipboard = Clipboard.supportsFindClipboard(); michael@0: michael@0: function addTabWithText(aText, aCallback) { michael@0: let newTab = gBrowser.addTab("data:text/html,

" + aText + "

"); michael@0: tabs.push(newTab); michael@0: gBrowser.selectedTab = newTab; michael@0: } michael@0: michael@0: function setFindString(aString) { michael@0: gFindBar.open(); michael@0: gFindBar._findField.focus(); michael@0: gFindBar._findField.select(); michael@0: EventUtils.sendString(aString); michael@0: is(gFindBar._findField.value, aString, "Set the field correctly!"); michael@0: } michael@0: michael@0: let newWindow; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: registerCleanupFunction(function () { michael@0: while (tabs.length) { michael@0: gBrowser.removeTab(tabs.pop()); michael@0: } michael@0: }); michael@0: texts.forEach(function(aText) addTabWithText(aText)); michael@0: michael@0: // Set up the first tab michael@0: gBrowser.selectedTab = tabs[0]; michael@0: michael@0: setFindString(texts[0]); michael@0: // Turn on highlight for testing bug 891638 michael@0: gFindBar.getElement("highlight").checked = true; michael@0: michael@0: // Make sure the second tab is correct, then set it up michael@0: gBrowser.selectedTab = tabs[1]; michael@0: gBrowser.selectedTab.addEventListener("TabFindInitialized", continueTests1); michael@0: // Initialize the findbar michael@0: gFindBar; michael@0: } michael@0: function continueTests1() { michael@0: gBrowser.selectedTab.removeEventListener("TabFindInitialized", michael@0: continueTests1); michael@0: ok(true, "'TabFindInitialized' event properly dispatched!"); michael@0: ok(gFindBar.hidden, "Second tab doesn't show find bar!"); michael@0: gFindBar.open(); michael@0: is(gFindBar._findField.value, texts[0], michael@0: "Second tab kept old find value for new initialization!"); michael@0: setFindString(texts[1]); michael@0: michael@0: // Confirm the first tab is still correct, ensure re-hiding works as expected michael@0: gBrowser.selectedTab = tabs[0]; michael@0: ok(!gFindBar.hidden, "First tab shows find bar!"); michael@0: // When the Find Clipboard is supported, this test not relevant. michael@0: if (!HasFindClipboard) michael@0: is(gFindBar._findField.value, texts[0], "First tab persists find value!"); michael@0: ok(gFindBar.getElement("highlight").checked, michael@0: "Highlight button state persists!"); michael@0: michael@0: // While we're here, let's test bug 253793 michael@0: gBrowser.reload(); michael@0: gBrowser.addEventListener("DOMContentLoaded", continueTests2, true); michael@0: } michael@0: michael@0: function continueTests2() { michael@0: gBrowser.removeEventListener("DOMContentLoaded", continueTests2, true); michael@0: ok(!gFindBar.getElement("highlight").checked, "Highlight button reset!"); michael@0: gFindBar.close(); michael@0: ok(gFindBar.hidden, "First tab doesn't show find bar!"); michael@0: gBrowser.selectedTab = tabs[1]; michael@0: ok(!gFindBar.hidden, "Second tab shows find bar!"); michael@0: // Test for bug 892384 michael@0: is(gFindBar._findField.getAttribute("focused"), "true", michael@0: "Open findbar refocused on tab change!"); michael@0: gURLBar.focus(); michael@0: gBrowser.selectedTab = tabs[0]; michael@0: ok(gFindBar.hidden, "First tab doesn't show find bar!"); michael@0: michael@0: // Set up a third tab, no tests here michael@0: gBrowser.selectedTab = tabs[2]; michael@0: setFindString(texts[2]); michael@0: michael@0: // Now we jump to the second, then first, and then fourth michael@0: gBrowser.selectedTab = tabs[1]; michael@0: // Test for bug 892384 michael@0: ok(!gFindBar._findField.hasAttribute("focused"), michael@0: "Open findbar not refocused on tab change!"); michael@0: gBrowser.selectedTab = tabs[0]; michael@0: gBrowser.selectedTab = tabs[3]; michael@0: ok(gFindBar.hidden, "Fourth tab doesn't show find bar!"); michael@0: is(gFindBar, gBrowser.getFindBar(), "Find bar is right one!"); michael@0: gFindBar.open(); michael@0: // Disabled the following assertion due to intermittent failure on OSX 10.6 Debug. michael@0: if (!HasFindClipboard) { michael@0: is(gFindBar._findField.value, texts[1], michael@0: "Fourth tab has second tab's find value!"); michael@0: } michael@0: michael@0: newWindow = gBrowser.replaceTabWithWindow(tabs.pop()); michael@0: whenDelayedStartupFinished(newWindow, checkNewWindow); michael@0: } michael@0: michael@0: // Test that findbar gets restored when a tab is moved to a new window. michael@0: function checkNewWindow() { michael@0: ok(!newWindow.gFindBar.hidden, "New window shows find bar!"); michael@0: // Disabled the following assertion due to intermittent failure on OSX 10.6 Debug. michael@0: if (!HasFindClipboard) { michael@0: is(newWindow.gFindBar._findField.value, texts[1], michael@0: "New window find bar has correct find value!"); michael@0: } michael@0: ok(!newWindow.gFindBar.getElement("find-next").disabled, michael@0: "New window findbar has enabled buttons!"); michael@0: newWindow.close(); michael@0: finish(); michael@0: }