blob: 3c3e549c12b6a4857c2b51ffe01707e306a00ac3 [file] [log] [blame]
[email protected]c1978abe2013-04-23 03:08:121// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
avi1023d012015-12-25 02:39:145#include <stddef.h>
6#include <stdint.h>
7
[email protected]c1978abe2013-04-23 03:08:128#include "base/bind.h"
9#include "base/command_line.h"
10#include "base/compiler_specific.h"
[email protected]14c1c232013-06-11 17:52:4411#include "base/containers/hash_tables.h"
[email protected]c1978abe2013-04-23 03:08:1212#include "base/files/file_path.h"
thestigb7aad54f2014-09-05 18:25:3913#include "base/files/file_util.h"
[email protected]21aa99682013-06-11 07:17:0114#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0015#include "base/strings/utf_string_conversions.h"
avi1023d012015-12-25 02:39:1416#include "build/build_config.h"
dcheng8b5e3022015-09-02 23:58:5517#include "content/public/browser/render_view_host.h"
18#include "content/public/browser/web_contents.h"
[email protected]c1978abe2013-04-23 03:08:1219#include "content/public/common/content_switches.h"
20#include "content/public/renderer/render_view.h"
21#include "content/public/renderer/render_view_observer.h"
[email protected]6e9def12014-03-27 20:23:2822#include "content/public/test/content_browser_test.h"
23#include "content/public/test/content_browser_test_utils.h"
[email protected]c1978abe2013-04-23 03:08:1224#include "content/public/test/test_utils.h"
[email protected]12a936d2013-05-15 04:55:4925#include "content/renderer/savable_resources.h"
[email protected]de7d61ff2013-08-20 11:30:4126#include "content/shell/browser/shell.h"
[email protected]d96cf752014-04-09 04:05:2827#include "net/base/filename_util.h"
[email protected]c1978abe2013-04-23 03:08:1228#include "net/url_request/url_request_context.h"
[email protected]de7d61ff2013-08-20 11:30:4129#include "third_party/WebKit/public/platform/WebCString.h"
30#include "third_party/WebKit/public/platform/WebData.h"
31#include "third_party/WebKit/public/platform/WebString.h"
32#include "third_party/WebKit/public/platform/WebURL.h"
33#include "third_party/WebKit/public/platform/WebVector.h"
[email protected]2255a9332013-06-17 05:12:3134#include "third_party/WebKit/public/web/WebDocument.h"
[email protected]2255a9332013-06-17 05:12:3135#include "third_party/WebKit/public/web/WebElement.h"
[email protected]c93932712014-02-07 18:49:0236#include "third_party/WebKit/public/web/WebElementCollection.h"
lukasza902fcc52015-12-31 04:45:2937#include "third_party/WebKit/public/web/WebFrameSerializer.h"
38#include "third_party/WebKit/public/web/WebFrameSerializerClient.h"
[email protected]d3576942014-04-10 18:45:3739#include "third_party/WebKit/public/web/WebLocalFrame.h"
esprehn467dcd92015-12-03 02:06:0940#include "third_party/WebKit/public/web/WebMetaElement.h"
[email protected]2255a9332013-06-17 05:12:3141#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3142#include "third_party/WebKit/public/web/WebView.h"
[email protected]c1978abe2013-04-23 03:08:1243
[email protected]180ef242013-11-07 06:50:4644using blink::WebCString;
45using blink::WebData;
46using blink::WebDocument;
47using blink::WebElement;
esprehn467dcd92015-12-03 02:06:0948using blink::WebMetaElement;
[email protected]c93932712014-02-07 18:49:0249using blink::WebElementCollection;
[email protected]180ef242013-11-07 06:50:4650using blink::WebFrame;
lukasza902fcc52015-12-31 04:45:2951using blink::WebFrameSerializer;
52using blink::WebFrameSerializerClient;
[email protected]d3576942014-04-10 18:45:3753using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:4654using blink::WebNode;
[email protected]180ef242013-11-07 06:50:4655using blink::WebString;
56using blink::WebURL;
57using blink::WebView;
58using blink::WebVector;
[email protected]c1978abe2013-04-23 03:08:1259
60namespace content {
61
[email protected]c1978abe2013-04-23 03:08:1262bool HasDocType(const WebDocument& doc) {
esprehn867ce322015-11-16 20:58:4963 return doc.firstChild().isDocumentTypeNode();
[email protected]c1978abe2013-04-23 03:08:1264}
65
[email protected]c1978abe2013-04-23 03:08:1266class LoadObserver : public RenderViewObserver {
67 public:
68 LoadObserver(RenderView* render_view, const base::Closure& quit_closure)
69 : RenderViewObserver(render_view),
70 quit_closure_(quit_closure) {}
71
dcheng6d18e402014-10-21 12:32:5272 void DidFinishLoad(blink::WebLocalFrame* frame) override {
[email protected]c1978abe2013-04-23 03:08:1273 if (frame == render_view()->GetWebView()->mainFrame())
74 quit_closure_.Run();
75 }
76
77 private:
78 base::Closure quit_closure_;
79};
80
81class DomSerializerTests : public ContentBrowserTest,
lukasza902fcc52015-12-31 04:45:2982 public WebFrameSerializerClient {
[email protected]c1978abe2013-04-23 03:08:1283 public:
lukasza4a96a1f02015-12-09 16:46:3484 DomSerializerTests() : serialization_reported_end_of_data_(false) {}
[email protected]c1978abe2013-04-23 03:08:1285
avi83883c82014-12-23 00:08:4986 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]c1978abe2013-04-23 03:08:1287 command_line->AppendSwitch(switches::kSingleProcess);
[email protected]0c2c0d12014-02-04 17:24:4388#if defined(OS_WIN)
[email protected]5d97f762013-04-23 06:15:4989 // Don't want to try to create a GPU process.
[email protected]7af65ca2014-04-16 20:25:5690 command_line->AppendSwitch(switches::kDisableGpu);
[email protected]5d97f762013-04-23 06:15:4991#endif
[email protected]c1978abe2013-04-23 03:08:1292 }
93
dcheng03226bd2015-09-03 17:36:2394 void SetUpOnMainThread() override {
95 render_view_routing_id_ =
96 shell()->web_contents()->GetRenderViewHost()->GetRoutingID();
97 }
98
[email protected]c1978abe2013-04-23 03:08:1299 // DomSerializerDelegate.
lukasza87f4e2ab2015-11-04 16:03:03100 void didSerializeDataForFrame(const WebCString& data,
lukasza902fcc52015-12-31 04:45:29101 FrameSerializationStatus status) override {
[email protected]c1978abe2013-04-23 03:08:12102 // Check finish status of current frame.
lukasza87f4e2ab2015-11-04 16:03:03103 ASSERT_FALSE(serialization_reported_end_of_data_);
[email protected]c1978abe2013-04-23 03:08:12104
105 // Add data to corresponding frame's content.
lukasza87f4e2ab2015-11-04 16:03:03106 serialized_contents_ += data;
[email protected]c1978abe2013-04-23 03:08:12107
108 // Current frame is completed saving, change the finish status.
lukasza902fcc52015-12-31 04:45:29109 if (status == WebFrameSerializerClient::CurrentFrameIsFinished)
lukasza87f4e2ab2015-11-04 16:03:03110 serialization_reported_end_of_data_ = true;
[email protected]c1978abe2013-04-23 03:08:12111 }
112
113 RenderView* GetRenderView() {
dcheng03226bd2015-09-03 17:36:23114 return RenderView::FromRoutingID(render_view_routing_id_);
[email protected]c1978abe2013-04-23 03:08:12115 }
116
117 WebView* GetWebView() {
118 return GetRenderView()->GetWebView();
119 }
120
121 WebFrame* GetMainFrame() {
122 return GetWebView()->mainFrame();
123 }
124
esprehn961779002015-11-16 04:35:13125 WebFrame* FindSubFrameByURL(const GURL& url) {
126 for (WebFrame* frame = GetWebView()->mainFrame(); frame;
127 frame = frame->traverseNext(false)) {
128 if (GURL(frame->document().url()) == url)
129 return frame;
130 }
131 return nullptr;
132 }
133
[email protected]c1978abe2013-04-23 03:08:12134 // Load web page according to input content and relative URLs within
135 // the document.
136 void LoadContents(const std::string& contents,
137 const GURL& base_url,
138 const WebString encoding_info) {
139 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner;
140 LoadObserver observer(GetRenderView(), runner->QuitClosure());
141
142 // If input encoding is empty, use UTF-8 as default encoding.
143 if (encoding_info.isEmpty()) {
144 GetMainFrame()->loadHTMLString(contents, base_url);
145 } else {
146 WebData data(contents.data(), contents.length());
147
148 // Do not use WebFrame.LoadHTMLString because it assumes that input
149 // html contents use UTF-8 encoding.
150 // TODO(darin): This should use WebFrame::loadData.
151 WebFrame* web_frame = GetMainFrame();
152
153 ASSERT_TRUE(web_frame != NULL);
154
clamy0f4ccc82016-02-24 12:43:53155 web_frame->toWebLocalFrame()->loadData(data, "text/html", encoding_info,
156 base_url);
[email protected]c1978abe2013-04-23 03:08:12157 }
158
159 runner->Run();
160 }
161
lukasza777a7dd2016-01-25 23:55:47162 class SingleLinkRewritingDelegate
163 : public WebFrameSerializer::LinkRewritingDelegate {
164 public:
165 SingleLinkRewritingDelegate(const WebURL& url, const WebString& localPath)
166 : url_(url), local_path_(localPath) {}
167
168 bool rewriteFrameSource(WebFrame* frame,
169 WebString* rewritten_link) override {
170 return false;
171 }
172
173 bool rewriteLink(const WebURL& url, WebString* rewritten_link) override {
174 if (url != url_)
175 return false;
176
177 *rewritten_link = local_path_;
178 return true;
179 }
180
181 private:
182 const WebURL url_;
183 const WebString local_path_;
184 };
185
lukaszad083d292015-09-30 00:42:44186 // Serialize DOM belonging to a frame with the specified |frame_url|.
187 void SerializeDomForURL(const GURL& frame_url) {
188 // Find corresponding WebFrame according to frame_url.
esprehn961779002015-11-16 04:35:13189 WebFrame* web_frame = FindSubFrameByURL(frame_url);
[email protected]c1978abe2013-04-23 03:08:12190 ASSERT_TRUE(web_frame != NULL);
[email protected]728c2ee2013-06-25 04:01:07191 WebString file_path =
192 base::FilePath(FILE_PATH_LITERAL("c:\\dummy.htm")).AsUTF16Unsafe();
lukasza777a7dd2016-01-25 23:55:47193 SingleLinkRewritingDelegate delegate(frame_url, file_path);
[email protected]c1978abe2013-04-23 03:08:12194 // Start serializing DOM.
lukasza777a7dd2016-01-25 23:55:47195 bool result = WebFrameSerializer::serialize(web_frame->toWebLocalFrame(),
196 this, &delegate);
[email protected]c1978abe2013-04-23 03:08:12197 ASSERT_TRUE(result);
[email protected]c1978abe2013-04-23 03:08:12198 }
199
200 void SerializeHTMLDOMWithDocTypeOnRenderer(const GURL& file_url) {
201 // Make sure original contents have document type.
esprehn961779002015-11-16 04:35:13202 WebFrame* web_frame = FindSubFrameByURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12203 ASSERT_TRUE(web_frame != NULL);
204 WebDocument doc = web_frame->document();
205 ASSERT_TRUE(HasDocType(doc));
206 // Do serialization.
lukaszad083d292015-09-30 00:42:44207 SerializeDomForURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12208 // Load the serialized contents.
lukasza87f4e2ab2015-11-04 16:03:03209 ASSERT_TRUE(serialization_reported_end_of_data_);
210 LoadContents(serialized_contents_, file_url,
[email protected]c1978abe2013-04-23 03:08:12211 web_frame->document().encoding());
212 // Make sure serialized contents still have document type.
213 web_frame = GetMainFrame();
214 doc = web_frame->document();
215 ASSERT_TRUE(HasDocType(doc));
216 }
217
218 void SerializeHTMLDOMWithoutDocTypeOnRenderer(const GURL& file_url) {
219 // Make sure original contents do not have document type.
esprehn961779002015-11-16 04:35:13220 WebFrame* web_frame = FindSubFrameByURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12221 ASSERT_TRUE(web_frame != NULL);
222 WebDocument doc = web_frame->document();
223 ASSERT_TRUE(!HasDocType(doc));
224 // Do serialization.
lukaszad083d292015-09-30 00:42:44225 SerializeDomForURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12226 // Load the serialized contents.
lukasza87f4e2ab2015-11-04 16:03:03227 ASSERT_TRUE(serialization_reported_end_of_data_);
228 LoadContents(serialized_contents_, file_url,
[email protected]c1978abe2013-04-23 03:08:12229 web_frame->document().encoding());
230 // Make sure serialized contents do not have document type.
231 web_frame = GetMainFrame();
232 doc = web_frame->document();
233 ASSERT_TRUE(!HasDocType(doc));
234 }
235
236 void SerializeXMLDocWithBuiltInEntitiesOnRenderer(
237 const GURL& xml_file_url, const std::string& original_contents) {
238 // Do serialization.
lukaszad083d292015-09-30 00:42:44239 SerializeDomForURL(xml_file_url);
[email protected]c1978abe2013-04-23 03:08:12240 // Compare the serialized contents with original contents.
lukasza87f4e2ab2015-11-04 16:03:03241 ASSERT_TRUE(serialization_reported_end_of_data_);
242 ASSERT_EQ(original_contents, serialized_contents_);
[email protected]c1978abe2013-04-23 03:08:12243 }
244
245 void SerializeHTMLDOMWithAddingMOTWOnRenderer(
[email protected]53625ac2013-04-23 04:28:11246 const GURL& file_url, const std::string& original_contents) {
247 // Make sure original contents does not have MOTW;
248 std::string motw_declaration =
lukasza902fcc52015-12-31 04:45:29249 WebFrameSerializer::generateMarkOfTheWebDeclaration(file_url).utf8();
[email protected]53625ac2013-04-23 04:28:11250 ASSERT_FALSE(motw_declaration.empty());
251 // The encoding of original contents is ISO-8859-1, so we convert the MOTW
252 // declaration to ASCII and search whether original contents has it or not.
253 ASSERT_TRUE(std::string::npos == original_contents.find(motw_declaration));
254
[email protected]c1978abe2013-04-23 03:08:12255 // Do serialization.
lukaszad083d292015-09-30 00:42:44256 SerializeDomForURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12257 // Make sure the serialized contents have MOTW ;
lukasza87f4e2ab2015-11-04 16:03:03258 ASSERT_TRUE(serialization_reported_end_of_data_);
[email protected]c1978abe2013-04-23 03:08:12259 ASSERT_FALSE(std::string::npos ==
lukasza87f4e2ab2015-11-04 16:03:03260 serialized_contents_.find(motw_declaration));
[email protected]c1978abe2013-04-23 03:08:12261 }
262
263 void SerializeHTMLDOMWithNoMetaCharsetInOriginalDocOnRenderer(
264 const GURL& file_url) {
265 // Make sure there is no META charset declaration in original document.
esprehn961779002015-11-16 04:35:13266 WebFrame* web_frame = FindSubFrameByURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12267 ASSERT_TRUE(web_frame != NULL);
268 WebDocument doc = web_frame->document();
269 ASSERT_TRUE(doc.isHTMLDocument());
270 WebElement head_element = doc.head();
271 ASSERT_TRUE(!head_element.isNull());
272 // Go through all children of HEAD element.
esprehn467dcd92015-12-03 02:06:09273 WebElementCollection meta_elements = head_element.
274 getElementsByHTMLTagName("meta");
275 for (WebElement element = meta_elements.firstItem(); !element.isNull();
276 element = meta_elements.nextItem()) {
277 ASSERT_TRUE(element.to<WebMetaElement>().computeEncoding().isEmpty());
[email protected]c1978abe2013-04-23 03:08:12278 }
279 // Do serialization.
lukaszad083d292015-09-30 00:42:44280 SerializeDomForURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12281
282 // Load the serialized contents.
lukasza87f4e2ab2015-11-04 16:03:03283 ASSERT_TRUE(serialization_reported_end_of_data_);
284 LoadContents(serialized_contents_, file_url,
[email protected]c1978abe2013-04-23 03:08:12285 web_frame->document().encoding());
286 // Make sure the first child of HEAD element is META which has charset
287 // declaration in serialized contents.
288 web_frame = GetMainFrame();
289 ASSERT_TRUE(web_frame != NULL);
290 doc = web_frame->document();
291 ASSERT_TRUE(doc.isHTMLDocument());
292 head_element = doc.head();
293 ASSERT_TRUE(!head_element.isNull());
esprehn467dcd92015-12-03 02:06:09294 ASSERT_TRUE(!head_element.firstChild().isNull());
295 ASSERT_TRUE(head_element.firstChild().isElementNode());
296 WebMetaElement meta_element = head_element.firstChild().
297 to<WebMetaElement>();
298 ASSERT_EQ(meta_element.computeEncoding(), web_frame->document().encoding());
[email protected]c1978abe2013-04-23 03:08:12299
300 // Make sure no more additional META tags which have charset declaration.
esprehn467dcd92015-12-03 02:06:09301 meta_elements = head_element.getElementsByHTMLTagName("meta");
302 for (WebElement element = meta_elements.firstItem(); !element.isNull();
303 element = meta_elements.nextItem()) {
304 if (element == meta_element)
305 continue;
306 ASSERT_TRUE(element.to<WebMetaElement>().computeEncoding().isEmpty());
[email protected]c1978abe2013-04-23 03:08:12307 }
308 }
309
310 void SerializeHTMLDOMWithMultipleMetaCharsetInOriginalDocOnRenderer(
311 const GURL& file_url) {
312 // Make sure there are multiple META charset declarations in original
313 // document.
esprehn961779002015-11-16 04:35:13314 WebFrame* web_frame = FindSubFrameByURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12315 ASSERT_TRUE(web_frame != NULL);
316 WebDocument doc = web_frame->document();
317 ASSERT_TRUE(doc.isHTMLDocument());
esprehn467dcd92015-12-03 02:06:09318 WebElement head_element = doc.head();
319 ASSERT_TRUE(!head_element.isNull());
[email protected]c1978abe2013-04-23 03:08:12320 // Go through all children of HEAD element.
321 int charset_declaration_count = 0;
esprehn467dcd92015-12-03 02:06:09322 WebElementCollection meta_elements = head_element.
323 getElementsByHTMLTagName("meta");
324 for (WebElement element = meta_elements.firstItem(); !element.isNull();
325 element = meta_elements.nextItem()) {
326 if (!element.to<WebMetaElement>().computeEncoding().isEmpty())
327 ++charset_declaration_count;
[email protected]c1978abe2013-04-23 03:08:12328 }
329 // The original doc has more than META tags which have charset declaration.
330 ASSERT_TRUE(charset_declaration_count > 1);
331
332 // Do serialization.
lukaszad083d292015-09-30 00:42:44333 SerializeDomForURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12334
335 // Load the serialized contents.
lukasza87f4e2ab2015-11-04 16:03:03336 ASSERT_TRUE(serialization_reported_end_of_data_);
337 LoadContents(serialized_contents_, file_url,
[email protected]c1978abe2013-04-23 03:08:12338 web_frame->document().encoding());
339 // Make sure only first child of HEAD element is META which has charset
340 // declaration in serialized contents.
341 web_frame = GetMainFrame();
342 ASSERT_TRUE(web_frame != NULL);
343 doc = web_frame->document();
344 ASSERT_TRUE(doc.isHTMLDocument());
esprehn467dcd92015-12-03 02:06:09345 head_element = doc.head();
346 ASSERT_TRUE(!head_element.isNull());
347 ASSERT_TRUE(!head_element.firstChild().isNull());
348 ASSERT_TRUE(head_element.firstChild().isElementNode());
349 WebMetaElement meta_element = head_element.firstChild().
350 to<WebMetaElement>();
351 ASSERT_EQ(meta_element.computeEncoding(), web_frame->document().encoding());
[email protected]c1978abe2013-04-23 03:08:12352
353 // Make sure no more additional META tags which have charset declaration.
esprehn467dcd92015-12-03 02:06:09354 meta_elements = head_element.getElementsByHTMLTagName("meta");
355 for (WebElement element = meta_elements.firstItem(); !element.isNull();
356 element = meta_elements.nextItem()) {
357 if (element == meta_element)
358 continue;
359 ASSERT_TRUE(element.to<WebMetaElement>().computeEncoding().isEmpty());
[email protected]c1978abe2013-04-23 03:08:12360 }
361 }
362
363 void SerializeHTMLDOMWithEntitiesInTextOnRenderer() {
364 base::FilePath page_file_path = GetTestFilePath(
365 "dom_serializer", "dom_serializer/htmlentities_in_text.htm");
366 // Get file URL. The URL is dummy URL to identify the following loading
367 // actions. The test content is in constant:original_contents.
368 GURL file_url = net::FilePathToFileURL(page_file_path);
369 ASSERT_TRUE(file_url.SchemeIsFile());
370 // Test contents.
371 static const char* const original_contents =
372 "<html><body>&amp;&lt;&gt;\"\'</body></html>";
373 // Load the test contents.
374 LoadContents(original_contents, file_url, WebString());
375
376 // Get BODY's text content in DOM.
esprehn961779002015-11-16 04:35:13377 WebFrame* web_frame = FindSubFrameByURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12378 ASSERT_TRUE(web_frame != NULL);
379 WebDocument doc = web_frame->document();
380 ASSERT_TRUE(doc.isHTMLDocument());
381 WebElement body_ele = doc.body();
382 ASSERT_TRUE(!body_ele.isNull());
383 WebNode text_node = body_ele.firstChild();
384 ASSERT_TRUE(text_node.isTextNode());
esprehn01ebca21a2015-09-17 09:32:56385 ASSERT_TRUE(std::string(text_node.nodeValue().utf8()) == "&<>\"\'");
[email protected]c1978abe2013-04-23 03:08:12386 // Do serialization.
lukaszad083d292015-09-30 00:42:44387 SerializeDomForURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12388 // Compare the serialized contents with original contents.
lukasza87f4e2ab2015-11-04 16:03:03389 ASSERT_TRUE(serialization_reported_end_of_data_);
[email protected]c1978abe2013-04-23 03:08:12390 // Compare the serialized contents with original contents to make sure
391 // they are same.
392 // Because we add MOTW when serializing DOM, so before comparison, we also
393 // need to add MOTW to original_contents.
394 std::string original_str =
lukasza902fcc52015-12-31 04:45:29395 WebFrameSerializer::generateMarkOfTheWebDeclaration(file_url).utf8();
[email protected]c1978abe2013-04-23 03:08:12396 original_str += original_contents;
397 // Since WebCore now inserts a new HEAD element if there is no HEAD element
398 // when creating BODY element. (Please see
399 // HTMLParser::bodyCreateErrorCheck.) We need to append the HEAD content and
400 // corresponding META content if we find WebCore-generated HEAD element.
401 if (!doc.head().isNull()) {
402 WebString encoding = web_frame->document().encoding();
403 std::string htmlTag("<html>");
404 std::string::size_type pos = original_str.find(htmlTag);
405 ASSERT_NE(std::string::npos, pos);
406 pos += htmlTag.length();
407 std::string head_part("<head>");
408 head_part +=
lukasza902fcc52015-12-31 04:45:29409 WebFrameSerializer::generateMetaCharsetDeclaration(encoding).utf8();
[email protected]c1978abe2013-04-23 03:08:12410 head_part += "</head>";
411 original_str.insert(pos, head_part);
412 }
lukasza87f4e2ab2015-11-04 16:03:03413 ASSERT_EQ(original_str, serialized_contents_);
[email protected]c1978abe2013-04-23 03:08:12414 }
415
416 void SerializeHTMLDOMWithEntitiesInAttributeValueOnRenderer() {
417 base::FilePath page_file_path = GetTestFilePath(
418 "dom_serializer", "dom_serializer/htmlentities_in_attribute_value.htm");
419 // Get file URL. The URL is dummy URL to identify the following loading
420 // actions. The test content is in constant:original_contents.
421 GURL file_url = net::FilePathToFileURL(page_file_path);
422 ASSERT_TRUE(file_url.SchemeIsFile());
423 // Test contents.
424 static const char* const original_contents =
tkent99b65112015-08-17 03:05:07425 "<html><body title=\"&amp;&lt;&gt;&quot;&#39;\"></body></html>";
[email protected]c1978abe2013-04-23 03:08:12426 // Load the test contents.
427 LoadContents(original_contents, file_url, WebString());
428 // Get value of BODY's title attribute in DOM.
esprehn961779002015-11-16 04:35:13429 WebFrame* web_frame = FindSubFrameByURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12430 ASSERT_TRUE(web_frame != NULL);
431 WebDocument doc = web_frame->document();
432 ASSERT_TRUE(doc.isHTMLDocument());
433 WebElement body_ele = doc.body();
434 ASSERT_TRUE(!body_ele.isNull());
435 WebString value = body_ele.getAttribute("title");
436 ASSERT_TRUE(std::string(value.utf8()) == "&<>\"\'");
437 // Do serialization.
lukaszad083d292015-09-30 00:42:44438 SerializeDomForURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12439 // Compare the serialized contents with original contents.
lukasza87f4e2ab2015-11-04 16:03:03440 ASSERT_TRUE(serialization_reported_end_of_data_);
[email protected]c1978abe2013-04-23 03:08:12441 // Compare the serialized contents with original contents to make sure
442 // they are same.
443 std::string original_str =
lukasza902fcc52015-12-31 04:45:29444 WebFrameSerializer::generateMarkOfTheWebDeclaration(file_url).utf8();
[email protected]c1978abe2013-04-23 03:08:12445 original_str += original_contents;
446 if (!doc.isNull()) {
447 WebString encoding = web_frame->document().encoding();
448 std::string htmlTag("<html>");
449 std::string::size_type pos = original_str.find(htmlTag);
450 ASSERT_NE(std::string::npos, pos);
451 pos += htmlTag.length();
452 std::string head_part("<head>");
453 head_part +=
lukasza902fcc52015-12-31 04:45:29454 WebFrameSerializer::generateMetaCharsetDeclaration(encoding).utf8();
[email protected]c1978abe2013-04-23 03:08:12455 head_part += "</head>";
456 original_str.insert(pos, head_part);
457 }
lukasza87f4e2ab2015-11-04 16:03:03458 ASSERT_EQ(original_str, serialized_contents_);
[email protected]c1978abe2013-04-23 03:08:12459 }
460
461 void SerializeHTMLDOMWithNonStandardEntitiesOnRenderer(const GURL& file_url) {
462 // Get value of BODY's title attribute in DOM.
esprehn961779002015-11-16 04:35:13463 WebFrame* web_frame = FindSubFrameByURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12464 WebDocument doc = web_frame->document();
465 ASSERT_TRUE(doc.isHTMLDocument());
466 WebElement body_element = doc.body();
467 // Unescaped string for "&percnt;&nsup;&sup1;&apos;".
468 static const wchar_t parsed_value[] = {
469 '%', 0x2285, 0x00b9, '\'', 0
470 };
471 WebString value = body_element.getAttribute("title");
dglazkov3c1f64f2015-05-15 17:50:52472 WebString content = doc.contentAsTextForTesting();
[email protected]32956122013-12-25 07:29:24473 ASSERT_TRUE(base::UTF16ToWide(value) == parsed_value);
dglazkov3c1f64f2015-05-15 17:50:52474 ASSERT_TRUE(base::UTF16ToWide(content) == parsed_value);
[email protected]c1978abe2013-04-23 03:08:12475
476 // Do serialization.
lukaszad083d292015-09-30 00:42:44477 SerializeDomForURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12478 // Check the serialized string.
lukasza87f4e2ab2015-11-04 16:03:03479 ASSERT_TRUE(serialization_reported_end_of_data_);
[email protected]c1978abe2013-04-23 03:08:12480 // Confirm that the serialized string has no non-standard HTML entities.
lukasza87f4e2ab2015-11-04 16:03:03481 ASSERT_EQ(std::string::npos, serialized_contents_.find("&percnt;"));
482 ASSERT_EQ(std::string::npos, serialized_contents_.find("&nsup;"));
483 ASSERT_EQ(std::string::npos, serialized_contents_.find("&sup1;"));
484 ASSERT_EQ(std::string::npos, serialized_contents_.find("&apos;"));
[email protected]c1978abe2013-04-23 03:08:12485 }
486
487 void SerializeHTMLDOMWithBaseTagOnRenderer(const GURL& file_url,
488 const GURL& path_dir_url) {
489 // There are total 2 available base tags in this test file.
490 const int kTotalBaseTagCountInTestFile = 2;
491
492 // Since for this test, we assume there is no savable sub-resource links for
493 // this test file, also all links are relative URLs in this test file, so we
494 // need to check those relative URLs and make sure document has BASE tag.
esprehn961779002015-11-16 04:35:13495 WebFrame* web_frame = FindSubFrameByURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12496 ASSERT_TRUE(web_frame != NULL);
497 WebDocument doc = web_frame->document();
498 ASSERT_TRUE(doc.isHTMLDocument());
499 // Go through all descent nodes.
[email protected]c93932712014-02-07 18:49:02500 WebElementCollection all = doc.all();
[email protected]c1978abe2013-04-23 03:08:12501 int original_base_tag_count = 0;
[email protected]c93932712014-02-07 18:49:02502 for (WebElement element = all.firstItem(); !element.isNull();
503 element = all.nextItem()) {
[email protected]498269f2014-06-24 13:40:50504 if (element.hasHTMLTagName("base")) {
[email protected]c1978abe2013-04-23 03:08:12505 original_base_tag_count++;
506 } else {
507 // Get link.
[email protected]12a936d2013-05-15 04:55:49508 WebString value = GetSubResourceLinkFromElement(element);
[email protected]498269f2014-06-24 13:40:50509 if (value.isNull() && element.hasHTMLTagName("a")) {
[email protected]c1978abe2013-04-23 03:08:12510 value = element.getAttribute("href");
511 if (value.isEmpty())
512 value = WebString();
513 }
514 // Each link is relative link.
515 if (!value.isNull()) {
516 GURL link(value.utf8());
517 ASSERT_TRUE(link.scheme().empty());
518 }
519 }
520 }
521 ASSERT_EQ(original_base_tag_count, kTotalBaseTagCountInTestFile);
522 // Make sure in original document, the base URL is not equal with the
523 // |path_dir_url|.
524 GURL original_base_url(doc.baseURL());
525 ASSERT_NE(original_base_url, path_dir_url);
526
527 // Do serialization.
lukaszad083d292015-09-30 00:42:44528 SerializeDomForURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12529
530 // Load the serialized contents.
lukasza87f4e2ab2015-11-04 16:03:03531 ASSERT_TRUE(serialization_reported_end_of_data_);
532 LoadContents(serialized_contents_, file_url,
[email protected]c1978abe2013-04-23 03:08:12533 web_frame->document().encoding());
534
535 // Make sure all links are absolute URLs and doc there are some number of
536 // BASE tags in serialized HTML data. Each of those BASE tags have same base
537 // URL which is as same as URL of current test file.
538 web_frame = GetMainFrame();
539 ASSERT_TRUE(web_frame != NULL);
540 doc = web_frame->document();
541 ASSERT_TRUE(doc.isHTMLDocument());
542 // Go through all descent nodes.
543 all = doc.all();
544 int new_base_tag_count = 0;
545 for (WebNode node = all.firstItem(); !node.isNull();
546 node = all.nextItem()) {
547 if (!node.isElementNode())
548 continue;
549 WebElement element = node.to<WebElement>();
[email protected]498269f2014-06-24 13:40:50550 if (element.hasHTMLTagName("base")) {
[email protected]c1978abe2013-04-23 03:08:12551 new_base_tag_count++;
552 } else {
553 // Get link.
[email protected]12a936d2013-05-15 04:55:49554 WebString value = GetSubResourceLinkFromElement(element);
[email protected]498269f2014-06-24 13:40:50555 if (value.isNull() && element.hasHTMLTagName("a")) {
[email protected]c1978abe2013-04-23 03:08:12556 value = element.getAttribute("href");
557 if (value.isEmpty())
558 value = WebString();
559 }
560 // Each link is absolute link.
561 if (!value.isNull()) {
562 GURL link(std::string(value.utf8()));
563 ASSERT_FALSE(link.scheme().empty());
564 }
565 }
566 }
tkent99b65112015-08-17 03:05:07567 // We have one more added BASE tag which is generated by JavaScript.
568 ASSERT_EQ(new_base_tag_count, original_base_tag_count + 1);
[email protected]c1978abe2013-04-23 03:08:12569 // Make sure in new document, the base URL is equal with the |path_dir_url|.
570 GURL new_base_url(doc.baseURL());
571 ASSERT_EQ(new_base_url, path_dir_url);
572 }
573
574 void SerializeHTMLDOMWithEmptyHeadOnRenderer() {
575 base::FilePath page_file_path = GetTestFilePath(
576 "dom_serializer", "empty_head.htm");
577 GURL file_url = net::FilePathToFileURL(page_file_path);
578 ASSERT_TRUE(file_url.SchemeIsFile());
579
580 // Load the test html content.
581 static const char* const empty_head_contents =
582 "<html><head></head><body>hello world</body></html>";
583 LoadContents(empty_head_contents, file_url, WebString());
584
585 // Make sure the head tag is empty.
586 WebFrame* web_frame = GetMainFrame();
587 ASSERT_TRUE(web_frame != NULL);
588 WebDocument doc = web_frame->document();
589 ASSERT_TRUE(doc.isHTMLDocument());
590 WebElement head_element = doc.head();
591 ASSERT_TRUE(!head_element.isNull());
592 ASSERT_TRUE(!head_element.hasChildNodes());
[email protected]c1978abe2013-04-23 03:08:12593
594 // Do serialization.
lukaszad083d292015-09-30 00:42:44595 SerializeDomForURL(file_url);
lukasza87f4e2ab2015-11-04 16:03:03596 ASSERT_TRUE(serialization_reported_end_of_data_);
[email protected]c1978abe2013-04-23 03:08:12597
598 // Reload serialized contents and make sure there is only one META tag.
lukasza87f4e2ab2015-11-04 16:03:03599 LoadContents(serialized_contents_, file_url,
[email protected]c1978abe2013-04-23 03:08:12600 web_frame->document().encoding());
601 web_frame = GetMainFrame();
602 ASSERT_TRUE(web_frame != NULL);
603 doc = web_frame->document();
604 ASSERT_TRUE(doc.isHTMLDocument());
605 head_element = doc.head();
606 ASSERT_TRUE(!head_element.isNull());
esprehn467dcd92015-12-03 02:06:09607 ASSERT_TRUE(!head_element.firstChild().isNull());
608 ASSERT_TRUE(head_element.firstChild().isElementNode());
609 ASSERT_TRUE(head_element.firstChild().nextSibling().isNull());
610 WebMetaElement meta_element = head_element.firstChild().
611 to<WebMetaElement>();
612 ASSERT_EQ(meta_element.computeEncoding(), web_frame->document().encoding());
[email protected]c1978abe2013-04-23 03:08:12613
614 // Check the body's first node is text node and its contents are
615 // "hello world"
616 WebElement body_element = doc.body();
617 ASSERT_TRUE(!body_element.isNull());
618 WebNode text_node = body_element.firstChild();
619 ASSERT_TRUE(text_node.isTextNode());
esprehn467dcd92015-12-03 02:06:09620 ASSERT_EQ("hello world", text_node.nodeValue());
[email protected]c1978abe2013-04-23 03:08:12621 }
622
[email protected]c1978abe2013-04-23 03:08:12623 void SubResourceForElementsInNonHTMLNamespaceOnRenderer(
624 const GURL& file_url) {
esprehn961779002015-11-16 04:35:13625 WebFrame* web_frame = FindSubFrameByURL(file_url);
[email protected]c1978abe2013-04-23 03:08:12626 ASSERT_TRUE(web_frame != NULL);
627 WebDocument doc = web_frame->document();
628 WebNode lastNodeInBody = doc.body().lastChild();
esprehn41212292015-09-17 16:48:03629 ASSERT_TRUE(lastNodeInBody.isElementNode());
[email protected]12a936d2013-05-15 04:55:49630 WebString uri = GetSubResourceLinkFromElement(
[email protected]c1978abe2013-04-23 03:08:12631 lastNodeInBody.to<WebElement>());
632 EXPECT_TRUE(uri.isNull());
633 }
634
635 private:
avi1023d012015-12-25 02:39:14636 int32_t render_view_routing_id_;
lukasza87f4e2ab2015-11-04 16:03:03637 std::string serialized_contents_;
638 bool serialization_reported_end_of_data_;
[email protected]c1978abe2013-04-23 03:08:12639};
640
641// If original contents have document type, the serialized contents also have
642// document type.
tsergeant97b442d2016-03-10 05:46:04643// Disabled on OSX by ellyjones@ on 2015-05-18, see https://crbug.com/488495,
644// on all platforms by tsergeant@ on 2016-03-10, see https://crbug.com/593575
ellyjones15a15d2d2015-05-18 21:26:37645
646IN_PROC_BROWSER_TEST_F(DomSerializerTests,
tsergeant97b442d2016-03-10 05:46:04647 DISABLED_SerializeHTMLDOMWithDocType) {
[email protected]c1978abe2013-04-23 03:08:12648 base::FilePath page_file_path =
649 GetTestFilePath("dom_serializer", "youtube_1.htm");
650 GURL file_url = net::FilePathToFileURL(page_file_path);
651 ASSERT_TRUE(file_url.SchemeIsFile());
652 // Load the test file.
653 NavigateToURL(shell(), file_url);
654
655 PostTaskToInProcessRendererAndWait(
656 base::Bind(&DomSerializerTests::SerializeHTMLDOMWithDocTypeOnRenderer,
657 base::Unretained(this), file_url));
658}
659
660// If original contents do not have document type, the serialized contents
661// also do not have document type.
662IN_PROC_BROWSER_TEST_F(DomSerializerTests, SerializeHTMLDOMWithoutDocType) {
663 base::FilePath page_file_path =
664 GetTestFilePath("dom_serializer", "youtube_2.htm");
665 GURL file_url = net::FilePathToFileURL(page_file_path);
666 ASSERT_TRUE(file_url.SchemeIsFile());
667 // Load the test file.
668 NavigateToURL(shell(), file_url);
669
670 PostTaskToInProcessRendererAndWait(
671 base::Bind(
672 &DomSerializerTests::SerializeHTMLDOMWithoutDocTypeOnRenderer,
673 base::Unretained(this), file_url));
674}
675
676// Serialize XML document which has all 5 built-in entities. After
677// finishing serialization, the serialized contents should be same
678// with original XML document.
tkent99b65112015-08-17 03:05:07679IN_PROC_BROWSER_TEST_F(DomSerializerTests,
lukaszaa5bb0172016-01-12 19:53:15680 SerializeXMLDocWithBuiltInEntities) {
[email protected]c1978abe2013-04-23 03:08:12681 base::FilePath page_file_path =
682 GetTestFilePath("dom_serializer", "note.html");
683 base::FilePath xml_file_path = GetTestFilePath("dom_serializer", "note.xml");
684 // Read original contents for later comparison.
685 std::string original_contents;
[email protected]82f84b92013-08-30 18:23:50686 ASSERT_TRUE(base::ReadFileToString(xml_file_path, &original_contents));
[email protected]c1978abe2013-04-23 03:08:12687 // Get file URL.
688 GURL file_url = net::FilePathToFileURL(page_file_path);
689 GURL xml_file_url = net::FilePathToFileURL(xml_file_path);
690 ASSERT_TRUE(file_url.SchemeIsFile());
691 // Load the test file.
692 NavigateToURL(shell(), file_url);
693
694 PostTaskToInProcessRendererAndWait(
695 base::Bind(
696 &DomSerializerTests::SerializeXMLDocWithBuiltInEntitiesOnRenderer,
697 base::Unretained(this), xml_file_url, original_contents));
698}
699
700// When serializing DOM, we add MOTW declaration before html tag.
701IN_PROC_BROWSER_TEST_F(DomSerializerTests, SerializeHTMLDOMWithAddingMOTW) {
702 base::FilePath page_file_path =
703 GetTestFilePath("dom_serializer", "youtube_2.htm");
704 // Read original contents for later comparison .
705 std::string original_contents;
[email protected]82f84b92013-08-30 18:23:50706 ASSERT_TRUE(base::ReadFileToString(page_file_path, &original_contents));
[email protected]c1978abe2013-04-23 03:08:12707 // Get file URL.
708 GURL file_url = net::FilePathToFileURL(page_file_path);
709 ASSERT_TRUE(file_url.SchemeIsFile());
[email protected]53625ac2013-04-23 04:28:11710
[email protected]c1978abe2013-04-23 03:08:12711 // Load the test file.
712 NavigateToURL(shell(), file_url);
713
714 PostTaskToInProcessRendererAndWait(
715 base::Bind(
716 &DomSerializerTests::SerializeHTMLDOMWithAddingMOTWOnRenderer,
[email protected]53625ac2013-04-23 04:28:11717 base::Unretained(this), file_url, original_contents));
[email protected]c1978abe2013-04-23 03:08:12718}
719
720// When serializing DOM, we will add the META which have correct charset
721// declaration as first child of HEAD element for resolving WebKit bug:
722// http://bugs.webkit.org/show_bug.cgi?id=16621 even the original document
723// does not have META charset declaration.
tsergeant97b442d2016-03-10 05:46:04724// Disabled on OSX by battre@ on 2015-05-21, see https://crbug.com/488495,
725// on all platforms by tsergeant@ on 2016-03-10, see https://crbug.com/593575
726IN_PROC_BROWSER_TEST_F(
727 DomSerializerTests,
728 DISABLED_SerializeHTMLDOMWithNoMetaCharsetInOriginalDoc) {
[email protected]c1978abe2013-04-23 03:08:12729 base::FilePath page_file_path =
730 GetTestFilePath("dom_serializer", "youtube_1.htm");
731 // Get file URL.
732 GURL file_url = net::FilePathToFileURL(page_file_path);
733 ASSERT_TRUE(file_url.SchemeIsFile());
734 // Load the test file.
735 NavigateToURL(shell(), file_url);
736
737 PostTaskToInProcessRendererAndWait(
738 base::Bind(
739 &DomSerializerTests::
740 SerializeHTMLDOMWithNoMetaCharsetInOriginalDocOnRenderer,
741 base::Unretained(this), file_url));
742}
743
744// When serializing DOM, if the original document has multiple META charset
745// declaration, we will add the META which have correct charset declaration
746// as first child of HEAD element and remove all original META charset
747// declarations.
748IN_PROC_BROWSER_TEST_F(DomSerializerTests,
749 SerializeHTMLDOMWithMultipleMetaCharsetInOriginalDoc) {
750 base::FilePath page_file_path =
751 GetTestFilePath("dom_serializer", "youtube_2.htm");
752 // Get file URL.
753 GURL file_url = net::FilePathToFileURL(page_file_path);
754 ASSERT_TRUE(file_url.SchemeIsFile());
755 // Load the test file.
756 NavigateToURL(shell(), file_url);
757
758 PostTaskToInProcessRendererAndWait(
759 base::Bind(
760 &DomSerializerTests::
761 SerializeHTMLDOMWithMultipleMetaCharsetInOriginalDocOnRenderer,
762 base::Unretained(this), file_url));
763}
764
765// Test situation of html entities in text when serializing HTML DOM.
766IN_PROC_BROWSER_TEST_F(DomSerializerTests, SerializeHTMLDOMWithEntitiesInText) {
767 // Need to spin up the renderer and also navigate to a file url so that the
768 // renderer code doesn't attempt a fork when it sees a load to file scheme
769 // from non-file scheme.
770 NavigateToURL(shell(), GetTestUrl(".", "simple_page.html"));
771
772 PostTaskToInProcessRendererAndWait(
773 base::Bind(
774 &DomSerializerTests::SerializeHTMLDOMWithEntitiesInTextOnRenderer,
775 base::Unretained(this)));
776}
777
778// Test situation of html entities in attribute value when serializing
779// HTML DOM.
780// This test started to fail at WebKit r65388. See http://crbug.com/52279.
[email protected]c1978abe2013-04-23 03:08:12781IN_PROC_BROWSER_TEST_F(DomSerializerTests,
lukaszaa5bb0172016-01-12 19:53:15782 SerializeHTMLDOMWithEntitiesInAttributeValue) {
[email protected]c1978abe2013-04-23 03:08:12783 // Need to spin up the renderer and also navigate to a file url so that the
784 // renderer code doesn't attempt a fork when it sees a load to file scheme
785 // from non-file scheme.
786 NavigateToURL(shell(), GetTestUrl(".", "simple_page.html"));
787
788 PostTaskToInProcessRendererAndWait(
789 base::Bind(
790 &DomSerializerTests::
791 SerializeHTMLDOMWithEntitiesInAttributeValueOnRenderer,
792 base::Unretained(this)));
793}
794
795// Test situation of non-standard HTML entities when serializing HTML DOM.
796// This test started to fail at WebKit r65351. See http://crbug.com/52279.
797IN_PROC_BROWSER_TEST_F(DomSerializerTests,
798 SerializeHTMLDOMWithNonStandardEntities) {
799 // Make a test file URL and load it.
800 base::FilePath page_file_path = GetTestFilePath(
801 "dom_serializer", "nonstandard_htmlentities.htm");
802 GURL file_url = net::FilePathToFileURL(page_file_path);
803 NavigateToURL(shell(), file_url);
804
805 PostTaskToInProcessRendererAndWait(
806 base::Bind(
807 &DomSerializerTests::
808 SerializeHTMLDOMWithNonStandardEntitiesOnRenderer,
809 base::Unretained(this), file_url));
810}
811
812// Test situation of BASE tag in original document when serializing HTML DOM.
813// When serializing, we should comment the BASE tag, append a new BASE tag.
814// rewrite all the savable URLs to relative local path, and change other URLs
815// to absolute URLs.
tkent99b65112015-08-17 03:05:07816IN_PROC_BROWSER_TEST_F(DomSerializerTests,
lukaszaa5bb0172016-01-12 19:53:15817 SerializeHTMLDOMWithBaseTag) {
[email protected]c1978abe2013-04-23 03:08:12818 base::FilePath page_file_path = GetTestFilePath(
819 "dom_serializer", "html_doc_has_base_tag.htm");
820
821 // Get page dir URL which is base URL of this file.
822 base::FilePath dir_name = page_file_path.DirName();
823 dir_name = dir_name.Append(
824 base::FilePath::StringType(base::FilePath::kSeparators[0], 1));
825 GURL path_dir_url = net::FilePathToFileURL(dir_name);
826
827 // Get file URL.
828 GURL file_url = net::FilePathToFileURL(page_file_path);
829 ASSERT_TRUE(file_url.SchemeIsFile());
830 // Load the test file.
831 NavigateToURL(shell(), file_url);
832
833 PostTaskToInProcessRendererAndWait(
834 base::Bind(
835 &DomSerializerTests::SerializeHTMLDOMWithBaseTagOnRenderer,
836 base::Unretained(this), file_url, path_dir_url));
837}
838
839// Serializing page which has an empty HEAD tag.
[email protected]185d5012014-06-10 22:01:34840IN_PROC_BROWSER_TEST_F(DomSerializerTests, SerializeHTMLDOMWithEmptyHead) {
[email protected]c1978abe2013-04-23 03:08:12841 // Need to spin up the renderer and also navigate to a file url so that the
842 // renderer code doesn't attempt a fork when it sees a load to file scheme
843 // from non-file scheme.
844 NavigateToURL(shell(), GetTestUrl(".", "simple_page.html"));
845
846 PostTaskToInProcessRendererAndWait(
847 base::Bind(&DomSerializerTests::SerializeHTMLDOMWithEmptyHeadOnRenderer,
848 base::Unretained(this)));
849}
850
[email protected]c1978abe2013-04-23 03:08:12851IN_PROC_BROWSER_TEST_F(DomSerializerTests,
852 SubResourceForElementsInNonHTMLNamespace) {
853 base::FilePath page_file_path = GetTestFilePath(
854 "dom_serializer", "non_html_namespace.htm");
855 GURL file_url = net::FilePathToFileURL(page_file_path);
856 NavigateToURL(shell(), file_url);
857
858 PostTaskToInProcessRendererAndWait(
859 base::Bind(
860 &DomSerializerTests::
861 SubResourceForElementsInNonHTMLNamespaceOnRenderer,
862 base::Unretained(this), file_url));
863}
864
[email protected]c1978abe2013-04-23 03:08:12865} // namespace content