mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-25 20:01:50 +00:00
Backed out 2 changesets (bug 1599773, bug 1599413) for browser_frameAttached.js failures CLOSED TREE
Backed out changeset 779bc06348ad (bug 1599773) Backed out changeset 6f223ae549d8 (bug 1599413)
This commit is contained in:
parent
f5342d154a
commit
3b974da483
@ -37,8 +37,6 @@ class Page extends ContentProcessDomain {
|
||||
this.scriptsToEvaluateOnLoad = new Map();
|
||||
this.worldsToEvaluateOnLoad = new Set();
|
||||
|
||||
this._onFrameAttached = this._onFrameAttached.bind(this);
|
||||
this._onFrameDetached = this._onFrameDetached.bind(this);
|
||||
this._onFrameNavigated = this._onFrameNavigated.bind(this);
|
||||
this._onScriptLoaded = this._onScriptLoaded.bind(this);
|
||||
|
||||
@ -57,8 +55,7 @@ class Page extends ContentProcessDomain {
|
||||
|
||||
async enable() {
|
||||
if (!this.enabled) {
|
||||
this.session.contextObserver.on("frame-attached", this._onFrameAttached);
|
||||
this.session.contextObserver.on("frame-detached", this._onFrameDetached);
|
||||
this.enabled = true;
|
||||
this.session.contextObserver.on(
|
||||
"frame-navigated",
|
||||
this._onFrameNavigated
|
||||
@ -85,15 +82,11 @@ class Page extends ContentProcessDomain {
|
||||
this.chromeEventHandler.addEventListener("pageshow", this, {
|
||||
mozSystemGroup: true,
|
||||
});
|
||||
|
||||
this.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
disable() {
|
||||
if (this.enabled) {
|
||||
this.session.contextObserver.off("frame-attached", this._onFrameAttached);
|
||||
this.session.contextObserver.off("frame-detached", this._onFrameDetached);
|
||||
this.session.contextObserver.off(
|
||||
"frame-navigated",
|
||||
this._onFrameNavigated
|
||||
@ -249,18 +242,6 @@ class Page extends ContentProcessDomain {
|
||||
return this.content.location.href;
|
||||
}
|
||||
|
||||
_onFrameAttached(name, { frameId, parentFrameId }) {
|
||||
this.emit("Page.frameAttached", {
|
||||
frameId,
|
||||
parentFrameId,
|
||||
stack: null,
|
||||
});
|
||||
}
|
||||
|
||||
_onFrameDetached(name, { frameId }) {
|
||||
this.emit("Page.frameDetached", { frameId });
|
||||
}
|
||||
|
||||
_onFrameNavigated(name, { frameId, window }) {
|
||||
const url = window.location.href;
|
||||
this.emit("Page.frameNavigated", {
|
||||
|
@ -32,8 +32,6 @@ const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const { executeSoon } = ChromeUtils.import("chrome://remote/content/Sync.jsm");
|
||||
|
||||
// Temporary flag to not emit frame related events until everything
|
||||
// has been completely implemented, and Puppeteer is no longer busted.
|
||||
const FRAMES_ENABLED = Services.prefs.getBoolPref(
|
||||
"remote.frames.enabled",
|
||||
false
|
||||
@ -57,11 +55,6 @@ class ContextObserver {
|
||||
});
|
||||
|
||||
Services.obs.addObserver(this, "inner-window-destroyed");
|
||||
|
||||
if (FRAMES_ENABLED) {
|
||||
Services.obs.addObserver(this, "webnavigation-create");
|
||||
Services.obs.addObserver(this, "webnavigation-destroy");
|
||||
}
|
||||
}
|
||||
|
||||
destructor() {
|
||||
@ -74,13 +67,7 @@ class ContextObserver {
|
||||
this.chromeEventHandler.removeEventListener("pagehide", this, {
|
||||
mozSystemGroup: true,
|
||||
});
|
||||
|
||||
Services.obs.removeObserver(this, "inner-window-destroyed");
|
||||
|
||||
if (FRAMES_ENABLED) {
|
||||
Services.obs.removeObserver(this, "webnavigation-create");
|
||||
Services.obs.removeObserver(this, "webnavigation-destroy");
|
||||
}
|
||||
}
|
||||
|
||||
handleEvent({ type, target, persisted }) {
|
||||
@ -127,37 +114,9 @@ class ContextObserver {
|
||||
}
|
||||
}
|
||||
|
||||
// "inner-window-destroyed" observer service listener
|
||||
observe(subject, topic, data) {
|
||||
switch (topic) {
|
||||
case "inner-window-destroyed":
|
||||
const windowId = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
|
||||
this.emit("context-destroyed", { windowId });
|
||||
break;
|
||||
case "webnavigation-create":
|
||||
subject.QueryInterface(Ci.nsIDocShell);
|
||||
this.onDocShellCreated(subject);
|
||||
break;
|
||||
case "webnavigation-destroy":
|
||||
subject.QueryInterface(Ci.nsIDocShell);
|
||||
this.onDocShellDestroyed(subject);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
onDocShellCreated(docShell) {
|
||||
const parent = docShell.browsingContext.parent;
|
||||
|
||||
// TODO: Use a unique identifier for frames (bug 1605359)
|
||||
this.emit("frame-attached", {
|
||||
frameId: docShell.browsingContext.id.toString(),
|
||||
parentFrameId: parent ? parent.id.toString() : null,
|
||||
});
|
||||
}
|
||||
|
||||
onDocShellDestroyed(docShell) {
|
||||
// TODO: Use a unique identifier for frames (bug 1605359)
|
||||
this.emit("frame-detached", {
|
||||
frameId: docShell.browsingContext.id.toString(),
|
||||
});
|
||||
const innerWindowID = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
|
||||
this.emit("context-destroyed", { windowId: innerWindowID });
|
||||
}
|
||||
}
|
||||
|
@ -264,48 +264,6 @@ function toDataURL(src, doctype = "html") {
|
||||
return `data:${mime},${encodeURIComponent(doc)}`;
|
||||
}
|
||||
|
||||
function convertArgument(arg) {
|
||||
if (typeof arg === "bigint") {
|
||||
return { unserializableValue: `${arg.toString()}n` };
|
||||
}
|
||||
if (Object.is(arg, -0)) {
|
||||
return { unserializableValue: "-0" };
|
||||
}
|
||||
if (Object.is(arg, Infinity)) {
|
||||
return { unserializableValue: "Infinity" };
|
||||
}
|
||||
if (Object.is(arg, -Infinity)) {
|
||||
return { unserializableValue: "-Infinity" };
|
||||
}
|
||||
if (Object.is(arg, NaN)) {
|
||||
return { unserializableValue: "NaN" };
|
||||
}
|
||||
|
||||
return { value: arg };
|
||||
}
|
||||
|
||||
async function evaluate(client, contextId, pageFunction, ...args) {
|
||||
const { Runtime } = client;
|
||||
|
||||
if (typeof pageFunction === "string") {
|
||||
return Runtime.evaluate({
|
||||
expression: pageFunction,
|
||||
contextId,
|
||||
returnByValue: true,
|
||||
awaitPromise: true,
|
||||
});
|
||||
} else if (typeof pageFunction === "function") {
|
||||
return Runtime.callFunctionOn({
|
||||
functionDeclaration: pageFunction.toString(),
|
||||
executionContextId: contextId,
|
||||
arguments: args.map(convertArgument),
|
||||
returnByValue: true,
|
||||
awaitPromise: true,
|
||||
});
|
||||
}
|
||||
throw new Error("pageFunction: expected 'string' or 'function'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a given URL in the currently selected tab
|
||||
*/
|
||||
@ -313,7 +271,7 @@ async function loadURL(url, expectedURL = undefined) {
|
||||
expectedURL = expectedURL || url;
|
||||
|
||||
const browser = gBrowser.selectedTab.linkedBrowser;
|
||||
const loaded = BrowserTestUtils.browserLoaded(browser, true, expectedURL);
|
||||
const loaded = BrowserTestUtils.browserLoaded(browser, false, expectedURL);
|
||||
|
||||
BrowserTestUtils.loadURI(browser, url);
|
||||
await loaded;
|
||||
|
@ -14,8 +14,6 @@ support-files =
|
||||
[browser_bringToFront.js]
|
||||
[browser_captureScreenshot.js]
|
||||
[browser_createIsolatedWorld.js]
|
||||
[browser_frameAttached.js]
|
||||
[browser_frameDetached.js]
|
||||
[browser_frameNavigated.js]
|
||||
[browser_getFrameTree.js]
|
||||
[browser_getLayoutMetrics.js]
|
||||
|
@ -1,137 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
const DOC = toDataURL("<div>foo</div>");
|
||||
const DOC_IFRAME_MULTI = toDataURL(`
|
||||
<iframe src='data:text/html,foo'></iframe>
|
||||
<iframe src='data:text/html,bar'></iframe>
|
||||
`);
|
||||
const DOC_IFRAME_NESTED = toDataURL(`
|
||||
<iframe src="data:text/html,<iframe src='data:text/html,foo'></iframe>">
|
||||
</iframe>
|
||||
`);
|
||||
|
||||
add_task(async function noEventWhenPageDomainDisabled({ client }) {
|
||||
await runFrameAttachedTest(client, 0, async () => {
|
||||
info("Navigate to a page with an iframe");
|
||||
await loadURL(DOC_IFRAME_MULTI);
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function noEventAfterPageDomainDisabled({ client }) {
|
||||
const { Page } = client;
|
||||
|
||||
await Page.enable();
|
||||
await Page.disable();
|
||||
|
||||
await runFrameAttachedTest(client, 0, async () => {
|
||||
info("Navigate to a page with an iframe");
|
||||
await loadURL(DOC_IFRAME_MULTI);
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function noEventWhenNavigatingWithNoFrames({ client }) {
|
||||
const { Page } = client;
|
||||
|
||||
await Page.enable();
|
||||
|
||||
info("Navigate to a page with iframes");
|
||||
await loadURL(DOC_IFRAME_MULTI);
|
||||
|
||||
await runFrameAttachedTest(client, 0, async () => {
|
||||
info("Navigate to a page without an iframe");
|
||||
await loadURL(DOC);
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function eventWhenNavigatingWithFrames({ client }) {
|
||||
const { Page } = client;
|
||||
|
||||
await Page.enable();
|
||||
|
||||
await runFrameAttachedTest(client, 2, async () => {
|
||||
info("Navigate to a page with an iframe");
|
||||
await loadURL(DOC_IFRAME_MULTI);
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function eventWhenNavigatingWithNestedFrames({ client }) {
|
||||
const { Page } = client;
|
||||
|
||||
await Page.enable();
|
||||
|
||||
await runFrameAttachedTest(client, 2, async () => {
|
||||
info("Navigate to a page with nested iframes");
|
||||
await loadURL(DOC_IFRAME_NESTED);
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function eventWhenAttachingFrame({ client }) {
|
||||
const { Page } = client;
|
||||
|
||||
await Page.enable();
|
||||
|
||||
await runFrameAttachedTest(client, 1, async () => {
|
||||
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async () => {
|
||||
const frame = content.document.createElement("iframe");
|
||||
frame.src = "data:text/html,frame content";
|
||||
|
||||
const loaded = new Promise(resolve => (frame.onload = resolve));
|
||||
content.document.body.appendChild(frame);
|
||||
await loaded;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
async function runFrameAttachedTest(client, expectedEventCount, callback) {
|
||||
const { Page } = client;
|
||||
|
||||
const frameAttachedEvents = [];
|
||||
Page.frameAttached(frame => frameAttachedEvents.push(frame));
|
||||
|
||||
const framesBefore = await getFlattendFrameList();
|
||||
await callback();
|
||||
const framesAfter = await getFlattendFrameList();
|
||||
|
||||
if (expectedEventCount == 0) {
|
||||
is(frameAttachedEvents.length, 0, "Got no frame attached event");
|
||||
return;
|
||||
}
|
||||
|
||||
// check how many frames were added or removed
|
||||
const count = Math.abs(framesBefore.size - framesAfter.size);
|
||||
|
||||
is(count, expectedEventCount, "Expected amount of frames added");
|
||||
is(
|
||||
frameAttachedEvents.length,
|
||||
count,
|
||||
"Received the expected amount of frameAttached events"
|
||||
);
|
||||
|
||||
// extract the new or removed frames
|
||||
const framesAll = new Map([...framesBefore, ...framesAfter]);
|
||||
const expectedFrames = new Map(
|
||||
[...framesAll].filter(([key, _value]) => {
|
||||
return !framesBefore.has(key) && framesAfter.has(key);
|
||||
})
|
||||
);
|
||||
|
||||
frameAttachedEvents.forEach(event => {
|
||||
console.log(`Check frame id ${event.frameId}`);
|
||||
const expectedFrame = expectedFrames.get(event.frameId);
|
||||
|
||||
ok(expectedFrame, `Found expected frame with id ${event.frameId}`);
|
||||
is(
|
||||
event.frameId,
|
||||
expectedFrame.id,
|
||||
"Got expected frame id for frameAttached event"
|
||||
);
|
||||
is(
|
||||
event.parentFrameId,
|
||||
expectedFrame.parentId,
|
||||
"Got expected parent frame id for frameAttached event"
|
||||
);
|
||||
});
|
||||
}
|
@ -1,162 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
const DOC = toDataURL("<div>foo</div>");
|
||||
const DOC_IFRAME_MULTI = toDataURL(`
|
||||
<iframe src='data:text/html,foo'></iframe>
|
||||
<iframe src='data:text/html,bar'></iframe>
|
||||
`);
|
||||
const DOC_IFRAME_NESTED = toDataURL(`
|
||||
<iframe src="data:text/html,<iframe src='data:text/html,foo'></iframe>">
|
||||
</iframe>
|
||||
`);
|
||||
|
||||
// Disable bfcache to force documents to be destroyed on navigation
|
||||
Services.prefs.setIntPref("browser.sessionhistory.max_total_viewers", 0);
|
||||
registerCleanupFunction(() => {
|
||||
Services.prefs.clearUserPref("browser.sessionhistory.max_total_viewers");
|
||||
});
|
||||
|
||||
add_task(async function noEventWhenPageDomainDisabled({ client }) {
|
||||
await loadURL(DOC_IFRAME_MULTI);
|
||||
|
||||
await runFrameDetachedTest(client, 0, async () => {
|
||||
info("Navigate away from a page with an iframe");
|
||||
await loadURL(DOC);
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function noEventAfterPageDomainDisabled({ client }) {
|
||||
const { Page } = client;
|
||||
|
||||
await Page.enable();
|
||||
|
||||
await loadURL(DOC_IFRAME_MULTI);
|
||||
|
||||
await Page.disable();
|
||||
|
||||
await runFrameDetachedTest(client, 0, async () => {
|
||||
info("Navigate away from a page with an iframe");
|
||||
await loadURL(DOC);
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function noEventWhenNavigatingWithNoFrames({ client }) {
|
||||
const { Page } = client;
|
||||
|
||||
await Page.enable();
|
||||
|
||||
await loadURL(DOC);
|
||||
|
||||
await runFrameDetachedTest(client, 0, async () => {
|
||||
info("Navigate away from a page with no iframes");
|
||||
await loadURL(DOC);
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function eventWhenNavigatingWithFrames({ client }) {
|
||||
const { Page } = client;
|
||||
|
||||
await Page.enable();
|
||||
|
||||
await loadURL(DOC_IFRAME_MULTI);
|
||||
|
||||
await runFrameDetachedTest(client, 2, async () => {
|
||||
info("Navigate away from a page with an iframe");
|
||||
await loadURL(DOC);
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function eventWhenNavigatingWithNestedFrames({ client }) {
|
||||
const { Page } = client;
|
||||
|
||||
await Page.enable();
|
||||
|
||||
await loadURL(DOC_IFRAME_NESTED);
|
||||
|
||||
await runFrameDetachedTest(client, 2, async () => {
|
||||
info("Navigate away from a page with nested iframes");
|
||||
await loadURL(DOC);
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function eventWhenDetachingFrame({ client }) {
|
||||
const { Page } = client;
|
||||
|
||||
await Page.enable();
|
||||
|
||||
await loadURL(DOC_IFRAME_MULTI);
|
||||
|
||||
await runFrameDetachedTest(client, 1, async () => {
|
||||
// Remove the single frame from the page
|
||||
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
|
||||
const frame = content.document.getElementsByTagName("iframe")[0];
|
||||
frame.remove();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function eventWhenDetachingNestedFrames({ client }) {
|
||||
const { Page, Runtime } = client;
|
||||
|
||||
await Page.enable();
|
||||
|
||||
await loadURL(DOC_IFRAME_NESTED);
|
||||
|
||||
await Runtime.enable();
|
||||
const { context } = await Runtime.executionContextCreated();
|
||||
|
||||
await runFrameDetachedTest(client, 2, async () => {
|
||||
// Remove top-frame, which also removes any nested frames
|
||||
await evaluate(client, context.id, async () => {
|
||||
const frame = document.getElementsByTagName("iframe")[0];
|
||||
frame.remove();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
async function runFrameDetachedTest(client, expectedEventCount, callback) {
|
||||
const { Page } = client;
|
||||
|
||||
const frameDetachedEvents = [];
|
||||
Page.frameDetached(frame => frameDetachedEvents.push(frame));
|
||||
|
||||
const framesBefore = await getFlattendFrameList();
|
||||
await callback();
|
||||
const framesAfter = await getFlattendFrameList();
|
||||
|
||||
// check how many frames were added or removed
|
||||
const count = Math.abs(framesBefore.size - framesAfter.size);
|
||||
|
||||
if (expectedEventCount == 0) {
|
||||
is(frameDetachedEvents.length, 0, "Got no frame detached event");
|
||||
return;
|
||||
}
|
||||
|
||||
is(count, expectedEventCount, "Expected amount of frames removed");
|
||||
is(
|
||||
frameDetachedEvents.length,
|
||||
count,
|
||||
"Received the expected amount of frameDetached events"
|
||||
);
|
||||
|
||||
// extract the new or removed frames
|
||||
const framesAll = new Map([...framesBefore, ...framesAfter]);
|
||||
const expectedFrames = new Map(
|
||||
[...framesAll].filter(([key, _value]) => {
|
||||
return framesBefore.has(key) && !framesAfter.has(key);
|
||||
})
|
||||
);
|
||||
|
||||
frameDetachedEvents.forEach(event => {
|
||||
const expectedFrame = expectedFrames.get(event.frameId);
|
||||
|
||||
is(
|
||||
event.frameId,
|
||||
expectedFrame.id,
|
||||
"Got expected frame id for frameDetached event"
|
||||
);
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user