Bug 1593186 - Invoke JS{Parent, Window}Actor.actorCreated;r=nika

Differential Revision: https://phabricator.services.mozilla.com/D74639
This commit is contained in:
David Teller 2020-05-11 16:23:52 +00:00
Родитель 72e80153f2
Коммит e11bdf2afc
10 изменённых файлов: 152 добавлений и 30 удалений

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

@ -29,7 +29,6 @@ class TranslationStub extends TranslationParent {
constructor(browser) {
super();
this._browser = browser;
this.actorCreated();
}
get browser() {

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

@ -31,6 +31,8 @@ void JSProcessActorParent::Init(const nsACString& aName,
MOZ_ASSERT(!mManager, "Cannot Init() a JSProcessActorParent twice!");
SetName(aName);
mManager = aManager;
InvokeCallback(CallbackFunction::ActorCreated);
}
JSProcessActorParent::~JSProcessActorParent() { MOZ_ASSERT(!mManager); }

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

@ -31,6 +31,8 @@ void JSWindowActorParent::Init(const nsACString& aName,
MOZ_ASSERT(!mManager, "Cannot Init() a JSWindowActorParent twice!");
SetName(aName);
mManager = aManager;
InvokeCallback(CallbackFunction::ActorCreated);
}
namespace {

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

@ -2,15 +2,35 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const ACTOR_PARENT_CREATED_NOTIFICATION = "test-process-actor-parent-created";
function promiseNotification(aNotification) {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
let notificationResolve;
let notificationObserver = function observer() {
notificationResolve();
Services.obs.removeObserver(notificationObserver, aNotification);
};
return new Promise(resolve => {
notificationResolve = resolve;
Services.obs.addObserver(notificationObserver, aNotification);
});
}
declTest("getActor on both sides", {
async test(browser) {
let parentCreationObserved = promiseNotification(
ACTOR_PARENT_CREATED_NOTIFICATION
);
let parent = browser.browsingContext.currentWindowGlobal.contentParent;
ok(parent, "WindowGlobalParent should have value.");
let actorParent = parent.getActor("TestProcessActor");
is(
actorParent.show(),
"TestProcessActorParent",
"actor show should have vaule."
"actor show should have value."
);
is(
actorParent.manager,
@ -18,20 +38,34 @@ declTest("getActor on both sides", {
"manager should match WindowGlobalParent.contentParent"
);
await SpecialPowers.spawn(browser, [], async function() {
let child = ChromeUtils.contentChild;
ok(child, "WindowGlobalChild should have value.");
let actorChild = child.getActor("TestProcessActor");
is(
actorChild.show(),
"TestProcessActorChild",
"actor show should have vaule."
);
is(
actorChild.manager,
child,
"manager should match ChromeUtils.contentChild."
);
});
await parentCreationObserved;
ok(true, "Parent creation was observed");
await SpecialPowers.spawn(
browser,
[promiseNotification.toString()],
async function(promiseNotificationSource) {
const ACTOR_CHILD_CREATED_NOTIFICATION =
"test-process-actor-child-created";
let childCreationObserved = new Function(promiseNotificationSource)(
ACTOR_CHILD_CREATED_NOTIFICATION
);
let child = ChromeUtils.contentChild;
ok(child, "WindowGlobalChild should have value.");
let actorChild = child.getActor("TestProcessActor");
is(
actorChild.show(),
"TestProcessActorChild",
"actor show should have vaule."
);
is(
actorChild.manager,
child,
"manager should match ChromeUtils.contentChild."
);
await childCreationObserved;
ok(true, "Child creation was observed");
}
);
},
});

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

@ -17,6 +17,21 @@ let processActorOptions = {
},
};
function promiseNotification(aNotification) {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
let notificationResolve;
let notificationObserver = function observer() {
notificationResolve();
Services.obs.removeObserver(notificationObserver, aNotification);
};
return new Promise(resolve => {
notificationResolve = resolve;
Services.obs.addObserver(notificationObserver, aNotification);
});
}
function declTest(name, cfg) {
let { url = "about:blank", remoteTypes, fission, test } = cfg;

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

@ -2,25 +2,69 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const ACTOR_PARENT_CREATED_NOTIFICATION = "test-window-actor-parent-created";
function promiseNotification(aNotification) {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
let notificationResolve;
let notificationObserver = function observer() {
notificationResolve();
Services.obs.removeObserver(notificationObserver, aNotification);
};
return new Promise(resolve => {
notificationResolve = resolve;
Services.obs.addObserver(notificationObserver, aNotification);
});
}
declTest("getActor on both sides", {
async test(browser) {
let parentCreationObserved = promiseNotification(
ACTOR_PARENT_CREATED_NOTIFICATION
);
let parent = browser.browsingContext.currentWindowGlobal;
ok(parent, "WindowGlobalParent should have value.");
let actorParent = parent.getActor("TestWindow");
is(actorParent.show(), "TestWindowParent", "actor show should have vaule.");
is(actorParent.manager, parent, "manager should match WindowGlobalParent.");
await SpecialPowers.spawn(browser, [], async function() {
let child = content.windowGlobalChild;
ok(child, "WindowGlobalChild should have value.");
is(
child.isInProcess,
false,
"Actor should be loaded in the content process."
);
let actorChild = child.getActor("TestWindow");
is(actorChild.show(), "TestWindowChild", "actor show should have vaule.");
is(actorChild.manager, child, "manager should match WindowGlobalChild.");
});
await parentCreationObserved;
ok(true, "Parent creation was observed");
await SpecialPowers.spawn(
browser,
[promiseNotification.toString()],
async function(promiseNotificationSource) {
const ACTOR_CHILD_CREATED_NOTIFICATION =
"test-window-actor-child-created";
let childCreationObserved = new Function(promiseNotificationSource)(
ACTOR_CHILD_CREATED_NOTIFICATION
);
let child = content.windowGlobalChild;
ok(child, "WindowGlobalChild should have value.");
is(
child.isInProcess,
false,
"Actor should be loaded in the content process."
);
let actorChild = child.getActor("TestWindow");
is(
actorChild.show(),
"TestWindowChild",
"actor show should have vaule."
);
is(
actorChild.manager,
child,
"manager should match WindowGlobalChild."
);
await childCreationObserved;
ok(true, "Child creation was observed");
}
);
},
});

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

@ -13,6 +13,13 @@ class TestProcessActorChild extends JSProcessActorChild {
super();
}
actorCreated() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
Services.obs.notifyObservers(null, "test-process-actor-child-created");
}
receiveMessage(aMessage) {
switch (aMessage.name) {
case "toChild":

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

@ -11,7 +11,12 @@ class TestProcessActorParent extends JSProcessActorParent {
super();
this.wrappedJSObject = this;
}
actorCreated() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
Services.obs.notifyObservers(null, "test-process-actor-parent-created");
}
receiveMessage(aMessage) {
switch (aMessage.name) {
case "init":

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

@ -13,6 +13,13 @@ class TestWindowChild extends JSWindowActorChild {
super();
}
actorCreated() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
Services.obs.notifyObservers(null, "test-window-actor-child-created");
}
receiveMessage(aMessage) {
switch (aMessage.name) {
case "toChild":

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

@ -14,6 +14,13 @@ class TestWindowParent extends JSWindowActorParent {
this.wrappedJSObject = this;
}
actorCreated() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
Services.obs.notifyObservers(null, "test-window-actor-child-created");
}
receiveMessage(aMessage) {
switch (aMessage.name) {
case "init":