From fd701272db873c77d8a5912064932cb77beb0c24 Mon Sep 17 00:00:00 2001 From: Manuel Bucher Date: Mon, 25 Jul 2022 11:27:54 +0000 Subject: [PATCH] Bug 1774404 - Split up 103 preload tests even further to avoid intermittent timeouts r=necko-reviewers,dragana Differential Revision: https://phabricator.services.mozilla.com/D151709 --- netwerk/test/browser/browser.ini | 10 +++ netwerk/test/browser/browser_103_csp.js | 64 +++++++++++++ netwerk/test/browser/browser_103_preload.js | 95 -------------------- netwerk/test/browser/browser_103_redirect.js | 51 +++++++++++ 4 files changed, 125 insertions(+), 95 deletions(-) create mode 100644 netwerk/test/browser/browser_103_csp.js create mode 100644 netwerk/test/browser/browser_103_redirect.js diff --git a/netwerk/test/browser/browser.ini b/netwerk/test/browser/browser.ini index f0931161134c..a4e95e4cbd86 100644 --- a/netwerk/test/browser/browser.ini +++ b/netwerk/test/browser/browser.ini @@ -80,10 +80,20 @@ support-files = file_lnk.lnk [browser_post_auth.js] skip-if = socketprocess_networking # Bug 1772209 +[browser_103_csp.js] +support-files = + early_hint_preload_test_helper.jsm +skip-if = + os == 'linux' && bits == 64 && !debug # Bug 1744028 and Bug 1746324 [browser_103_telemetry.js] skip-if = os == 'linux' && bits == 64 # Bug 1744028 and Bug 1746324 [browser_103_preload.js] +support-files = + early_hint_preload_test_helper.jsm +skip-if = + os == 'linux' && bits == 64 && !debug # Bug 1744028 and Bug 1746324 +[browser_103_redirect.js] support-files = early_hint_preload_test_helper.jsm skip-if = diff --git a/netwerk/test/browser/browser_103_csp.js b/netwerk/test/browser/browser_103_csp.js new file mode 100644 index 000000000000..ad10d181def9 --- /dev/null +++ b/netwerk/test/browser/browser_103_csp.js @@ -0,0 +1,64 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { lax_request_count_checking } = ChromeUtils.import( + "resource://testing-common/early_hint_preload_test_helper.jsm" +); + +// csp header with "img-src: 'none'" only on main html response, don't show the image on the page +add_task(async function test_preload_csp_imgsrc_none() { + // reset the count + let headers = new Headers(); + headers.append("X-Early-Hint-Count-Start", ""); + await fetch( + "https://example.com/browser/netwerk/test/browser/early_hint_pixel_count.sjs", + { headers } + ); + + let requestUrl = + "https://example.com/browser/netwerk/test/browser/103_preload_csp_imgsrc_none.html"; + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: requestUrl, + waitForLoad: true, + }, + async function(browser) { + let noImgLoaded = await SpecialPowers.spawn(browser, [], function() { + let loadInfo = content.performance.getEntriesByName( + "https://example.com/browser/netwerk/test/browser/early_hint_pixel.sjs?1ac2a5e1-90c7-4171-b0f0-676f7d899af3" + ); + return loadInfo.every(entry => entry.decodedBodySize === 0); + }); + await Assert.ok( + noImgLoaded, + "test_preload_csp_imgsrc_none: Image dislpayed unexpectedly" + ); + } + ); + + let gotRequestCount = await fetch( + "https://example.com/browser/netwerk/test/browser/early_hint_pixel_count.sjs" + ).then(response => response.json()); + let expectedRequestCount = { hinted: 1, normal: 0 }; + + // TODO: Switch to stricter counting method after fixing https://bugzilla.mozilla.org/show_bug.cgi?id=1753730#c11 + await lax_request_count_checking( + "test_preload_csp_imgsrc_none", + gotRequestCount, + expectedRequestCount + ); + /* stricter counting method: + await Assert.deepEqual( + gotRequestCount, + { hinted: 1, normal: 0 }, + "test_preload_csp_imgsrc_none: Unexpected amount of requests made" + ); + */ + + Services.cache2.clear(); +}); diff --git a/netwerk/test/browser/browser_103_preload.js b/netwerk/test/browser/browser_103_preload.js index 12c73a320965..190198fcbf1b 100644 --- a/netwerk/test/browser/browser_103_preload.js +++ b/netwerk/test/browser/browser_103_preload.js @@ -169,36 +169,6 @@ add_task(async function test_103_insecure_preload() { ); }); -// Early hint to redirect to same origin in secure context -add_task(async function test_103_redirect_same_origin() { - await test_hint_preload( - "test_103_redirect_same_origin", - "https://example.com", - "https://example.com/browser/netwerk/test/browser/early_hint_redirect.sjs?https://example.com/browser/netwerk/test/browser/early_hint_pixel.sjs", - { hinted: 2, normal: 0 } // successful preload of redirect and resulting image - ); -}); - -// Early hint to redirect to cross origin in secure context -add_task(async function test_103_redirect_cross_origin() { - await test_hint_preload( - "test_103_redirect_cross_origin", - "https://example.com", - "https://example.com/browser/netwerk/test/browser/early_hint_redirect.sjs?https://example.net/browser/netwerk/test/browser/early_hint_pixel.sjs", - { hinted: 2, normal: 0 } // successful load of redirect in preload, but image loaded via normal load - ); -}); - -// Early hint to redirect to cross origin in insecure context -add_task(async function test_103_redirect_insecure_cross_origin() { - await test_hint_preload( - "test_103_redirect_insecure_cross_origin", - "https://example.com", - "https://example.com/browser/netwerk/test/browser/early_hint_redirect.sjs?http://mochi.test:8888/browser/netwerk/test/browser/early_hint_pixel.sjs", - { hinted: 1, normal: 1 } - ); -}); - // Cross origin preload from secure context to insecure context on same domain add_task(async function test_103_preload_mixed_content() { await test_hint_preload( @@ -209,16 +179,6 @@ add_task(async function test_103_preload_mixed_content() { ); }); -// Cross origin preload from secure context to redirected insecure context on same domain -add_task(async function test_103_preload_redirect_mixed_content() { - await test_hint_preload( - "test_103_preload_redirect_mixed_content", - "https://example.org", - "https://example.org/browser/netwerk/test/browser/early_hint_redirect.sjs?http://example.org/browser/netwerk/test/browser/early_hint_pixel.sjs", - { hinted: 1, normal: 1 } - ); -}); - // Relative url, correct file for requested uri add_task(async function test_103_preload_only_file() { await test_hint_preload( @@ -229,61 +189,6 @@ add_task(async function test_103_preload_only_file() { ); }); -// csp header with "img-src: 'none'" only on main html response, don't show the image on the page -add_task(async function test_preload_csp_imgsrc_none() { - // reset the count - let headers = new Headers(); - headers.append("X-Early-Hint-Count-Start", ""); - await fetch( - "https://example.com/browser/netwerk/test/browser/early_hint_pixel_count.sjs", - { headers } - ); - - let requestUrl = - "https://example.com/browser/netwerk/test/browser/103_preload_csp_imgsrc_none.html"; - - await BrowserTestUtils.withNewTab( - { - gBrowser, - url: requestUrl, - waitForLoad: true, - }, - async function(browser) { - let noImgLoaded = await SpecialPowers.spawn(browser, [], function() { - let loadInfo = content.performance.getEntriesByName( - "https://example.com/browser/netwerk/test/browser/early_hint_pixel.sjs?1ac2a5e1-90c7-4171-b0f0-676f7d899af3" - ); - return loadInfo.every(entry => entry.decodedBodySize === 0); - }); - await Assert.ok( - noImgLoaded, - "test_preload_csp_imgsrc_none: Image dislpayed unexpectedly" - ); - } - ); - - let gotRequestCount = await fetch( - "https://example.com/browser/netwerk/test/browser/early_hint_pixel_count.sjs" - ).then(response => response.json()); - let expectedRequestCount = { hinted: 1, normal: 0 }; - - // TODO: Switch to stricter counting method after fixing https://bugzilla.mozilla.org/show_bug.cgi?id=1753730#c11 - await lax_request_count_checking( - "test_preload_csp_imgsrc_none", - gotRequestCount, - expectedRequestCount - ); - /* stricter counting method: - await Assert.deepEqual( - gotRequestCount, - { hinted: 1, normal: 0 }, - "test_preload_csp_imgsrc_none: Unexpected amount of requests made" - ); - */ - - Services.cache2.clear(); -}); - // Test that preloads in iframes don't get triggered add_task(async function test_103_iframe() { // reset the count diff --git a/netwerk/test/browser/browser_103_redirect.js b/netwerk/test/browser/browser_103_redirect.js new file mode 100644 index 000000000000..221ccdf6c359 --- /dev/null +++ b/netwerk/test/browser/browser_103_redirect.js @@ -0,0 +1,51 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +Services.prefs.setBoolPref("network.early-hints.enabled", true); + +const { test_hint_preload } = ChromeUtils.import( + "resource://testing-common/early_hint_preload_test_helper.jsm" +); + +// Early hint to redirect to same origin in secure context +add_task(async function test_103_redirect_same_origin() { + await test_hint_preload( + "test_103_redirect_same_origin", + "https://example.com", + "https://example.com/browser/netwerk/test/browser/early_hint_redirect.sjs?https://example.com/browser/netwerk/test/browser/early_hint_pixel.sjs", + { hinted: 2, normal: 0 } // successful preload of redirect and resulting image + ); +}); + +// Early hint to redirect to cross origin in secure context +add_task(async function test_103_redirect_cross_origin() { + await test_hint_preload( + "test_103_redirect_cross_origin", + "https://example.com", + "https://example.com/browser/netwerk/test/browser/early_hint_redirect.sjs?https://example.net/browser/netwerk/test/browser/early_hint_pixel.sjs", + { hinted: 2, normal: 0 } // successful load of redirect in preload, but image loaded via normal load + ); +}); + +// Early hint to redirect to cross origin in insecure context +add_task(async function test_103_redirect_insecure_cross_origin() { + await test_hint_preload( + "test_103_redirect_insecure_cross_origin", + "https://example.com", + "https://example.com/browser/netwerk/test/browser/early_hint_redirect.sjs?http://mochi.test:8888/browser/netwerk/test/browser/early_hint_pixel.sjs", + { hinted: 1, normal: 1 } + ); +}); + +// Cross origin preload from secure context to redirected insecure context on same domain +add_task(async function test_103_preload_redirect_mixed_content() { + await test_hint_preload( + "test_103_preload_redirect_mixed_content", + "https://example.org", + "https://example.org/browser/netwerk/test/browser/early_hint_redirect.sjs?http://example.org/browser/netwerk/test/browser/early_hint_pixel.sjs", + { hinted: 1, normal: 1 } + ); +});