Backed out 2 changesets (bug 1745650) for causing mochitest failures on browser_slow_download.js CLOSED TREE

Backed out changeset 98712a0ace1e (bug 1745650)
Backed out changeset efb69ab57dc9 (bug 1745650)
This commit is contained in:
Cristian Tuns 2022-01-14 08:02:45 -05:00
Родитель eca2e1798c
Коммит cb6d193f17
8 изменённых файлов: 7 добавлений и 235 удалений

Просмотреть файл

@ -680,10 +680,6 @@ static void LogHTTPSOnlyInfo(nsILoadInfo* aLoadInfo) {
MOZ_LOG(sCSMLog, LogLevel::Verbose,
(" - HTTPS_ONLY_TOP_LEVEL_LOAD_IN_PROGRESS"));
}
if (httpsOnlyStatus & nsILoadInfo::HTTPS_ONLY_DOWNLOAD_IN_PROGRESS) {
MOZ_LOG(sCSMLog, LogLevel::Verbose,
(" - HTTPS_ONLY_DOWNLOAD_IN_PROGRESS"));
}
if (httpsOnlyStatus & nsILoadInfo::HTTPS_ONLY_DO_NOT_LOG_TO_CONSOLE) {
MOZ_LOG(sCSMLog, LogLevel::Verbose,
(" - HTTPS_ONLY_DO_NOT_LOG_TO_CONSOLE"));

Просмотреть файл

@ -986,11 +986,8 @@ TestHTTPAnswerRunnable::Notify(nsITimer* aTimer) {
nsCOMPtr<nsIChannel> origChannel = mDocumentLoadListener->GetChannel();
nsCOMPtr<nsILoadInfo> origLoadInfo = origChannel->LoadInfo();
uint32_t origHttpsOnlyStatus = origLoadInfo->GetHttpsOnlyStatus();
uint32_t topLevelLoadInProgress =
origHttpsOnlyStatus & nsILoadInfo::HTTPS_ONLY_TOP_LEVEL_LOAD_IN_PROGRESS;
uint32_t downloadInProgress =
origHttpsOnlyStatus & nsILoadInfo::HTTPS_ONLY_DOWNLOAD_IN_PROGRESS;
if (topLevelLoadInProgress || downloadInProgress) {
if ((origHttpsOnlyStatus &
nsILoadInfo::HTTPS_ONLY_TOP_LEVEL_LOAD_IN_PROGRESS)) {
return NS_OK;
}

Просмотреть файл

@ -12,9 +12,6 @@ support-files = file_downgrade_view_source.sjs
support-files = file_navigation.html
[browser_httpsfirst_speculative_connect.js]
support-files = file_httpsfirst_speculative_connect.html
[browser_slow_download.js]
support-files = file_slow_download.html
file_slow_download.sjs
[browser_download_attribute.js]
support-files = file_download_attribute.html
file_download_attribute.sjs

Просмотреть файл

@ -1,157 +0,0 @@
"use strict";
XPCOMUtils.defineLazyModuleGetters(this, {
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
});
// Create a uri for an https site
const testPath = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"https://example.com"
);
const TEST_URI = testPath + "file_slow_download.html";
const EXPECTED_DOWNLOAD_URL =
"example.com/browser/dom/security/test/https-first/file_slow_download.sjs";
// Since the server send the complete download file after 3 seconds we need an longer timeout
requestLongerTimeout(4);
function promisePanelOpened() {
if (DownloadsPanel.panel && DownloadsPanel.panel.state == "open") {
return Promise.resolve();
}
return BrowserTestUtils.waitForEvent(DownloadsPanel.panel, "popupshown");
}
/**
* Waits for a download to finish, in case it has not finished already.
*
* @param aDownload
* The Download object to wait upon.
*
* @return {Promise}
* @resolves When the download has finished successfully.
* @rejects JavaScript exception if the download failed.
*/
function promiseDownloadStopped(aDownload) {
if (!aDownload.stopped) {
// The download is in progress, wait for the current attempt to finish and
// report any errors that may occur.
return aDownload.start();
}
if (aDownload.succeeded) {
return Promise.resolve();
}
// The download failed or was canceled.
return Promise.reject(aDownload.error || new Error("Download canceled."));
}
// Verifys that no background request was send
let requestCounter = 0;
function examiner() {
SpecialPowers.addObserver(this, "specialpowers-http-notify-request");
}
examiner.prototype = {
observe(subject, topic, data) {
if (topic !== "specialpowers-http-notify-request") {
return;
}
// On Android we have other requests appear here as well. Let's make
// sure we only evaluate requests triggered by the test.
if (
!data.startsWith("http://example.com") &&
!data.startsWith("https://example.com")
) {
return;
}
++requestCounter;
if (requestCounter == 1) {
is(data, TEST_URI, "Download start page is https");
return;
}
if (requestCounter == 2) {
// The specialpowers-http-notify-request fires before the internal redirect( /upgrade) to
// https happens.
is(
data,
"http://" + EXPECTED_DOWNLOAD_URL,
"First download request is http (internal)"
);
return;
}
if (requestCounter == 3) {
is(
data,
"https://" + EXPECTED_DOWNLOAD_URL,
"Download got upgraded to https"
);
return;
}
ok(false, "we should never get here, but just in case");
},
remove() {
SpecialPowers.removeObserver(this, "specialpowers-http-notify-request");
},
};
// Test description:
// 1. Open https://example.com
// 2. Start download - location of download is http
// 3. https-first upgrades to https
// 4. Server send first part of download and after 3 seconds the rest
// 5. Complete download of text file
add_task(async function test_slow_download() {
await SpecialPowers.pushPrefEnv({
set: [
["dom.security.https_first", true],
// ensure that download panel gets opened
["browser.download.improvements_to_download_panel", true],
],
});
// add observer to ensure that the background request gets canceled for the upgraded Download
this.examiner = new examiner();
let downloadsPanelPromise = promisePanelOpened();
let downloadsPromise = Downloads.getList(Downloads.PUBLIC);
BrowserTestUtils.loadURI(gBrowser, TEST_URI);
// wait for downloadsPanel to open before continuing with test
await downloadsPanelPromise;
let downloadList = await downloadsPromise;
is(DownloadsPanel.isPanelShowing, true, "DownloadsPanel should be open.");
is(downloadList._downloads.length, 1, "File should be downloaded.");
let [download] = downloadList._downloads;
// wait for download to finish (with success or error)
await promiseDownloadStopped(download);
is(download.contentType, "text/plain", "File contentType should be correct.");
// ensure https-first did upgrade the scheme.
is(
download.source.url,
"https://" + EXPECTED_DOWNLOAD_URL,
"Scheme should be https."
);
// ensure that no background request was send
is(
requestCounter,
3,
"three requests total (download page, download http, download https/ upgraded)"
);
// ensure that downloaded is complete
is(download.target.size, 25, "Download size is correct");
//clean up
this.examiner.remove();
info("cleaning up downloads");
try {
if (Services.appinfo.OS === "WINNT") {
// We need to make the file writable to delete it on Windows.
await IOUtils.setPermissions(download.target.path, 0o600);
}
await IOUtils.remove(download.target.path);
} catch (error) {
info("The file " + download.target.path + " is not removed, " + error);
}
await downloadList.remove(download);
await download.finalize();
});

Просмотреть файл

@ -1,14 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test slow download from an http site that gets upgraded to https</title>
</head>
<body>
<a href="http://example.com/browser/dom/security/test/https-first/file_slow_download.sjs" download="large-dummy-file.txt" id="testlink">download by attribute</a>
<script>
// click the link to start download
let testlink = document.getElementById("testlink");
testlink.click();
</script>
</body>
</html>

Просмотреть файл

@ -1,26 +0,0 @@
"use strict";
let timer;
// Send a part of the file then wait for 3 second before sending the rest.
// If download isn't exempt from background timer of https-only/-first then the download
// gets cancelled before it completed.
const DELAY_MS = 3500;
function handleRequest(request, response) {
response.processAsync();
timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
response.setHeader("Cache-Control", "no-cache", false);
response.setHeader(
"Content-Disposition",
"attachment; filename=large-dummy-file.txt"
);
response.setHeader("Content-Type", "text/plain");
response.write("Begin the file");
timer.init(
() => {
response.write("End of file");
response.finish();
},
DELAY_MS,
Ci.nsITimer.TYPE_ONE_SHOT
);
}

Просмотреть файл

@ -464,25 +464,17 @@ interface nsILoadInfo : nsISupports
*/
const unsigned long HTTPS_ONLY_TOP_LEVEL_LOAD_IN_PROGRESS = (1 << 4);
/**
* This flag can only ever be set on downloads. It indicates
* that the download https connection succeeded. This flag is mostly
* used to counter time-outs which allows to cancel the channel
* if the https load has not started.
/**
* This flag indicates that the request should not be logged to the
* console.
*/
const unsigned long HTTPS_ONLY_DOWNLOAD_IN_PROGRESS = (1 << 5);
const unsigned long HTTPS_ONLY_DO_NOT_LOG_TO_CONSOLE = (1 << 5);
/**
* This flag indicates that the request should not be logged to the
* console.
*/
const unsigned long HTTPS_ONLY_DO_NOT_LOG_TO_CONSOLE = (1 << 6);
/**
* This flag indicates that the request should not be logged to the
* console.
*/
const unsigned long HTTPS_ONLY_UPGRADED_HTTPS_FIRST = (1 << 7);
const unsigned long HTTPS_ONLY_UPGRADED_HTTPS_FIRST = (1 << 6);
/**
* Upgrade state of HTTPS-Only Mode. The flag HTTPS_ONLY_EXEMPT can get

Просмотреть файл

@ -96,8 +96,6 @@
#include "nsPIDOMWindow.h"
#include "ExternalHelperAppChild.h"
#include "mozilla/dom/nsHTTPSOnlyUtils.h"
#ifdef XP_WIN
# include "nsWindowsHelpers.h"
#endif
@ -1743,17 +1741,6 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest* request) {
// Now get the URI
if (aChannel) {
aChannel->GetURI(getter_AddRefs(mSourceUrl));
// HTTPS-Only/HTTPS-FirstMode tries to upgrade connections to https. Once
// the download is in progress we set that flag so that timeout counter
// measures do not kick in.
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
bool isPrivateWin = loadInfo->GetOriginAttributes().mPrivateBrowsingId > 0;
if (nsHTTPSOnlyUtils::IsHttpsOnlyModeEnabled(isPrivateWin) ||
nsHTTPSOnlyUtils::IsHttpsFirstModeEnabled(isPrivateWin)) {
uint32_t httpsOnlyStatus = loadInfo->GetHttpsOnlyStatus();
httpsOnlyStatus |= nsILoadInfo::HTTPS_ONLY_DOWNLOAD_IN_PROGRESS;
loadInfo->SetHttpsOnlyStatus(httpsOnlyStatus);
}
}
if (!mForceSave && StaticPrefs::browser_download_enable_spam_prevention() &&