Bug 789550 - Avoid using document title while saving data URIs. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D111857
This commit is contained in:
Ava Katushka 2021-04-22 16:14:02 +00:00
parent 4e708d5beb
commit 78e863a680
6 changed files with 135 additions and 9 deletions

View File

@ -1834,7 +1834,7 @@ class nsContextMenu {
referrerInfo,
cookieJarSettings,
this.frameOuterWindowID,
"",
this.mediaURL.startsWith("data") ? "index" : "", // use default file name "index" for data URIs
isContentWindowPrivate
);
}

View File

@ -1053,7 +1053,8 @@ function getDefaultFileName(
// This is something like a data: and so forth URI... no filename here.
}
if (docTitle) {
// Don't use the title if it's from a data URI
if (docTitle && aURI?.scheme != "data") {
// 4) Use the document title
return docTitle;
}

File diff suppressed because one or more lines are too long

View File

@ -72,6 +72,8 @@ skip-if = !e10s || !crashreporter
run-if = e10s && crashreporter
[browser_datetime_datepicker.js]
skip-if = tsan # Frequently times out on TSan
[browser_default_audio_filename.js]
support-files = audio_file.txt
[browser_default_image_filename.js]
[browser_default_image_filename_redirect.js]
support-files =

View File

@ -0,0 +1,98 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
var MockFilePicker = SpecialPowers.MockFilePicker;
MockFilePicker.init(window);
registerCleanupFunction(function() {
MockFilePicker.cleanup();
});
/**
* TestCase for bug 789550
* <https://bugzilla.mozilla.org/show_bug.cgi?id=789550>
*/
add_task(async function() {
const DATA_AUDIO_URL = await fetch(
getRootDirectory(gTestPath) + "audio_file.txt"
).then(async response => response.text());
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: DATA_AUDIO_URL,
},
async function(browser) {
let popupShownPromise = BrowserTestUtils.waitForEvent(
document,
"popupshown"
);
await BrowserTestUtils.synthesizeMouseAtCenter(
"video",
{
type: "contextmenu",
button: 2,
},
browser
);
await popupShownPromise;
let showFilePickerPromise = new Promise(resolve => {
MockFilePicker.showCallback = function(fp) {
is(
fp.defaultString.startsWith("index"),
true,
"File name should be index"
);
resolve();
};
});
// Select "Save Audio As" option from context menu
var saveImageAsCommand = document.getElementById("context-saveaudio");
saveImageAsCommand.doCommand();
await showFilePickerPromise;
let contextMenu = document.getElementById("contentAreaContextMenu");
let popupHiddenPromise = BrowserTestUtils.waitForEvent(
contextMenu,
"popuphidden"
);
contextMenu.hidePopup();
await popupHiddenPromise;
}
);
});
/**
* TestCase for bug 789550
* <https://bugzilla.mozilla.org/show_bug.cgi?id=789550>
*/
add_task(async function() {
const DATA_AUDIO_URL = await fetch(
getRootDirectory(gTestPath) + "audio_file.txt"
).then(async response => response.text());
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: DATA_AUDIO_URL,
},
async function(browser) {
let showFilePickerPromise = new Promise(resolve => {
MockFilePicker.showCallback = function(fp) {
is(
fp.defaultString.startsWith("index"),
true,
"File name should be index"
);
resolve();
};
});
saveBrowser(browser);
await showFilePickerPromise;
}
);
});

View File

@ -3,7 +3,11 @@
var MockFilePicker = SpecialPowers.MockFilePicker;
MockFilePicker.init(window);
const DATA_IMAGE_GIF_URL =
"data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7";
registerCleanupFunction(function() {
MockFilePicker.cleanup();
});
/**
* TestCase for bug 564387
* <https://bugzilla.mozilla.org/show_bug.cgi?id=564387>
@ -12,8 +16,7 @@ add_task(async function() {
await BrowserTestUtils.withNewTab(
{
gBrowser,
url:
"data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7",
url: DATA_IMAGE_GIF_URL,
},
async function(browser) {
let popupShownPromise = BrowserTestUtils.waitForEvent(
@ -39,10 +42,6 @@ add_task(async function() {
};
});
registerCleanupFunction(function() {
MockFilePicker.cleanup();
});
// Select "Save Image As" option from context menu
var saveImageAsCommand = document.getElementById("context-saveimage");
saveImageAsCommand.doCommand();
@ -59,3 +58,28 @@ add_task(async function() {
}
);
});
/**
* TestCase for bug 789550
* <https://bugzilla.mozilla.org/show_bug.cgi?id=789550>
*/
add_task(async function() {
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: DATA_IMAGE_GIF_URL,
},
async function(browser) {
let showFilePickerPromise = new Promise(resolve => {
MockFilePicker.showCallback = function(fp) {
is(fp.defaultString, "index.gif");
resolve();
};
});
saveBrowser(browser);
await showFilePickerPromise;
}
);
});