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 | function test() { |
michael@0 | 5 | waitForExplicitFinish(); |
michael@0 | 6 | |
michael@0 | 7 | nextTest(); |
michael@0 | 8 | } |
michael@0 | 9 | |
michael@0 | 10 | let urls = [ |
michael@0 | 11 | "javascript:'foopy';", |
michael@0 | 12 | "data:text/html,<body>hi" |
michael@0 | 13 | ]; |
michael@0 | 14 | |
michael@0 | 15 | function urlEnter(url) { |
michael@0 | 16 | gURLBar.value = url; |
michael@0 | 17 | gURLBar.focus(); |
michael@0 | 18 | EventUtils.synthesizeKey("VK_RETURN", {}); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | function urlClick(url) { |
michael@0 | 22 | gURLBar.value = url; |
michael@0 | 23 | gURLBar.focus(); |
michael@0 | 24 | let goButton = document.getElementById("urlbar-go-button"); |
michael@0 | 25 | EventUtils.synthesizeMouseAtCenter(goButton, {}); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function nextTest() { |
michael@0 | 29 | let url = urls.shift(); |
michael@0 | 30 | if (url) { |
michael@0 | 31 | testURL(url, urlEnter, function () { |
michael@0 | 32 | testURL(url, urlClick, nextTest); |
michael@0 | 33 | }); |
michael@0 | 34 | } |
michael@0 | 35 | else |
michael@0 | 36 | finish(); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function testURL(url, loadFunc, endFunc) { |
michael@0 | 40 | let tab = gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 41 | registerCleanupFunction(function () { |
michael@0 | 42 | gBrowser.removeTab(tab); |
michael@0 | 43 | }); |
michael@0 | 44 | addPageShowListener(function () { |
michael@0 | 45 | let pagePrincipal = gBrowser.contentPrincipal; |
michael@0 | 46 | loadFunc(url); |
michael@0 | 47 | |
michael@0 | 48 | addPageShowListener(function () { |
michael@0 | 49 | let fm = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager); |
michael@0 | 50 | is(fm.focusedElement, null, "should be no focused element"); |
michael@0 | 51 | is(fm.focusedWindow, gBrowser.contentWindow, "content window should be focused"); |
michael@0 | 52 | |
michael@0 | 53 | ok(!gBrowser.contentPrincipal.equals(pagePrincipal), |
michael@0 | 54 | "load of " + url + " by " + loadFunc.name + " should produce a page with a different principal"); |
michael@0 | 55 | endFunc(); |
michael@0 | 56 | }); |
michael@0 | 57 | }); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function addPageShowListener(func) { |
michael@0 | 61 | gBrowser.selectedBrowser.addEventListener("pageshow", function loadListener() { |
michael@0 | 62 | gBrowser.selectedBrowser.removeEventListener("pageshow", loadListener, false); |
michael@0 | 63 | func(); |
michael@0 | 64 | }); |
michael@0 | 65 | } |