Skip to content
Permalink
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
Tibor Meszaros authored and webkit-commit-queue committed Dec 16, 2014
1 parent 18cccab commit 3d3c8b67ebc9800c1128d6483346957d920796e7
Showing 38 changed files with 544 additions and 3 deletions.
@@ -1,3 +1,44 @@
2014-12-16 Tibor Meszaros <tmeszaros.u-szeged@partner.samsung.com>

Document.contentType implementation
https://bugs.webkit.org/show_bug.cgi?id=132269

Reviewed by Darin Adler.

Chromium merge from https://codereview.chromium.org/151653004

* 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):

2014-12-16 Alexey Proskuryakov <ap@apple.com>

media/track/track-language-preference.html and media/track/track-prefer-captions.html time out on Mac
@@ -6,10 +6,12 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS doc.cloneNode(false).__proto__ is Document.prototype
PASS className(doc.cloneNode(false)) is "Document"
PASS doc.cloneNode(true).documentElement.localName is "root"
PASS doc.cloneNode(true).contentType is "application/xml"
PASS document.cloneNode(true).compatMode is "CSS1Compat"
PASS document.cloneNode(false).URL is document.URL
PASS document.cloneNode(false).baseURI is document.baseURI
PASS document.cloneNode(false).characterSet is document.characterSet
PASS document.cloneNode(true).contentType is "text/html"
PASS successfullyParsed is true

TEST COMPLETE
@@ -14,10 +14,12 @@
shouldBe('doc.cloneNode(false).__proto__', 'Document.prototype');
shouldBeEqualToString('className(doc.cloneNode(false))', 'Document');
shouldBeEqualToString('doc.cloneNode(true).documentElement.localName', 'root');
shouldBeEqualToString('doc.cloneNode(true).contentType', 'application/xml');
shouldBeEqualToString('document.cloneNode(true).compatMode', 'CSS1Compat');
shouldBe('document.cloneNode(false).URL', 'document.URL');
shouldBe('document.cloneNode(false).baseURI', 'document.baseURI');
shouldBe('document.cloneNode(false).characterSet', 'document.characterSet');
shouldBeEqualToString('document.cloneNode(true).contentType', 'text/html');

</script>
<script src="../../../resources/js-test-post.js"></script>
@@ -7,10 +7,12 @@ PASS document.cloneNode(false).__proto__ is HTMLDocument.prototype
PASS className(document.cloneNode(false)) is "HTMLDocument"
PASS document.cloneNode(true).title is document.title
PASS document.cloneNode(true).compatMode is "BackCompat"
PASS document.cloneNode(true).contentType is "text/html"
PASS doc.cloneNode(false).__proto__ is HTMLDocument.prototype
PASS className(doc.cloneNode(false)) is "HTMLDocument"
PASS doc.cloneNode(true).title is doc.title
PASS doc.cloneNode(true).compatMode is "CSS1Compat"
PASS doc.cloneNode(true).contentType is "text/html"
PASS successfullyParsed is true

TEST COMPLETE
@@ -11,12 +11,14 @@
shouldBeEqualToString('className(document.cloneNode(false))', 'HTMLDocument');
shouldBe('document.cloneNode(true).title', 'document.title');
shouldBeEqualToString('document.cloneNode(true).compatMode', 'BackCompat');
shouldBeEqualToString('document.cloneNode(true).contentType', 'text/html');

var doc = document.implementation.createHTMLDocument('title');
shouldBe('doc.cloneNode(false).__proto__', 'HTMLDocument.prototype');
shouldBeEqualToString('className(doc.cloneNode(false))', 'HTMLDocument');
shouldBe('doc.cloneNode(true).title', 'doc.title');
shouldBeEqualToString('doc.cloneNode(true).compatMode', 'CSS1Compat');
shouldBeEqualToString('doc.cloneNode(true).contentType', 'text/html');

</script>
<script src="../../../resources/js-test-post.js"></script>
@@ -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

@@ -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>
@@ -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

@@ -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>
@@ -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

@@ -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>
@@ -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

@@ -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>
@@ -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

@@ -0,0 +1,5 @@
PASS document.getElementsByTagName("META")[0].content is "text/xml"
PASS successfullyParsed is true

TEST COMPLETE

0 comments on commit 3d3c8b6

Please sign in to comment.