Bug 1789439 - Test. r=smaug,peterv

Depends on D156683

Differential Revision: https://phabricator.services.mozilla.com/D156684
This commit is contained in:
Emilio Cobos Álvarez 2023-02-27 23:30:10 +00:00
parent a3fb56e5ce
commit 91093183a6
3 changed files with 44 additions and 0 deletions

View file

@ -60,6 +60,7 @@ support-files =
file_window_print_another_iframe_and_remove.html
file_window_print_iframe_remove_on_afterprint.html
file_window_print_srcdoc_base_uri.html
file_window_print_reentrant.html
file_coop_header2.html
file_coop_header2.html^headers^

View file

@ -303,3 +303,34 @@ add_task(async function test_base_uri_srcdoc() {
gBrowser.getTabDialogBox(browser).abortAllDialogs();
});
});
add_task(async function test_print_reentrant() {
is(
document.querySelector(".printPreviewBrowser"),
null,
"There shouldn't be any print preview browser"
);
const URI = `${TEST_PATH}file_window_print_reentrant.html`;
await BrowserTestUtils.withNewTab(URI, async function(browser) {
info(
"Waiting for window.print() to run and ensure we're showing the preview..."
);
let helper = new PrintHelper(browser);
await helper.waitForDialog();
let previewBrowser = document.querySelector(".printPreviewBrowser");
isnot(previewBrowser, null, "Should open the print preview correctly");
gBrowser.getTabDialogBox(browser).abortAllDialogs();
let count = await SpecialPowers.spawn(browser, [], () => {
return parseInt(
content.document.getElementById("before-print-count").innerText
);
});
is(count, 1, "Should've fired beforeprint just once");
});
});

View file

@ -0,0 +1,12 @@
<!doctype html>
<div id="before-print-count"></div>
<script>
let count = 0;
onload = function() {
window.addEventListener('beforeprint', (event) => {
document.getElementById("before-print-count").innerText = ++count;
print()
});
print()
};
</script>