Bug 1425818 - Stop using CPOW in devtools/server/tests/browser/browser_canvasframe_helper_*.js. r=pbro

MozReview-Commit-ID: 70IEX3Q5iGa

--HG--
extra : rebase_source : 970990e5425eab8c5a1914fef86a4b539030b3f0
This commit is contained in:
Alexandre Poirot 2017-12-18 02:21:41 -08:00
Родитель 11a1f0db42
Коммит 6d25219f3c
10 изменённых файлов: 487 добавлений и 460 удалений

Просмотреть файл

@ -693,3 +693,47 @@ function createTestHTTPServer() {
server.start(-1);
return server;
}
/**
* Inject `EventUtils` helpers into ContentTask scope.
*
* This helper is automatically exposed to mochitest browser tests,
* but is missing from content task scope.
* You should call this method only once per <browser> tag
*
* @param {xul:browser} browser
* Reference to the browser in which we load content task
*/
async function injectEventUtilsInContentTask(browser) {
await ContentTask.spawn(browser, {}, function* () {
if ("EventUtils" in this) {
return;
}
let EventUtils = this.EventUtils = {};
EventUtils.window = {};
EventUtils.parent = EventUtils.window;
/* eslint-disable camelcase */
EventUtils._EU_Ci = Components.interfaces;
EventUtils._EU_Cc = Components.classes;
/* eslint-enable camelcase */
// EventUtils' `sendChar` function relies on the navigator to synthetize events.
EventUtils.navigator = content.navigator;
EventUtils.KeyboardEvent = content.KeyboardEvent;
EventUtils.synthesizeClick = element => new Promise(resolve => {
element.addEventListener("click", function () {
resolve();
}, {once: true});
EventUtils.synthesizeMouseAtCenter(element,
{ type: "mousedown", isSynthesized: false }, content);
EventUtils.synthesizeMouseAtCenter(element,
{ type: "mouseup", isSynthesized: false }, content);
});
Services.scriptloader.loadSubScript(
"chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
});
}

Просмотреть файл

@ -9,6 +9,8 @@ const TEST_URL = `${URL_ROOT}touch.html`;
const PREF_DOM_META_VIEWPORT_ENABLED = "dom.meta-viewport.enabled";
addRDMTask(TEST_URL, function* ({ ui }) {
yield injectEventUtilsInContentTask(ui.getViewportBrowser());
yield waitBootstrap(ui);
yield testWithNoTouch(ui);
yield toggleTouchSimulation(ui);
@ -19,10 +21,7 @@ addRDMTask(TEST_URL, function* ({ ui }) {
});
function* testWithNoTouch(ui) {
yield injectEventUtils(ui);
yield ContentTask.spawn(ui.getViewportBrowser(), {}, function* () {
let { EventUtils } = content;
let div = content.document.querySelector("div");
let x = 0, y = 0;
@ -62,11 +61,7 @@ function* testWithNoTouch(ui) {
}
function* testWithTouch(ui) {
yield injectEventUtils(ui);
yield ContentTask.spawn(ui.getViewportBrowser(), {}, function* () {
let { EventUtils } = content;
let div = content.document.querySelector("div");
let x = 0, y = 0;
@ -105,10 +100,8 @@ function* testWithTouch(ui) {
function* testWithMetaViewportEnabled(ui) {
yield SpecialPowers.pushPrefEnv({set: [[PREF_DOM_META_VIEWPORT_ENABLED, true]]});
yield injectEventUtils(ui);
yield ContentTask.spawn(ui.getViewportBrowser(), {}, function* () {
let { synthesizeClick } = content.EventUtils;
let { synthesizeClick } = EventUtils;
let meta = content.document.querySelector("meta[name=viewport]");
let div = content.document.querySelector("div");
@ -150,10 +143,8 @@ function* testWithMetaViewportEnabled(ui) {
function* testWithMetaViewportDisabled(ui) {
yield SpecialPowers.pushPrefEnv({set: [[PREF_DOM_META_VIEWPORT_ENABLED, false]]});
yield injectEventUtils(ui);
yield ContentTask.spawn(ui.getViewportBrowser(), {}, function* () {
let { synthesizeClick } = content.EventUtils;
let { synthesizeClick } = EventUtils;
let meta = content.document.querySelector("meta[name=viewport]");
let div = content.document.querySelector("div");
@ -191,37 +182,3 @@ function* waitBootstrap(ui) {
yield waitUntilState(store, state => state.viewports.length == 1);
yield waitForFrameLoad(ui, TEST_URL);
}
function* injectEventUtils(ui) {
yield ContentTask.spawn(ui.getViewportBrowser(), {}, function* () {
if ("EventUtils" in content) {
return;
}
let EventUtils = content.EventUtils = {};
EventUtils.window = {};
EventUtils.parent = EventUtils.window;
/* eslint-disable camelcase */
EventUtils._EU_Ci = Components.interfaces;
EventUtils._EU_Cc = Components.classes;
/* eslint-enable camelcase */
// EventUtils' `sendChar` function relies on the navigator to synthetize events.
EventUtils.navigator = content.navigator;
EventUtils.KeyboardEvent = content.KeyboardEvent;
EventUtils.synthesizeClick = element => new Promise(resolve => {
element.addEventListener("click", function () {
resolve();
}, {once: true});
EventUtils.synthesizeMouseAtCenter(element,
{ type: "mousedown", isSynthesized: false }, content);
EventUtils.synthesizeMouseAtCenter(element,
{ type: "mouseup", isSynthesized: false }, content);
});
Services.scriptloader.loadSubScript(
"chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
});
}

Просмотреть файл

@ -25,6 +25,7 @@ support-files =
timeline-iframe-parent.html
storage-helpers.js
!/devtools/server/tests/mochitest/hello-actor.js
!/devtools/client/framework/test/shared-head.js
[browser_accessibility_node_events.js]
[browser_accessibility_node.js]

Просмотреть файл

@ -6,86 +6,84 @@
// Simple CanvasFrameAnonymousContentHelper tests.
// This makes sure the 'domnode' protocol actor type is known when importing
// highlighter.
require("devtools/server/actors/inspector");
const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
const {
CanvasFrameAnonymousContentHelper
} = require("devtools/server/actors/highlighters/utils/markup");
const TEST_URL = "data:text/html;charset=utf-8,CanvasFrameAnonymousContentHelper test";
add_task(function* () {
let browser = yield addTab(TEST_URL);
// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = browser.contentDocument;
add_task(async function () {
let browser = await addTab(TEST_URL);
let nodeBuilder = () => {
let root = doc.createElement("div");
let child = doc.createElement("div");
child.style = "width:200px;height:200px;background:red;";
child.id = "child-element";
child.className = "child-element";
child.textContent = "test element";
root.appendChild(child);
return root;
};
await ContentTask.spawn(browser, null, async function () {
const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
const {
CanvasFrameAnonymousContentHelper
} = require("devtools/server/actors/highlighters/utils/markup");
let doc = content.document;
info("Building the helper");
let env = new HighlighterEnvironment();
env.initFromWindow(doc.defaultView);
let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
let nodeBuilder = () => {
let root = doc.createElement("div");
let child = doc.createElement("div");
child.style = "width:200px;height:200px;background:red;";
child.id = "child-element";
child.className = "child-element";
child.textContent = "test element";
root.appendChild(child);
return root;
};
ok(helper.content instanceof AnonymousContent,
"The helper owns the AnonymousContent object");
ok(helper.getTextContentForElement,
"The helper has the getTextContentForElement method");
ok(helper.setTextContentForElement,
"The helper has the setTextContentForElement method");
ok(helper.setAttributeForElement,
"The helper has the setAttributeForElement method");
ok(helper.getAttributeForElement,
"The helper has the getAttributeForElement method");
ok(helper.removeAttributeForElement,
"The helper has the removeAttributeForElement method");
ok(helper.addEventListenerForElement,
"The helper has the addEventListenerForElement method");
ok(helper.removeEventListenerForElement,
"The helper has the removeEventListenerForElement method");
ok(helper.getElement,
"The helper has the getElement method");
ok(helper.scaleRootElement,
"The helper has the scaleRootElement method");
info("Building the helper");
let env = new HighlighterEnvironment();
env.initFromWindow(doc.defaultView);
let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
is(helper.getTextContentForElement("child-element"), "test element",
"The text content was retrieve correctly");
is(helper.getAttributeForElement("child-element", "id"), "child-element",
"The ID attribute was retrieve correctly");
is(helper.getAttributeForElement("child-element", "class"), "child-element",
"The class attribute was retrieve correctly");
ok(helper.content instanceof content.AnonymousContent,
"The helper owns the AnonymousContent object");
ok(helper.getTextContentForElement,
"The helper has the getTextContentForElement method");
ok(helper.setTextContentForElement,
"The helper has the setTextContentForElement method");
ok(helper.setAttributeForElement,
"The helper has the setAttributeForElement method");
ok(helper.getAttributeForElement,
"The helper has the getAttributeForElement method");
ok(helper.removeAttributeForElement,
"The helper has the removeAttributeForElement method");
ok(helper.addEventListenerForElement,
"The helper has the addEventListenerForElement method");
ok(helper.removeEventListenerForElement,
"The helper has the removeEventListenerForElement method");
ok(helper.getElement,
"The helper has the getElement method");
ok(helper.scaleRootElement,
"The helper has the scaleRootElement method");
let el = helper.getElement("child-element");
ok(el, "The DOMNode-like element was created");
is(helper.getTextContentForElement("child-element"), "test element",
"The text content was retrieve correctly");
is(helper.getAttributeForElement("child-element", "id"), "child-element",
"The ID attribute was retrieve correctly");
is(helper.getAttributeForElement("child-element", "class"), "child-element",
"The class attribute was retrieve correctly");
is(el.getTextContent(), "test element",
"The text content was retrieve correctly");
is(el.getAttribute("id"), "child-element",
"The ID attribute was retrieve correctly");
is(el.getAttribute("class"), "child-element",
"The class attribute was retrieve correctly");
let el = helper.getElement("child-element");
ok(el, "The DOMNode-like element was created");
info("Destroying the helper");
helper.destroy();
env.destroy();
is(el.getTextContent(), "test element",
"The text content was retrieve correctly");
is(el.getAttribute("id"), "child-element",
"The ID attribute was retrieve correctly");
is(el.getAttribute("class"), "child-element",
"The class attribute was retrieve correctly");
ok(!helper.getTextContentForElement("child-element"),
"No text content was retrieved after the helper was destroyed");
ok(!helper.getAttributeForElement("child-element", "id"),
"No ID attribute was retrieved after the helper was destroyed");
ok(!helper.getAttributeForElement("child-element", "class"),
"No class attribute was retrieved after the helper was destroyed");
info("Destroying the helper");
helper.destroy();
env.destroy();
ok(!helper.getTextContentForElement("child-element"),
"No text content was retrieved after the helper was destroyed");
ok(!helper.getAttributeForElement("child-element", "id"),
"No ID attribute was retrieved after the helper was destroyed");
ok(!helper.getAttributeForElement("child-element", "class"),
"No class attribute was retrieved after the helper was destroyed");
});
gBrowser.removeCurrentTab();
});

Просмотреть файл

@ -7,43 +7,40 @@
// Test that the CanvasFrameAnonymousContentHelper does not insert content in
// XUL windows.
// This makes sure the 'domnode' protocol actor type is known when importing
// highlighter.
require("devtools/server/actors/inspector");
add_task(async function () {
let browser = await addTab("about:preferences");
const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
await ContentTask.spawn(browser, null, async function () {
const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
const {
CanvasFrameAnonymousContentHelper
} = require("devtools/server/actors/highlighters/utils/markup");
let doc = content.document;
const {
CanvasFrameAnonymousContentHelper
} = require("devtools/server/actors/highlighters/utils/markup");
let nodeBuilder = () => {
let root = doc.createElement("div");
let child = doc.createElement("div");
child.style = "width:200px;height:200px;background:red;";
child.id = "child-element";
child.className = "child-element";
child.textContent = "test element";
root.appendChild(child);
return root;
};
add_task(function* () {
let browser = yield addTab("about:preferences");
// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = browser.contentDocument;
info("Building the helper");
let env = new HighlighterEnvironment();
env.initFromWindow(doc.defaultView);
let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
let nodeBuilder = () => {
let root = doc.createElement("div");
let child = doc.createElement("div");
child.style = "width:200px;height:200px;background:red;";
child.id = "child-element";
child.className = "child-element";
child.textContent = "test element";
root.appendChild(child);
return root;
};
ok(!helper.content, "The AnonymousContent was not inserted in the window");
ok(!helper.getTextContentForElement("child-element"),
"No text content is returned");
info("Building the helper");
let env = new HighlighterEnvironment();
env.initFromWindow(doc.defaultView);
let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
ok(!helper.content, "The AnonymousContent was not inserted in the window");
ok(!helper.getTextContentForElement("child-element"),
"No text content is returned");
env.destroy();
helper.destroy();
env.destroy();
helper.destroy();
});
gBrowser.removeCurrentTab();
});

Просмотреть файл

@ -6,98 +6,108 @@
// Test the CanvasFrameAnonymousContentHelper event handling mechanism.
// This makes sure the 'domnode' protocol actor type is known when importing
// highlighter.
require("devtools/server/actors/inspector");
const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
const {
CanvasFrameAnonymousContentHelper
} = require("devtools/server/actors/highlighters/utils/markup");
const TEST_URL = "data:text/html;charset=utf-8,CanvasFrameAnonymousContentHelper test";
add_task(function* () {
let browser = yield addTab(TEST_URL);
// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = browser.contentDocument;
add_task(async function () {
let browser = await addTab(TEST_URL);
await ContentTask.spawn(browser, null, async function () {
const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
const {
CanvasFrameAnonymousContentHelper
} = require("devtools/server/actors/highlighters/utils/markup");
let doc = content.document;
let nodeBuilder = () => {
let root = doc.createElement("div");
let child = doc.createElement("div");
child.style = "pointer-events:auto;width:200px;height:200px;background:red;";
child.id = "child-element";
child.className = "child-element";
root.appendChild(child);
return root;
};
let nodeBuilder = () => {
let root = doc.createElement("div");
let child = doc.createElement("div");
child.style = "pointer-events:auto;width:200px;height:200px;background:red;";
child.id = "child-element";
child.className = "child-element";
root.appendChild(child);
return root;
};
info("Building the helper");
let env = new HighlighterEnvironment();
env.initFromWindow(doc.defaultView);
let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
info("Building the helper");
let env = new HighlighterEnvironment();
env.initFromWindow(doc.defaultView);
let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
let el = helper.getElement("child-element");
let el = helper.getElement("child-element");
info("Adding an event listener on the inserted element");
let mouseDownHandled = 0;
function onMouseDown(e, id) {
is(id, "child-element", "The mousedown event was triggered on the element");
ok(!e.originalTarget, "The originalTarget property isn't available");
mouseDownHandled++;
}
el.addEventListener("mousedown", onMouseDown);
info("Adding an event listener on the inserted element");
let mouseDownHandled = 0;
function onMouseDown(e, id) {
is(id, "child-element", "The mousedown event was triggered on the element");
ok(!e.originalTarget, "The originalTarget property isn't available");
mouseDownHandled++;
}
el.addEventListener("mousedown", onMouseDown);
info("Synthesizing an event on the inserted element");
let onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(100, 100, doc.defaultView);
yield onDocMouseDown;
function once(target, event) {
return new Promise(done => {
target.addEventListener(event, done, { once: true });
});
}
is(mouseDownHandled, 1, "The mousedown event was handled once on the element");
info("Synthesizing an event on the inserted element");
let onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(100, 100, doc.defaultView);
await onDocMouseDown;
info("Synthesizing an event somewhere else");
onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(400, 400, doc.defaultView);
yield onDocMouseDown;
is(mouseDownHandled, 1, "The mousedown event was handled once on the element");
is(mouseDownHandled, 1, "The mousedown event was not handled on the element");
info("Synthesizing an event somewhere else");
onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(400, 400, doc.defaultView);
await onDocMouseDown;
info("Removing the event listener");
el.removeEventListener("mousedown", onMouseDown);
is(mouseDownHandled, 1, "The mousedown event was not handled on the element");
info("Synthesizing another event after the listener has been removed");
// Using a document event listener to know when the event has been synthesized.
onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(100, 100, doc.defaultView);
yield onDocMouseDown;
info("Removing the event listener");
el.removeEventListener("mousedown", onMouseDown);
is(mouseDownHandled, 1,
"The mousedown event hasn't been handled after the listener was removed");
info("Synthesizing another event after the listener has been removed");
// Using a document event listener to know when the event has been synthesized.
onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(100, 100, doc.defaultView);
await onDocMouseDown;
info("Adding again the event listener");
el.addEventListener("mousedown", onMouseDown);
is(mouseDownHandled, 1,
"The mousedown event hasn't been handled after the listener was removed");
info("Destroying the helper");
env.destroy();
helper.destroy();
info("Adding again the event listener");
el.addEventListener("mousedown", onMouseDown);
info("Synthesizing another event after the helper has been destroyed");
// Using a document event listener to know when the event has been synthesized.
onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(100, 100, doc.defaultView);
yield onDocMouseDown;
info("Destroying the helper");
env.destroy();
helper.destroy();
is(mouseDownHandled, 1,
"The mousedown event hasn't been handled after the helper was destroyed");
info("Synthesizing another event after the helper has been destroyed");
// Using a document event listener to know when the event has been synthesized.
onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(100, 100, doc.defaultView);
await onDocMouseDown;
is(mouseDownHandled, 1,
"The mousedown event hasn't been handled after the helper was destroyed");
function synthesizeMouseDown(x, y, win) {
// We need to make sure the inserted anonymous content can be targeted by the
// event right after having been inserted, and so we need to force a sync
// reflow.
win.document.documentElement.offsetWidth;
// Minimal environment for EventUtils to work.
let EventUtils = {
window: content,
parent: content,
_EU_Ci: Components.interfaces,
_EU_Cc: Components.classes,
};
Services.scriptloader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
EventUtils.synthesizeMouseAtPoint(x, y, {type: "mousedown"}, win);
}
});
gBrowser.removeCurrentTab();
});
function synthesizeMouseDown(x, y, win) {
// We need to make sure the inserted anonymous content can be targeted by the
// event right after having been inserted, and so we need to force a sync
// reflow.
win.document.documentElement.offsetWidth;
EventUtils.synthesizeMouseAtPoint(x, y, {type: "mousedown"}, win);
}

Просмотреть файл

@ -7,95 +7,99 @@
// Test the CanvasFrameAnonymousContentHelper re-inserts the content when the
// page reloads.
// This makes sure the 'domnode' protocol actor type is known when importing
// highlighter.
require("devtools/server/actors/inspector");
const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
const {
CanvasFrameAnonymousContentHelper
} = require("devtools/server/actors/highlighters/utils/markup");
const TEST_URL_1 =
"data:text/html;charset=utf-8,CanvasFrameAnonymousContentHelper test 1";
const TEST_URL_2 =
"data:text/html;charset=utf-8,CanvasFrameAnonymousContentHelper test 2";
add_task(function* () {
let browser = yield addTab(TEST_URL_1);
// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = browser.contentDocument;
add_task(async function () {
let browser = await addTab(TEST_URL_1);
await injectEventUtilsInContentTask(browser);
await ContentTask.spawn(browser, TEST_URL_2, async function (url2) {
const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
const {
CanvasFrameAnonymousContentHelper
} = require("devtools/server/actors/highlighters/utils/markup");
let doc = content.document;
let nodeBuilder = () => {
let root = doc.createElement("div");
let child = doc.createElement("div");
child.style = "pointer-events:auto;width:200px;height:200px;background:red;";
child.id = "child-element";
child.className = "child-element";
child.textContent = "test content";
root.appendChild(child);
return root;
};
let nodeBuilder = () => {
let root = doc.createElement("div");
let child = doc.createElement("div");
child.style = "pointer-events:auto;width:200px;height:200px;background:red;";
child.id = "child-element";
child.className = "child-element";
child.textContent = "test content";
root.appendChild(child);
return root;
};
info("Building the helper");
let env = new HighlighterEnvironment();
env.initFromWindow(doc.defaultView);
let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
info("Building the helper");
let env = new HighlighterEnvironment();
env.initFromWindow(doc.defaultView);
let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
info("Get an element from the helper");
let el = helper.getElement("child-element");
info("Get an element from the helper");
let el = helper.getElement("child-element");
info("Try to access the element");
is(el.getAttribute("class"), "child-element",
"The attribute is correct before navigation");
is(el.getTextContent(), "test content",
"The text content is correct before navigation");
info("Try to access the element");
is(el.getAttribute("class"), "child-element",
"The attribute is correct before navigation");
is(el.getTextContent(), "test content",
"The text content is correct before navigation");
info("Add an event listener on the element");
let mouseDownHandled = 0;
function onMouseDown(e, id) {
is(id, "child-element", "The mousedown event was triggered on the element");
mouseDownHandled++;
}
el.addEventListener("mousedown", onMouseDown);
info("Add an event listener on the element");
let mouseDownHandled = 0;
let onMouseDown = (e, id) => {
is(id, "child-element", "The mousedown event was triggered on the element");
mouseDownHandled++;
};
el.addEventListener("mousedown", onMouseDown);
info("Synthesizing an event on the element");
let onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(100, 100, doc.defaultView);
yield onDocMouseDown;
is(mouseDownHandled, 1, "The mousedown event was handled once before navigation");
let once = function once(target, event) {
return new Promise(done => {
target.addEventListener(event, done, { once: true });
});
};
info("Navigating to a new page");
let loaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
BrowserTestUtils.loadURI(browser, TEST_URL_2);
yield loaded;
// eslint-disable-next-line mozilla/no-cpows-in-tests
doc = gBrowser.selectedBrowser.contentWindow.document;
let synthesizeMouseDown = function synthesizeMouseDown(x, y, win) {
// We need to make sure the inserted anonymous content can be targeted by the
// event right after having been inserted, and so we need to force a sync
// reflow.
win.document.documentElement.offsetWidth;
EventUtils.synthesizeMouseAtPoint(x, y, {type: "mousedown"}, win);
};
info("Try to access the element again");
is(el.getAttribute("class"), "child-element",
"The attribute is correct after navigation");
is(el.getTextContent(), "test content",
"The text content is correct after navigation");
info("Synthesizing an event on the element");
let onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(100, 100, doc.defaultView);
await onDocMouseDown;
is(mouseDownHandled, 1, "The mousedown event was handled once before navigation");
info("Synthesizing an event on the element again");
onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(100, 100, doc.defaultView);
yield onDocMouseDown;
is(mouseDownHandled, 1, "The mousedown event was not handled after navigation");
info("Navigating to a new page");
let loaded = once(this, "load");
content.location = url2;
await loaded;
info("Destroying the helper");
env.destroy();
helper.destroy();
// Update to the new document we just loaded
doc = content.document;
info("Try to access the element again");
is(el.getAttribute("class"), "child-element",
"The attribute is correct after navigation");
is(el.getTextContent(), "test content",
"The text content is correct after navigation");
info("Synthesizing an event on the element again");
onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(100, 100, doc.defaultView);
await onDocMouseDown;
is(mouseDownHandled, 1, "The mousedown event was not handled after navigation");
info("Destroying the helper");
env.destroy();
helper.destroy();
});
gBrowser.removeCurrentTab();
});
function synthesizeMouseDown(x, y, win) {
// We need to make sure the inserted anonymous content can be targeted by the
// event right after having been inserted, and so we need to force a sync
// reflow.
win.document.documentElement.offsetWidth;
EventUtils.synthesizeMouseAtPoint(x, y, {type: "mousedown"}, win);
}

Просмотреть файл

@ -7,107 +7,117 @@
// Test some edge cases of the CanvasFrameAnonymousContentHelper event handling
// mechanism.
// This makes sure the 'domnode' protocol actor type is known when importing
// highlighter.
require("devtools/server/actors/inspector");
const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
const {
CanvasFrameAnonymousContentHelper
} = require("devtools/server/actors/highlighters/utils/markup");
const TEST_URL = "data:text/html;charset=utf-8,CanvasFrameAnonymousContentHelper test";
add_task(function* () {
let browser = yield addTab(TEST_URL);
// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = browser.contentDocument;
add_task(async function () {
let browser = await addTab(TEST_URL);
await ContentTask.spawn(browser, null, async function () {
const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
const {
CanvasFrameAnonymousContentHelper
} = require("devtools/server/actors/highlighters/utils/markup");
let doc = content.document;
let nodeBuilder = () => {
let root = doc.createElement("div");
let nodeBuilder = () => {
let root = doc.createElement("div");
let parent = doc.createElement("div");
parent.style = "pointer-events:auto;width:300px;height:300px;background:yellow;";
parent.id = "parent-element";
root.appendChild(parent);
let parent = doc.createElement("div");
parent.style = "pointer-events:auto;width:300px;height:300px;background:yellow;";
parent.id = "parent-element";
root.appendChild(parent);
let child = doc.createElement("div");
child.style = "pointer-events:auto;width:200px;height:200px;background:red;";
child.id = "child-element";
parent.appendChild(child);
let child = doc.createElement("div");
child.style = "pointer-events:auto;width:200px;height:200px;background:red;";
child.id = "child-element";
parent.appendChild(child);
return root;
};
return root;
};
info("Building the helper");
let env = new HighlighterEnvironment();
env.initFromWindow(doc.defaultView);
let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
info("Building the helper");
let env = new HighlighterEnvironment();
env.initFromWindow(doc.defaultView);
let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
info("Getting the parent and child elements");
let parentEl = helper.getElement("parent-element");
let childEl = helper.getElement("child-element");
info("Getting the parent and child elements");
let parentEl = helper.getElement("parent-element");
let childEl = helper.getElement("child-element");
info("Adding an event listener on both elements");
let mouseDownHandled = [];
function onMouseDown(e, id) {
mouseDownHandled.push(id);
}
parentEl.addEventListener("mousedown", onMouseDown);
childEl.addEventListener("mousedown", onMouseDown);
info("Adding an event listener on both elements");
let mouseDownHandled = [];
function onMouseDown(e, id) {
mouseDownHandled.push(id);
}
parentEl.addEventListener("mousedown", onMouseDown);
childEl.addEventListener("mousedown", onMouseDown);
info("Synthesizing an event on the child element");
let onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(100, 100, doc.defaultView);
yield onDocMouseDown;
function once(target, event) {
return new Promise(done => {
target.addEventListener(event, done, { once: true });
});
}
is(mouseDownHandled.length, 2, "The mousedown event was handled twice");
is(mouseDownHandled[0], "child-element",
"The mousedown event was handled on the child element");
is(mouseDownHandled[1], "parent-element",
"The mousedown event was handled on the parent element");
info("Synthesizing an event on the child element");
let onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(100, 100, doc.defaultView);
await onDocMouseDown;
info("Synthesizing an event on the parent, outside of the child element");
mouseDownHandled = [];
onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(250, 250, doc.defaultView);
yield onDocMouseDown;
is(mouseDownHandled.length, 2, "The mousedown event was handled twice");
is(mouseDownHandled[0], "child-element",
"The mousedown event was handled on the child element");
is(mouseDownHandled[1], "parent-element",
"The mousedown event was handled on the parent element");
is(mouseDownHandled.length, 1, "The mousedown event was handled only once");
is(mouseDownHandled[0], "parent-element",
"The mousedown event was handled on the parent element");
info("Synthesizing an event on the parent, outside of the child element");
mouseDownHandled = [];
onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(250, 250, doc.defaultView);
await onDocMouseDown;
info("Removing the event listener");
parentEl.removeEventListener("mousedown", onMouseDown);
childEl.removeEventListener("mousedown", onMouseDown);
is(mouseDownHandled.length, 1, "The mousedown event was handled only once");
is(mouseDownHandled[0], "parent-element",
"The mousedown event was handled on the parent element");
info("Adding an event listener on the parent element only");
mouseDownHandled = [];
parentEl.addEventListener("mousedown", onMouseDown);
info("Removing the event listener");
parentEl.removeEventListener("mousedown", onMouseDown);
childEl.removeEventListener("mousedown", onMouseDown);
info("Synthesizing an event on the child element");
onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(100, 100, doc.defaultView);
yield onDocMouseDown;
info("Adding an event listener on the parent element only");
mouseDownHandled = [];
parentEl.addEventListener("mousedown", onMouseDown);
is(mouseDownHandled.length, 1, "The mousedown event was handled once");
is(mouseDownHandled[0], "parent-element",
"The mousedown event did bubble to the parent element");
info("Synthesizing an event on the child element");
onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(100, 100, doc.defaultView);
await onDocMouseDown;
info("Removing the parent listener");
parentEl.removeEventListener("mousedown", onMouseDown);
is(mouseDownHandled.length, 1, "The mousedown event was handled once");
is(mouseDownHandled[0], "parent-element",
"The mousedown event did bubble to the parent element");
env.destroy();
helper.destroy();
info("Removing the parent listener");
parentEl.removeEventListener("mousedown", onMouseDown);
env.destroy();
helper.destroy();
function synthesizeMouseDown(x, y, win) {
// We need to make sure the inserted anonymous content can be targeted by the
// event right after having been inserted, and so we need to force a sync
// reflow.
win.document.documentElement.offsetWidth;
// Minimal environment for EventUtils to work.
let EventUtils = {
window: content,
parent: content,
_EU_Ci: Components.interfaces,
_EU_Cc: Components.classes,
};
Services.scriptloader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
EventUtils.synthesizeMouseAtPoint(x, y, {type: "mousedown"}, win);
}
});
gBrowser.removeCurrentTab();
});
function synthesizeMouseDown(x, y, win) {
// We need to make sure the inserted anonymous content can be targeted by the
// event right after having been inserted, and so we need to force a sync
// reflow.
win.document.documentElement.offsetWidth;
EventUtils.synthesizeMouseAtPoint(x, y, {type: "mousedown"}, win);
}

Просмотреть файл

@ -7,95 +7,105 @@
// Test support for event propagation stop in the
// CanvasFrameAnonymousContentHelper event handling mechanism.
// This makes sure the 'domnode' protocol actor type is known when importing
// highlighter.
require("devtools/server/actors/inspector");
const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
const {
CanvasFrameAnonymousContentHelper
} = require("devtools/server/actors/highlighters/utils/markup");
const TEST_URL = "data:text/html;charset=utf-8,CanvasFrameAnonymousContentHelper test";
add_task(function* () {
let browser = yield addTab(TEST_URL);
// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = browser.contentDocument;
add_task(async function () {
let browser = await addTab(TEST_URL);
await ContentTask.spawn(browser, null, async function () {
const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
const {
CanvasFrameAnonymousContentHelper
} = require("devtools/server/actors/highlighters/utils/markup");
let doc = content.document;
let nodeBuilder = () => {
let root = doc.createElement("div");
let nodeBuilder = () => {
let root = doc.createElement("div");
let parent = doc.createElement("div");
parent.style = "pointer-events:auto;width:300px;height:300px;background:yellow;";
parent.id = "parent-element";
root.appendChild(parent);
let parent = doc.createElement("div");
parent.style = "pointer-events:auto;width:300px;height:300px;background:yellow;";
parent.id = "parent-element";
root.appendChild(parent);
let child = doc.createElement("div");
child.style = "pointer-events:auto;width:200px;height:200px;background:red;";
child.id = "child-element";
parent.appendChild(child);
let child = doc.createElement("div");
child.style = "pointer-events:auto;width:200px;height:200px;background:red;";
child.id = "child-element";
parent.appendChild(child);
return root;
};
return root;
};
info("Building the helper");
let env = new HighlighterEnvironment();
env.initFromWindow(doc.defaultView);
let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
info("Building the helper");
let env = new HighlighterEnvironment();
env.initFromWindow(doc.defaultView);
let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
info("Getting the parent and child elements");
let parentEl = helper.getElement("parent-element");
let childEl = helper.getElement("child-element");
info("Getting the parent and child elements");
let parentEl = helper.getElement("parent-element");
let childEl = helper.getElement("child-element");
info("Adding an event listener on both elements");
let mouseDownHandled = [];
info("Adding an event listener on both elements");
let mouseDownHandled = [];
function onParentMouseDown(e, id) {
mouseDownHandled.push(id);
}
parentEl.addEventListener("mousedown", onParentMouseDown);
function onParentMouseDown(e, id) {
mouseDownHandled.push(id);
}
parentEl.addEventListener("mousedown", onParentMouseDown);
function onChildMouseDown(e, id) {
mouseDownHandled.push(id);
e.stopPropagation();
}
childEl.addEventListener("mousedown", onChildMouseDown);
function onChildMouseDown(e, id) {
mouseDownHandled.push(id);
e.stopPropagation();
}
childEl.addEventListener("mousedown", onChildMouseDown);
info("Synthesizing an event on the child element");
let onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(100, 100, doc.defaultView);
yield onDocMouseDown;
function once(target, event) {
return new Promise(done => {
target.addEventListener(event, done, { once: true });
});
}
is(mouseDownHandled.length, 1, "The mousedown event was handled only once");
is(mouseDownHandled[0], "child-element",
"The mousedown event was handled on the child element");
info("Synthesizing an event on the child element");
let onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(100, 100, doc.defaultView);
await onDocMouseDown;
info("Synthesizing an event on the parent, outside of the child element");
mouseDownHandled = [];
onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(250, 250, doc.defaultView);
yield onDocMouseDown;
is(mouseDownHandled.length, 1, "The mousedown event was handled only once");
is(mouseDownHandled[0], "child-element",
"The mousedown event was handled on the child element");
is(mouseDownHandled.length, 1, "The mousedown event was handled only once");
is(mouseDownHandled[0], "parent-element",
"The mousedown event was handled on the parent element");
info("Synthesizing an event on the parent, outside of the child element");
mouseDownHandled = [];
onDocMouseDown = once(doc, "mousedown");
synthesizeMouseDown(250, 250, doc.defaultView);
await onDocMouseDown;
info("Removing the event listener");
parentEl.removeEventListener("mousedown", onParentMouseDown);
childEl.removeEventListener("mousedown", onChildMouseDown);
is(mouseDownHandled.length, 1, "The mousedown event was handled only once");
is(mouseDownHandled[0], "parent-element",
"The mousedown event was handled on the parent element");
env.destroy();
helper.destroy();
info("Removing the event listener");
parentEl.removeEventListener("mousedown", onParentMouseDown);
childEl.removeEventListener("mousedown", onChildMouseDown);
env.destroy();
helper.destroy();
function synthesizeMouseDown(x, y, win) {
// We need to make sure the inserted anonymous content can be targeted by the
// event right after having been inserted, and so we need to force a sync
// reflow.
win.document.documentElement.offsetWidth;
// Minimal environment for EventUtils to work.
let EventUtils = {
window: content,
parent: content,
_EU_Ci: Components.interfaces,
_EU_Cc: Components.classes,
};
Services.scriptloader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
EventUtils.synthesizeMouseAtPoint(x, y, {type: "mousedown"}, win);
}
});
gBrowser.removeCurrentTab();
});
function synthesizeMouseDown(x, y, win) {
// We need to make sure the inserted anonymous content can be targeted by the
// event right after having been inserted, and so we need to force a sync
// reflow.
win.document.documentElement.offsetWidth;
EventUtils.synthesizeMouseAtPoint(x, y, {type: "mousedown"}, win);
}

Просмотреть файл

@ -5,18 +5,14 @@
"use strict";
/* eslint no-unused-vars: [2, {"vars": "local"}] */
/* import-globals-from ../../../client/framework/test/shared-head.js */
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/devtools/client/framework/test/shared-head.js",
this);
const {console} = Cu.import("resource://gre/modules/Console.jsm", {});
const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
const {DebuggerClient} = require("devtools/shared/client/debugger-client");
const {DebuggerServer} = require("devtools/server/main");
const {defer} = require("promise");
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
const Services = require("Services");
const PATH = "browser/devtools/server/tests/browser/";
const MAIN_DOMAIN = "http://test1.example.org/" + PATH;