michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: const middleMousePastePref = "middlemouse.contentLoadURL"; michael@0: const autoScrollPref = "general.autoScroll"; michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: Services.prefs.setBoolPref(middleMousePastePref, true); michael@0: Services.prefs.setBoolPref(autoScrollPref, false); michael@0: let tab = gBrowser.selectedTab = gBrowser.addTab(); michael@0: michael@0: registerCleanupFunction(function () { michael@0: Services.prefs.clearUserPref(middleMousePastePref); michael@0: Services.prefs.clearUserPref(autoScrollPref); michael@0: gBrowser.removeTab(tab); michael@0: }); michael@0: michael@0: addPageShowListener(function () { michael@0: let pagePrincipal = gBrowser.contentPrincipal; michael@0: michael@0: // copy javascript URI to the clipboard michael@0: let url = "javascript:1+1"; michael@0: waitForClipboard(url, michael@0: function() { michael@0: Components.classes["@mozilla.org/widget/clipboardhelper;1"] michael@0: .getService(Components.interfaces.nsIClipboardHelper) michael@0: .copyString(url, document); michael@0: }, michael@0: function () { michael@0: // Middle click on the content area michael@0: info("Middle clicking"); michael@0: EventUtils.sendMouseEvent({type: "click", button: 1}, gBrowser); michael@0: }, michael@0: function() { michael@0: ok(false, "Failed to copy URL to the clipboard"); michael@0: finish(); michael@0: } michael@0: ); michael@0: michael@0: addPageShowListener(function () { michael@0: is(gBrowser.currentURI.spec, url, "url loaded by middle click"); michael@0: ok(!gBrowser.contentPrincipal.equals(pagePrincipal), michael@0: "middle click load of " + url + " should produce a page with a different principal"); michael@0: finish(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function addPageShowListener(func) { michael@0: gBrowser.selectedBrowser.addEventListener("pageshow", function loadListener() { michael@0: gBrowser.selectedBrowser.removeEventListener("pageshow", loadListener, false); michael@0: func(); michael@0: }); michael@0: }