mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
Bug 1708734 - Part 3: Add tests for createActor: false, r=kmag
Differential Revision: https://phabricator.services.mozilla.com/D114793
This commit is contained in:
parent
9c17d49cce
commit
ad678cf076
@ -2,33 +2,77 @@
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
"use strict";
|
||||
|
||||
async function createAndShowDropdown(browser) {
|
||||
// Add a select element to the DOM of the loaded document.
|
||||
await SpecialPowers.spawn(browser, [], async function() {
|
||||
content.document.body.innerHTML += `
|
||||
<select id="testSelect">
|
||||
<option>A</option>
|
||||
<option>B</option>
|
||||
</select>`;
|
||||
});
|
||||
|
||||
// Click on the select to show the dropdown.
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter("#testSelect", {}, browser);
|
||||
}
|
||||
|
||||
declTest("test event triggering actor creation", {
|
||||
events: { mozshowdropdown: {} },
|
||||
|
||||
async test(browser) {
|
||||
// Add a select element to the DOM of the loaded document.
|
||||
await SpecialPowers.spawn(browser, [], async function() {
|
||||
content.document.body.innerHTML += `
|
||||
<select id="testSelect">
|
||||
<option>A</option>
|
||||
<option>B</option>
|
||||
</select>`;
|
||||
});
|
||||
|
||||
// Wait for the observer notification.
|
||||
let observePromise = new Promise(resolve => {
|
||||
const TOPIC = "test-js-window-actor-parent-event";
|
||||
Services.obs.addObserver(function obs(subject, topic, data) {
|
||||
is(topic, TOPIC, "topic matches");
|
||||
let observePromise = TestUtils.topicObserved(
|
||||
"test-js-window-actor-parent-event"
|
||||
);
|
||||
|
||||
Services.obs.removeObserver(obs, TOPIC);
|
||||
resolve({ subject, data });
|
||||
}, TOPIC);
|
||||
});
|
||||
|
||||
// Click on the select to show the dropdown.
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter("#testSelect", {}, browser);
|
||||
await createAndShowDropdown(browser);
|
||||
|
||||
// Wait for the observer notification to fire, and inspect the results.
|
||||
let { subject, data } = await observePromise;
|
||||
let [subject, data] = await observePromise;
|
||||
is(data, "mozshowdropdown");
|
||||
|
||||
let parent = browser.browsingContext.currentWindowGlobal;
|
||||
let actorParent = parent.getActor("TestWindow");
|
||||
ok(actorParent, "JSWindowActorParent should have value.");
|
||||
is(
|
||||
subject.wrappedJSObject,
|
||||
actorParent,
|
||||
"Should have been recieved on the right actor"
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
declTest("test createActor:false not triggering actor creation", {
|
||||
events: { mozshowdropdown: { createActor: false } },
|
||||
|
||||
async test(browser) {
|
||||
info("before actor has been created");
|
||||
const TOPIC = "test-js-window-actor-parent-event";
|
||||
function obs() {
|
||||
ok(false, "actor should not be created");
|
||||
}
|
||||
Services.obs.addObserver(obs, TOPIC);
|
||||
|
||||
await createAndShowDropdown(browser);
|
||||
|
||||
// Bounce into the content process & create the actor after showing the
|
||||
// dropdown, in order to be sure that if an event was going to be
|
||||
// delivered, it already would've been.
|
||||
await SpecialPowers.spawn(browser, [], async () => {
|
||||
content.windowGlobalChild.getActor("TestWindow");
|
||||
});
|
||||
ok(true, "observer notification should not have fired");
|
||||
Services.obs.removeObserver(obs, TOPIC);
|
||||
|
||||
// ----------------------------------------------------
|
||||
info("after actor has been created");
|
||||
let observePromise = TestUtils.topicObserved(
|
||||
"test-js-window-actor-parent-event"
|
||||
);
|
||||
await createAndShowDropdown(browser);
|
||||
|
||||
// Wait for the observer notification to fire, and inspect the results.
|
||||
let [subject, data] = await observePromise;
|
||||
is(data, "mozshowdropdown");
|
||||
|
||||
let parent = browser.browsingContext.currentWindowGlobal;
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
/* eslint-disable no-unused-vars */
|
||||
declTest("test observer triggering actor creation", {
|
||||
observers: ["test-js-window-actor-child-observer"],
|
||||
|
||||
async test(browser) {
|
||||
await SpecialPowers.spawn(browser, [], async function() {
|
||||
const TOPIC = "test-js-window-actor-child-observer";
|
||||
@ -26,6 +28,8 @@ declTest("test observer triggering actor creation", {
|
||||
});
|
||||
|
||||
declTest("test observers with null data", {
|
||||
observers: ["test-js-window-actor-child-observer"],
|
||||
|
||||
async test(browser) {
|
||||
await SpecialPowers.spawn(browser, [], async function() {
|
||||
const TOPIC = "test-js-window-actor-child-observer";
|
||||
@ -48,6 +52,8 @@ declTest("test observers with null data", {
|
||||
});
|
||||
|
||||
declTest("observers don't notify with wrong window", {
|
||||
observers: ["test-js-window-actor-child-observer"],
|
||||
|
||||
async test(browser) {
|
||||
const MSG_RE = /JSWindowActor TestWindow: expected window subject for topic 'test-js-window-actor-child-observer'/;
|
||||
let expectMessage = new Promise(resolve => {
|
||||
@ -86,6 +92,7 @@ declTest("observers don't notify with wrong window", {
|
||||
});
|
||||
|
||||
declTest("observers notify with audio-playback", {
|
||||
observers: ["audio-playback"],
|
||||
url:
|
||||
"http://example.com/browser/dom/ipc/tests/JSWindowActor/file_mediaPlayback.html",
|
||||
|
||||
|
@ -13,12 +13,6 @@ let windowActorOptions = {
|
||||
},
|
||||
child: {
|
||||
moduleURI: "resource://testing-common/TestWindowChild.jsm",
|
||||
|
||||
events: {
|
||||
mozshowdropdown: {},
|
||||
},
|
||||
|
||||
observers: ["test-js-window-actor-child-observer", "audio-playback"],
|
||||
},
|
||||
};
|
||||
|
||||
@ -30,14 +24,16 @@ function declTest(name, cfg) {
|
||||
matches,
|
||||
remoteTypes,
|
||||
messageManagerGroups,
|
||||
events,
|
||||
observers,
|
||||
test,
|
||||
} = cfg;
|
||||
|
||||
// Build the actor options object which will be used to register & unregister
|
||||
// our window actor.
|
||||
let actorOptions = {
|
||||
parent: Object.assign({}, windowActorOptions.parent),
|
||||
child: Object.assign({}, windowActorOptions.child),
|
||||
parent: { ...windowActorOptions.parent },
|
||||
child: { ...windowActorOptions.child, events, observers },
|
||||
};
|
||||
actorOptions.allFrames = allFrames;
|
||||
actorOptions.includeChrome = includeChrome;
|
||||
|
Loading…
Reference in New Issue
Block a user