Bug 701353 - Tests that <label> actually activates <input type='file'>. r=smaug

This commit is contained in:
Mounir Lamouri 2013-04-03 17:06:19 +01:00
parent b0874a13a4
commit bd28e1602c
3 changed files with 35 additions and 113 deletions

View File

@ -1,18 +1,16 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=377624
https://bugzilla.mozilla.org/show_bug.cgi?id=565274
-->
<head>
<title>Test for Bug 377624</title>
<title>Test for &lt;input type='file'&gt; file picker</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=377624">Mozilla Bug 36619</a>
<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>
<p id="display"></p>
<div id="content">
<input id='a' type='file' accept="image/*">
@ -37,11 +35,24 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=565274
<input id='right-click' type='file'>
<input id='middle-click' type='file'>
<input id='left-click' type='file'>
<label id='label-1'>foo<input type='file'></label>
<label id='label-2' for='labeled-2'>foo</label><input id='labeled-2' type='file'></label>
<label id='label-3'>foo<input type='file'></label>
<label id='label-4' for='labeled-4'>foo</label><input id='labeled-4' type='file'></label>
<input id='by-button' type='file'>
<button id='button-click' onclick="document.getElementById('by-button').click();">foo</button>
<button id='button-down' onclick="document.getElementById('by-button').click();">foo</button>
<button id='button-up' onclick="document.getElementById('by-button').click();">foo</button>
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 377624 and Bug 565274 **/
/**
* This test checks various scenarios and make sure that a file picker is being
* shown in all of them (minus a few exceptions).
* |testData| defines the tests to do and |launchNextTest| can be used to have
* specific behaviour for some tests. Everything else should just work.
*/
SimpleTest.waitForExplicitFinish();
@ -76,6 +87,13 @@ var testData = [["a", 1, MockFilePicker.filterImages, 1],
["right-click", 0, undefined, 0, true],
["middle-click", 0, undefined, 0, true],
["left-click", 0, undefined, 0],
["label-1", 0, undefined, 0],
["label-2", 0, undefined, 0],
["label-3", 0, undefined, 0],
["label-4", 0, undefined, 0],
["button-click", 0, undefined, 0],
["button-down", 0, undefined, 0],
["button-up", 0, undefined, 0],
];
var currentTest = 0;
@ -93,6 +111,10 @@ function launchNextTest() {
filters = [];
filterIndex = 0;
// Focusing the element will scroll them into view so making sure the clicks
// will work.
document.getElementById(testData[currentTest][0]).focus();
if (testData[currentTest][0] == "untrusted-click") {
var e = document.createEvent('MouseEvents');
e.initEvent('click', true, false);
@ -127,6 +149,13 @@ function launchNextTest() {
++currentTest;
launchNextTest();
}, 500);
} else if (testData[currentTest][0] == 'label-3' ||
testData[currentTest][0] == 'label-4') {
synthesizeMouse(document.getElementById(testData[currentTest][0]), 5, 5, {});
} else if (testData[currentTest][0] == 'button-click' ||
testData[currentTest][0] == 'button-down' ||
testData[currentTest][0] == 'button-up') {
synthesizeMouseAtCenter(document.getElementById(testData[currentTest][0]), {});
} else {
document.getElementById(testData[currentTest][0]).click();
}

View File

@ -38,7 +38,6 @@ MOCHITEST_FILES = test_bug231389.html \
test_bug571352.html \
test_bug572406.html \
test_bug572649.html \
test_bug36619.html \
test_bug620936.html \
test_bug595310.html \
test_bug644542.html \

View File

@ -1,106 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=36619
-->
<head>
<title>Test for Bug 36619</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=36619">Mozilla Bug 36619</a>
<p id="display"></p>
<div id="content" style="display:none;">
<input id='a' type='file'>
</div>
<button id='b' onclick="document.getElementById('a').click();">Show Filepicker</button>
<button id='c' onmousedown="document.getElementById('a').click();">Show Filepicker</button>
<button id='d' onmouseup="document.getElementById('a').click();">Show Filepicker</button>
<pre id="test">
<script type="application/javascript;version=1.8">
/** Test for Bug 36619 **/
let gGen = doTest();
function continueTest() {
gGen.next();
}
function waitForCondition(condition, errorMsg) {
var tries = 0;
var interval = setInterval(function() {
if (tries >= 10) {
ok(false, errorMsg);
moveOn();
}
if (condition()) {
moveOn();
}
tries++;
}, 100);
var moveOn = function() {
clearInterval(interval);
try {
continueTest();
} catch (e if e instanceof StopIteration) {
SimpleTest.finish();
}
};
}
SimpleTest.waitForExplicitFinish();
var MockFilePicker = SpecialPowers.MockFilePicker;
MockFilePicker.init(window);
// enable popups the first time
SpecialPowers.pushPrefEnv({'set': [
["dom.disable_open_during_load", true],
["privacy.popups.showBrowserMessage", false]
]}, function() {
SimpleTest.waitForFocus(function() {
continueTest();
});
});
let showing = function() MockFilePicker.showing;
let notShowing = function() !MockFilePicker.showing;
function doTest() {
ok(true, "Test start");
var b = document.getElementById('b');
b.focus(); // Be sure the element is visible.
synthesizeMouseAtCenter(b, {});
yield waitForCondition(showing,
"File picker showAsync method should have been called");
MockFilePicker.reset();
// Tests that a click on 'a' doesn't call the show method, because it is hidden.
document.getElementById("a").click();
yield waitForCondition(notShowing,
"File picker showAsync method should not have been called");
MockFilePicker.reset();
synthesizeMouseAtCenter(document.getElementById('c'), {});
yield waitForCondition(notShowing,
"File picker showAsync method should not have been called");
MockFilePicker.reset();
synthesizeMouseAtCenter(document.getElementById('d'), {});
yield waitForCondition(showing,
"File picker showAsync method should have been called");
ok(true, "Test completed");
MockFilePicker.cleanup();
}
</script>
</pre>
</body>
</html>