Backed out 2 changesets (bug 1338637) for perma failures on test_webkitdirectory.html. CLOSED TREE

Backed out changeset 5bddcb99f650 (bug 1338637)
Backed out changeset 5c29fd30af97 (bug 1338637)
This commit is contained in:
Razvan Maries 2020-11-16 18:49:34 +02:00
Родитель bd8ba64c9d
Коммит d92ef717a6
8 изменённых файлов: 1 добавлений и 238 удалений

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

@ -2,7 +2,6 @@
support-files = file_beforeunload_stop.html
[browser_closeTabSpecificPanels.js]
skip-if = verify && debug && (os == 'linux')
[browser_confirmFolderUpload.js]
[browser_multiplePrompts.js]
[browser_openPromptInBackgroundTab.js]
support-files = openPromptOffTimeout.html

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

@ -1,140 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { PromptTestUtils } = ChromeUtils.import(
"resource://testing-common/PromptTestUtils.jsm"
);
/**
* Create a temporary test directory that will be cleaned up on test shutdown.
* @returns {String} - absolute directory path.
*/
function getTestDirectory() {
let tmpDir = Services.dirsvc.get("TmpD", Ci.nsIFile);
tmpDir.append("testdir");
if (!tmpDir.exists()) {
tmpDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
registerCleanupFunction(() => {
tmpDir.remove(true);
});
}
let file1 = tmpDir.clone();
file1.append("foo.txt");
if (!file1.exists()) {
file1.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
}
let file2 = tmpDir.clone();
file2.append("bar.txt");
if (!file2.exists()) {
file2.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
}
return tmpDir.path;
}
add_task(async function setup() {
await SpecialPowers.pushPrefEnv({
set: [
// Allow using our MockFilePicker in the content process.
["dom.filesystem.pathcheck.disabled", true],
["dom.webkitBlink.dirPicker.enabled", true],
],
});
});
/**
* Create a file input, select a folder and wait for the upload confirmation
* prompt to open.
* @param {boolean} confirmUpload - Whether to accept (true) or cancel the
* prompt (false).
* @returns {Promise} - Resolves once the prompt has been closed.
*/
async function testUploadPrompt(confirmUpload) {
await BrowserTestUtils.withNewTab("http://example.com", async browser => {
// Create file input element
await ContentTask.spawn(browser, null, () => {
let input = content.document.createElement("input");
input.id = "filepicker";
input.setAttribute("type", "file");
input.setAttribute("webkitdirectory", "");
content.document.body.appendChild(input);
});
// If we're confirming the dialog, register a "change" listener on the
// file input.
let changePromise;
if (confirmUpload) {
changePromise = ContentTask.spawn(browser, null, async () => {
let input = content.document.getElementById("filepicker");
return ContentTaskUtils.waitForEvent(input, "change").then(
e => e.target.files.length
);
});
}
// Register prompt promise
let promptPromise = PromptTestUtils.waitForPrompt(browser, {
modalType: Services.prompt.MODAL_TYPE_TAB,
promptType: "confirmEx",
});
// Open filepicker
let path = getTestDirectory();
await ContentTask.spawn(browser, { path }, args => {
let MockFilePicker = content.SpecialPowers.MockFilePicker;
MockFilePicker.init(
content,
"A Mock File Picker",
content.SpecialPowers.Ci.nsIFilePicker.modeGetFolder
);
MockFilePicker.useDirectory(args.path);
let input = content.document.getElementById("filepicker");
input.click();
});
// Wait for confirmation prompt
let prompt = await promptPromise;
ok(prompt, "Shown upload confirmation prompt");
is(prompt.ui.button0.label, "Upload", "Accept button label");
ok(prompt.ui.button1.hasAttribute("default"), "Cancel is default button");
// Close confirmation prompt
await PromptTestUtils.handlePrompt(prompt, {
buttonNumClick: confirmUpload ? 0 : 1,
});
// If we accepted, wait for the input elements "change" event
if (changePromise) {
let fileCount = await changePromise;
is(fileCount, 2, "Should have selected 2 files");
} else {
let fileCount = await ContentTask.spawn(browser, null, () => {
return content.document.getElementById("filepicker").files.length;
});
is(fileCount, 0, "Should not have selected any files");
}
// Cleanup
await ContentTask.spawn(browser, null, () => {
content.SpecialPowers.MockFilePicker.cleanup();
});
});
}
// Tests the confirmation prompt that shows after the user picked a folder.
// Confirm the prompt
add_task(async function test_confirm() {
await testUploadPrompt(true);
});
// Cancel the prompt
add_task(async function test_cancel() {
await testUploadPrompt(false);
});

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

