mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-11 05:39:41 +02:00
These tests were using chrome mochitest which forces the test page to be running in chrome and in parent process. This doesn't reflect typical setup where the page runs unprivileged in content process. Also, with the current bug, the pages running in system principal will be debugged with a special setup. Actors will be run with modules loaded in a distinct loader in order to be executed in a distinct compartment, distinct from the shared system principal compartment. That a prerequisite for the Debugger API. It has to run in a distinct compartment than its debuggee. Depends on D16825 Differential Revision: https://phabricator.services.mozilla.com/D16826 --HG-- rename : devtools/server/tests/mochitest/animation-data.html => devtools/server/tests/browser/animation-data.html rename : devtools/server/tests/mochitest/test_inspector-mutations-childlist.html => devtools/server/tests/browser/browser_inspector-mutations-childlist.js rename : devtools/server/tests/mochitest/inspector-helpers.js => devtools/server/tests/browser/inspector-helpers.js extra : moz-landing-system : lando
119 lines
4.5 KiB
JavaScript
119 lines
4.5 KiB
JavaScript
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
"use strict";
|
|
|
|
add_task(async function setup() {
|
|
const { walker } =
|
|
await initInspectorFront(MAIN_DOMAIN + "inspector-traversal-data.html");
|
|
|
|
await testRearrange(walker);
|
|
await testInsertInvalidInput(walker);
|
|
});
|
|
|
|
async function testRearrange(walker) {
|
|
const longlist = await walker.querySelector(walker.rootNode, "#longlist");
|
|
let children = await walker.children(longlist);
|
|
const nodeA = children.nodes[0];
|
|
is(nodeA.id, "a", "Got the expected node.");
|
|
|
|
// Move nodeA to the end of the list.
|
|
await walker.insertBefore(nodeA, longlist, null);
|
|
|
|
await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
|
|
ok(!content.document.querySelector("#a").nextSibling,
|
|
"a should now be at the end of the list.");
|
|
});
|
|
|
|
children = await walker.children(longlist);
|
|
is(nodeA, children.nodes[children.nodes.length - 1],
|
|
"a should now be the last returned child.");
|
|
|
|
// Now move it to the middle of the list.
|
|
const nextNode = children.nodes[13];
|
|
await walker.insertBefore(nodeA, longlist, nextNode);
|
|
|
|
await ContentTask.spawn(gBrowser.selectedBrowser, [nextNode.actorID],
|
|
async function(actorID) {
|
|
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
|
|
const { DebuggerServer } = require("devtools/server/main");
|
|
const {DocumentWalker} = require("devtools/server/actors/inspector/document-walker");
|
|
const sibling =
|
|
new DocumentWalker(content.document.querySelector("#a"), content).nextSibling();
|
|
// Convert actorID to current compartment string otherwise
|
|
// searchAllConnectionsForActor is confused and won't find the actor.
|
|
actorID = String(actorID);
|
|
const nodeActor = DebuggerServer.searchAllConnectionsForActor(actorID);
|
|
is(sibling, nodeActor.rawNode, "Node should match the expected next node.");
|
|
});
|
|
|
|
children = await walker.children(longlist);
|
|
is(nodeA, children.nodes[13], "a should be where we expect it.");
|
|
is(nextNode, children.nodes[14], "next node should be where we expect it.");
|
|
}
|
|
|
|
async function testInsertInvalidInput(walker) {
|
|
const longlist = await walker.querySelector(walker.rootNode, "#longlist");
|
|
const children = await walker.children(longlist);
|
|
const nodeA = children.nodes[0];
|
|
const nextSibling = children.nodes[1];
|
|
|
|
// Now move it to the original location and make sure no mutation happens.
|
|
await ContentTask.spawn(gBrowser.selectedBrowser, [longlist.actorID],
|
|
async function(actorID) {
|
|
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
|
|
const { DebuggerServer } = require("devtools/server/main");
|
|
// Convert actorID to current compartment string otherwise
|
|
// searchAllConnectionsForActor is confused and won't find the actor.
|
|
actorID = String(actorID);
|
|
const nodeActor = DebuggerServer.searchAllConnectionsForActor(actorID);
|
|
content.hasMutated = false;
|
|
content.observer = new content.MutationObserver(() => {
|
|
content.hasMutated = true;
|
|
});
|
|
content.observer.observe(nodeActor.rawNode, {
|
|
childList: true,
|
|
});
|
|
});
|
|
|
|
await walker.insertBefore(nodeA, longlist, nodeA);
|
|
let hasMutated = await ContentTask.spawn(gBrowser.selectedBrowser, null,
|
|
async function() {
|
|
const state = content.hasMutated;
|
|
content.hasMutated = false;
|
|
return state;
|
|
});
|
|
ok(!hasMutated, "hasn't mutated");
|
|
|
|
await walker.insertBefore(nodeA, longlist, nextSibling);
|
|
hasMutated = await ContentTask.spawn(gBrowser.selectedBrowser, null,
|
|
async function() {
|
|
const state = content.hasMutated;
|
|
content.hasMutated = false;
|
|
return state;
|
|
});
|
|
ok(!hasMutated, "still hasn't mutated after inserting before nextSibling");
|
|
|
|
await walker.insertBefore(nodeA, longlist);
|
|
hasMutated = await ContentTask.spawn(gBrowser.selectedBrowser, null,
|
|
async function() {
|
|
const state = content.hasMutated;
|
|
content.hasMutated = false;
|
|
return state;
|
|
});
|
|
ok(hasMutated, "has mutated after inserting with null sibling");
|
|
|
|
await walker.insertBefore(nodeA, longlist);
|
|
hasMutated = await ContentTask.spawn(gBrowser.selectedBrowser, null,
|
|
async function() {
|
|
const state = content.hasMutated;
|
|
content.hasMutated = false;
|
|
return state;
|
|
});
|
|
ok(!hasMutated, "hasn't mutated after inserting with null sibling again");
|
|
|
|
await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
|
|
content.observer.disconnect();
|
|
});
|
|
}
|