Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Document.contentType implementation
https://bugs.webkit.org/show_bug.cgi?id=132269 Patch by Tibor Meszaros <tmeszaros.u-szeged@partner.samsung.com> on 2014-12-16 Reviewed by Darin Adler. Chromium merge from https://codereview.chromium.org/151653004 Source/WebCore: Tests: fast/dom/document-contentType-DOMParser.html fast/dom/document-contentType-createDocument.html fast/dom/document-contentType-data-uri.html fast/xsl/xslt-contentType.html http/tests/dom/document-contentType-meta.html http/tests/dom/document-contentType-xhr.html http/tests/dom/document-contentType.html * dom/Document.cpp: (WebCore::Document::overrideMIMEType): (WebCore::Document::contentType): (WebCore::Document::cloneDataFromDocument): * dom/Document.h: * dom/Document.idl: * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::currentContentType): * loader/DocumentLoader.h: * xml/XMLHttpRequest.cpp: (WebCore::XMLHttpRequest::responseXML): * xml/XSLTProcessor.cpp: (WebCore::XSLTProcessor::createDocumentFromSource): LayoutTests: * fast/dom/Document/clone-node-expected.txt: * fast/dom/Document/clone-node.html: * fast/dom/HTMLDocument/clone-node-quirks-mode-expected.txt: * fast/dom/HTMLDocument/clone-node-quirks-mode.html: * fast/dom/document-contentType-DOMParser-expected.txt: Added. * fast/dom/document-contentType-DOMParser.html: Added. * fast/dom/document-contentType-createDocument-expected.txt: Added. * fast/dom/document-contentType-createDocument.html: Added. * fast/dom/document-contentType-data-uri-expected.txt: Added. * fast/dom/document-contentType-data-uri.html: Added. * fast/xsl/xslt-contentType-expected.txt: Added. * fast/xsl/xslt-contentType.html: Added. * http/tests/dom/document-contentType-expected.txt: Added. * http/tests/dom/document-contentType-meta-expected.txt: Added. * http/tests/dom/document-contentType-meta.html: Added. * http/tests/dom/document-contentType-xhr-expected.txt: Added. * http/tests/dom/document-contentType-xhr.html: Added. * http/tests/dom/document-contentType.html: Added. * http/tests/dom/resources/dummy.css: Added. (body): * http/tests/dom/resources/dummy.html: Added. * http/tests/dom/resources/dummy.js: Added. * http/tests/dom/resources/dummy.txt: Added. * http/tests/dom/resources/dummy.xml: Added. * http/tests/dom/resources/send-mime-type.php: Added. * http/tests/dom/resources/square20.bmp: Added. * http/tests/dom/resources/square20.gif: Added. * http/tests/dom/resources/square20.jpg: Added. * http/tests/dom/resources/square20.png: Added. * resources/js-test.js: (shouldBeEqualToNumber): Canonical link: https://commits.webkit.org/157574@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@177366 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
with
544 additions
and 3 deletions.
- +41 −0 LayoutTests/ChangeLog
- +2 −0 LayoutTests/fast/dom/Document/clone-node-expected.txt
- +2 −0 LayoutTests/fast/dom/Document/clone-node.html
- +2 −0 LayoutTests/fast/dom/HTMLDocument/clone-node-quirks-mode-expected.txt
- +2 −0 LayoutTests/fast/dom/HTMLDocument/clone-node-quirks-mode.html
- +12 −0 LayoutTests/fast/dom/document-contentType-DOMParser-expected.txt
- +85 −0 LayoutTests/fast/dom/document-contentType-DOMParser.html
- +8 −0 LayoutTests/fast/dom/document-contentType-createDocument-expected.txt
- +19 −0 LayoutTests/fast/dom/document-contentType-createDocument.html
- +8 −0 LayoutTests/fast/dom/document-contentType-data-uri-expected.txt
- +55 −0 LayoutTests/fast/dom/document-contentType-data-uri.html
- +9 −0 LayoutTests/fast/xsl/xslt-contentType-expected.txt
- +53 −0 LayoutTests/fast/xsl/xslt-contentType.html
- +32 −0 LayoutTests/http/tests/dom/document-contentType-expected.txt
- +5 −0 LayoutTests/http/tests/dom/document-contentType-meta-expected.txt
- +13 −0 LayoutTests/http/tests/dom/document-contentType-meta.html
- +16 −0 LayoutTests/http/tests/dom/document-contentType-xhr-expected.txt
- +51 −0 LayoutTests/http/tests/dom/document-contentType-xhr.html
- +37 −0 LayoutTests/http/tests/dom/document-contentType.html
- +1 −0 LayoutTests/http/tests/dom/resources/dummy.css
- +2 −0 LayoutTests/http/tests/dom/resources/dummy.html
- +1 −0 LayoutTests/http/tests/dom/resources/dummy.js
- +1 −0 LayoutTests/http/tests/dom/resources/dummy.txt
- +2 −0 LayoutTests/http/tests/dom/resources/dummy.xml
- +6 −0 LayoutTests/http/tests/dom/resources/send-mime-type.php
- BIN LayoutTests/http/tests/dom/resources/square20.bmp
- BIN LayoutTests/http/tests/dom/resources/square20.gif
- BIN LayoutTests/http/tests/dom/resources/square20.jpg
- BIN LayoutTests/http/tests/dom/resources/square20.png
- +8 −0 LayoutTests/resources/js-test.js
- +31 −0 Source/WebCore/ChangeLog
- +21 −0 Source/WebCore/dom/Document.cpp
- +6 −0 Source/WebCore/dom/Document.h
- +2 −0 Source/WebCore/dom/Document.idl
- +5 −0 Source/WebCore/loader/DocumentLoader.cpp
- +1 −1 Source/WebCore/loader/DocumentLoader.h
- +4 −1 Source/WebCore/xml/XMLHttpRequest.cpp
- +1 −1 Source/WebCore/xml/XSLTProcessor.cpp
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,12 @@ | ||
PASS new DOMParser().parseFromString(htmlContent, "text/html").contentType is "text/html" | ||
PASS new DOMParser().parseFromString(xmlContent, "application/xml").contentType is "application/xml" | ||
PASS new DOMParser().parseFromString(xhtmlContent, "application/xhtml+xml").contentType is "application/xhtml+xml" | ||
PASS new DOMParser().parseFromString(svgImageContent, "image/svg+xml").contentType is "image/svg+xml" | ||
PASS new DOMParser().parseFromString(xslContent, "text/xsl").contentType threw exception TypeError: Type error. | ||
PASS new DOMParser().parseFromString(xmlContent, "text/dummy+xml").contentType threw exception TypeError: Type error. | ||
PASS new DOMParser().parseFromString(xmlContent, "text/XML").contentType threw exception TypeError: Type error. | ||
PASS new DOMParser().parseFromString(htmlContent, "TEXT/html").contentType threw exception TypeError: Type error. | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,85 @@ | ||
<!DOCTYPE html> | ||
<head> | ||
<title>document.contentType</title> | ||
<link rel="help" href="http://dom.spec.whatwg.org/#dom-document-contenttype"> | ||
<script src="../../resources/js-test-pre.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
|
||
var htmlContent = | ||
"<html>" + | ||
"<head>" + | ||
"<noscript>" + | ||
"Scripts must be disabled for the document created using DOMParser.parseFromString()" + | ||
"</noscript>" + | ||
"</head>" + | ||
"<body>" + | ||
"<div id='text'>Sample text content</div>" + | ||
"<script>document.getElementById('text').textContent = 'Modified text content';<\/script>" + | ||
"</body>" + | ||
"</html>"; | ||
|
||
var xmlContent = | ||
"<root>" + | ||
"</root>"; | ||
|
||
|
||
var xhtmlContent = | ||
"<!DOCTYPE html>" + | ||
"<html xmlns=\"http://www.w3.org/1999/xhtml\">" + | ||
"<head>" + | ||
"<title>Title of document</title>" + | ||
"<noscript>" + | ||
"Scripts must be disabled for the document created using DOMParser.parseFromString()" + | ||
"</noscript>" + | ||
"</head>" + | ||
"<body>" + | ||
"<div id='text'></div>" + | ||
"<script>document.getElementById('text').textContent = 'Newly added text';<\/script>" + | ||
"</body>" + | ||
"</html>"; | ||
|
||
var svgImageContent = | ||
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">" + | ||
"<circle cx=\"100\" cy=\"50\" r=\"40\" stroke=\"black\" stroke-width=\"2\" fill=\"red\"/>" + | ||
"</svg>"; | ||
|
||
var xslContent = | ||
"<?xml version=\"1.0\"?>" + | ||
"<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" + | ||
"<xsl:template match=\"/\">" + | ||
"<html>" + | ||
"<head>" + | ||
"<title>XML XSL Example</title>" + | ||
"<style type=\"text/css\">" + | ||
"body" + | ||
"{" + | ||
"background-color:red;" + | ||
"}" + | ||
"</style>" + | ||
"</head>" + | ||
"<body>" + | ||
"<xsl:apply-templates/>" + | ||
"</body>" + | ||
"</html>" + | ||
"</xsl:template>" + | ||
"" + | ||
"<xsl:template match=\"tutorial\">" + | ||
"<span><xsl:value-of select=\"name\"/></span>" + | ||
"<span><xsl:value-of select=\"url\"/></span>" + | ||
"</xsl:template>" + | ||
"</xsl:stylesheet>"; | ||
|
||
shouldBeEqualToString('new DOMParser().parseFromString(htmlContent, "text/html").contentType', 'text/html'); | ||
shouldBeEqualToString('new DOMParser().parseFromString(xmlContent, "application/xml").contentType', 'application/xml'); | ||
shouldBeEqualToString('new DOMParser().parseFromString(xhtmlContent, "application/xhtml+xml").contentType', 'application/xhtml+xml'); | ||
shouldBeEqualToString('new DOMParser().parseFromString(svgImageContent, "image/svg+xml").contentType', 'image/svg+xml'); | ||
shouldThrow('new DOMParser().parseFromString(xslContent, "text/xsl").contentType', "'TypeError: Type error'"); | ||
shouldThrow('new DOMParser().parseFromString(xmlContent, "text/dummy+xml").contentType', "'TypeError: Type error'"); | ||
shouldThrow('new DOMParser().parseFromString(xmlContent, "text/XML").contentType', "'TypeError: Type error'"); | ||
shouldThrow('new DOMParser().parseFromString(htmlContent, "TEXT/html").contentType', "'TypeError: Type error'"); | ||
|
||
</script> | ||
<script src="../../resources/js-test-post.js"></script> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,8 @@ | ||
PASS doc.contentType is "text/html" | ||
PASS doc.contentType is "application/xml" | ||
PASS doc.contentType is "application/xml" | ||
PASS doc.contentType is "image/svg+xml" | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<title>document.contentType</title> | ||
<link rel="help" href="http://dom.spec.whatwg.org/#dom-document-contenttype"> | ||
<script src="../../resources/js-test.js"></script> | ||
<body> | ||
<script> | ||
var doc = document.implementation.createHTMLDocument('f'); | ||
shouldBe('doc.contentType', '"text/html"'); | ||
|
||
doc = document.implementation.createDocument(null, 'root', null); | ||
shouldBe('doc.contentType', '"application/xml"'); | ||
|
||
var foo = document.implementation.createDocumentType("foobar", "", ""); | ||
doc = document.implementation.createDocument(null, null, foo); | ||
shouldBe('doc.contentType', '"application/xml"'); | ||
|
||
doc = document.implementation.createDocument('http://www.w3.org/2000/svg', 'svg:svg', null); | ||
shouldBe('doc.contentType', '"image/svg+xml"'); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,8 @@ | ||
PASS "application/xml" is "application/xml" | ||
PASS "image/svg+xml" is "image/svg+xml" | ||
PASS "text/html" is "text/html" | ||
PASS "text/xml" is "text/xml" | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,55 @@ | ||
<!DOCTYPE html> | ||
<title>document.contentType</title> | ||
<link rel="help" href="http://dom.spec.whatwg.org/#dom-document-contenttype"> | ||
<script src="../../resources/js-test.js"></script> | ||
<body> | ||
<p> | ||
<iframe data-mimetype="text/html"></iframe> | ||
<iframe data-mimetype="text/xml"></iframe> | ||
<iframe data-mimetype="application/xml"></iframe> | ||
<iframe data-mimetype="image/svg+xml"></iframe> | ||
</p> | ||
<script> | ||
window.jsTestIsAsync = true; | ||
var tests = new Array(); | ||
|
||
window.onmessage = function(e) { | ||
if (e.data) | ||
tests[--expectedMessagesCount]=e.data; | ||
else | ||
testFailed("Null message payload"); | ||
|
||
if (expectedMessagesCount == 0) { | ||
runTests(); | ||
finishJSTest(); | ||
} | ||
}; | ||
|
||
function runTests(){ | ||
tests.sort(function(a,b){ | ||
if (a.obtained > b.obtained) | ||
return -1; | ||
if (a.obtained < b.obtained) | ||
return 1; | ||
return 0; | ||
}); | ||
|
||
for (var i = tests.length - 1; i >= 0; i--) { | ||
shouldBe('"' + tests[i].obtained + '"', '"' + tests[i].expected + '"'); | ||
}; | ||
} | ||
|
||
var documentContents = '<script xmlns="http://www.w3.org/1999/xhtml">' + | ||
'parent.postMessage(' + | ||
'{obtained: document.contentType, expected: "{0}"}, "*");' + | ||
'<' + '/script>'; | ||
|
||
var iframes = document.getElementsByTagName('iframe'); | ||
for (var k = 0, f; f = iframes[k]; k++) { | ||
f.src = 'data:' + f.dataset.mimetype + ',' + encodeURIComponent(documentContents.replace('{0}', f.dataset.mimetype)); | ||
} | ||
|
||
var expectedMessagesCount = iframes.length; | ||
|
||
</script> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,9 @@ | ||
PASS doc.contentType is "text/html" | ||
PASS doc.contentType is "application/xml" | ||
PASS doc.contentType is "application/xhtml+xml" | ||
PASS doc.contentType is "application/xml" | ||
PASS doc.contentType is "application/xml" | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,53 @@ | ||
<!DOCTYPE html> | ||
<head> | ||
<script src="../../resources/js-test-pre.js"></script> | ||
</head> | ||
<body > | ||
<script> | ||
if (window.testRunner) | ||
testRunner.dumpAsText(); | ||
|
||
var xsltp = new XSLTProcessor(); | ||
var doc; | ||
|
||
function test(method) { | ||
try { | ||
var xml = '<?xml version="1.0" encoding="UTF-8"?>'; | ||
var style = '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> \ | ||
<xsl:output indent="yes" method="'+method+'"/> \ | ||
</xsl:stylesheet>'; | ||
|
||
var xmlDoc = new DOMParser().parseFromString(xml, "text/xml"); | ||
var xslDoc = new DOMParser().parseFromString(style, "text/xml"); | ||
|
||
xsltp.importStylesheet(xslDoc); | ||
doc = xsltp.transformToDocument(xmlDoc); | ||
|
||
xsltp.reset(); | ||
} catch(e) { | ||
document.write("Exception: " + e); | ||
} | ||
} | ||
|
||
function runTests() { | ||
test('html'); | ||
shouldBe('doc.contentType','"text/html"'); | ||
|
||
test('xml'); | ||
shouldBe('doc.contentType','"application/xml"'); | ||
|
||
test('text'); | ||
shouldBe('doc.contentType','"application/xhtml+xml"'); | ||
|
||
test('foo'); | ||
shouldBe('doc.contentType','"application/xml"'); | ||
|
||
test('xhtml/foo'); | ||
shouldBe('doc.contentType','"application/xml"'); | ||
} | ||
|
||
runTests(); | ||
</script> | ||
</body> | ||
<script src="../../resources/js-test-post.js"></script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,32 @@ | ||
PASS iframes[0].contentDocument.contentType is "text/css" | ||
PASS iframes[0].contentDocument.cloneNode(false).contentType is "text/css" | ||
PASS iframes[1].contentDocument.contentType is "application/x-javascript" | ||
PASS iframes[1].contentDocument.cloneNode(false).contentType is "application/x-javascript" | ||
PASS iframes[2].contentDocument.contentType is "text/html" | ||
PASS iframes[2].contentDocument.cloneNode(false).contentType is "text/html" | ||
PASS iframes[3].contentDocument.contentType is "text/html" | ||
PASS iframes[3].contentDocument.cloneNode(false).contentType is "text/html" | ||
PASS iframes[4].contentDocument.contentType is "text/xml" | ||
PASS iframes[4].contentDocument.cloneNode(false).contentType is "text/xml" | ||
PASS iframes[5].contentDocument.contentType is "text/xml" | ||
PASS iframes[5].contentDocument.cloneNode(false).contentType is "text/xml" | ||
PASS iframes[6].contentDocument.contentType is "text/html" | ||
PASS iframes[6].contentDocument.cloneNode(false).contentType is "text/html" | ||
PASS iframes[7].contentDocument.contentType is "text/html" | ||
PASS iframes[7].contentDocument.cloneNode(false).contentType is "text/html" | ||
PASS iframes[8].contentDocument.contentType is "text/plain" | ||
PASS iframes[8].contentDocument.cloneNode(false).contentType is "text/plain" | ||
PASS iframes[9].contentDocument.contentType is "application/xml" | ||
PASS iframes[9].contentDocument.cloneNode(false).contentType is "application/xml" | ||
PASS iframes[10].contentDocument.contentType is "image/bmp" | ||
PASS iframes[10].contentDocument.cloneNode(false).contentType is "image/bmp" | ||
PASS iframes[11].contentDocument.contentType is "image/gif" | ||
PASS iframes[11].contentDocument.cloneNode(false).contentType is "image/gif" | ||
PASS iframes[12].contentDocument.contentType is "image/jpeg" | ||
PASS iframes[12].contentDocument.cloneNode(false).contentType is "image/jpeg" | ||
PASS iframes[13].contentDocument.contentType is "image/png" | ||
PASS iframes[13].contentDocument.cloneNode(false).contentType is "image/png" | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,5 @@ | ||
PASS document.getElementsByTagName("META")[0].content is "text/xml" | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
Oops, something went wrong.