зеркало из https://github.com/mozilla/gecko-dev.git
145 строки
4.3 KiB
HTML
145 строки
4.3 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=558788
|
|
-->
|
|
<head>
|
|
<title>Test for Bug 558788</title>
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=558788">Mozilla Bug 558788</a>
|
|
<p id="display"></p>
|
|
<div id="content" style="display:none;">
|
|
</div>
|
|
<pre id="test">
|
|
<script type="application/javascript">
|
|
|
|
/** Test for Bug 558788 **/
|
|
|
|
var validElementsDescription = [
|
|
/* element type value required pattern maxlength */
|
|
/* <input> */
|
|
[ "input", null, null, null, null, null ],
|
|
/* <input required value='foo'> */
|
|
[ "input", null, "foo", true, null, null ],
|
|
/* <input type='email'> */
|
|
[ "input", "email", null, null, null, null ],
|
|
/* <input type='email' value='foo@mozilla.org'> */
|
|
[ "input", "email", "foo@mozilla.org", null, null, null ],
|
|
/* <input type='url'> */
|
|
[ "input", "url", null, null, null, null ],
|
|
/* <input type='url' value='http://mozilla.org'> */
|
|
[ "input", "url", "http://mozilla.org", null, null, null ],
|
|
/* <input pattern='\\d\\d'> */
|
|
[ "input", null, null, null, "\\d\\d", null ],
|
|
/* <input pattern='\\d\\d' value='42'> */
|
|
[ "input", null, "42", null, "\\d\\d", null ],
|
|
/* <input maxlength='3'> */
|
|
[ "input", null, null, null, null, "3" ],
|
|
/* <input maxlength='3'> */
|
|
[ "input", null, "foo", null, null, "3" ],
|
|
/* <textarea></textarea> */
|
|
[ "textarea", null, null, null, null, null ],
|
|
/* <textarea required>foo</textarea> */
|
|
[ "textarea", null, "foo", true, null, null ],
|
|
/* <input maxlength='3' value='foo'> */
|
|
[ "input", null, "foobar", null, null, "3", "foo" ],
|
|
];
|
|
|
|
var invalidElementsDescription = [
|
|
/* element type value required pattern maxlength valid-value */
|
|
/* <input required> */
|
|
[ "input", null, null, true, null, null, "foo" ],
|
|
/* <input type='email' value='foo'> */
|
|
[ "input", "email", "foo", null, null, null, "foo@mozilla.org" ],
|
|
/* <input type='url' value='foo'> */
|
|
[ "input", "url", "foo", null, null, null, "http://mozilla.org" ],
|
|
/* <input pattern='\\d\\d' value='foo'> */
|
|
[ "input", null, "foo", null, "\\d\\d", null, "42" ],
|
|
/* <textarea required></textarea> */
|
|
[ "textarea", null, null, true, null, null, "foo" ],
|
|
];
|
|
|
|
var validElements = [];
|
|
var invalidElements = [];
|
|
|
|
function appendElements(aElementsDesc, aElements)
|
|
{
|
|
var content = document.getElementById('content');
|
|
var length = aElementsDesc.length;
|
|
|
|
for (var i=0; i<length; ++i) {
|
|
var e = document.createElement(aElementsDesc[i][0]);
|
|
if (aElementsDesc[i][1]) {
|
|
e.type = aElementsDesc[i][1];
|
|
}
|
|
if (aElementsDesc[i][2]) {
|
|
e.value = aElementsDesc[i][2];
|
|
}
|
|
if (aElementsDesc[i][3]) {
|
|
e.required = true;
|
|
}
|
|
if (aElementsDesc[i][4]) {
|
|
e.pattern = aElementsDesc[i][4];
|
|
}
|
|
if (aElementsDesc[i][5]) {
|
|
e.maxLength = aElementsDesc[i][5];
|
|
}
|
|
|
|
content.appendChild(e);
|
|
|
|
// Adding the element to the appropriate list.
|
|
aElements.push(e);
|
|
}
|
|
}
|
|
|
|
function compareArrayWithSelector(aElements, aSelector)
|
|
{
|
|
var aSelectorElements = document.querySelectorAll(aSelector);
|
|
|
|
is(aSelectorElements.length, aElements.length,
|
|
aSelector + " selector should return the correct number of elements");
|
|
|
|
if (aSelectorElements.length != aElements.length) {
|
|
return;
|
|
}
|
|
|
|
var length = aElements.length;
|
|
for (var i=0; i<length; ++i) {
|
|
is(aSelectorElements[i], aElements[i],
|
|
aSelector + " should return the correct elements");
|
|
}
|
|
}
|
|
|
|
function makeInvalidElementsValid(aInvalidElements,
|
|
aInvalidElementsDesc,
|
|
aValidElements)
|
|
{
|
|
var length = aInvalidElementsDesc.length;
|
|
|
|
for (var i=0; i<length; ++i) {
|
|
var e = aInvalidElements.shift();
|
|
e.value = aInvalidElementsDesc[i][6];
|
|
aValidElements.push(e);
|
|
}
|
|
}
|
|
|
|
appendElements(validElementsDescription, validElements);
|
|
appendElements(invalidElementsDescription, invalidElements);
|
|
|
|
compareArrayWithSelector(validElements, ":valid");
|
|
compareArrayWithSelector(invalidElements, ":invalid");
|
|
|
|
makeInvalidElementsValid(invalidElements, invalidElementsDescription,
|
|
validElements);
|
|
|
|
compareArrayWithSelector(validElements, ":valid");
|
|
compareArrayWithSelector(invalidElements, ":invalid");
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|