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