Bug 1701461 - Corrects screenshot filename. r=nchevobbe

Differential Revision: https://phabricator.services.mozilla.com/D110364
This commit is contained in:
Kajal Sah 2021-04-02 17:12:10 +00:00
parent a37b56a98d
commit 1a85ea7596
2 changed files with 29 additions and 1 deletions

View File

@ -81,6 +81,31 @@ add_task(async function() {
label: "The remote iframe is rendered properly in the screenshot",
});
info("Test :screenshot to file default filename");
const message = await executeAndWaitForMessage(
hud,
`:screenshot ${dpr}`,
`Saved to`
);
const date = new Date();
const monthString = (date.getMonth() + 1).toString().padStart(2, "0");
const dayString = date
.getDate()
.toString()
.padStart(2, "0");
const expectedDateString = `${date.getFullYear()}-${monthString}-${dayString}`;
const {
renderedDate,
} = /Saved to .*Screen Shot (?<renderedDate>\d{4}-\d{2}-\d{2}) at \d{2}.\d{2}.\d{2}/.exec(
message.node.textContent
).groups;
is(
renderedDate,
expectedDateString,
`Screenshot file has expected default name (full message: ${message.node.textContent})`
);
info("Remove the downloaded screenshot file and cleanup downloads");
await OS.File.remove(file.path);
await resetDownloads();

View File

@ -187,7 +187,10 @@ function getFilename(defaultName) {
const date = new Date();
const monthString = (date.getMonth() + 1).toString().padStart(2, "0");
const dayString = (date.getDate() + 1).toString().padStart(2, "0");
const dayString = date
.getDate()
.toString()
.padStart(2, "0");
const dateString = `${date.getFullYear()}-${monthString}-${dayString}`;
const timeString = date