fune/remote/test/browser/browser_page_javascriptDialog_otherTarget.js
Andreas Tolfsen 37c8f955e6 bug 1570378: remote: add bc test helper setup() for empty documents r=remote-protocol-reviewers,jdescottes
For many browser-chrome (bc) tests is does not matter what the
document is, as long as it is does not cause state to bleed over
from the previous test.

For these cases this patch introduces a shorthand, setup(), which
calls setupForURL(url) with an empty document generated by toDataURL("").

Differential Revision: https://phabricator.services.mozilla.com/D40216

--HG--
extra : moz-landing-system : lando
2019-08-05 11:43:58 +00:00

58 lines
1.8 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const FIRST_DOC = toDataURL("default-test-page");
const SECOND_DOC = toDataURL("other-test-page");
// Test that javascript dialog events are emitted by the page domain only if
// the dialog is created for the window of the target.
add_task(async function() {
const { client, tab } = await setupForURL(FIRST_DOC);
const { Page } = client;
info("Enable the page domain");
await Page.enable();
// Add a listener for dialogs on the test page.
Page.javascriptDialogOpening(() => {
ok(false, "Should never receive this event");
});
info("Open another tab");
const otherTab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
SECOND_DOC
);
is(gBrowser.selectedTab, otherTab, "Selected tab is now the new tab");
// Create a promise that resolve when dialog prompt is created.
// It will also take care of closing the dialog.
const onOtherPageDialog = new Promise(r => {
Services.obs.addObserver(function onDialogLoaded(promptContainer) {
Services.obs.removeObserver(onDialogLoaded, "tabmodal-dialog-loaded");
promptContainer.querySelector(".tabmodalprompt-button0").click();
r();
}, "tabmodal-dialog-loaded");
});
info("Trigger an alert in the second page");
ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
content.alert("test");
});
info("Wait for the alert to be detected and closed");
await onOtherPageDialog;
info("Call bringToFront on the test page to make sure we received");
await Page.bringToFront();
BrowserTestUtils.removeTab(otherTab);
await client.close();
ok(true, "The client is closed");
BrowserTestUtils.removeTab(tab);
await RemoteAgent.close();
});