+2012-04-10 Rob Buis <rbuis@rim.com>
+
+ getElementsByTagName unable to find SVG camelCase elements imported into HTML
+ https://bugs.webkit.org/show_bug.cgi?id=46800
+
+ Reviewed by Nikolas Zimmermann.
+
+ Add tests for getElementsByTagName(NS) in html, xhtml, and svg documents.
+
+ * fast/dom/getElementsByTagName-localName-matching-expected.txt: Added.
+ * fast/dom/getElementsByTagName-localName-matching.html: Added.
+ * fast/dom/getElementsByTagName-localName-matching2-expected.txt: Added.
+ * fast/dom/getElementsByTagName-localName-matching2.xhtml: Added.
+ * svg/dom/getElementsByTagName-localName-matching-expected.txt: Added.
+ * svg/dom/getElementsByTagName-localName-matching.html: Added.
+ * svg/dom/script-tests/getElementsByTagName-localName-matching.js: Added.
+
2012-04-09 Alexander Pavlov <apavlov@chromium.org>
Web Inspector: [Device Metrics] Introduce the "Fit window" option
--- /dev/null
+PASS container.getElementsByTagName('linearGradient').length is 2
+PASS container.getElementsByTagName('lineargradient').length is 1
+PASS container.getElementsByTagName('LINEARGRADIENT').length is 1
+PASS container.getElementsByTagName('FOO').length is 2
+PASS container.getElementsByTagName('foo').length is 2
+PASS container.getElementsByTagName('Foo').length is 2
+PASS container.getElementsByTagName('img').length is 2
+PASS container.getElementsByTagName('IMG').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'linearGradient').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'lineargradient').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'LINEARGRADIENT').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'FOO').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'Foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'img').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'IMG').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'linearGradient').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'lineargradient').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'LINEARGRADIENT').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'FOO').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'foo').length is 2
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'Foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'img').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'IMG').length is 0
+
--- /dev/null
+<!doctype html>
+<head>
+ <script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="container"><FOO><foo><linearGradient/></foo></FOO><img/></div>
+
+<script>
+if (window.layoutTestController)
+ layoutTestController.dumpAsText();
+
+var container = document.getElementById('container');
+var svgdoc = new DOMParser().parseFromString(
+ '<svg xmlns="http://www.w3.org/2000/svg"><linearGradient></linearGradient><img/></svg>', 'text/xml');
+
+var elem = document.importNode(svgdoc.documentElement,true);
+container.appendChild(elem);
+
+shouldBe("container.getElementsByTagName('linearGradient').length", "2");
+shouldBe("container.getElementsByTagName('lineargradient').length", "1");
+shouldBe("container.getElementsByTagName('LINEARGRADIENT').length", "1");
+shouldBe("container.getElementsByTagName('FOO').length", "2");
+shouldBe("container.getElementsByTagName('foo').length", "2");
+shouldBe("container.getElementsByTagName('Foo').length", "2");
+shouldBe("container.getElementsByTagName('img').length", "2");
+shouldBe("container.getElementsByTagName('IMG').length", "1");
+
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'linearGradient').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'lineargradient').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'LINEARGRADIENT').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'FOO').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'Foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'img').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'IMG').length", "0");
+
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'linearGradient').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'lineargradient').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'LINEARGRADIENT').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'FOO').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'foo').length", "2");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'Foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'img').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'IMG').length", "0");
+</script>
+</body>
--- /dev/null
+PASS container.getElementsByTagName('linearGradient').length is 2
+PASS container.getElementsByTagName('lineargradient').length is 0
+PASS container.getElementsByTagName('LINEARGRADIENT').length is 0
+PASS container.getElementsByTagName('FOO').length is 1
+PASS container.getElementsByTagName('foo').length is 1
+PASS container.getElementsByTagName('Foo').length is 0
+PASS container.getElementsByTagName('img').length is 2
+PASS container.getElementsByTagName('IMG').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'linearGradient').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'lineargradient').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'LINEARGRADIENT').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'FOO').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'Foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'img').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'IMG').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'linearGradient').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'lineargradient').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'LINEARGRADIENT').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'FOO').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'foo').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'Foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'img').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'IMG').length is 0
+
--- /dev/null
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="container"><FOO><foo><linearGradient/></foo></FOO><img/></div>
+
+<script><![CDATA[
+if (window.layoutTestController)
+ layoutTestController.dumpAsText();
+
+var container = document.getElementById('container');
+var svgdoc = new DOMParser().parseFromString(
+ '<svg xmlns="http://www.w3.org/2000/svg"><linearGradient></linearGradient><img/></svg>', 'text/xml');
+
+var elem = document.importNode(svgdoc.documentElement,true);
+container.appendChild(elem);
+
+shouldBe("container.getElementsByTagName('linearGradient').length", "2");
+shouldBe("container.getElementsByTagName('lineargradient').length", "0");
+shouldBe("container.getElementsByTagName('LINEARGRADIENT').length", "0");
+shouldBe("container.getElementsByTagName('FOO').length", "1");
+shouldBe("container.getElementsByTagName('foo').length", "1");
+shouldBe("container.getElementsByTagName('Foo').length", "0");
+shouldBe("container.getElementsByTagName('img').length", "2");
+shouldBe("container.getElementsByTagName('IMG').length", "0");
+
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'linearGradient').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'lineargradient').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'LINEARGRADIENT').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'FOO').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'Foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'img').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'IMG').length", "0");
+
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'linearGradient').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'lineargradient').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'LINEARGRADIENT').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'FOO').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'foo').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'Foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'img').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'IMG').length", "0");
+]]></script>
+</body>
+</html>
--- /dev/null
+This test checks the behaviour of getElementsByTagName in a non-HTML document
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS container.getElementsByTagName('linearGradient').length is 1
+PASS container.getElementsByTagName('lineargradient').length is 0
+PASS container.getElementsByTagName('LINEARGRADIENT').length is 0
+PASS container.getElementsByTagName('FOO').length is 1
+PASS container.getElementsByTagName('foo').length is 1
+PASS container.getElementsByTagName('Foo').length is 0
+PASS container.getElementsByTagName('img').length is 1
+PASS container.getElementsByTagName('IMG').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'linearGradient').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'lineargradient').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'LINEARGRADIENT').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'FOO').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'Foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'img').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'IMG').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'linearGradient').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'lineargradient').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'LINEARGRADIENT').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'FOO').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'foo').length is 1
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'Foo').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'img').length is 0
+PASS container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'IMG').length is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/getElementsByTagName-localName-matching.js"></script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
--- /dev/null
+description("This test checks the behaviour of getElementsByTagName in a non-HTML document");
+
+var documentString = "<svg xmlns='http://www.w3.org/2000/svg' width='400' height='400'>" +
+ "<linearGradient/><img/><foreignObject><body xmlns='http://www.w3.org/1999/xhtml'><foo/><FOO/></body></foreignObject>" +
+ "</svg>";
+
+var parser = new DOMParser();
+var svgDocument = parser.parseFromString(documentString, "image/svg+xml");
+var container = svgDocument.documentElement;
+
+shouldBe("container.getElementsByTagName('linearGradient').length", "1");
+shouldBe("container.getElementsByTagName('lineargradient').length", "0");
+shouldBe("container.getElementsByTagName('LINEARGRADIENT').length", "0");
+shouldBe("container.getElementsByTagName('FOO').length", "1");
+shouldBe("container.getElementsByTagName('foo').length", "1");
+shouldBe("container.getElementsByTagName('Foo').length", "0");
+shouldBe("container.getElementsByTagName('img').length", "1");
+shouldBe("container.getElementsByTagName('IMG').length", "0");
+
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'linearGradient').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'lineargradient').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'LINEARGRADIENT').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'FOO').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'Foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'img').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'IMG').length", "0");
+
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'linearGradient').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'lineargradient').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'LINEARGRADIENT').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'FOO').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'foo').length", "1");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'Foo').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'img').length", "0");
+shouldBe("container.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'IMG').length", "0");
+
+var successfullyParsed = true;
+2012-04-10 Rob Buis <rbuis@rim.com>
+
+ getElementsByTagName unable to find SVG camelCase elements imported into HTML
+ https://bugs.webkit.org/show_bug.cgi?id=46800
+
+ Reviewed by Nikolas Zimmermann.
+
+ Implement getElementsByTagName according to the algorithm in
+ http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-getelementsbytagname.
+ If the owner document of the element is html, the new class HTMLTagNodeList deals with
+ finding the match(es) based on this algorithm. If the owner document is non HTML, the existing
+ TagNodeList is used.
+
+ Implement getElementsByTagNameNS according to the algorithm in
+ http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-getelementsbytagnamens.
+ The existing TagNodeList implements this algorithm.
+
+ Cached results may have less hits after this change. Tag names that are equal when case
+ insensitive but different when case sensitive can't share the result due to above algorithms, i.e.
+ they would match differently in the non html part of the document.
+
+ Tests: fast/dom/getElementsByTagName-localName-matching.html
+ fast/dom/getElementsByTagName-localName-matching2.xhtml
+ svg/dom/getElementsByTagName-localName-matching.html
+
+ * dom/Node.cpp:
+ (WebCore::Node::getElementsByTagName): create TagNodeList depending on owner document type.
+ (WebCore::Node::getElementsByTagNameNS): do not lowercase localName for html.
+ * dom/TagNodeList.cpp:
+ (WebCore::HTMLTagNodeList::HTMLTagNodeList): add specialized TagNodeList for html matching rules.
+ (WebCore):
+ (WebCore::HTMLTagNodeList::nodeMatches):
+ * dom/TagNodeList.h:
+ (TagNodeList):
+ (HTMLTagNodeList):
+ (WebCore::HTMLTagNodeList::create):
+
2012-04-09 Alexander Pavlov <apavlov@chromium.org>
Web Inspector: [Device Metrics] Introduce the "Fit window" option
if (localName.isNull())
return 0;
- String name = localName;
- if (document()->isHTMLDocument())
- name = localName.lower();
-
- AtomicString localNameAtom = name;
+ AtomicString localNameAtom = localName;
NodeListsNodeData::TagNodeListCache::AddResult result = ensureRareData()->ensureNodeLists(this)->m_tagNodeListCache.add(localNameAtom, 0);
if (!result.isNewEntry)
return PassRefPtr<TagNodeList>(result.iterator->second);
- RefPtr<TagNodeList> list = TagNodeList::create(this, starAtom, localNameAtom);
+ RefPtr<TagNodeList> list;
+ if (document()->isHTMLDocument())
+ list = HTMLTagNodeList::create(this, starAtom, localNameAtom);
+ else
+ list = TagNodeList::create(this, starAtom, localNameAtom);
result.iterator->second = list.get();
return list.release();
}
if (namespaceURI == starAtom)
return getElementsByTagName(localName);
- String name = localName;
- if (document()->isHTMLDocument())
- name = localName.lower();
-
- AtomicString localNameAtom = name;
+ AtomicString localNameAtom = localName;
NodeListsNodeData::TagNodeListCacheNS::AddResult result
= ensureRareData()->ensureNodeLists(this)->m_tagNodeListCacheNS.add(QualifiedName(nullAtom, localNameAtom, namespaceURI).impl(), 0);
bool TagNodeList::nodeMatches(Element* testNode) const
{
+ // Implements http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-getelementsbytagnamens
if (m_localName != starAtom && m_localName != testNode->localName())
return false;
return m_namespaceURI == starAtom || m_namespaceURI == testNode->namespaceURI();
}
+HTMLTagNodeList::HTMLTagNodeList(PassRefPtr<Node> rootNode, const AtomicString& namespaceURI, const AtomicString& localName)
+ : TagNodeList(rootNode, namespaceURI, localName)
+ , m_loweredLocalName(localName.lower())
+{
+}
+
+bool HTMLTagNodeList::nodeMatches(Element* testNode) const
+{
+ // Implements http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-getelementsbytagname
+ if (m_localName != starAtom) {
+ const AtomicString& localName = testNode->isHTMLElement() ? m_loweredLocalName : m_localName;
+ if (localName != testNode->localName())
+ return false;
+ }
+
+ return m_namespaceURI == starAtom || m_namespaceURI == testNode->namespaceURI();
+}
+
} // namespace WebCore
virtual ~TagNodeList();
- private:
+ protected:
TagNodeList(PassRefPtr<Node> rootNode, const AtomicString& namespaceURI, const AtomicString& localName);
virtual bool nodeMatches(Element*) const;
AtomicString m_localName;
};
+ class HTMLTagNodeList : public TagNodeList {
+ public:
+ static PassRefPtr<TagNodeList> create(PassRefPtr<Node> rootNode, const AtomicString& namespaceURI, const AtomicString& localName)
+ {
+ return adoptRef(new HTMLTagNodeList(rootNode, namespaceURI, localName));
+ }
+
+ private:
+ HTMLTagNodeList(PassRefPtr<Node> rootNode, const AtomicString& namespaceURI, const AtomicString& localName);
+
+ virtual bool nodeMatches(Element*) const;
+
+ AtomicString m_loweredLocalName;
+ };
} // namespace WebCore
#endif // TagNodeList_h