Title: [98353] trunk
Revision
98353
Author
commit-qu...@webkit.org
Date
2011-10-25 09:53:52 -0700 (Tue, 25 Oct 2011)

Log Message

Source/WebCore: Microdata: itemtype attribute should be space-separated list to allow multiple types.
https://bugs.webkit.org/show_bug.cgi?id=70501

Patch by Arko Saha <a...@motorola.com> on 2011-10-25
Reviewed by Ryosuke Niwa.

Tests: fast/dom/MicroData/getitems-multiple-itemtypes.html
       fast/dom/MicroData/itemtype-add-remove-tokens.html
       fast/dom/MicroData/itemtype-attribute-test.html

* dom/MicroDataItemList.cpp:
(WebCore::MicroDataItemList::nodeMatches):
* html/DOMSettableTokenList.h:
(WebCore::DOMSettableTokenList::tokens):
* html/HTMLElement.cpp:
(WebCore::HTMLElement::parseMappedAttribute):
(WebCore::HTMLElement::setItemValueText):
(WebCore::HTMLElement::itemType):
(WebCore::HTMLElement::setItemType):
* html/HTMLElement.h:
* html/HTMLElement.idl:

LayoutTests: Microdata: itemtype attribute should be space-separated list to allow multiple types
https://bugs.webkit.org/show_bug.cgi?id=70501

Patch by Arko Saha <a...@motorola.com> on 2011-10-25
Reviewed by Ryosuke Niwa.

* fast/dom/MicroData/006.html:
* fast/dom/MicroData/007.html:
* fast/dom/MicroData/getitems-multiple-itemtypes-expected.txt: Added.
* fast/dom/MicroData/getitems-multiple-itemtypes.html: Added.
* fast/dom/MicroData/itemtype-add-remove-tokens-expected.txt: Added.
* fast/dom/MicroData/itemtype-add-remove-tokens.html: Added.
* fast/dom/MicroData/itemtype-attribute-test-expected.txt: Added.
* fast/dom/MicroData/itemtype-attribute-test.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (98352 => 98353)


--- trunk/LayoutTests/ChangeLog	2011-10-25 16:52:50 UTC (rev 98352)
+++ trunk/LayoutTests/ChangeLog	2011-10-25 16:53:52 UTC (rev 98353)
@@ -1,3 +1,19 @@
+2011-10-25  Arko Saha  <a...@motorola.com>
+
+        Microdata: itemtype attribute should be space-separated list to allow multiple types
+        https://bugs.webkit.org/show_bug.cgi?id=70501
+
+        Reviewed by Ryosuke Niwa.
+
+        * fast/dom/MicroData/006.html:
+        * fast/dom/MicroData/007.html:
+        * fast/dom/MicroData/getitems-multiple-itemtypes-expected.txt: Added.
+        * fast/dom/MicroData/getitems-multiple-itemtypes.html: Added.
+        * fast/dom/MicroData/itemtype-add-remove-tokens-expected.txt: Added.
+        * fast/dom/MicroData/itemtype-add-remove-tokens.html: Added.
+        * fast/dom/MicroData/itemtype-attribute-test-expected.txt: Added.
+        * fast/dom/MicroData/itemtype-attribute-test.html: Added.
+
 2011-10-25  Cary Clark  <carycl...@google.com>
 
         Unreviewed gardening: fourth chunk of baselines for Chromium-Skia

Modified: trunk/LayoutTests/fast/dom/MicroData/006.html (98352 => 98353)


--- trunk/LayoutTests/fast/dom/MicroData/006.html	2011-10-25 16:52:50 UTC (rev 98352)
+++ trunk/LayoutTests/fast/dom/MicroData/006.html	2011-10-25 16:53:52 UTC (rev 98353)
@@ -7,9 +7,9 @@
 <p>This tests that document.getItems must locate items when parameters are separated by spaces.
 <br>This test also ensure that document.getItems must ignore duplicated tokens.
 </p>
