Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: LayoutTests/fast/dom/domparser-parsefromstring-mimetype-support.html

Issue 23903014: DOMParser.parseFromString() should support creating HTML Document with mimetype text/html (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Patch for landing! Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | LayoutTests/fast/dom/domparser-parsefromstring-mimetype-support-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <style>
5 .fail {
6 color: red;
7 font-weight: bold;
8 }
9
10 .pass {
11 color: green;
12 font-weight: bold;
13 }
14 </style>
15 <script>
16 var htmlContent =
17 "<html>" +
18 "<head>" +
19 "<noscript>" +
20 "Scripts must be disabled for the document created u sing DOMParser.parseFromString()" +
21 "</noscript>" +
22 "</head>" +
23 "<body>" +
24 "<div id='text'>Sample text content</div>" +
25 "<script>document.getElementById('text').textContent = ' Modified text content';<\/script>" +
26 "</body>" +
27 "</html>";
28
29 var xmlContent =
30 "<root>" +
31 "</root>";
32
33
34 var xhtmlContent =
35 "<!DOCTYPE html>" +
36 "<html xmlns=\"http://www.w3.org/1999/xhtml\">" +
37 "<head>" +
38 "<title>Title of document</title>" +
39 "<noscript>" +
40 "Scripts must be disabled for the document created u sing DOMParser.parseFromString()" +
41 "</noscript>" +
42 "</head>" +
43 "<body>" +
44 "<div id='text'></div>" +
45 "<script>document.getElementById('text').textContent = ' Newly added text';<\/script>" +
46 "</body>" +
47 "</html>";
48
49 var svgImageContent =
50 "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">" +
51 "<circle cx=\"100\" cy=\"50\" r=\"40\" stroke=\"black\" stro ke-width=\"2\" fill=\"red\"/>" +
52 "</svg>";
53
54 var xslContent =
55 "<?xml version=\"1.0\"?>" +
56 "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1 999/XSL/Transform\">" +
57 "<xsl:template match=\"/\">" +
58 "<html>" +
59 "<head>" +
60 "<title>XML XSL Example</title>" +
61 "<style type=\"text/css\">" +
62 "body" +
63 "{" +
64 "background-color:red;" +
65 "}" +
66 "</style>" +
67 "</head>" +
68 "<body>" +
69 "<xsl:apply-templates/>" +
70 "</body>" +
71 "</html>" +
72 "</xsl:template>" +
73 "" +
74 "<xsl:template match=\"tutorial\">" +
75 "<span><xsl:value-of select=\"name\"/></span>" +
76 "<span><xsl:value-of select=\"url\"/></span>" +
77 "</xsl:template>" +
78 "</xsl:stylesheet>";
79
80 var count = 0;
81
82 function shouldSupport(content, mimeType)
83 {
84 var description = document.createElement("div");
85 description.innerHTML = (++count) + ". Should support mime-type = \"" + mime Type + "\"";
86 document.body.appendChild(description);
87
88 var parser = new DOMParser();
89 var resultDocument = parser.parseFromString(content, mimeType);
90 if (!resultDocument) {
91 var result = document.createElement("div");
92 result.className = "fail";
93 result.textContent = "FAIL";
94 document.body.appendChild(result);
95 } else {
96 var content = document.createElement("div");
97 var docElement = resultDocument.documentElement;
98 if (mimeType.lastIndexOf("xml") === mimeType.length - 3)
99 content.innerHTML = "Root element: " + docElement.tagName;
100 else
101 content.innerHTML = "HTML content:<br>" + docElement.innerHTML;
102 document.body.appendChild(content);
103
104 var result = document.createElement("div");
105 result.className = "pass";
106 result.textContent = "PASS";
107 document.body.appendChild(result);
108 }
109 document.body.appendChild(document.createElement("br"));
110 }
111
112 function shouldNotSupport(content, mimeType)
113 {
114 var description = document.createElement("div");
115 description.innerHTML = (++count) + ". Should NOT support mime-type = \"" + mimeType + "\"";
116 document.body.appendChild(description);
117
118 var parser = new DOMParser();
119 var resultDocument = parser.parseFromString(content, mimeType);
120 if (!resultDocument) {
121 var result = document.createElement("div");
122 result.className = "pass";
123 result.textContent = "PASS";
124 document.body.appendChild(result);
125 } else {
126 var result = document.createElement("div");
127 result.className = "fail";
128 result.textContent = "FAIL";
129 document.body.appendChild(result);
130 }
131 document.body.appendChild(document.createElement("br"));
132 }
133
134 function runTest()
135 {
136 if (window.testRunner) {
137 testRunner.dumpAsText();
138 }
139 shouldSupport(htmlContent, "text/html");
140 shouldSupport(xmlContent, "text/xml");
141 shouldSupport(xmlContent, "application/xml");
142 shouldSupport(xhtmlContent, "application/xhtml+xml");
143 shouldSupport(svgImageContent, "image/svg+xml");
144 shouldNotSupport(xslContent, "text/xsl");
145 }
146 </script>
147 </head>
148 <body onload="runTest();">
149 <p>This tests DOMParser supports creating Document for HTML content with mime-ty pe "text/html".</p>
150 </body>
151 </html>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/fast/dom/domparser-parsefromstring-mimetype-support-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698