/**
* This test checks the behavior of :valid and :invalid pseudo-classes
* when the user is typing/interacting with the element.
* Only <input> and <textarea> elements can have there validity changed by an
* user input.
*/
var gContent = document.getElementById('content');
function checkValidApplies(elmt)
{
is(window.getComputedStyle(elmt).getPropertyValue('background-color'), "rgb(0, 255, 0)", ":valid pseudo-class should apply");
}
function checkInvalidApplies(elmt, aTodo)
{
if (aTodo) {
todo_is(window.getComputedStyle(elmt).getPropertyValue('background-color'), "rgb(255, 0, 0)", ":invalid pseudo-class should apply");
return;
}
is(window.getComputedStyle(elmt).getPropertyValue('background-color'), "rgb(255, 0, 0)", ":invalid pseudo-class should apply");
}
function checkMissing(elementName)
{ var element = document.createElement(elementName);
element.required = true;
gContent.appendChild(element);
checkInvalidApplies(element);
function checkTextAreaMissing()
{
checkMissing('textarea');
}
function checkTextAreaTooLong()
{
checkTooLong('textarea');
}
function checkTextArea()
{
checkTextAreaMissing();
checkTextAreaTooLong();
}
function checkInputMissing()
{
checkMissing('input');
}
function checkInputTooLong()
{
checkTooLong('input');
}
function checkInputEmail()
{ var element = document.createElement('input');
element.type = 'email';
gContent.appendChild(element);
checkValidApplies(element);
element.focus();
sendString("a");
checkInvalidApplies(element);
sendString("@b.c");
checkValidApplies(element);
synthesizeKey("KEY_Backspace");
for (var i=0; i<4; ++i) {
if (i == 1) {
// a@b is a valid value.
checkValidApplies(element);
} else {
checkInvalidApplies(element);
}
synthesizeKey("KEY_Backspace");
}
checkValidApplies(element);
gContent.removeChild(element);
}
function checkInputURL()
{ var element = document.createElement('input');
element.type = 'url';
gContent.appendChild(element);
checkValidApplies(element);
for (var i=0; i<10; ++i) {
synthesizeKey("KEY_Backspace");
checkValidApplies(element);
}
synthesizeKey("KEY_Backspace");
// "http://" is now invalid
for (var i=0; i<7; ++i) {
checkInvalidApplies(element);
synthesizeKey("KEY_Backspace");
}
checkValidApplies(element);
gContent.removeChild(element);
}
function checkInputPattern()
{ var element = document.createElement('input');
element.pattern = "[0-9]*"
gContent.appendChild(element);
checkValidApplies(element);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.