-<div itemscope itemtype="http://example.com/foo"></div>
-<div itemscope itemtype="http://example.com/bar">
-<div itemscope itemtype="data:text/plain"></div>
+<div itemscope itemtype="http://example.com/foo http://example.com/bar data:text/plain"></div>
+<div itemscope itemtype="http://example.com/bar http://example.com/foo">
+<div itemscope itemtype="data:text/plain http://example.com/foo"></div>
 </div>
 <div id="console"></div>
 <script>

Modified: trunk/LayoutTests/fast/dom/MicroData/007.html (98352 => 98353)


--- trunk/LayoutTests/fast/dom/MicroData/007.html	2011-10-25 16:52:50 UTC (rev 98352)
+++ trunk/LayoutTests/fast/dom/MicroData/007.html	2011-10-25 16:53:52 UTC (rev 98353)
@@ -14,7 +14,7 @@
 <div itemscope id="five"></div>
 <div id="console"></div>
 <script>
-var nodeList = document.getItems('http://example.com/bar data:text/plain, http://example.com/foo');
+var nodeList = document.getItems();
 
 shouldBe("nodeList[0].id", "'one'");
 shouldBe("nodeList[1].id", "'two'");

Added: trunk/LayoutTests/fast/dom/MicroData/getitems-multiple-itemtypes-expected.txt (0 => 98353)


--- trunk/LayoutTests/fast/dom/MicroData/getitems-multiple-itemtypes-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/MicroData/getitems-multiple-itemtypes-expected.txt	2011-10-25 16:53:52 UTC (rev 98353)
@@ -0,0 +1,10 @@
+document.getItems() with multiple itemtypes: PASS
+document.getItems() with multiple itemtypes: PASS
+document.getItems() with 'http://example.com/foo' itemtype in the aurgument: PASS
+document.getItems() with 'http://example.com/bar' itemtype in the aurgument: PASS
+PASS successfullyParsed is true
+
+TEST COMPLETE
+This test ensures that document.getItems() returns nodes that match all the types specified in the method's argument.
+
+

Added: trunk/LayoutTests/fast/dom/MicroData/getitems-multiple-itemtypes.html (0 => 98353)


--- trunk/LayoutTests/fast/dom/MicroData/getitems-multiple-itemtypes.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/MicroData/getitems-multiple-itemtypes.html	2011-10-25 16:53:52 UTC (rev 98353)
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p>This test ensures that document.getItems() returns nodes that match all the types specified in the method's argument.</p>
+
+<div itemscope itemtype="http://example.com/foo http://example.com/bar" id="one"></div>
+<div itemscope itemtype="http://example.com/foo" id="two"></div>
+
+<script>
+var _one_ = document.getElementById('one');
+var two = document.getElementById('two');
+
+runTest(document.getItems('http://example.com/foo http://example.com/bar'), [one], "document.getItems() with multiple itemtypes");
+runTest(document.getItems('http://example.com/bar http://example.com/foo'), [one], "document.getItems() with multiple itemtypes");
+runTest(document.getItems('http://example.com/foo'), [one, two], "document.getItems() with 'http://example.com/foo' itemtype in the aurgument");
+runTest(document.getItems('http://example.com/bar'), [one], "document.getItems() with 'http://example.com/bar' itemtype in the aurgument");
+
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/dom/MicroData/itemtype-add-remove-tokens-expected.txt (0 => 98353)


