diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /toolkit/components/httpsonlyerror/tests/browser/browser_errorpage_www_suggestion.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/httpsonlyerror/tests/browser/browser_errorpage_www_suggestion.js')
-rw-r--r-- | toolkit/components/httpsonlyerror/tests/browser/browser_errorpage_www_suggestion.js | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/toolkit/components/httpsonlyerror/tests/browser/browser_errorpage_www_suggestion.js b/toolkit/components/httpsonlyerror/tests/browser/browser_errorpage_www_suggestion.js new file mode 100644 index 0000000000..7e3eac9817 --- /dev/null +++ b/toolkit/components/httpsonlyerror/tests/browser/browser_errorpage_www_suggestion.js @@ -0,0 +1,80 @@ +/* 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"; +requestLongerTimeout(2); + +const TEST_PATH = getRootDirectory(gTestPath).replace( + "chrome://mochitests/content", + "" +); +const HTML_PATH = "/file_errorpage_www_suggestion.html"; +const KICK_OF_REQUEST_WITH_SUGGESTION = + "http://suggestion-example.com" + TEST_PATH + HTML_PATH; + +add_task(async function () { + info("Check that the www button shows up and leads to a secure www page"); + + await SpecialPowers.pushPrefEnv({ + set: [ + ["dom.security.https_only_mode", true], + ["dom.security.https_only_mode_send_http_background_request", false], + ["dom.security.https_only_mode_error_page_user_suggestions", true], + ], + }); + + let browser = gBrowser.selectedBrowser; + let errorPageLoaded = BrowserTestUtils.waitForErrorPage(browser); + BrowserTestUtils.startLoadingURIString( + browser, + KICK_OF_REQUEST_WITH_SUGGESTION + ); + await errorPageLoaded; + + let pageShownPromise = BrowserTestUtils.waitForContentEvent( + browser, + "pageshow", + true + ); + + // There's an arbitrary interval of 2 seconds in which the background + // request for the www page is made. we wait this out to ensure the + // www button has shown up. + // eslint-disable-next-line mozilla/no-arbitrary-setTimeout + await new Promise(c => setTimeout(c, 2000)); + + await SpecialPowers.spawn(browser, [], async function () { + let doc = content.document; + let innerHTML = doc.body.innerHTML; + let errorPageL10nId = "about-httpsonly-title-alert"; + let suggestionBoxL10nId = "about-httpsonly-suggestion-box-www-text"; + + ok(innerHTML.includes(errorPageL10nId), "the error page should show up"); + ok(doc.documentURI.startsWith("about:httpsonlyerror")); + ok( + innerHTML.includes(suggestionBoxL10nId), + "the suggestion box should show up" + ); + + // click on www button + let wwwButton = content.document.getElementById("openWWW"); + Assert.notStrictEqual(wwwButton, null, "The www Button should be shown"); + + if (!wwwButton) { + ok(false, "We should not be here"); + } else { + wwwButton.click(); + } + }); + await pageShownPromise; + await SpecialPowers.spawn(browser, [], async function () { + let doc = content.document; + let innerHTML = doc.body.innerHTML; + ok( + innerHTML.includes("You are now on the secure www. page"), + "The secure page should be reached after clicking the button" + ); + ok(doc.documentURI.startsWith("https://www."), "Page should be secure www"); + }); +}); |