Bug 1649532 - Add cross origin DecoderDoctor notification test. r=Gijs

Expand the decoder doctor browser chrome test to check that notifications
trigger the expected UI behaviour when sent from cross origin iframes.

Differential Revision: https://phabricator.services.mozilla.com/D88651
This commit is contained in:
Bryce Seager van Dyk 2020-09-01 15:09:19 +00:00
Родитель a90a447c1c
Коммит d4f39d03a6
1 изменённых файлов: 113 добавлений и 64 удалений

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

@ -20,28 +20,61 @@ async function test_decoder_doctor_notification(
accessKey,
tabChecker
) {
if (typeof data.type === "undefined") {
ok(false, "Test implementation error: data.type must be provided");
return;
}
data.isSolved = data.isSolved || false;
if (typeof data.decoderDoctorReportId === "undefined") {
data.decoderDoctorReportId = "testReportId";
}
await BrowserTestUtils.withNewTab({ gBrowser }, async function(browser) {
const TEST_URL = "https://example.org";
// A helper closure to test notifications in same or different origins.
// 'test_cross_origin' is used to determine if the observers used in the test
// are notified in the same frame (when false) or in a cross origin iframe
// (when true).
async function create_tab_and_test(test_cross_origin) {
await BrowserTestUtils.withNewTab(
{ gBrowser, url: TEST_URL },
async function(browser) {
let awaitNotificationBar = BrowserTestUtils.waitForNotificationBar(
gBrowser,
browser,
"decoder-doctor-notification"
);
await SpecialPowers.spawn(browser, [data], async function(aData) {
await SpecialPowers.spawn(
browser,
[data, test_cross_origin],
/* eslint-disable-next-line no-shadow */
async function(data, test_cross_origin) {
if (!test_cross_origin) {
// Notify in the same origin.
Services.obs.notifyObservers(
content.window,
"decoder-doctor-notification",
JSON.stringify(aData)
JSON.stringify(data)
);
return;
// Done notifying in the same origin.
}
// Notify in a different origin.
const CROSS_ORIGIN_URL = "https://example.com";
let frame = content.document.createElement("iframe");
frame.src = CROSS_ORIGIN_URL;
await new Promise(resolve => {
frame.addEventListener("load", () => {
resolve();
});
content.document.body.appendChild(frame);
});
await content.SpecialPowers.spawn(frame, [data], async function(
/* eslint-disable-next-line no-shadow */
data
) {
Services.obs.notifyObservers(
content.window,
"decoder-doctor-notification",
JSON.stringify(data)
);
});
// Done notifying in a different origin.
}
);
if (!notificationMessage) {
ok(
@ -92,7 +125,23 @@ async function test_decoder_doctor_notification(
let openedTab = await awaitNewTab;
tabChecker(openedTab);
BrowserTestUtils.removeTab(openedTab);
});
}
);
}
if (typeof data.type === "undefined") {
ok(false, "Test implementation error: data.type must be provided");
return;
}
data.isSolved = data.isSolved || false;
if (typeof data.decoderDoctorReportId === "undefined") {
data.decoderDoctorReportId = "testReportId";
}
// Test same origin.
await create_tab_and_test(false);
// Test cross origin.
await create_tab_and_test(true);
}
function tab_checker_for_sumo(expectedPath) {