Commit b8661d0e authored by pkasting@chromium.org's avatar pkasting@chromium.org

WebCore:

2009-07-27  Michelangelo De Simone  <micdesim@gmail.com>

        Reviewed by Darin Adler.

        https://bugs.webkit.org/show_bug.cgi?id=25552
        Added new "pattern" attribute to HTMLInputElement and validation code
        (validity.patternMismatch) as per HTML5 specs.
        http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#attr-input-pattern

        Tests: fast/forms/ValidityState-002.html
               fast/forms/ValidityState-patternMismatch-001.html
               fast/forms/ValidityState-patternMismatch-002.html
               fast/forms/ValidityState-patternMismatch-003.html
               fast/forms/ValidityState-patternMismatch-004.html
               fast/forms/ValidityState-patternMismatch-005.html
               fast/forms/ValidityState-patternMismatch-006.html
               fast/forms/ValidityState-patternMismatch-007.html
               fast/forms/pattern-attribute-001.html
               fast/forms/pattern-attribute-002.html
               fast/forms/pattern-attribute-003.html

        * html/HTMLAttributeNames.in: pattern attribute
        * html/HTMLFormControlElement.h:
        (WebCore::HTMLFormControlElement::patternMismatch): method definition
        * html/HTMLInputElement.cpp:
        (WebCore::HTMLInputElement::patternMismatch): validation method
        * html/HTMLInputElement.h:
        * html/HTMLInputElement.idl:
        * html/ValidityState.h:
        (WebCore::ValidityState::patternMismatch): validation flag

LayoutTests:

2009-07-27  Michelangelo De Simone  <micdesim@gmail.com>

        Reviewed by Darin Adler.

        https://bugs.webkit.org/show_bug.cgi?id=25552
        First series of tests for the "pattern" attribute and related validation
        code

        * fast/forms/ValidityState-002-expected.txt: Copied from LayoutTests/fast/forms/willvalidate-001-expected.txt.
        * fast/forms/ValidityState-002.html: Added.
        * fast/forms/ValidityState-patternMismatch-001-expected.txt: Added.
        * fast/forms/ValidityState-patternMismatch-001.html: Added.
        * fast/forms/ValidityState-patternMismatch-002-expected.txt: Added.
        * fast/forms/ValidityState-patternMismatch-002.html: Added.
        * fast/forms/ValidityState-patternMismatch-003-expected.txt: Added.
        * fast/forms/ValidityState-patternMismatch-003.html: Added.
        * fast/forms/ValidityState-patternMismatch-004-expected.txt: Added.
        * fast/forms/ValidityState-patternMismatch-004.html: Added.
        * fast/forms/ValidityState-patternMismatch-005-expected.txt: Added.
        * fast/forms/ValidityState-patternMismatch-005.html: Added.
        * fast/forms/ValidityState-patternMismatch-006-expected.txt: Added.
        * fast/forms/ValidityState-patternMismatch-006.html: Added.
        * fast/forms/ValidityState-patternMismatch-007-expected.txt: Added.
        * fast/forms/ValidityState-patternMismatch-007.html: Added.
        * fast/forms/pattern-attribute-001-expected.txt: Added.
        * fast/forms/pattern-attribute-001.html: Added.
        * fast/forms/pattern-attribute-002-expected.txt: Added.
        * fast/forms/pattern-attribute-002.html: Added.
        * fast/forms/pattern-attribute-003-expected.txt: Added.
        * fast/forms/pattern-attribute-003.html: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@46423 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 33cde501
