Commit a73b559f authored by chang.shu@nokia.com's avatar chang.shu@nokia.com
Browse files

2011-01-20 Chang Shu <chang.shu@nokia.com>

        Reviewed by Darin Adler.

        setContentEditable with invalid string should throw exception.
        https://bugs.webkit.org/show_bug.cgi?id=52057

        Updated expected results after the fix. Also corrected test cases.

        * editing/editability/set-invalid-value-expected.txt:
        * editing/editability/set-invalid-value.html: 1. Fixed the getAttribute expectation as "abc" was failed to set. 2. Added additional check for setting empty string.
        * editing/editability/set-value-caseinsensitive-expected.txt:
        * editing/editability/set-value-caseinsensitive.html: Fixed the getAttribute expectations as all strings should be converted to lower cases.
        * fast/dom/element-attribute-js-null-expected.txt:
        * fast/dom/element-attribute-js-null.html: Fixed this existing test as the expectation for setting with null should throw exception instead of "false". Also added handling code when exception was thrown.
2011-01-20  Chang Shu  <chang.shu@nokia.com>

        Reviewed by Darin Adler.

        setContentEditable with invalid string should throw exception.
        https://bugs.webkit.org/show_bug.cgi?id=52057

        Implemented exception throwing for setContentEditable according to the following spec:
        http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#attr-contenteditable
        Related quotas: "On setting, if the new value is an ASCII case-insensitive match for the
        string 'inherit' then the content attribute must be removed, if the new value is an ASCII
        case-insensitive match for the string 'true' then the content attribute must be set to the
        string 'true', if the new value is an ASCII case-insensitive match for the string 'false'
        then the content attribute must be set to the string 'false', and otherwise the attribute
        setter must raise a SYNTAX_ERR exception."

        * html/HTMLElement.cpp:
        (WebCore::HTMLElement::setContentEditable): Throw exception on invalid input strings; Make setting values case-insensitive and also convert them to lower cases according to the spec.
        * html/HTMLElement.h: Add additional parameter ExceptionCode& for function setContentEditable.
        * html/HTMLElement.idl: Add exception throwing support for contentEditable setter.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@76301 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2c5dbcb8
2011-01-20 Chang Shu <chang.shu@nokia.com>
Reviewed by Darin Adler.
setContentEditable with invalid string should throw exception.
https://bugs.webkit.org/show_bug.cgi?id=52057
Updated expected results after the fix. Also corrected test cases.
* editing/editability/set-invalid-value-expected.txt:
* editing/editability/set-invalid-value.html: 1. Fixed the getAttribute expectation as "abc" was failed to set. 2. Added additional check for setting empty string.
* editing/editability/set-value-caseinsensitive-expected.txt:
* editing/editability/set-value-caseinsensitive.html: Fixed the getAttribute expectations as all strings should be converted to lower cases.
* fast/dom/element-attribute-js-null-expected.txt:
* fast/dom/element-attribute-js-null.html: Fixed this existing test as the expectation for setting with null should throw exception instead of "false". Also added handling code when exception was thrown.
2011-01-20 Adrienne Walker <enne@google.com>
 
