summaryrefslogtreecommitdiffstats
path: root/dom/browser-element/mochitest/browserElement_OpenTab.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/browser-element/mochitest/browserElement_OpenTab.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/browser-element/mochitest/browserElement_OpenTab.js')
-rw-r--r--dom/browser-element/mochitest/browserElement_OpenTab.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/dom/browser-element/mochitest/browserElement_OpenTab.js b/dom/browser-element/mochitest/browserElement_OpenTab.js
new file mode 100644
index 000000000..d01927e9b
--- /dev/null
+++ b/dom/browser-element/mochitest/browserElement_OpenTab.js
@@ -0,0 +1,69 @@
+/* Any copyright is dedicated to the public domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Bug 1144015 - test middle/ctrl/cmd-click on a link.
+
+"use strict";
+SimpleTest.waitForExplicitFinish();
+browserElementTestHelpers.setEnabledPref(true);
+browserElementTestHelpers.addPermission();
+
+function runTest() {
+ let iframe = document.createElement('iframe');
+ iframe.setAttribute('mozbrowser', 'true');
+ document.body.appendChild(iframe);
+
+ let x = 2;
+ let y = 2;
+ // First we force a reflow so that getChildProcessOffset actually returns
+ // meaningful data.
+ iframe.getBoundingClientRect();
+ // We need to make sure the event coordinates are actually inside the iframe,
+ // relative to the chome window.
+ let tabParent = SpecialPowers.wrap(iframe)
+ .QueryInterface(SpecialPowers.Ci.nsIFrameLoaderOwner)
+ .frameLoader.tabParent;
+ if (tabParent) {
+ let offsetX = {};
+ let offsetY = {};
+ tabParent.getChildProcessOffset(offsetX, offsetY);
+ x -= offsetX.value;
+ y -= offsetY.value;
+ }
+
+ let sendCtrlClick = () => {
+ let nsIDOMWindowUtils = SpecialPowers.Ci.nsIDOMWindowUtils;
+ let mod = nsIDOMWindowUtils.MODIFIER_META |
+ nsIDOMWindowUtils.MODIFIER_CONTROL;
+ iframe.sendMouseEvent('mousedown', x, y, 0, 1, mod);
+ iframe.sendMouseEvent('mouseup', x, y, 0, 1, mod);
+ }
+
+ let onCtrlClick = e => {
+ is(e.detail.url, 'http://example.com/', 'URL matches');
+ iframe.removeEventListener('mozbrowseropentab', onCtrlClick);
+ iframe.addEventListener('mozbrowseropentab', onMiddleClick);
+ sendMiddleClick();
+ }
+
+ let sendMiddleClick = () => {
+ iframe.sendMouseEvent('mousedown', x, y, 1, 1, 0);
+ iframe.sendMouseEvent('mouseup', x, y, 1, 1, 0);
+ }
+
+ let onMiddleClick = e => {
+ is(e.detail.url, 'http://example.com/', 'URL matches');
+ iframe.removeEventListener('mozbrowseropentab', onMiddleClick);
+ SimpleTest.finish();
+ }
+
+ iframe.addEventListener('mozbrowserloadend', e => {
+ iframe.addEventListener('mozbrowseropentab', onCtrlClick);
+ sendCtrlClick();
+ });
+
+
+ iframe.src = 'data:text/html,<body style="margin:0"><a href="http://example.com"><span>click here</span></a></body>';
+}
+
+addEventListener('testready', runTest);