mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 826176 - Part 2 - Remove similar file picker filters from accept attribute. r=smaug
This commit is contained in:
parent
f2e759905d
commit
3a8a1d2d33
@ -7382,6 +7382,28 @@ HTMLInputElement::SetFilePickerFiltersFromAccept(nsIFilePicker* filePicker)
|
||||
}
|
||||
}
|
||||
|
||||
// Remove similar filters
|
||||
// Iterate over a copy, as we might modify the original filters list
|
||||
nsTArray<nsFilePickerFilter> filtersCopy;
|
||||
filtersCopy = filters;
|
||||
for (uint32_t i = 0; i < filtersCopy.Length(); ++i) {
|
||||
const nsFilePickerFilter& filterToCheck = filtersCopy[i];
|
||||
if (filterToCheck.mFilterMask) {
|
||||
continue;
|
||||
}
|
||||
for (uint32_t j = 0; j < filtersCopy.Length(); ++j) {
|
||||
if (i == j) {
|
||||
continue;
|
||||
}
|
||||
if (FindInReadable(filterToCheck.mFilter, filtersCopy[j].mFilter)) {
|
||||
// We already have a similar, less restrictive filter (i.e.
|
||||
// filterToCheck extensionList is just a subset of another filter
|
||||
// extension list): remove this one
|
||||
filters.RemoveElement(filterToCheck);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add "All Supported Types" filter
|
||||
if (filters.Length() > 1) {
|
||||
nsXPIDLString title;
|
||||
|
@ -323,6 +323,8 @@ public:
|
||||
* filter specified or not.
|
||||
* @note If more than one valid filter is found, the "All Supported Types"
|
||||
* filter is added, which is the concatenation of all valid filters.
|
||||
* @note Duplicate filters and similar filters (i.e. filters whose file
|
||||
* extensions already exist in another filter) are ignored.
|
||||
* @note "All Files" filter will be selected by default if unknown mime types
|
||||
* have been specified and no file extension filter has been specified.
|
||||
* Otherwise, specified filter or "All Supported Types" filter will be
|
||||
|
@ -11,6 +11,7 @@
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=377624">Mozilla Bug 377624</a>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=565274">Mozilla Bug 565274</a>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=701353">Mozilla Bug 701353</a>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=826176">Mozilla Bug 826176</a>
|
||||
<p id="display"></p>
|
||||
<div id="content">
|
||||
<input id='a' type='file' accept="image/*">
|
||||
@ -29,7 +30,10 @@
|
||||
<input id='n' type="file" accept="">
|
||||
<input id='o' type="file" accept=".test">
|
||||
<input id='p' type="file" accept="image/gif,.csv">
|
||||
<input id='q' type="file" accept="image/gif,.gif">
|
||||
<input id='z' type='file' accept="i/am,a,pathological,;,,,,test/case">
|
||||
<input id='mix-ref' type="file" accept="image/jpeg">
|
||||
<input id='mix' type="file" accept="image/jpeg,.jpg">
|
||||
<input id='hidden' hidden type='file'>
|
||||
<input id='untrusted-click' type='file'>
|
||||
<input id='prevent-default' type='file'>
|
||||
@ -86,7 +90,11 @@ var testData = [["a", 1, MockFilePicker.filterImages, 1],
|
||||
["n", 0, undefined, 0],
|
||||
["o", 1, "*.test", 1],
|
||||
["p", 3, "*.gif; *.csv", 1],
|
||||
["q", 1, "*.gif", 1],
|
||||
["z", 0, undefined, 0],
|
||||
// Note: mix and mix-ref tests extension lists are checked differently: see SimpleTest.executeSoon below
|
||||
["mix-ref", undefined, undefined, undefined],
|
||||
["mix", 1, undefined, 1],
|
||||
["hidden", 0, undefined, 0],
|
||||
["untrusted-click", 0, undefined, 0],
|
||||
["prevent-default", 0, undefined, 0, true],
|
||||
@ -109,6 +117,7 @@ var currentTest = 0;
|
||||
var filterAllAdded;
|
||||
var filters;
|
||||
var filterIndex;
|
||||
var mixRefExtensionList;
|
||||
|
||||
// disable popups to make sure that the popup blocker does not interfere
|
||||
// with manually opened file pickers.
|
||||
@ -196,12 +205,31 @@ function runTests() {
|
||||
"File picker show method should have been called (" + testName + ")");
|
||||
ok(filterAllAdded,
|
||||
"filterAll is missing (" + testName + ")");
|
||||
is(filters.length, testData[currentTest][1],
|
||||
"appendFilters not called as often as expected (" + testName + ")");
|
||||
is(filters[0], testData[currentTest][2],
|
||||
"Correct filters should have been added (" + testName + ")");
|
||||
is(filterIndex, testData[currentTest][3],
|
||||
"File picker should show the correct filter index (" + testName + ")");
|
||||
if (testName == "mix-ref") {
|
||||
// Used only for reference for next test: nothing to be tested here
|
||||
mixRefExtensionList = filters[0];
|
||||
if (mixRefExtensionList == undefined) {
|
||||
mixRefExtensionList = "";
|
||||
}
|
||||
} else {
|
||||
if (testName == "mix") {
|
||||
// Mixing mime type and file extension filters ("image/jpeg" and
|
||||
// ".jpg" here) shouldn't restrict the list but only extend it, if file
|
||||
// extension filter isn't a duplicate
|
||||
ok(filters[0].contains(mixRefExtensionList),
|
||||
"Mixing mime types and file extension filters shouldn't restrict extension list: " +
|
||||
mixRefExtensionList + " | " + filters[0]);
|
||||
ok(filters[0].contains("*.jpg"),
|
||||
"Filter should contain '.jpg' extension", filters[0]);
|
||||
} else {
|
||||
is(filters[0], testData[currentTest][2],
|
||||
"Correct filters should have been added (" + testName + ")");
|
||||
is(filters.length, testData[currentTest][1],
|
||||
"appendFilters not called as often as expected (" + testName + ")");
|
||||
}
|
||||
is(filterIndex, testData[currentTest][3],
|
||||
"File picker should show the correct filter index (" + testName + ")");
|
||||
}
|
||||
|
||||
if (++currentTest == testData.length) {
|
||||
MockFilePicker.cleanup();
|
||||
|
Loading…
Reference in New Issue
Block a user