Bug 1559548 - Dismissing a download highlight makes it go away and reappear (#5152)

This commit is contained in:
Ed Lee 2019-07-03 14:54:11 -07:00 коммит произвёл GitHub
Родитель 70e4f81313
Коммит 459451d305
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 35 добавлений и 0 удалений

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

@ -8,6 +8,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
DownloadsCommon: "resource:///modules/DownloadsCommon.jsm",
DownloadsViewUI: "resource:///modules/DownloadsViewUI.jsm",
FileUtils: "resource://gre/modules/FileUtils.jsm",
NewTabUtils: "resource://gre/modules/NewTabUtils.jsm",
});
const DOWNLOAD_CHANGED_DELAY_TIME = 1000; // time in ms to delay timer for downloads changed events
@ -82,6 +83,14 @@ this.DownloadsManager = class DownloadsManager {
.sort((download1, download2) => download1.endTime < download2.endTime);
for (const download of downloads) {
// Ignore blocked links, but allow long (data:) uris to avoid high CPU
if (
download.source.url.length < 10000 &&
NewTabUtils.blockedLinks.isBlocked(download.source)
) {
continue;
}
// Only include downloads where the file still exists
if (onlyExists) {
// Refresh download to ensure the 'exists' attribute is up to date

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

@ -39,6 +39,8 @@ describe("Downloads Manager", () => {
refresh: async () => {},
});
assert.ok(downloadsManager._downloadItems.has(DOWNLOAD_URL));
globals.set("NewTabUtils", { blockedLinks: { isBlocked() {} } });
});
afterEach(() => {
downloadsManager._downloadItems.clear();
@ -200,6 +202,30 @@ describe("Downloads Manager", () => {
assert.equal(results[0].url, newDownload.source.url);
assert.equal(results[1].url, nonExistantDownload.source.url);
});
it("should return only unblocked downloads", async () => {
const nonExistantDownload = {
source: { url: "https://site.com/nonExistantDownload.pdf" },
endTime: Date.now() - 40 * 60 * 60 * 1000,
target: { path: "/path/to/nonExistantDownload.pdf", exists: false },
succeeded: true,
refresh: async () => {},
};
downloadsManager.onDownloadAdded(newDownload);
downloadsManager.onDownloadAdded(nonExistantDownload);
globals.set("NewTabUtils", {
blockedLinks: {
isBlocked: item => item.url === nonExistantDownload.source.url,
},
});
const results = await downloadsManager.getDownloads(Infinity, {
numItems: 5,
onlySucceeded: true,
});
assert.equal(results.length, 1);
assert.propertyVal(results[0], "url", newDownload.source.url);
});
it("should only return downloads that were successful if specified", async () => {
const nonSuccessfulDownload = {
source: {url: "https://site.com/nonSuccessfulDownload.pdf"},