Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Errors

  • This test gets skipped with pattern: os == 'linux' && os_version == '18.04' && processor == 'x86_64' && socketprocess_networking OR os == 'linux' && os_version == '24.04' && processor == 'x86_64' && display == 'x11' && socketprocess_networking
  • This test failed 1 times in the preceding 30 days. quicksearch this test
  • Manifest: browser/components/downloads/test/browser/browser.toml
/* Any copyright is dedicated to the Public Domain.
"use strict";
const TEST_URL =
const { FileTestUtils } = ChromeUtils.importESModule(
);
add_task(async function test_save_jsonview() {
// Create a cookie that will be valid for the given JSON Document
const cv = Services.cookies.add(
"example.org",
"/",
"cookieKey",
"cookieValue",
false,
false,
false,
Date.now() + 24000 * 60 * 60,
{},
Ci.nsICookie.SAMESITE_LAX,
Ci.nsICookie.SCHEME_HTTPS
);
Assert.equal(cv.result, Ci.nsICookieValidation.eOK);
// Set up the download
let MockFilePicker = SpecialPowers.MockFilePicker;
MockFilePicker.init(window.browsingContext);
let list = await Downloads.getList(Downloads.PUBLIC);
let downloadFinishedPromise = promiseDownloadFinished(list);
let saveFile = FileTestUtils.getTempFile("cookies.sjs");
if (!saveFile.exists()) {
saveFile.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
}
// Open the JSONview
await BrowserTestUtils.withNewTab(TEST_URL, async _ => {
await new Promise(resolve => {
MockFilePicker.showCallback = function (fp) {
saveFile.append("testfile");
MockFilePicker.setFiles([saveFile]);
setTimeout(() => {
resolve(fp.defaultString);
}, 0);
return Ci.nsIFilePicker.returnOK;
};
// Download the JSONview page
document.getElementById("Browser:SavePage").doCommand();
});
});
// Wait for the download and make sure it is the right size
let download = await downloadFinishedPromise;
Assert.ok(download.stopped);
Assert.ok(download.hasProgress);
Assert.equal(download.progress, 100);
Assert.equal(download.currentBytes, 45);
Assert.equal(download.source.url, TEST_URL);
Assert.equal(
await IOUtils.readUTF8(download.target.path),
'{"cookieHeaderValue":"cookieKey=cookieValue"}'
);
Assert.equal(await expectNonZeroDownloadTargetSize(download.target), 45);
MockFilePicker.cleanup();
});