--- trunk/LayoutTests/fast/dom/MicroData/itemtype-add-remove-tokens-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/MicroData/itemtype-add-remove-tokens-expected.txt	2011-10-25 16:53:52 UTC (rev 98353)
@@ -0,0 +1,33 @@
+This tests that itemType attribute must update correctly when token have been added or removed.
+
+Created element of type: div
+itemType.add must reflect correctly.
+PASS element.itemType.length == 2 is true
+PASS element.itemType.toString() == 'http://example.com/foo http://example.com/FOO' is true
+PASS element.itemType[0] is 'http://example.com/foo'
+PASS element.itemType[1] is 'http://example.com/FOO'
+PASS element.itemType.item(0) is 'http://example.com/foo'
+PASS element.itemType.item(1) is 'http://example.com/FOO'
+
+itemType.add must not make any changes if an existing token is added.
+PASS element.itemType.length == 2 is true
+PASS element.itemType.toString() == 'http://example.com/foo http://example.com/FOO' is true
+
+itemType.remove must reflect correctly.
+PASS element.itemType.length == 1 is true
+PASS element.itemType.contains('http://example.com/foo') is false
+PASS element.itemType.toString() == 'http://example.com/FOO' is true
+
+itemType.remove must not make any changes if remove is called for a token that doesn't exist.
+PASS element.itemType.length == 1 is true
+PASS element.itemType.contains('http://example.com/foo') is false
+PASS element.itemType.toString() == 'http://example.com/FOO' is true
+
+itemType.length must be 0 when all tokens are removed.
+PASS element.itemType.length == 0 is true
+PASS element.itemType.contains('http://example.com/foo') is false
+PASS element.itemType.contains('http://example.com/FOO') is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/MicroData/itemtype-add-remove-tokens.html (0 => 98353)


--- trunk/LayoutTests/fast/dom/MicroData/itemtype-add-remove-tokens.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/MicroData/itemtype-add-remove-tokens.html	2011-10-25 16:53:52 UTC (rev 98353)
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p>This tests that itemType attribute must update correctly when token have been added or removed.</p>
+<div id="console"></div>
+<script>
+var element = createElement('div', {});
+
+debug("itemType.add must reflect correctly.");
+element.itemType.add('http://example.com/foo');
+element.itemType.add('http://example.com/FOO');
+
+shouldBeTrue("element.itemType.length == 2");
+shouldBeTrue("element.itemType.toString() == 'http://example.com/foo http://example.com/FOO'");
+shouldBe("element.itemType[0]", "'http://example.com/foo'");
+shouldBe("element.itemType[1]", "'http://example.com/FOO'");
+shouldBe("element.itemType.item(0)", "'http://example.com/foo'");
+shouldBe("element.itemType.item(1)", "'http://example.com/FOO'");
+
+debug("<br>itemType.add must not make any changes if an existing token is added.");
+element.itemType.add('http://example.com/foo');
+shouldBeTrue("element.itemType.length == 2");
+shouldBeTrue("element.itemType.toString() == 'http://example.com/foo http://example.com/FOO'");
+
+debug("<br>itemType.remove must reflect correctly.");
+element.itemType.remove('http://example.com/foo');
+shouldBeTrue("element.itemType.length == 1");
+shouldBeFalse("element.itemType.contains('http://example.com/foo')")
+shouldBeTrue("element.itemType.toString() == 'http://example.com/FOO'");
+
+debug("<br>itemType.remove must not make any changes if remove is called for a token that doesn't exist.");
+element.itemType.remove('http://example.com/foo');
+shouldBeTrue("element.itemType.length == 1");
+shouldBeFalse("element.itemType.contains('http://example.com/foo')");
+shouldBeTrue("element.itemType.toString() == 'http://example.com/FOO'");
+
+debug("<br>itemType.length must be 0 when all tokens are removed.");
+element.itemType.remove('http://example.com/FOO');
+shouldBeTrue("element.itemType.length == 0");
+shouldBeFalse("element.itemType.contains('http://example.com/foo')");
+shouldBeFalse("element.itemType.contains('http://example.com/FOO')");
+
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/dom/MicroData/itemtype-attribute-test-expected.txt (0 => 98353)


