From 4b7a2c677a8bda717cbc21f8e06ee43c0d9f0005 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 6 May 2018 14:31:20 +0200 Subject: moebius#231: Consider blocking top level window data: URIs (tests) https://github.com/MoonchildProductions/moebius/pull/231 --- toolkit/components/printing/tests/browser.ini | 3 +++ .../printing/tests/browser_page_change_print_original.js | 13 ++++++++----- .../printing/tests/file_page_change_print_original_1.html | 8 ++++++++ .../printing/tests/file_page_change_print_original_2.html | 1 + .../mozapps/extensions/test/xpinstall/browser_datauri.js | 8 ++++++++ 5 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 toolkit/components/printing/tests/file_page_change_print_original_1.html create mode 100644 toolkit/components/printing/tests/file_page_change_print_original_2.html (limited to 'toolkit') diff --git a/toolkit/components/printing/tests/browser.ini b/toolkit/components/printing/tests/browser.ini index 88d6bb454..5f2867189 100644 --- a/toolkit/components/printing/tests/browser.ini +++ b/toolkit/components/printing/tests/browser.ini @@ -1,2 +1,5 @@ [browser_page_change_print_original.js] +support-files = + file_page_change_print_original_1.html + file_page_change_print_original_2.html skip-if = os == "mac" diff --git a/toolkit/components/printing/tests/browser_page_change_print_original.js b/toolkit/components/printing/tests/browser_page_change_print_original.js index 5990a486b..864150451 100644 --- a/toolkit/components/printing/tests/browser_page_change_print_original.js +++ b/toolkit/components/printing/tests/browser_page_change_print_original.js @@ -3,8 +3,11 @@ * and we re-initialize print preview (e.g. by changing page orientation), * we still show (and will therefore print) the original contents. */ +const TEST_PATH = getRootDirectory(gTestPath) + .replace("chrome://mochitests/content", "http://example.com"); + add_task(function* pp_after_orientation_change() { - const DATA_URI = `data:text/html,
INITIAL PAGE
`; + const URI = TEST_PATH + "file_page_change_print_original_1.html"; // Can only do something if we have a print preview UI: if (AppConstants.platform != "win" && AppConstants.platform != "linux") { ok(true, "Can't test if there's no print preview."); @@ -12,7 +15,7 @@ add_task(function* pp_after_orientation_change() { } // Ensure we get a browserStopped for this browser - let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, DATA_URI, false, true); + let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, URI, false, true); let browserToPrint = tab.linkedBrowser; let ppBrowser = PrintPreviewListener.getPrintPreviewBrowser(); @@ -26,7 +29,7 @@ add_task(function* pp_after_orientation_change() { // Assert that we are showing the original page yield ContentTask.spawn(ppBrowser, null, function* () { - is(content.document.body.textContent, "INITIAL PAGE", "Should have initial page print previewed."); + is(content.document.body.textContent.trim(), "INITIAL PAGE", "Should have initial page print previewed."); }); yield originalTabNavigated; @@ -43,12 +46,12 @@ add_task(function* pp_after_orientation_change() { // Check that we're still showing the original page. yield ContentTask.spawn(ppBrowser, null, function* () { - is(content.document.body.textContent, "INITIAL PAGE", "Should still have initial page print previewed."); + is(content.document.body.textContent.trim(), "INITIAL PAGE", "Should still have initial page print previewed."); }); // Check that the other tab is definitely showing the new page: yield ContentTask.spawn(browserToPrint, null, function* () { - is(content.document.body.textContent, "REPLACED PAGE!", "Original page should have changed."); + is(content.document.body.textContent.trim(), "REPLACED PAGE!", "Original page should have changed."); }); PrintUtils.exitPrintPreview(); diff --git a/toolkit/components/printing/tests/file_page_change_print_original_1.html b/toolkit/components/printing/tests/file_page_change_print_original_1.html new file mode 100644 index 000000000..76e3be137 --- /dev/null +++ b/toolkit/components/printing/tests/file_page_change_print_original_1.html @@ -0,0 +1,8 @@ + +
INITIAL PAGE
diff --git a/toolkit/components/printing/tests/file_page_change_print_original_2.html b/toolkit/components/printing/tests/file_page_change_print_original_2.html new file mode 100644 index 000000000..44f33281c --- /dev/null +++ b/toolkit/components/printing/tests/file_page_change_print_original_2.html @@ -0,0 +1 @@ +REPLACED PAGE! diff --git a/toolkit/mozapps/extensions/test/xpinstall/browser_datauri.js b/toolkit/mozapps/extensions/test/xpinstall/browser_datauri.js index 917f2465d..b24bce4b5 100644 --- a/toolkit/mozapps/extensions/test/xpinstall/browser_datauri.js +++ b/toolkit/mozapps/extensions/test/xpinstall/browser_datauri.js @@ -13,6 +13,13 @@ function setup_redirect(aSettings) { } function test() { + waitForExplicitFinish(); + SpecialPowers.pushPrefEnv({ + "set": [["security.data_uri.block_toplevel_data_uri_navigations", false]] + }, runTest); +} + +function runTest() { Harness.installOriginBlockedCallback = install_blocked; Harness.installsCompletedCallback = finish_test; Harness.setup(); @@ -33,4 +40,5 @@ function finish_test(count) { gBrowser.removeCurrentTab(); Harness.finish(); + finish(); } -- cgit v1.2.3