|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 const middleMousePastePref = "middlemouse.contentLoadURL"; |
|
5 const autoScrollPref = "general.autoScroll"; |
|
6 function test() { |
|
7 waitForExplicitFinish(); |
|
8 |
|
9 Services.prefs.setBoolPref(middleMousePastePref, true); |
|
10 Services.prefs.setBoolPref(autoScrollPref, false); |
|
11 let tab = gBrowser.selectedTab = gBrowser.addTab(); |
|
12 |
|
13 registerCleanupFunction(function () { |
|
14 Services.prefs.clearUserPref(middleMousePastePref); |
|
15 Services.prefs.clearUserPref(autoScrollPref); |
|
16 gBrowser.removeTab(tab); |
|
17 }); |
|
18 |
|
19 addPageShowListener(function () { |
|
20 let pagePrincipal = gBrowser.contentPrincipal; |
|
21 |
|
22 // copy javascript URI to the clipboard |
|
23 let url = "javascript:1+1"; |
|
24 waitForClipboard(url, |
|
25 function() { |
|
26 Components.classes["@mozilla.org/widget/clipboardhelper;1"] |
|
27 .getService(Components.interfaces.nsIClipboardHelper) |
|
28 .copyString(url, document); |
|
29 }, |
|
30 function () { |
|
31 // Middle click on the content area |
|
32 info("Middle clicking"); |
|
33 EventUtils.sendMouseEvent({type: "click", button: 1}, gBrowser); |
|
34 }, |
|
35 function() { |
|
36 ok(false, "Failed to copy URL to the clipboard"); |
|
37 finish(); |
|
38 } |
|
39 ); |
|
40 |
|
41 addPageShowListener(function () { |
|
42 is(gBrowser.currentURI.spec, url, "url loaded by middle click"); |
|
43 ok(!gBrowser.contentPrincipal.equals(pagePrincipal), |
|
44 "middle click load of " + url + " should produce a page with a different principal"); |
|
45 finish(); |
|
46 }); |
|
47 }); |
|
48 } |
|
49 |
|
50 function addPageShowListener(func) { |
|
51 gBrowser.selectedBrowser.addEventListener("pageshow", function loadListener() { |
|
52 gBrowser.selectedBrowser.removeEventListener("pageshow", loadListener, false); |
|
53 func(); |
|
54 }); |
|
55 } |