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 /browser/base/content/test/general/browser_star_hsts.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 '')
-rw-r--r-- | browser/base/content/test/general/browser_star_hsts.js | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/browser/base/content/test/general/browser_star_hsts.js b/browser/base/content/test/general/browser_star_hsts.js new file mode 100644 index 0000000000..92c1dcdb8b --- /dev/null +++ b/browser/base/content/test/general/browser_star_hsts.js @@ -0,0 +1,87 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ +/* eslint-disable mozilla/no-arbitrary-setTimeout */ + +var secureURL = + "https://example.com/browser/browser/base/content/test/general/browser_star_hsts.sjs"; +var unsecureURL = + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + "http://example.com/browser/browser/base/content/test/general/browser_star_hsts.sjs"; + +add_task(async function test_star_redirect() { + registerCleanupFunction(async () => { + // Ensure to remove example.com from the HSTS list. + let sss = Cc["@mozilla.org/ssservice;1"].getService( + Ci.nsISiteSecurityService + ); + sss.resetState( + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + NetUtil.newURI("http://example.com/"), + Services.prefs.getBoolPref("privacy.partition.network_state") + ? { partitionKey: "(http,example.com)" } + : {} + ); + await PlacesUtils.bookmarks.eraseEverything(); + gBrowser.removeCurrentTab(); + }); + + let tab = (gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser)); + // This will add the page to the HSTS cache. + await promiseTabLoadEvent(tab, secureURL, secureURL); + // This should transparently be redirected to the secure page. + await promiseTabLoadEvent(tab, unsecureURL, secureURL); + + await promiseStarState(BookmarkingUI.STATUS_UNSTARRED); + + StarUI._createPanelIfNeeded(); + let bookmarkPanel = document.getElementById("editBookmarkPanel"); + let shownPromise = promisePopupShown(bookmarkPanel); + BookmarkingUI.star.click(); + await shownPromise; + + is(BookmarkingUI.status, BookmarkingUI.STATUS_STARRED, "The star is starred"); +}); + +/** + * Waits for the star to reflect the expected state. + */ +function promiseStarState(aValue) { + return new Promise(resolve => { + let expectedStatus = aValue + ? BookmarkingUI.STATUS_STARRED + : BookmarkingUI.STATUS_UNSTARRED; + (function checkState() { + if ( + BookmarkingUI.status == BookmarkingUI.STATUS_UPDATING || + BookmarkingUI.status != expectedStatus + ) { + info("Waiting for star button change."); + setTimeout(checkState, 1000); + } else { + resolve(); + } + })(); + }); +} + +/** + * Starts a load in an existing tab and waits for it to finish (via some event). + * + * @param aTab + * The tab to load into. + * @param aUrl + * The url to load. + * @param [optional] aFinalURL + * The url to wait for, same as aURL if not defined. + * @return {Promise} resolved when the event is handled. + */ +function promiseTabLoadEvent(aTab, aURL, aFinalURL) { + if (!aFinalURL) { + aFinalURL = aURL; + } + + info("Wait for load tab event"); + BrowserTestUtils.startLoadingURIString(aTab.linkedBrowser, aURL); + return BrowserTestUtils.browserLoaded(aTab.linkedBrowser, false, aFinalURL); +} |