@ -131,48 +131,6 @@ class PromptCollection {
result.QueryInterface(Ci.nsIPropertyBag2).get("buttonNumClicked") == 0
);
}
confirmFolderUpload(browsingContext, directoryName) {
let title;
let message;
let acceptLabel;
try {
title = this.stringBundles.dom.GetStringFromName(
"FolderUploadPrompt.title"
);
message = this.stringBundles.dom.formatStringFromName(
"FolderUploadPrompt.message",
[directoryName]
);
acceptLabel = this.stringBundles.dom.GetStringFromName(
"FolderUploadPrompt.acceptButtonLabel"
);
} catch (exception) {
Cu.reportError("Failed to get strings from dom.properties");
return false;
}
let buttonFlags =
Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0 +
Services.prompt.BUTTON_TITLE_CANCEL * Services.prompt.BUTTON_POS_1 +
Services.prompt.BUTTON_POS_1_DEFAULT;
return (
Services.prompt.confirmExBC(
browsingContext,
Services.prompt.MODAL_TYPE_TAB,
title,
message,
buttonFlags,
acceptLabel,
null,
null,
null,
{}
) === 0
);
}
}
const BUNDLES = {

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

@ -54,7 +54,6 @@
#include "nsError.h"
#include "nsIEditor.h"
#include "nsAttrValueOrString.h"
#include "nsIPromptCollection.h"
#include "mozilla/PresState.h"
#include "nsLinebreakConverter.h" //to strip out carriage returns
@ -481,37 +480,6 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult) {
mode == static_cast<int16_t>(nsIFilePicker::modeGetFolder));
nsCOMPtr<nsISupports> tmp;
nsresult rv = mFilePicker->GetDomFileOrDirectory(getter_AddRefs(tmp));
// Show a prompt to get user confirmation before allowing folder access.
// This is to prevent sites from tricking the user into uploading files.
// See Bug 1338637.
if (mode == static_cast<int16_t>(nsIFilePicker::modeGetFolder)) {
nsCOMPtr<nsIPromptCollection> prompter =
do_GetService("@mozilla.org/embedcomp/prompt-collection;1");
if (!prompter) {
return NS_ERROR_NOT_AVAILABLE;
}
bool confirmed = false;
BrowsingContext* bc = mInput->OwnerDoc()->GetBrowsingContext();
// Get directory name
RefPtr<Directory> directory = static_cast<Directory*>(tmp.get());
nsAutoString directoryName;
ErrorResult error;
directory->GetName(directoryName, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
rv = prompter->ConfirmFolderUpload(bc, directoryName, &confirmed);
NS_ENSURE_SUCCESS(rv, rv);
if (!confirmed) {
// User aborted upload
return NS_OK;
}
}
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<Blob> blob = do_QueryObject(tmp);

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

@ -401,7 +401,3 @@ RequestStorageAccessNested=document.requestStorageAccess() may not be called in
RequestStorageAccessUserGesture=document.requestStorageAccess() may only be requested from inside a short running user-generated event handler.
# LOCALIZATION NOTE: Do not translate "Location" and "History".
LocChangeFloodingPrevented=Too many calls to Location or History APIs within a short timeframe.
FolderUploadPrompt.title = Confirm Upload
# LOCALIZATION NOTE: %S is the name of the folder the user selected in the file picker.
FolderUploadPrompt.message = Are you sure you want to upload all files from “%S”? Only do this if you trust the site.
FolderUploadPrompt.acceptButtonLabel = Upload

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

@ -38,11 +38,6 @@ class PromptCollection {
prompter.asyncShowPrompt(msg, resolve);
}).then(result => !!result?.allow);
}
confirmFolderUpload() {
// Folder upload is not supported by GeckoView yet, see Bug 1674428.
return false;
}
}
PromptCollection.prototype.QueryInterface = ChromeUtils.generateQI([

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

@ -183,7 +183,7 @@ function MockFilePickerInstance(window) {
MockFilePickerInstance.prototype = {
QueryInterface: ChromeUtils.generateQI(["nsIFilePicker"]),
init(aParent, aTitle, aMode) {
this.mode = aMode;
MockFilePicker.mode = aMode;
this.filterIndex = MockFilePicker.filterIndex;
this.parent = aParent;
},

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

@ -33,17 +33,4 @@ interface nsIPromptCollection : nsISupports
* @return true if the page should be allowed to repost data.
*/
boolean confirmRepost(in BrowsingContext aBrowsingContext);
/**
* Ask the user for confirmation to upload a selected folder.
*
* @param aBrowsingContext
* The browsing context the prompt should be opened for.
* @param aDirectoryName
* Name of the folder that will be uploaded.
*
* @return true if the user confirmed the upload, false otherwise.
*/
boolean confirmFolderUpload(in BrowsingContext aBrowsingContext,
in AString aDirectoryName);
};