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, accessKey,
tabChecker tabChecker
) { ) {
if (typeof data.type === "undefined") { const TEST_URL = "https://example.org";
ok(false, "Test implementation error: data.type must be provided"); // A helper closure to test notifications in same or different origins.
return; // '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
data.isSolved = data.isSolved || false; // (when true).
if (typeof data.decoderDoctorReportId === "undefined") { async function create_tab_and_test(test_cross_origin) {
data.decoderDoctorReportId = "testReportId"; await BrowserTestUtils.withNewTab(
} { gBrowser, url: TEST_URL },
await BrowserTestUtils.withNewTab({ gBrowser }, async function(browser) { async function(browser) {
let awaitNotificationBar = BrowserTestUtils.waitForNotificationBar( let awaitNotificationBar = BrowserTestUtils.waitForNotificationBar(
gBrowser, gBrowser,
browser, browser,
"decoder-doctor-notification" "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( Services.obs.notifyObservers(
content.window, content.window,
"decoder-doctor-notification", "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) { if (!notificationMessage) {
ok( ok(
@ -92,7 +125,23 @@ async function test_decoder_doctor_notification(
let openedTab = await awaitNewTab; let openedTab = await awaitNewTab;
tabChecker(openedTab); tabChecker(openedTab);
BrowserTestUtils.removeTab(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) { function tab_checker_for_sumo(expectedPath) {