--- trunk/LayoutTests/fast/dom/MicroData/itemtype-attribute-test-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/MicroData/itemtype-attribute-test-expected.txt	2011-10-25 16:53:52 UTC (rev 98353)
@@ -0,0 +1,20 @@
+itemType attribute simple test.
+
+Created element of type: div
+Set attribute: itemtype, value: http://example.com/foo
+
+The itemType attribute must be defined.
+PASS element.itemType is defined.
+PASS element.itemType.toString() is 'http://example.com/foo'
+
+itemType and itemType.length must be read-only.
+PASS element.itemType = 'http://example.com/test'; element.itemType.toString() == 'http://example.com/foo' is true
+PASS element.itemType.contains('http://example.com/test') is false
+PASS element.itemType.length = 0; element.itemType.length == 1 is true
+
+removeAttribute('itemType') must reflect correctly.
+PASS element.itemType.toString() is ''
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/MicroData/itemtype-attribute-test.html (0 => 98353)


--- trunk/LayoutTests/fast/dom/MicroData/itemtype-attribute-test.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/MicroData/itemtype-attribute-test.html	2011-10-25 16:53:52 UTC (rev 98353)
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p>itemType attribute simple test.</p>
+<div id="console"></div>
+<script>
+var element = createElement('div', {itemtype: 'http://example.com/foo'});
+
+debug("<br>The itemType attribute must be defined.");
+shouldBeDefined("element.itemType");
+shouldBe("element.itemType.toString()", "'http://example.com/foo'");
+
+debug("<br>itemType and itemType.length must be read-only.");
+shouldBeTrue("element.itemType = 'http://example.com/test'; element.itemType.toString() == 'http://example.com/foo'");
+shouldBeFalse("element.itemType.contains('http://example.com/test')");
+shouldBeTrue("element.itemType.length = 0; element.itemType.length == 1");
+
+debug("<br>removeAttribute('itemType') must reflect correctly.");
+element.removeAttribute('itemType');
+shouldBe("element.itemType.toString()", "''");
+
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (98352 => 98353)


--- trunk/Source/WebCore/ChangeLog	2011-10-25 16:52:50 UTC (rev 98352)
+++ trunk/Source/WebCore/ChangeLog	2011-10-25 16:53:52 UTC (rev 98353)
@@ -1,3 +1,26 @@
+2011-10-25  Arko Saha  <a...@motorola.com>
+
+        Microdata: itemtype attribute should be space-separated list to allow multiple types.
+        https://bugs.webkit.org/show_bug.cgi?id=70501
+
+        Reviewed by Ryosuke Niwa.
+
+        Tests: fast/dom/MicroData/getitems-multiple-itemtypes.html
+               fast/dom/MicroData/itemtype-add-remove-tokens.html
+               fast/dom/MicroData/itemtype-attribute-test.html
+
+        * dom/MicroDataItemList.cpp:
+        (WebCore::MicroDataItemList::nodeMatches):
+        * html/DOMSettableTokenList.h:
+        (WebCore::DOMSettableTokenList::tokens):
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::parseMappedAttribute):
+        (WebCore::HTMLElement::setItemValueText):
+        (WebCore::HTMLElement::itemType):
+        (WebCore::HTMLElement::setItemType):
+        * html/HTMLElement.h:
+        * html/HTMLElement.idl:
+
 2011-10-25  Dan Bernstein  <m...@apple.com>
 
         <rdar://problem/10337033> DOMRangeOfString:relativeTo:options has problems with -webkit-user-select: none

Modified: trunk/Source/WebCore/dom/MicroDataItemList.cpp (98352 => 98353)


--- trunk/Source/WebCore/dom/MicroDataItemList.cpp	2011-10-25 16:52:50 UTC (rev 98352)
+++ trunk/Source/WebCore/dom/MicroDataItemList.cpp	2011-10-25 16:53:52 UTC (rev 98353)
@@ -60,7 +60,7 @@
     if (!m_typeNames.size())
         return true;
 
