1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_bug537013.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,129 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/* Tests for bug 537013 to ensure proper tab-sequestration of find bar. */ 1.8 + 1.9 +let tabs = []; 1.10 +let texts = [ 1.11 + "This side up.", 1.12 + "The world is coming to an end. Please log off.", 1.13 + "Klein bottle for sale. Inquire within.", 1.14 + "To err is human; to forgive is not company policy." 1.15 +]; 1.16 + 1.17 +let Clipboard = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard); 1.18 +let HasFindClipboard = Clipboard.supportsFindClipboard(); 1.19 + 1.20 +function addTabWithText(aText, aCallback) { 1.21 + let newTab = gBrowser.addTab("data:text/html,<h1 id='h1'>" + aText + "</h1>"); 1.22 + tabs.push(newTab); 1.23 + gBrowser.selectedTab = newTab; 1.24 +} 1.25 + 1.26 +function setFindString(aString) { 1.27 + gFindBar.open(); 1.28 + gFindBar._findField.focus(); 1.29 + gFindBar._findField.select(); 1.30 + EventUtils.sendString(aString); 1.31 + is(gFindBar._findField.value, aString, "Set the field correctly!"); 1.32 +} 1.33 + 1.34 +let newWindow; 1.35 + 1.36 +function test() { 1.37 + waitForExplicitFinish(); 1.38 + registerCleanupFunction(function () { 1.39 + while (tabs.length) { 1.40 + gBrowser.removeTab(tabs.pop()); 1.41 + } 1.42 + }); 1.43 + texts.forEach(function(aText) addTabWithText(aText)); 1.44 + 1.45 + // Set up the first tab 1.46 + gBrowser.selectedTab = tabs[0]; 1.47 + 1.48 + setFindString(texts[0]); 1.49 + // Turn on highlight for testing bug 891638 1.50 + gFindBar.getElement("highlight").checked = true; 1.51 + 1.52 + // Make sure the second tab is correct, then set it up 1.53 + gBrowser.selectedTab = tabs[1]; 1.54 + gBrowser.selectedTab.addEventListener("TabFindInitialized", continueTests1); 1.55 + // Initialize the findbar 1.56 + gFindBar; 1.57 +} 1.58 +function continueTests1() { 1.59 + gBrowser.selectedTab.removeEventListener("TabFindInitialized", 1.60 + continueTests1); 1.61 + ok(true, "'TabFindInitialized' event properly dispatched!"); 1.62 + ok(gFindBar.hidden, "Second tab doesn't show find bar!"); 1.63 + gFindBar.open(); 1.64 + is(gFindBar._findField.value, texts[0], 1.65 + "Second tab kept old find value for new initialization!"); 1.66 + setFindString(texts[1]); 1.67 + 1.68 + // Confirm the first tab is still correct, ensure re-hiding works as expected 1.69 + gBrowser.selectedTab = tabs[0]; 1.70 + ok(!gFindBar.hidden, "First tab shows find bar!"); 1.71 + // When the Find Clipboard is supported, this test not relevant. 1.72 + if (!HasFindClipboard) 1.73 + is(gFindBar._findField.value, texts[0], "First tab persists find value!"); 1.74 + ok(gFindBar.getElement("highlight").checked, 1.75 + "Highlight button state persists!"); 1.76 + 1.77 + // While we're here, let's test bug 253793 1.78 + gBrowser.reload(); 1.79 + gBrowser.addEventListener("DOMContentLoaded", continueTests2, true); 1.80 +} 1.81 + 1.82 +function continueTests2() { 1.83 + gBrowser.removeEventListener("DOMContentLoaded", continueTests2, true); 1.84 + ok(!gFindBar.getElement("highlight").checked, "Highlight button reset!"); 1.85 + gFindBar.close(); 1.86 + ok(gFindBar.hidden, "First tab doesn't show find bar!"); 1.87 + gBrowser.selectedTab = tabs[1]; 1.88 + ok(!gFindBar.hidden, "Second tab shows find bar!"); 1.89 + // Test for bug 892384 1.90 + is(gFindBar._findField.getAttribute("focused"), "true", 1.91 + "Open findbar refocused on tab change!"); 1.92 + gURLBar.focus(); 1.93 + gBrowser.selectedTab = tabs[0]; 1.94 + ok(gFindBar.hidden, "First tab doesn't show find bar!"); 1.95 + 1.96 + // Set up a third tab, no tests here 1.97 + gBrowser.selectedTab = tabs[2]; 1.98 + setFindString(texts[2]); 1.99 + 1.100 + // Now we jump to the second, then first, and then fourth 1.101 + gBrowser.selectedTab = tabs[1]; 1.102 + // Test for bug 892384 1.103 + ok(!gFindBar._findField.hasAttribute("focused"), 1.104 + "Open findbar not refocused on tab change!"); 1.105 + gBrowser.selectedTab = tabs[0]; 1.106 + gBrowser.selectedTab = tabs[3]; 1.107 + ok(gFindBar.hidden, "Fourth tab doesn't show find bar!"); 1.108 + is(gFindBar, gBrowser.getFindBar(), "Find bar is right one!"); 1.109 + gFindBar.open(); 1.110 + // Disabled the following assertion due to intermittent failure on OSX 10.6 Debug. 1.111 + if (!HasFindClipboard) { 1.112 + is(gFindBar._findField.value, texts[1], 1.113 + "Fourth tab has second tab's find value!"); 1.114 + } 1.115 + 1.116 + newWindow = gBrowser.replaceTabWithWindow(tabs.pop()); 1.117 + whenDelayedStartupFinished(newWindow, checkNewWindow); 1.118 +} 1.119 + 1.120 +// Test that findbar gets restored when a tab is moved to a new window. 1.121 +function checkNewWindow() { 1.122 + ok(!newWindow.gFindBar.hidden, "New window shows find bar!"); 1.123 + // Disabled the following assertion due to intermittent failure on OSX 10.6 Debug. 1.124 + if (!HasFindClipboard) { 1.125 + is(newWindow.gFindBar._findField.value, texts[1], 1.126 + "New window find bar has correct find value!"); 1.127 + } 1.128 + ok(!newWindow.gFindBar.getElement("find-next").disabled, 1.129 + "New window findbar has enabled buttons!"); 1.130 + newWindow.close(); 1.131 + finish(); 1.132 +}