Reviewed by James Robinson.
......
......@@ -6,12 +6,16 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
FAIL exceptionThrown should be true. Was false.
FIXME: setContentEditable with invalid string should throw exception. https://bugs.webkit.org/show_bug.cgi?id=52057
PASS document.getElementById("div").getAttribute("contentEditable") is "abc"
FAIL document.getElementById("div").contentEditable should be true. Was inherit.
PASS document.getElementById('div').contentEditable = 'abc' threw exception Error: SYNTAX_ERR: DOM Exception 12.
PASS document.getElementById("div").getAttribute("contentEditable") is "true"
PASS document.getElementById("div").contentEditable is "true"
PASS document.getElementById("div").isContentEditable is true
FAIL window.getComputedStyle(div, "").getPropertyValue("-webkit-user-modify") should be read-write. Was read-only.
PASS window.getComputedStyle(div, "").getPropertyValue("-webkit-user-modify") is "read-write"
PASS document.getElementById('div').contentEditable = '' threw exception Error: SYNTAX_ERR: DOM Exception 12.
PASS document.getElementById("div").getAttribute("contentEditable") is "true"
PASS document.getElementById("div").contentEditable is "true"
PASS document.getElementById("div").isContentEditable is true
PASS window.getComputedStyle(div, "").getPropertyValue("-webkit-user-modify") is "read-write"
PASS successfullyParsed is true
......
......@@ -11,18 +11,14 @@
<script>
description('When contentEditable is set to invalid string, SYNTAX_ERR exception (code: 12) must be raised.')
exceptionThrown = false;
try {
document.getElementById("div").contentEditable = "abc";
} catch (e) {
if (e.code == 12)
exceptionThrown = true;
}
shouldThrow("document.getElementById('div').contentEditable = 'abc'", '"Error: SYNTAX_ERR: DOM Exception 12"');
shouldBe('document.getElementById("div").getAttribute("contentEditable")','"true"');
shouldBe('document.getElementById("div").contentEditable', '"true"');
shouldBe('document.getElementById("div").isContentEditable', 'true');
shouldBe('window.getComputedStyle(div, "").getPropertyValue("-webkit-user-modify")', '"read-write"');
shouldBe('exceptionThrown', 'true');
debug("FIXME: setContentEditable with invalid string should throw exception. https://bugs.webkit.org/show_bug.cgi?id=52057");
shouldBe('document.getElementById("div").getAttribute("contentEditable")','"abc"');
shouldThrow("document.getElementById('div').contentEditable = ''", '"Error: SYNTAX_ERR: DOM Exception 12"');
shouldBe('document.getElementById("div").getAttribute("contentEditable")','"true"');
shouldBe('document.getElementById("div").contentEditable', '"true"');
shouldBe('document.getElementById("div").isContentEditable', 'true');
shouldBe('window.getComputedStyle(div, "").getPropertyValue("-webkit-user-modify")', '"read-write"');
......
......@@ -8,19 +8,19 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS document.getElementById("div1").getAttribute("contentEditable") is "TRue"
PASS document.getElementById("div1").getAttribute("contentEditable") is "true"
PASS document.getElementById("div1").contentEditable is "true"
FAIL document.getElementById("div1").isContentEditable should be true. Was false.
FIXME: isContentEditable is not working properly. Related to https://bugs.webkit.org/show_bug.cgi?id=52058
PASS window.getComputedStyle(div1, "").getPropertyValue("-webkit-user-modify") is "read-write"
PASS document.getElementById("p1").getAttribute("contentEditable") is "faLSE"
PASS document.getElementById("p1").getAttribute("contentEditable") is "false"
PASS document.getElementById("p1").contentEditable is "false"
PASS document.getElementById("p1").isContentEditable is false
PASS window.getComputedStyle(p1, "").getPropertyValue("-webkit-user-modify") is "read-only"
FAIL document.getElementById("p2").hasAttribute("contentEditable") should be false. Was true.
PASS document.getElementById("p2").hasAttribute("contentEditable") is false
PASS document.getElementById("p2").contentEditable is "inherit"
FAIL document.getElementById("p2").isContentEditable should be true. Was false.
FAIL window.getComputedStyle(p2, "").getPropertyValue("-webkit-user-modify") should be read-write. Was read-only.
FIXME: setContentEditable should be case insensitive. https://bugs.webkit.org/show_bug.cgi?id=52059
PASS document.getElementById("p2").isContentEditable is true
PASS window.getComputedStyle(p2, "").getPropertyValue("-webkit-user-modify") is "read-write"
PASS successfullyParsed is true
......
......@@ -19,12 +19,13 @@ document.getElementById("div1").contentEditable = "TRue";
document.getElementById("p1").contentEditable = "faLSE";
document.getElementById("p2").contentEditable = "inHERIT";
shouldBe('document.getElementById("div1").getAttribute("contentEditable")','"TRue"');
shouldBe('document.getElementById("div1").getAttribute("contentEditable")','"true"');
shouldBe('document.getElementById("div1").contentEditable', '"true"');
shouldBe('document.getElementById("div1").isContentEditable', 'true');
debug("FIXME: isContentEditable is not working properly. Related to https://bugs.webkit.org/show_bug.cgi?id=52058");
shouldBe('window.getComputedStyle(div1, "").getPropertyValue("-webkit-user-modify")', '"read-write"');
shouldBe('document.getElementById("p1").getAttribute("contentEditable")','"faLSE"');
shouldBe('document.getElementById("p1").getAttribute("contentEditable")','"false"');
shouldBe('document.getElementById("p1").contentEditable', '"false"');
shouldBe('document.getElementById("p1").isContentEditable', 'false');
shouldBe('window.getComputedStyle(p1, "").getPropertyValue("-webkit-user-modify")', '"read-only"');
......@@ -34,8 +35,6 @@ shouldBe('document.getElementById("p2").contentEditable', '"inherit"');
shouldBe('document.getElementById("p2").isContentEditable', 'true');
shouldBe('window.getComputedStyle(p2, "").getPropertyValue("-webkit-user-modify")', '"read-write"');
debug("FIXME: setContentEditable should be case insensitive. https://bugs.webkit.org/show_bug.cgi?id=52059");
document.getElementById("div1").style.display= 'none';
document.getElementById("p1").style.display= 'none';
document.getElementById("div2").style.display= 'none';
......
......@@ -11,7 +11,7 @@ TEST SUCCEEDED: The value was the empty string. [tested HTMLElement.dir]
TEST SUCCEEDED: The value was the empty string. [tested HTMLElement.className]
TEST SUCCEEDED: The value was the empty string. [tested HTMLElement.innerHTML]
TEST SUCCEEDED: The value was the empty string. [tested HTMLElement.innerText]
TEST FAILED: The value should have been the string 'false' but was the string 'true'. [tested HTMLElement.contentEditable]
TEST SUCCEEDED: Exception (Error: SYNTAX_ERR: DOM Exception 12) was thrown as expected. [tested HTMLElement.contentEditable]
TEST SUCCEEDED: The value was the empty string. [tested HTMLAnchorElement.accessKey]
TEST SUCCEEDED: The value was the empty string. [tested HTMLAnchorElement.charset]
......
......@@ -26,14 +26,26 @@
function nullTestElementAttribute(elementType, element, attr, expected)
{
element[attr] = null;
var exceptionThrown;
try {
element[attr] = null;
} catch (ec) {
exceptionThrown = ec;
}
var result;
if (element[attr] === expected)
result = "<span class='pass'>TEST SUCCEEDED:</span> The value was " + resultStringifier(expected) + ".";
else
result = "<span class='fail'>TEST FAILED:</span> The value should have been " + resultStringifier(expected) + " but was " + resultStringifier(element[attr]) + ".";
if (exceptionThrown) {
if (expected === 'exception')
result = "<span class='pass'>TEST SUCCEEDED:</span> Exception (" + exceptionThrown + ") was thrown as expected.";
else
result = "<span class='fail'>TEST FAILED:</span> An exception was thrown unexpectedly.";
} else {
if (expected === 'exception')
result = "<span class='fail'>TEST FAILED:</span> An exception should have been thrown.";
else if (element[attr] === expected)
result = "<span class='pass'>TEST SUCCEEDED:</span> The value was " + resultStringifier(expected) + ".";
else
result = "<span class='fail'>TEST FAILED:</span> The value should have been " + resultStringifier(expected) + " but was " + resultStringifier(element[attr]) + ".";
}
result += " [tested " + elementType + "." + attr + "]";
printOut(result);
}
......@@ -57,7 +69,7 @@
attributes: [
{name: 'nodeValue', expectedNull: null},
// 'prefix' only works because this is an HTMLElement type node, if it were an
// XML node (created using createElementNS()) this would throw an excection. We
// XML node (created using createElementNS()) this would throw an exception. We
// should test this further as Firefox has a different behavior.
{name: 'prefix', expectedNull: null},
{name: 'textContent', expectedNull: ''}
......@@ -77,7 +89,7 @@
// FIXME: TEST THESE
// {name: 'outerHTML', expectedNull: ''},
// {name: 'outerText', expectedNull: ''},
{name: 'contentEditable', expectedNull: 'false'}
{name: 'contentEditable', expectedNull: 'exception'}
]
},
{
......
2011-01-20 Chang Shu <chang.shu@nokia.com>
Reviewed by Darin Adler.
setContentEditable with invalid string should throw exception.
https://bugs.webkit.org/show_bug.cgi?id=52057
Implemented exception throwing for setContentEditable according to the following spec:
http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#attr-contenteditable
Related quotas: "On setting, if the new value is an ASCII case-insensitive match for the
string 'inherit' then the content attribute must be removed, if the new value is an ASCII
case-insensitive match for the string 'true' then the content attribute must be set to the
string 'true', if the new value is an ASCII case-insensitive match for the string 'false'
then the content attribute must be set to the string 'false', and otherwise the attribute
setter must raise a SYNTAX_ERR exception."
* html/HTMLElement.cpp:
(WebCore::HTMLElement::setContentEditable): Throw exception on invalid input strings; Make setting values case-insensitive and also convert them to lower cases according to the spec.
* html/HTMLElement.h: Add additional parameter ExceptionCode& for function setContentEditable.
* html/HTMLElement.idl: Add exception throwing support for contentEditable setter.
2011-01-19 Adrienne Walker <enne@google.com>
 
Reviewed by James Robinson.
......@@ -729,14 +729,16 @@ void HTMLElement::setContentEditable(Attribute* attr)
}
}
void HTMLElement::setContentEditable(const String &enabled)
void HTMLElement::setContentEditable(const String& enabled, ExceptionCode& ec)
{
if (enabled == "inherit") {
ExceptionCode ec;
if (equalIgnoringCase(enabled, "true"))
setAttribute(contenteditableAttr, "true", ec);
else if (equalIgnoringCase(enabled, "false"))
setAttribute(contenteditableAttr, "false", ec);
else if (equalIgnoringCase(enabled, "inherit"))
removeAttribute(contenteditableAttr, ec);
}
else
setAttribute(contenteditableAttr, enabled.isEmpty() ? "true" : enabled);
ec = SYNTAX_ERR;
}
bool HTMLElement::draggable() const
......
......@@ -61,7 +61,7 @@ public:
virtual bool isContentRichlyEditable() const;
String contentEditable() const;
void setContentEditable(const String&);
void setContentEditable(const String&, ExceptionCode&);
virtual bool draggable() const;
void setDraggable(bool);
......
......@@ -59,7 +59,8 @@ module html {
readonly attribute HTMLCollection children;
attribute [ConvertNullToNullString] DOMString contentEditable;
attribute [ConvertNullToNullString] DOMString contentEditable
setter raises(DOMException);
readonly attribute boolean isContentEditable;
attribute boolean spellcheck;
......
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