1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_locationBarExternalLoad.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,65 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +function test() { 1.8 + waitForExplicitFinish(); 1.9 + 1.10 + nextTest(); 1.11 +} 1.12 + 1.13 +let urls = [ 1.14 + "javascript:'foopy';", 1.15 + "data:text/html,<body>hi" 1.16 +]; 1.17 + 1.18 +function urlEnter(url) { 1.19 + gURLBar.value = url; 1.20 + gURLBar.focus(); 1.21 + EventUtils.synthesizeKey("VK_RETURN", {}); 1.22 +} 1.23 + 1.24 +function urlClick(url) { 1.25 + gURLBar.value = url; 1.26 + gURLBar.focus(); 1.27 + let goButton = document.getElementById("urlbar-go-button"); 1.28 + EventUtils.synthesizeMouseAtCenter(goButton, {}); 1.29 +} 1.30 + 1.31 +function nextTest() { 1.32 + let url = urls.shift(); 1.33 + if (url) { 1.34 + testURL(url, urlEnter, function () { 1.35 + testURL(url, urlClick, nextTest); 1.36 + }); 1.37 + } 1.38 + else 1.39 + finish(); 1.40 +} 1.41 + 1.42 +function testURL(url, loadFunc, endFunc) { 1.43 + let tab = gBrowser.selectedTab = gBrowser.addTab(); 1.44 + registerCleanupFunction(function () { 1.45 + gBrowser.removeTab(tab); 1.46 + }); 1.47 + addPageShowListener(function () { 1.48 + let pagePrincipal = gBrowser.contentPrincipal; 1.49 + loadFunc(url); 1.50 + 1.51 + addPageShowListener(function () { 1.52 + let fm = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager); 1.53 + is(fm.focusedElement, null, "should be no focused element"); 1.54 + is(fm.focusedWindow, gBrowser.contentWindow, "content window should be focused"); 1.55 + 1.56 + ok(!gBrowser.contentPrincipal.equals(pagePrincipal), 1.57 + "load of " + url + " by " + loadFunc.name + " should produce a page with a different principal"); 1.58 + endFunc(); 1.59 + }); 1.60 + }); 1.61 +} 1.62 + 1.63 +function addPageShowListener(func) { 1.64 + gBrowser.selectedBrowser.addEventListener("pageshow", function loadListener() { 1.65 + gBrowser.selectedBrowser.removeEventListener("pageshow", loadListener, false); 1.66 + func(); 1.67 + }); 1.68 +}