2009-07-27 Michelangelo De Simone <micdesim@gmail.com>
Reviewed by Darin Adler.
https://bugs.webkit.org/show_bug.cgi?id=25552
First series of tests for the "pattern" attribute and related validation
code
* fast/forms/ValidityState-002-expected.txt: Copied from LayoutTests/fast/forms/willvalidate-001-expected.txt.
* fast/forms/ValidityState-002.html: Added.
* fast/forms/ValidityState-patternMismatch-001-expected.txt: Added.
* fast/forms/ValidityState-patternMismatch-001.html: Added.
* fast/forms/ValidityState-patternMismatch-002-expected.txt: Added.
* fast/forms/ValidityState-patternMismatch-002.html: Added.
* fast/forms/ValidityState-patternMismatch-003-expected.txt: Added.
* fast/forms/ValidityState-patternMismatch-003.html: Added.
* fast/forms/ValidityState-patternMismatch-004-expected.txt: Added.
* fast/forms/ValidityState-patternMismatch-004.html: Added.
* fast/forms/ValidityState-patternMismatch-005-expected.txt: Added.
* fast/forms/ValidityState-patternMismatch-005.html: Added.
* fast/forms/ValidityState-patternMismatch-006-expected.txt: Added.
* fast/forms/ValidityState-patternMismatch-006.html: Added.
* fast/forms/ValidityState-patternMismatch-007-expected.txt: Added.
* fast/forms/ValidityState-patternMismatch-007.html: Added.
* fast/forms/pattern-attribute-001-expected.txt: Added.
* fast/forms/pattern-attribute-001.html: Added.
* fast/forms/pattern-attribute-002-expected.txt: Added.
* fast/forms/pattern-attribute-002.html: Added.
* fast/forms/pattern-attribute-003-expected.txt: Added.
* fast/forms/pattern-attribute-003.html: Added.
2009-07-27 Jian Li <jianli@chromium.org>
Reviewed by David Levin.
......
<html>
<head>
<title>patternMismatch and valueMissing</title>
<script language="JavaScript" type="text/javascript">
function log(message) {
document.getElementById("console").innerHTML += "<li>"+message+"</li>";
}
function test() {
if (window.layoutTestController)
layoutTestController.dumpAsText();
v = document.getElementsByName("victim");
log(!v[0].validity.patternMismatch && v[0].validity.valueMissing ? "SUCCESS" : "FAILURE");
}
</script>
</head>
<body onload="test()">
<input name="victim" type="text" pattern="[0-9][A-Z]{3}" required/>
<hr>
<ol id="console"></ol>
</body>
</html>
There is an input type text with pattern attribute set to [0-9][A-Z]{3}, checking its validity.patternMismatch flag.
SUCCESS
<html>
<head>
<title>basic patternMismatch test</title>
<script language="JavaScript" type="text/javascript">
function log(message) {
document.getElementById("console").innerHTML += "<li>"+message+"</li>";
}
function test() {
if (window.layoutTestController)
layoutTestController.dumpAsText();
v = document.getElementsByName("victim");
log(!v[0].validity.patternMismatch ? "SUCCESS" : "FAILURE");
}
</script>
</head>
<body onload="test()">
<p>There is an input type text with pattern attribute set to [0-9][A-Z]{3}, checking its validity.patternMismatch flag.</p>
<input name="victim" pattern="[0-9][A-Z]{3}" value="0AAA"/>
<hr>
<ol id="console"></ol>
</body>
</html>
There is an input type text with no pattern attribute.
SUCCESS
<html>
<head>
<title>basic patternMismatch test 2</title>
<script language="JavaScript" type="text/javascript">
function log(message) {
document.getElementById("console").innerHTML += "<li>"+message+"</li>";
}
function test() {
if (window.layoutTestController)
layoutTestController.dumpAsText();
v = document.getElementsByName("victim");
log(!v[0].validity.patternMismatch ? "SUCCESS" : "FAILURE");
}
</script>
</head>
<body onload="test()">
<p>There is an input type text with no pattern attribute.</p>
<input name="victim" />
<hr>
<ol id="console"></ol>
</body>
</html>
IP Address: Email address:
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
<html>
<head>
<title>basic patternMismatch test 3</title>
<script language="JavaScript" type="text/javascript">
function log(message) {
document.getElementById("console").innerHTML += "<li>"+message+"</li>";
}
function test() {
if (window.layoutTestController)
layoutTestController.dumpAsText();
v = document.getElementsByName("victim");
for (i = 0; i < v.length; i++)
log(!v[i].validity.patternMismatch ? "SUCCESS" : "FAILURE");
}
</script>
</head>
<body onload="test()">
IP Address:
<input name="victim" type="text" pattern="\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b" value="127.0.0.1" />
Email address:
<input name="victim" type="text" pattern="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" value="someone@somewhere.com" />
<input name="victim" type="text" pattern="\b(word1|word2|word3)(?:\W+\w+){1,6}?\W+(word1|word2|word3)\b" value="word1 near word2" />
<input name="victim" type="text" pattern=".{5,}" value="12345" />
<input name="victim" type="text" pattern=".{5,}" value="*(@$!" />
<input name="victim" type="text" pattern=".{5,}" value="*(@^$!" />
<input name="victim" type="text" pattern="0|1|2|3|4|5|6|7|8|" value="3" />
<input name="victim" type="text" pattern="^(foo).*" value="foo"/>
<input name="victim" type="text" pattern="^(foo).*" value="fooo"/>
<input name="victim" type="text" pattern="\w" value="f"/>
<input name="victim" type="text" pattern="\." value="."/>
<input name="victim" type="text" pattern="\)\(" value=")("/>
<input name="victim" type="text" pattern="ab" value="ab"/>
<input name="victim" type="text" pattern="^ab" value="ab"/>
<input name="victim" type="text" pattern="^\(" value="("/>
<input name="victim" type="text" pattern="...\)\(..." value="aaa)(bbb"/>
<input name="victim" type="text" pattern="^" value=""/>
<input name="victim" type="text" pattern="$" value=""/>
<input name="victim" type="text" pattern="foobar" value=""/>
<hr>
<ol id="console"></ol>
</body>
</html>
<html>
<head>
<title>basic patternMismatch test 4</title>
<script language="JavaScript" type="text/javascript">
function log(message) {
document.getElementById("console").innerHTML += "<li>"+message+"</li>";
}
function test() {
if (window.layoutTestController)
layoutTestController.dumpAsText();
v = document.getElementsByName("victim");
log(v[0].validity.patternMismatch ? "SUCCESS" : "FAILURE");
v[0].value = "someone@somewhere.com";
log(!v[0].validity.patternMismatch ? "SUCCESS" : "FAILURE");
}
</script>
</head>
<body onload="test()">
<input name="victim" type="text" pattern="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" value="Wrong!"/>
<hr>
<ol id="console"></ol>
</body>
</html>
<html>
<head>
<title>basic patternMismatch test 5</title>
<script language="JavaScript" type="text/javascript">
function log(message) {
document.getElementById("console").innerHTML += "<li>"+message+"</li>";
}
function test() {
if (window.layoutTestController)
layoutTestController.dumpAsText();
v = document.getElementsByName("victim");
log(v[0].validity.patternMismatch ? "SUCCESS" : "FAILURE");
v[0].value = "gray";
log(!v[0].validity.patternMismatch ? "SUCCESS" : "FAILURE");
v[0].value = "grey";
log(!v[0].validity.patternMismatch ? "SUCCESS" : "FAILURE");
v[0].value = "";
log(!v[0].validity.patternMismatch ? "SUCCESS" : "FAILURE");
}
</script>
</head>
<body onload="test()">
<input name="victim" type="text" pattern="gr[ae]y" value="Wrong!"/>
<hr>
<ol id="console"></ol>
</body>
</html>
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
<html>
<head>
<title>basic patternMismatch test 6</title>
<script language="JavaScript" type="text/javascript">
function log(message) {
document.getElementById("console").innerHTML += "<li>"+message+"</li>";
}
function test() {
if (window.layoutTestController)
layoutTestController.dumpAsText();
v = document.getElementsByName("victim");
for (i = 0; i < v.length; i++)
log(v[i].validity.patternMismatch ? "SUCCESS" : "FAILURE");
}
</script>
</head>
<body onload="test()">
<input name="victim" type="text" pattern="((4\.[0-3])|(2\.[0-3]))" value="Something 4.0"/>
<input name="victim" type="text" pattern="\w" value="*"/>
<input name="victim" type="email" pattern="[0-9]" value="something"/>
<input name="victim" type="text" pattern=".{5,}" value="1234" />
<input name="victim" type="text" pattern=".{5,}" value="*)$!" />
<input name="victim" type="text" pattern=".{5,}" value="(^$!" />
<input name="victim" type="text" pattern="0|1|2|3|4|5|6|7|8|" value="a" />
<input name="victim" type="text" pattern="^(foo).*" value="a foo"/>
<input name="victim" type="text" pattern="\w" value="134"/>
<input name="victim" type="text" pattern="\." value="\."/>
<input name="victim" type="text" pattern="\)\(" value=") ("/>
<input name="victim" type="text" pattern="ab" value="a"/>
<input name="victim" type="text" pattern="ab" value="b"/>
<input name="victim" type="text" pattern="^ab" value="abc"/>
<input name="victim" type="text" pattern="^\(" value="(something"/>
<input name="victim" type="text" pattern="\)\\" value="something)\"/>
<input name="victim" type="text" pattern="...\)\([b]{3}" value="adf)(bbbTEST"/>
<input name="victim" type="text" pattern="foo\\" value="food"/>
<input name="victim" type="text" pattern="^" value="wrong"/>
<input name="victim" type="text" pattern="$" value="wrong"/>
<hr>
<ol id="console"></ol>
</body>
</html>
<html>
<head>
<title>basic patternMismatch test 7</title>
<script language="JavaScript" type="text/javascript">
function log(message) {
document.getElementById("console").innerHTML += "<li>"+message+"</li>";
}
function test() {
if (window.layoutTestController)
layoutTestController.dumpAsText();
v = document.getElementsByName("victim");
log(!v[0].validity.patternMismatch ? "SUCCESS" : "FAILURE");
}
</script>
</head>
<body onload="test()">
<input name="victim" type="text" pattern="" value="Lorem Ipsum"/>
<hr>
<ol id="console"></ol>
</body>
</html>
There an input element with the pattern attribute set.
SUCCESS
<html>
<head>
<title>pattern attribute presence test</title>
<script language="JavaScript" type="text/javascript">
function log(message) {
document.getElementById("console").innerHTML += "<li>"+message+"</li>";
}
function test() {
if (window.layoutTestController)
layoutTestController.dumpAsText();
v = document.getElementsByName("victim");
log(v[0].pattern ? "SUCCESS" : "FAILURE");
}
</script>
</head>
<body onload="test()">
<p>There an input element with the pattern attribute set.</p>
<input name="victim" pattern="something" />
<hr>
<ol id="console"></ol>
</body>
</html>
There an input element with the pattern attribute not set.
SUCCESS
<html>
<head>
<title>pattern attribute set/get test</title>
<script language="JavaScript" type="text/javascript">
function log(message) {
document.getElementById("console").innerHTML += "<li>"+message+"</li>";
}
function test() {
if (window.layoutTestController)
layoutTestController.dumpAsText();
v = document.getElementsByName("victim");
v[0].pattern = "something";
log(v[0].pattern == "something" ? "SUCCESS" : "FAILURE");
}
</script>
</head>
<body onload="test()">
<p>There an input element with the pattern attribute not set.</p>
<input name="victim" />
<hr>
<ol id="console"></ol>
</body>
</html>
There an input element with the pattern attribute set.
SUCCESS
<html>
<head>
<title>pattern attribute set test</title>
<script language="JavaScript" type="text/javascript">
function log(message) {
document.getElementById("console").innerHTML += "<li>"+message+"</li>";
}
function test() {
if (window.layoutTestController)
layoutTestController.dumpAsText();
v = document.getElementsByName("victim");
v[0].pattern += " else";
log(v[0].pattern == "something else" ? "SUCCESS" : "FAILURE");
}
</script>
</head>
<body onload="test()">
<p>There an input element with the pattern attribute set.</p>
<input name="victim" pattern="something" />
<hr>
<ol id="console"></ol>
</body>
</html>
2009-07-27 Michelangelo De Simone <micdesim@gmail.com>
Reviewed by Darin Adler.
https://bugs.webkit.org/show_bug.cgi?id=25552
Added new "pattern" attribute to HTMLInputElement and validation code
(validity.patternMismatch) as per HTML5 specs.
http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#attr-input-pattern
Tests: fast/forms/ValidityState-002.html
fast/forms/ValidityState-patternMismatch-001.html
fast/forms/ValidityState-patternMismatch-002.html
fast/forms/ValidityState-patternMismatch-003.html
fast/forms/ValidityState-patternMismatch-004.html
fast/forms/ValidityState-patternMismatch-005.html
fast/forms/ValidityState-patternMismatch-006.html
fast/forms/ValidityState-patternMismatch-007.html
fast/forms/pattern-attribute-001.html
fast/forms/pattern-attribute-002.html
fast/forms/pattern-attribute-003.html
* html/HTMLAttributeNames.in: pattern attribute
* html/HTMLFormControlElement.h:
(WebCore::HTMLFormControlElement::patternMismatch): method definition
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::patternMismatch): validation method
* html/HTMLInputElement.h:
* html/HTMLInputElement.idl:
* html/ValidityState.h:
(WebCore::ValidityState::patternMismatch): validation flag
2009-07-27 Nikolas Zimmermann <nikolas.zimmermann@torchmobile.com>
Reviewed by George Staikos.
......
......@@ -185,6 +185,7 @@ onwebkitanimationstart
onwebkitanimationiteration
onwebkitanimationend
onwebkittransitionend
pattern
placeholder
pluginurl
poster
......
......@@ -105,6 +105,8 @@ public:
virtual bool willValidate() const;
virtual bool patternMismatch() const { return false; }
void formDestroyed() { m_form = 0; }
virtual void dispatchFocusEvent();
......
......@@ -47,6 +47,7 @@
#include "MappedAttribute.h"
#include "MouseEvent.h"
#include "Page.h"
#include "RegularExpression.h"
#include "RenderButton.h"
#include "RenderFileUploadControl.h"
#include "RenderImage.h"
......@@ -147,6 +148,46 @@ bool HTMLInputElement::valueMissing() const
return false;
}
bool HTMLInputElement::patternMismatch() const
{
switch (inputType()) {
case ISINDEX:
case CHECKBOX:
case RADIO:
case SUBMIT:
case RESET:
case FILE:
case HIDDEN:
case IMAGE:
case BUTTON:
case RANGE:
case NUMBER:
return false;
case TEXT:
case SEARCH:
case URL:
case TELEPHONE:
case EMAIL:
case PASSWORD:
const AtomicString& pattern = getAttribute(patternAttr);
String value = this->value();
// Empty values can't be mismatched
if (pattern.isEmpty() || value.isEmpty())
return false;
RegularExpression patternRegExp(pattern, TextCaseSensitive);
int matchLength = 0;
int valueLength = value.length();
int matchOffset = patternRegExp.match(value, 0, &matchLength);
return matchOffset != 0 || matchLength != valueLength;
}
ASSERT_NOT_REACHED();
return false;
}
static inline CheckedRadioButtons& checkedRadioButtons(const HTMLInputElement *element)
{
if (HTMLFormElement* form = element->form())
......
......@@ -91,6 +91,7 @@ public:
virtual bool isTextFormControl() const { return isTextField(); }
virtual bool valueMissing() const;
virtual bool patternMismatch() const;
bool isTextButton() const { return m_type == SUBMIT || m_type == RESET || m_type == BUTTON; }
virtual bool isRadioButton() const { return m_type == RADIO; }
......
......@@ -41,6 +41,7 @@ module html {
attribute long maxLength;
attribute boolean multiple;
attribute [ConvertNullToNullString] DOMString name;
attribute [Reflect] DOMString pattern;
attribute DOMString placeholder;
attribute boolean readOnly;
attribute boolean required;
......
......@@ -40,7 +40,7 @@ namespace WebCore {
bool valueMissing() { return control()->valueMissing(); }
bool typeMismatch() { return false; }
bool patternMismatch() { return false; }
bool patternMismatch() { return control()->patternMismatch(); }
bool tooLong() { return false; }
bool rangeUnderflow() { return false; }
bool rangeOverflow() { return false; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment