Bug 561635 - Implement constraint validation API for output element. r=sicking a2.0=blocking

This commit is contained in:
Mounir Lamouri 2010-08-21 19:54:53 +02:00
parent 4961d1afbf
commit f0abd62b35
3 changed files with 46 additions and 27 deletions

View File

@ -40,11 +40,13 @@
#include "nsFormSubmission.h"
#include "nsDOMSettableTokenList.h"
#include "nsStubMutationObserver.h"
#include "nsConstraintValidation.h"
class nsHTMLOutputElement : public nsGenericHTMLFormElement,
public nsIDOMHTMLOutputElement,
public nsStubMutationObserver
public nsStubMutationObserver,
public nsConstraintValidation
{
public:
nsHTMLOutputElement(already_AddRefed<nsINodeInfo> aNodeInfo);
@ -79,6 +81,9 @@ public:
// has to be used to update the defaultValue attribute.
void DescendantsChanged();
// nsConstraintValidation
PRBool IsBarredFromConstraintValidation() const { return PR_TRUE; }
// nsIMutationObserver
NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
@ -137,6 +142,9 @@ NS_IMPL_ELEMENT_CLONE(nsHTMLOutputElement)
NS_IMPL_STRING_ATTR(nsHTMLOutputElement, Name, name)
// nsConstraintValidation
NS_IMPL_NSCONSTRAINTVALIDATION(nsHTMLOutputElement)
NS_IMETHODIMP
nsHTMLOutputElement::Reset()
{

View File

@ -9,7 +9,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=345624
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<style>
input, textarea, fieldset, button, select, keygen { background-color: rgb(0,0,0) !important; }
input, textarea, fieldset, button, select, keygen, output { background-color: rgb(0,0,0) !important; }
:valid { background-color: rgb(0,255,0) !important; }
:invalid { background-color: rgb(255,0,0) !important; }
</style>
@ -24,6 +24,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=345624
<select id='s' oninvalid="invalidEventHandler(event);"></select>
<textarea id='t' oninvalid="invalidEventHandler(event);"></textarea>
<keygen id='k'></keygen>
<output id='o'></output>
</div>
<pre id="test">
<script type="application/javascript">
@ -87,11 +88,14 @@ function checkConstraintValidationAPIDefaultValues(element)
function checkDefaultPseudoClass()
{
// TODO: add check for <output>
is(window.getComputedStyle(document.getElementById('f'), null)
.getPropertyValue('background-color'), "rgb(0, 0, 0)",
"Nor :valid and :invalid should apply");
is(window.getComputedStyle(document.getElementById('o'), null)
.getPropertyValue('background-color'), "rgb(0, 0, 0)",
"Nor :valid and :invalid should apply");
todo_is(window.getComputedStyle(document.getElementById('k'), null)
.getPropertyValue('background-color'), "rgb(0, 0, 0)",
"Nor :valid and :invalid should apply");
@ -115,8 +119,9 @@ function checkDefaultPseudoClass()
function checkSpecificWillValidate()
{
// fieldset, keygen (TODO) and select elements
// fieldset, output, keygen (TODO) and select elements
ok(!document.getElementById('f').willValidate, "Fielset element should be barred from constraint validation");
ok(!document.getElementById('o').willValidate, "Output element should be barred from constraint validation");
todo(!document.getElementById('k').willValidate, "Keygen element should be barred from constraint validation");
ok(document.getElementById('s').willValidate, "Select element should not be barred from constraint validation");
@ -190,15 +195,22 @@ function checkCommonWillValidate(element)
// TODO: If an element has a datalist element ancestor, it is barred from constraint validation.
}
function checkCustomError(element)
function checkCustomError(element, isBarred)
{
element.setCustomValidity("message");
is(element.validationMessage, "message", "When the element has a custom validity message, validation message should return it");
if (!isBarred) {
is(element.validationMessage, "message",
"When the element has a custom validity message, validation message should return it");
} else {
is(element.validationMessage, "",
"An element barred from constraint validation can't have a validation message");
}
ok(element.validity.customError, "The element should suffer from a custom error");
ok(!element.validity.valid, "The element should not be valid with a custom error");
is(window.getComputedStyle(element, null).getPropertyValue('background-color'),
"rgb(255, 0, 0)", ":invalid pseudo-classs should apply");
isBarred ? "rgb(0, 0, 0)" : "rgb(255, 0, 0)",
":invalid pseudo-classs should apply");
element.setCustomValidity("");
is(element.validationMessage, "", "The element should not have a validation message when reseted");
@ -206,7 +218,8 @@ function checkCustomError(element)
ok(element.validity.valid, "The element should now be valid");
is(window.getComputedStyle(element, null).getPropertyValue('background-color'),
"rgb(0, 255, 0)", ":valid pseudo-class should apply");
isBarred ? "rgb(0, 0, 0)" : "rgb(0, 255, 0)",
":valid pseudo-classs should apply");
}
function checkCheckValidity(element)
@ -253,21 +266,21 @@ function checkValidityStateObjectAliveWithoutElement(element)
ok(v.valid, "When the element is not alive, it should be valid");
}
/* TODO: add <output> element when it will be implemented */
checkConstraintValidationAPIExist(document.getElementById('f'));
checkConstraintValidationAPIExist(document.getElementById('i'));
checkConstraintValidationAPIExist(document.getElementById('b'));
checkConstraintValidationAPIExist(document.getElementById('s'));
checkConstraintValidationAPIExist(document.getElementById('t'));
checkConstraintValidationAPIExist(document.getElementById('k'));
checkConstraintValidationAPIExist(document.getElementById('o'));
/* TODO: add <output> element when it will be implemented */
checkConstraintValidationAPIDefaultValues(document.getElementById('f'));
checkConstraintValidationAPIDefaultValues(document.getElementById('i'));
checkConstraintValidationAPIDefaultValues(document.getElementById('b'));
checkConstraintValidationAPIDefaultValues(document.getElementById('s'));
checkConstraintValidationAPIDefaultValues(document.getElementById('t'));
checkConstraintValidationAPIDefaultValues(document.getElementById('k'));
checkConstraintValidationAPIDefaultValues(document.getElementById('o'));
checkDefaultPseudoClass();
@ -280,12 +293,13 @@ checkCommonWillValidate(document.getElementById('b'));
checkCommonWillValidate(document.getElementById('s'));
checkCommonWillValidate(document.getElementById('t'));
// Not checking fieldset, output and keygen
// because they are always barred from constraint validation.
checkCustomError(document.getElementById('i'));
checkCustomError(document.getElementById('b'));
checkCustomError(document.getElementById('s'));
checkCustomError(document.getElementById('t'));
/* TODO: add "keygen" element */
checkCustomError(document.getElementById('i'), false);
checkCustomError(document.getElementById('b'), false);
checkCustomError(document.getElementById('s'), false);
checkCustomError(document.getElementById('t'), false);
checkCustomError(document.getElementById('f'), true);
checkCustomError(document.getElementById('o'), true);
// Not checking fieldset, output and keygen
// because they are always barred from constraint validation.
@ -294,12 +308,13 @@ checkCheckValidity(document.getElementById('b'));
checkCheckValidity(document.getElementById('s'));
checkCheckValidity(document.getElementById('t'));
/* TODO: add "output" and "keygen" elements */
/* TODO: add "keygen" element */
checkValidityStateObjectAliveWithoutElement("fieldset");
checkValidityStateObjectAliveWithoutElement("input");
checkValidityStateObjectAliveWithoutElement("button");
checkValidityStateObjectAliveWithoutElement("select");
checkValidityStateObjectAliveWithoutElement("textarea");
checkValidityStateObjectAliveWithoutElement("output");
</script>
</pre>

View File

@ -48,6 +48,7 @@
*/
interface nsIDOMDOMSettableTokenList;
interface nsIDOMValidityState;
[scriptable, uuid(0f7f15a9-ea72-4feb-b2b5-2fcbc9c10ab8)]
interface nsIDOMHTMLOutputElement : nsIDOMHTMLElement
@ -60,16 +61,11 @@ interface nsIDOMHTMLOutputElement : nsIDOMHTMLElement
attribute DOMString defaultValue;
attribute DOMString value;
/**
* The next attributes depend on the constraint validation API.
* Keeping them commented until the constraint validation API is implemented.
* See bug bug 345624.
*/
//readonly attribute boolean willValidate;
//readonly attribute ValidityState validity;
//readonly attribute DOMString validationMessage;
//boolean checkValidity();
//void setCustomValidity(in DOMString error);
readonly attribute boolean willValidate;
readonly attribute nsIDOMValidityState validity;
readonly attribute DOMString validationMessage;
boolean checkValidity();
void setCustomValidity(in DOMString error);
/**
* The labels IDL attribute will be added with bug 556743.