diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/base/content/test/general/browser_bug537013.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/test/general/browser_bug537013.js')
-rw-r--r-- | browser/base/content/test/general/browser_bug537013.js | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/browser/base/content/test/general/browser_bug537013.js b/browser/base/content/test/general/browser_bug537013.js new file mode 100644 index 0000000000..5c871a759c --- /dev/null +++ b/browser/base/content/test/general/browser_bug537013.js @@ -0,0 +1,168 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/* Tests for bug 537013 to ensure proper tab-sequestration of find bar. */ + +var tabs = []; +var texts = [ + "This side up.", + "The world is coming to an end. Please log off.", + "Klein bottle for sale. Inquire within.", + "To err is human; to forgive is not company policy.", +]; + +var HasFindClipboard = Services.clipboard.isClipboardTypeSupported( + Services.clipboard.kFindClipboard +); + +function addTabWithText(aText, aCallback) { + let newTab = BrowserTestUtils.addTab( + gBrowser, + "data:text/html;charset=utf-8,<h1 id='h1'>" + aText + "</h1>" + ); + tabs.push(newTab); + gBrowser.selectedTab = newTab; +} + +function setFindString(aString) { + gFindBar.open(); + gFindBar._findField.focus(); + gFindBar._findField.select(); + EventUtils.sendString(aString); + is(gFindBar._findField.value, aString, "Set the field correctly!"); +} + +var newWindow; + +function test() { + waitForExplicitFinish(); + registerCleanupFunction(function () { + while (tabs.length) { + gBrowser.removeTab(tabs.pop()); + } + }); + texts.forEach(aText => addTabWithText(aText)); + + // Set up the first tab + gBrowser.selectedTab = tabs[0]; + + gBrowser.getFindBar().then(initialTest); +} + +function initialTest() { + setFindString(texts[0]); + // Turn on highlight for testing bug 891638 + gFindBar.getElement("highlight").checked = true; + + // Make sure the second tab is correct, then set it up + gBrowser.selectedTab = tabs[1]; + gBrowser.selectedTab.addEventListener("TabFindInitialized", continueTests1, { + once: true, + }); + // Initialize the findbar + gBrowser.getFindBar(); +} +function continueTests1() { + ok(true, "'TabFindInitialized' event properly dispatched!"); + ok(gFindBar.hidden, "Second tab doesn't show find bar!"); + gFindBar.open(); + is( + gFindBar._findField.value, + texts[0], + "Second tab kept old find value for new initialization!" + ); + setFindString(texts[1]); + + // Confirm the first tab is still correct, ensure re-hiding works as expected + gBrowser.selectedTab = tabs[0]; + ok(!gFindBar.hidden, "First tab shows find bar!"); + // When the Find Clipboard is supported, this test not relevant. + if (!HasFindClipboard) { + is(gFindBar._findField.value, texts[0], "First tab persists find value!"); + } + ok( + gFindBar.getElement("highlight").checked, + "Highlight button state persists!" + ); + + // While we're here, let's test bug 253793 + gBrowser.reload(); + gBrowser.addEventListener("DOMContentLoaded", continueTests2, true); +} + +function continueTests2() { + gBrowser.removeEventListener("DOMContentLoaded", continueTests2, true); + ok(gFindBar.getElement("highlight").checked, "Highlight never reset!"); + continueTests3(); +} + +function continueTests3() { + ok(gFindBar.getElement("highlight").checked, "Highlight button reset!"); + gFindBar.close(); + ok(gFindBar.hidden, "First tab doesn't show find bar!"); + gBrowser.selectedTab = tabs[1]; + ok(!gFindBar.hidden, "Second tab shows find bar!"); + // Test for bug 892384 + is( + gFindBar._findField.getAttribute("focused"), + "true", + "Open findbar refocused on tab change!" + ); + gURLBar.focus(); + gBrowser.selectedTab = tabs[0]; + ok(gFindBar.hidden, "First tab doesn't show find bar!"); + + // Set up a third tab, no tests here + gBrowser.selectedTab = tabs[2]; + gBrowser.selectedTab.addEventListener("TabFindInitialized", continueTests4, { + once: true, + }); + gBrowser.getFindBar(); +} + +function continueTests4() { + setFindString(texts[2]); + + // Now we jump to the second, then first, and then fourth + gBrowser.selectedTab = tabs[1]; + // Test for bug 892384 + ok( + !gFindBar._findField.hasAttribute("focused"), + "Open findbar not refocused on tab change!" + ); + gBrowser.selectedTab = tabs[0]; + gBrowser.selectedTab = tabs[3]; + ok(gFindBar.hidden, "Fourth tab doesn't show find bar!"); + is(gFindBar, gBrowser.getFindBar(), "Find bar is right one!"); + gFindBar.open(); + // Disabled the following assertion due to intermittent failure on OSX 10.6 Debug. + if (!HasFindClipboard) { + is( + gFindBar._findField.value, + texts[1], + "Fourth tab has second tab's find value!" + ); + } + + newWindow = gBrowser.replaceTabWithWindow(tabs.pop()); + whenDelayedStartupFinished(newWindow, checkNewWindow); +} + +// Test that findbar gets restored when a tab is moved to a new window. +function checkNewWindow() { + ok(!newWindow.gFindBar.hidden, "New window shows find bar!"); + // Disabled the following assertion due to intermittent failure on OSX 10.6 Debug. + if (!HasFindClipboard) { + is( + newWindow.gFindBar._findField.value, + texts[1], + "New window find bar has correct find value!" + ); + ok( + !newWindow.gFindBar.getElement("find-next").disabled, + "New window findbar has enabled buttons!" + ); + } + newWindow.close(); + finish(); +} |