1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_zbug569342.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +var gTab = null; 1.9 + 1.10 +function load(url, cb) { 1.11 + gTab = gBrowser.addTab(url); 1.12 + gBrowser.addEventListener("load", function (event) { 1.13 + if (event.target.location != url) 1.14 + return; 1.15 + 1.16 + gBrowser.removeEventListener("load", arguments.callee, true); 1.17 + // Trigger onLocationChange by switching tabs. 1.18 + gBrowser.selectedTab = gTab; 1.19 + cb(); 1.20 + }, true); 1.21 +} 1.22 + 1.23 +function test() { 1.24 + waitForExplicitFinish(); 1.25 + 1.26 + ok(gFindBar.hidden, "Find bar should not be visible by default"); 1.27 + 1.28 + // Open the Find bar before we navigate to pages that shouldn't have it. 1.29 + EventUtils.synthesizeKey("f", { accelKey: true }); 1.30 + ok(!gFindBar.hidden, "Find bar should be visible"); 1.31 + 1.32 + nextTest(); 1.33 +} 1.34 + 1.35 +let urls = [ 1.36 + "about:config", 1.37 + "about:addons", 1.38 + "about:permissions" 1.39 +]; 1.40 + 1.41 +function nextTest() { 1.42 + let url = urls.shift(); 1.43 + if (url) { 1.44 + testFindDisabled(url, nextTest); 1.45 + } else { 1.46 + // Make sure the find bar is re-enabled after disabled page is closed. 1.47 + testFindEnabled("about:blank", function () { 1.48 + EventUtils.synthesizeKey("VK_ESCAPE", { }); 1.49 + ok(gFindBar.hidden, "Find bar should now be hidden"); 1.50 + finish(); 1.51 + }); 1.52 + } 1.53 +} 1.54 + 1.55 +function testFindDisabled(url, cb) { 1.56 + load(url, function() { 1.57 + ok(gFindBar.hidden, "Find bar should not be visible"); 1.58 + EventUtils.synthesizeKey("/", {}, gTab.linkedBrowser.contentWindow); 1.59 + ok(gFindBar.hidden, "Find bar should not be visible"); 1.60 + EventUtils.synthesizeKey("f", { accelKey: true }); 1.61 + ok(gFindBar.hidden, "Find bar should not be visible"); 1.62 + ok(document.getElementById("cmd_find").getAttribute("disabled"), 1.63 + "Find command should be disabled"); 1.64 + 1.65 + gBrowser.removeTab(gTab); 1.66 + cb(); 1.67 + }); 1.68 +} 1.69 + 1.70 +function testFindEnabled(url, cb) { 1.71 + load(url, function() { 1.72 + ok(!document.getElementById("cmd_find").getAttribute("disabled"), 1.73 + "Find command should not be disabled"); 1.74 + 1.75 + // Open Find bar and then close it. 1.76 + EventUtils.synthesizeKey("f", { accelKey: true }); 1.77 + ok(!gFindBar.hidden, "Find bar should be visible again"); 1.78 + EventUtils.synthesizeKey("VK_ESCAPE", { }); 1.79 + ok(gFindBar.hidden, "Find bar should now be hidden"); 1.80 + 1.81 + gBrowser.removeTab(gTab); 1.82 + cb(); 1.83 + }); 1.84 +}