-    return m_typeNames.contains(testElement->fastGetAttribute(itemtypeAttr));
+    return testElement->itemType()->tokens().containsAll(m_typeNames);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/DOMSettableTokenList.h (98352 => 98353)


--- trunk/Source/WebCore/html/DOMSettableTokenList.h	2011-10-25 16:52:50 UTC (rev 98352)
+++ trunk/Source/WebCore/html/DOMSettableTokenList.h	2011-10-25 16:53:52 UTC (rev 98353)
@@ -55,6 +55,7 @@
     virtual String toString() const { return value(); }
 
     String value() const { return m_value; }
+    const SpaceSplitString& tokens() const { return m_tokens; }
     void setValue(const String&);
 
 private:

Modified: trunk/Source/WebCore/html/HTMLElement.cpp (98352 => 98353)


--- trunk/Source/WebCore/html/HTMLElement.cpp	2011-10-25 16:52:50 UTC (rev 98352)
+++ trunk/Source/WebCore/html/HTMLElement.cpp	2011-10-25 16:53:52 UTC (rev 98353)
@@ -207,6 +207,7 @@
     } else if (attr->name() == itemrefAttr) {
         setItemRef(attr->value());
     } else if (attr->name() == itemtypeAttr) {
+        setItemType(attr->value());
         itemTypeAttributeChanged();
 #endif
     }
@@ -1056,6 +1057,22 @@
 {
     setTextContent(value, ec);
 }
+
+PassRefPtr<DOMSettableTokenList> HTMLElement::itemType() const
+{
+    if (!m_itemType)
+        m_itemType = DOMSettableTokenList::create();
+
+    return m_itemType;
+}
+
+void HTMLElement::setItemType(const String& value)
+{
+    if (!m_itemType)
+        m_itemType = DOMSettableTokenList::create();
+
+    m_itemType->setValue(value);
+}
 #endif
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/HTMLElement.h (98352 => 98353)


--- trunk/Source/WebCore/html/HTMLElement.h	2011-10-25 16:52:50 UTC (rev 98352)
+++ trunk/Source/WebCore/html/HTMLElement.h	2011-10-25 16:53:52 UTC (rev 98353)
@@ -92,6 +92,7 @@
 #if ENABLE(MICRODATA)
     PassRefPtr<DOMSettableTokenList> itemRef() const;
     PassRefPtr<DOMSettableTokenList> itemProp() const;
+    PassRefPtr<DOMSettableTokenList> itemType() const;
 
     void setItemValue(const String&, ExceptionCode&);
     PassRefPtr<MicroDataItemValue> itemValue() const;
@@ -127,12 +128,14 @@
 #if ENABLE(MICRODATA)
     void setItemProp(const String&);
     void setItemRef(const String&);
+    void setItemType(const String&);
 
     virtual String itemValueText() const;
     virtual void setItemValueText(const String&, ExceptionCode&);
 
     mutable RefPtr<DOMSettableTokenList> m_itemProp;
     mutable RefPtr<DOMSettableTokenList> m_itemRef;
+    mutable RefPtr<DOMSettableTokenList> m_itemType;
 #endif
 };
 

Modified: trunk/Source/WebCore/html/HTMLElement.idl (98352 => 98353)


--- trunk/Source/WebCore/html/HTMLElement.idl	2011-10-25 16:52:50 UTC (rev 98352)
+++ trunk/Source/WebCore/html/HTMLElement.idl	2011-10-25 16:53:52 UTC (rev 98353)
@@ -67,7 +67,7 @@
                  attribute boolean spellcheck;
 
                  attribute [Conditional=MICRODATA, Reflect] boolean itemScope;
-                 attribute [Conditional=MICRODATA, Reflect] DOMString itemType;
+        readonly attribute [Conditional=MICRODATA] DOMSettableTokenList itemType;
                  attribute [Conditional=MICRODATA, Reflect] DOMString itemId;
 
         readonly attribute [Conditional=MICRODATA] DOMSettableTokenList itemRef;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to