1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_middleMouse_inherit.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,55 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +const middleMousePastePref = "middlemouse.contentLoadURL"; 1.8 +const autoScrollPref = "general.autoScroll"; 1.9 +function test() { 1.10 + waitForExplicitFinish(); 1.11 + 1.12 + Services.prefs.setBoolPref(middleMousePastePref, true); 1.13 + Services.prefs.setBoolPref(autoScrollPref, false); 1.14 + let tab = gBrowser.selectedTab = gBrowser.addTab(); 1.15 + 1.16 + registerCleanupFunction(function () { 1.17 + Services.prefs.clearUserPref(middleMousePastePref); 1.18 + Services.prefs.clearUserPref(autoScrollPref); 1.19 + gBrowser.removeTab(tab); 1.20 + }); 1.21 + 1.22 + addPageShowListener(function () { 1.23 + let pagePrincipal = gBrowser.contentPrincipal; 1.24 + 1.25 + // copy javascript URI to the clipboard 1.26 + let url = "javascript:1+1"; 1.27 + waitForClipboard(url, 1.28 + function() { 1.29 + Components.classes["@mozilla.org/widget/clipboardhelper;1"] 1.30 + .getService(Components.interfaces.nsIClipboardHelper) 1.31 + .copyString(url, document); 1.32 + }, 1.33 + function () { 1.34 + // Middle click on the content area 1.35 + info("Middle clicking"); 1.36 + EventUtils.sendMouseEvent({type: "click", button: 1}, gBrowser); 1.37 + }, 1.38 + function() { 1.39 + ok(false, "Failed to copy URL to the clipboard"); 1.40 + finish(); 1.41 + } 1.42 + ); 1.43 + 1.44 + addPageShowListener(function () { 1.45 + is(gBrowser.currentURI.spec, url, "url loaded by middle click"); 1.46 + ok(!gBrowser.contentPrincipal.equals(pagePrincipal), 1.47 + "middle click load of " + url + " should produce a page with a different principal"); 1.48 + finish(); 1.49 + }); 1.50 + }); 1.51 +} 1.52 + 1.53 +function addPageShowListener(func) { 1.54 + gBrowser.selectedBrowser.addEventListener("pageshow", function loadListener() { 1.55 + gBrowser.selectedBrowser.removeEventListener("pageshow", loadListener, false); 1.56 + func(); 1.57 + }); 1.58 +}