OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/containers/hash_tables.h" | 8 #include "base/containers/hash_tables.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 WebFrame* web_frame = GetMainFrame(); | 253 WebFrame* web_frame = GetMainFrame(); |
254 | 254 |
255 ASSERT_TRUE(web_frame != NULL); | 255 ASSERT_TRUE(web_frame != NULL); |
256 | 256 |
257 web_frame->loadData(data, "text/html", encoding_info, base_url); | 257 web_frame->loadData(data, "text/html", encoding_info, base_url); |
258 } | 258 } |
259 | 259 |
260 runner->Run(); | 260 runner->Run(); |
261 } | 261 } |
262 | 262 |
263 // Serialize page DOM according to specific page URL. The parameter | 263 // Serialize DOM belonging to a frame with the specified |frame_url|. |
264 // recursive_serialization indicates whether we will serialize all | 264 void SerializeDomForURL(const GURL& frame_url) { |
265 // sub-frames. | 265 // Find corresponding WebFrame according to frame_url. |
266 void SerializeDomForURL(const GURL& page_url, | 266 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), frame_url); |
267 bool recursive_serialization) { | |
268 // Find corresponding WebFrame according to page_url. | |
269 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), page_url); | |
270 ASSERT_TRUE(web_frame != NULL); | 267 ASSERT_TRUE(web_frame != NULL); |
271 WebVector<WebURL> links; | 268 WebVector<WebURL> links; |
272 links.assign(&page_url, 1); | 269 links.assign(&frame_url, 1); |
273 WebString file_path = | 270 WebString file_path = |
274 base::FilePath(FILE_PATH_LITERAL("c:\\dummy.htm")).AsUTF16Unsafe(); | 271 base::FilePath(FILE_PATH_LITERAL("c:\\dummy.htm")).AsUTF16Unsafe(); |
275 WebVector<WebString> local_paths; | 272 WebVector<WebString> local_paths; |
276 local_paths.assign(&file_path, 1); | 273 local_paths.assign(&file_path, 1); |
277 // Start serializing DOM. | 274 // Start serializing DOM. |
278 bool result = WebPageSerializer::serialize(web_frame->toWebLocalFrame(), | 275 bool result = WebPageSerializer::serialize(web_frame->toWebLocalFrame(), |
279 recursive_serialization, | |
280 static_cast<WebPageSerializerClient*>(this), | 276 static_cast<WebPageSerializerClient*>(this), |
281 links, | 277 links, |
282 local_paths, | 278 local_paths, |
283 local_directory_name_.AsUTF16Unsafe()); | 279 local_directory_name_.AsUTF16Unsafe()); |
284 ASSERT_TRUE(result); | 280 ASSERT_TRUE(result); |
285 ASSERT_TRUE(serialized_); | 281 ASSERT_TRUE(serialized_); |
286 } | 282 } |
287 | 283 |
288 void SerializeHTMLDOMWithDocTypeOnRenderer(const GURL& file_url) { | 284 void SerializeHTMLDOMWithDocTypeOnRenderer(const GURL& file_url) { |
289 // Make sure original contents have document type. | 285 // Make sure original contents have document type. |
290 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url); | 286 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url); |
291 ASSERT_TRUE(web_frame != NULL); | 287 ASSERT_TRUE(web_frame != NULL); |
292 WebDocument doc = web_frame->document(); | 288 WebDocument doc = web_frame->document(); |
293 ASSERT_TRUE(HasDocType(doc)); | 289 ASSERT_TRUE(HasDocType(doc)); |
294 // Do serialization. | 290 // Do serialization. |
295 SerializeDomForURL(file_url, false); | 291 SerializeDomForURL(file_url); |
296 // Load the serialized contents. | 292 // Load the serialized contents. |
297 ASSERT_TRUE(HasSerializedFrame(file_url)); | 293 ASSERT_TRUE(HasSerializedFrame(file_url)); |
298 const std::string& serialized_contents = | 294 const std::string& serialized_contents = |
299 GetSerializedContentForFrame(file_url); | 295 GetSerializedContentForFrame(file_url); |
300 LoadContents(serialized_contents, file_url, | 296 LoadContents(serialized_contents, file_url, |
301 web_frame->document().encoding()); | 297 web_frame->document().encoding()); |
302 // Make sure serialized contents still have document type. | 298 // Make sure serialized contents still have document type. |
303 web_frame = GetMainFrame(); | 299 web_frame = GetMainFrame(); |
304 doc = web_frame->document(); | 300 doc = web_frame->document(); |
305 ASSERT_TRUE(HasDocType(doc)); | 301 ASSERT_TRUE(HasDocType(doc)); |
306 } | 302 } |
307 | 303 |
308 void SerializeHTMLDOMWithoutDocTypeOnRenderer(const GURL& file_url) { | 304 void SerializeHTMLDOMWithoutDocTypeOnRenderer(const GURL& file_url) { |
309 // Make sure original contents do not have document type. | 305 // Make sure original contents do not have document type. |
310 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url); | 306 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url); |
311 ASSERT_TRUE(web_frame != NULL); | 307 ASSERT_TRUE(web_frame != NULL); |
312 WebDocument doc = web_frame->document(); | 308 WebDocument doc = web_frame->document(); |
313 ASSERT_TRUE(!HasDocType(doc)); | 309 ASSERT_TRUE(!HasDocType(doc)); |
314 // Do serialization. | 310 // Do serialization. |
315 SerializeDomForURL(file_url, false); | 311 SerializeDomForURL(file_url); |
316 // Load the serialized contents. | 312 // Load the serialized contents. |
317 ASSERT_TRUE(HasSerializedFrame(file_url)); | 313 ASSERT_TRUE(HasSerializedFrame(file_url)); |
318 const std::string& serialized_contents = | 314 const std::string& serialized_contents = |
319 GetSerializedContentForFrame(file_url); | 315 GetSerializedContentForFrame(file_url); |
320 LoadContents(serialized_contents, file_url, | 316 LoadContents(serialized_contents, file_url, |
321 web_frame->document().encoding()); | 317 web_frame->document().encoding()); |
322 // Make sure serialized contents do not have document type. | 318 // Make sure serialized contents do not have document type. |
323 web_frame = GetMainFrame(); | 319 web_frame = GetMainFrame(); |
324 doc = web_frame->document(); | 320 doc = web_frame->document(); |
325 ASSERT_TRUE(!HasDocType(doc)); | 321 ASSERT_TRUE(!HasDocType(doc)); |
326 } | 322 } |
327 | 323 |
328 void SerializeXMLDocWithBuiltInEntitiesOnRenderer( | 324 void SerializeXMLDocWithBuiltInEntitiesOnRenderer( |
329 const GURL& xml_file_url, const std::string& original_contents) { | 325 const GURL& xml_file_url, const std::string& original_contents) { |
330 // Do serialization. | 326 // Do serialization. |
331 SerializeDomForURL(xml_file_url, false); | 327 SerializeDomForURL(xml_file_url); |
332 // Compare the serialized contents with original contents. | 328 // Compare the serialized contents with original contents. |
333 ASSERT_TRUE(HasSerializedFrame(xml_file_url)); | 329 ASSERT_TRUE(HasSerializedFrame(xml_file_url)); |
334 const std::string& serialized_contents = | 330 const std::string& serialized_contents = |
335 GetSerializedContentForFrame(xml_file_url); | 331 GetSerializedContentForFrame(xml_file_url); |
336 ASSERT_EQ(original_contents, serialized_contents); | 332 ASSERT_EQ(original_contents, serialized_contents); |
337 } | 333 } |
338 | 334 |
339 void SerializeHTMLDOMWithAddingMOTWOnRenderer( | 335 void SerializeHTMLDOMWithAddingMOTWOnRenderer( |
340 const GURL& file_url, const std::string& original_contents) { | 336 const GURL& file_url, const std::string& original_contents) { |
341 // Make sure original contents does not have MOTW; | 337 // Make sure original contents does not have MOTW; |
342 std::string motw_declaration = | 338 std::string motw_declaration = |
343 WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8(); | 339 WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8(); |
344 ASSERT_FALSE(motw_declaration.empty()); | 340 ASSERT_FALSE(motw_declaration.empty()); |
345 // The encoding of original contents is ISO-8859-1, so we convert the MOTW | 341 // The encoding of original contents is ISO-8859-1, so we convert the MOTW |
346 // declaration to ASCII and search whether original contents has it or not. | 342 // declaration to ASCII and search whether original contents has it or not. |
347 ASSERT_TRUE(std::string::npos == original_contents.find(motw_declaration)); | 343 ASSERT_TRUE(std::string::npos == original_contents.find(motw_declaration)); |
348 | 344 |
349 // Do serialization. | 345 // Do serialization. |
350 SerializeDomForURL(file_url, false); | 346 SerializeDomForURL(file_url); |
351 // Make sure the serialized contents have MOTW ; | 347 // Make sure the serialized contents have MOTW ; |
352 ASSERT_TRUE(HasSerializedFrame(file_url)); | 348 ASSERT_TRUE(HasSerializedFrame(file_url)); |
353 const std::string& serialized_contents = | 349 const std::string& serialized_contents = |
354 GetSerializedContentForFrame(file_url); | 350 GetSerializedContentForFrame(file_url); |
355 ASSERT_FALSE(std::string::npos == | 351 ASSERT_FALSE(std::string::npos == |
356 serialized_contents.find(motw_declaration)); | 352 serialized_contents.find(motw_declaration)); |
357 } | 353 } |
358 | 354 |
359 void SerializeHTMLDOMWithNoMetaCharsetInOriginalDocOnRenderer( | 355 void SerializeHTMLDOMWithNoMetaCharsetInOriginalDocOnRenderer( |
360 const GURL& file_url) { | 356 const GURL& file_url) { |
361 // Make sure there is no META charset declaration in original document. | 357 // Make sure there is no META charset declaration in original document. |
362 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url); | 358 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url); |
363 ASSERT_TRUE(web_frame != NULL); | 359 ASSERT_TRUE(web_frame != NULL); |
364 WebDocument doc = web_frame->document(); | 360 WebDocument doc = web_frame->document(); |
365 ASSERT_TRUE(doc.isHTMLDocument()); | 361 ASSERT_TRUE(doc.isHTMLDocument()); |
366 WebElement head_element = doc.head(); | 362 WebElement head_element = doc.head(); |
367 ASSERT_TRUE(!head_element.isNull()); | 363 ASSERT_TRUE(!head_element.isNull()); |
368 // Go through all children of HEAD element. | 364 // Go through all children of HEAD element. |
369 for (WebNode child = head_element.firstChild(); !child.isNull(); | 365 for (WebNode child = head_element.firstChild(); !child.isNull(); |
370 child = child.nextSibling()) { | 366 child = child.nextSibling()) { |
371 std::string charset_info; | 367 std::string charset_info; |
372 if (IsMetaElement(child, charset_info)) | 368 if (IsMetaElement(child, charset_info)) |
373 ASSERT_TRUE(charset_info.empty()); | 369 ASSERT_TRUE(charset_info.empty()); |
374 } | 370 } |
375 // Do serialization. | 371 // Do serialization. |
376 SerializeDomForURL(file_url, false); | 372 SerializeDomForURL(file_url); |
377 | 373 |
378 // Load the serialized contents. | 374 // Load the serialized contents. |
379 ASSERT_TRUE(HasSerializedFrame(file_url)); | 375 ASSERT_TRUE(HasSerializedFrame(file_url)); |
380 const std::string& serialized_contents = | 376 const std::string& serialized_contents = |
381 GetSerializedContentForFrame(file_url); | 377 GetSerializedContentForFrame(file_url); |
382 LoadContents(serialized_contents, file_url, | 378 LoadContents(serialized_contents, file_url, |
383 web_frame->document().encoding()); | 379 web_frame->document().encoding()); |
384 // Make sure the first child of HEAD element is META which has charset | 380 // Make sure the first child of HEAD element is META which has charset |
385 // declaration in serialized contents. | 381 // declaration in serialized contents. |
386 web_frame = GetMainFrame(); | 382 web_frame = GetMainFrame(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 for (WebNode child = head_ele.firstChild(); !child.isNull(); | 418 for (WebNode child = head_ele.firstChild(); !child.isNull(); |
423 child = child.nextSibling()) { | 419 child = child.nextSibling()) { |
424 std::string charset_info; | 420 std::string charset_info; |
425 if (IsMetaElement(child, charset_info) && !charset_info.empty()) | 421 if (IsMetaElement(child, charset_info) && !charset_info.empty()) |
426 charset_declaration_count++; | 422 charset_declaration_count++; |
427 } | 423 } |
428 // The original doc has more than META tags which have charset declaration. | 424 // The original doc has more than META tags which have charset declaration. |
429 ASSERT_TRUE(charset_declaration_count > 1); | 425 ASSERT_TRUE(charset_declaration_count > 1); |
430 | 426 |
431 // Do serialization. | 427 // Do serialization. |
432 SerializeDomForURL(file_url, false); | 428 SerializeDomForURL(file_url); |
433 | 429 |
434 // Load the serialized contents. | 430 // Load the serialized contents. |
435 ASSERT_TRUE(HasSerializedFrame(file_url)); | 431 ASSERT_TRUE(HasSerializedFrame(file_url)); |
436 const std::string& serialized_contents = | 432 const std::string& serialized_contents = |
437 GetSerializedContentForFrame(file_url); | 433 GetSerializedContentForFrame(file_url); |
438 LoadContents(serialized_contents, file_url, | 434 LoadContents(serialized_contents, file_url, |
439 web_frame->document().encoding()); | 435 web_frame->document().encoding()); |
440 // Make sure only first child of HEAD element is META which has charset | 436 // Make sure only first child of HEAD element is META which has charset |
441 // declaration in serialized contents. | 437 // declaration in serialized contents. |
442 web_frame = GetMainFrame(); | 438 web_frame = GetMainFrame(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url); | 476 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url); |
481 ASSERT_TRUE(web_frame != NULL); | 477 ASSERT_TRUE(web_frame != NULL); |
482 WebDocument doc = web_frame->document(); | 478 WebDocument doc = web_frame->document(); |
483 ASSERT_TRUE(doc.isHTMLDocument()); | 479 ASSERT_TRUE(doc.isHTMLDocument()); |
484 WebElement body_ele = doc.body(); | 480 WebElement body_ele = doc.body(); |
485 ASSERT_TRUE(!body_ele.isNull()); | 481 ASSERT_TRUE(!body_ele.isNull()); |
486 WebNode text_node = body_ele.firstChild(); | 482 WebNode text_node = body_ele.firstChild(); |
487 ASSERT_TRUE(text_node.isTextNode()); | 483 ASSERT_TRUE(text_node.isTextNode()); |
488 ASSERT_TRUE(std::string(text_node.nodeValue().utf8()) == "&<>\"\'"); | 484 ASSERT_TRUE(std::string(text_node.nodeValue().utf8()) == "&<>\"\'"); |
489 // Do serialization. | 485 // Do serialization. |
490 SerializeDomForURL(file_url, false); | 486 SerializeDomForURL(file_url); |
491 // Compare the serialized contents with original contents. | 487 // Compare the serialized contents with original contents. |
492 ASSERT_TRUE(HasSerializedFrame(file_url)); | 488 ASSERT_TRUE(HasSerializedFrame(file_url)); |
493 const std::string& serialized_contents = | 489 const std::string& serialized_contents = |
494 GetSerializedContentForFrame(file_url); | 490 GetSerializedContentForFrame(file_url); |
495 // Compare the serialized contents with original contents to make sure | 491 // Compare the serialized contents with original contents to make sure |
496 // they are same. | 492 // they are same. |
497 // Because we add MOTW when serializing DOM, so before comparison, we also | 493 // Because we add MOTW when serializing DOM, so before comparison, we also |
498 // need to add MOTW to original_contents. | 494 // need to add MOTW to original_contents. |
499 std::string original_str = | 495 std::string original_str = |
500 WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8(); | 496 WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 // Get value of BODY's title attribute in DOM. | 529 // Get value of BODY's title attribute in DOM. |
534 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url); | 530 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url); |
535 ASSERT_TRUE(web_frame != NULL); | 531 ASSERT_TRUE(web_frame != NULL); |
536 WebDocument doc = web_frame->document(); | 532 WebDocument doc = web_frame->document(); |
537 ASSERT_TRUE(doc.isHTMLDocument()); | 533 ASSERT_TRUE(doc.isHTMLDocument()); |
538 WebElement body_ele = doc.body(); | 534 WebElement body_ele = doc.body(); |
539 ASSERT_TRUE(!body_ele.isNull()); | 535 ASSERT_TRUE(!body_ele.isNull()); |
540 WebString value = body_ele.getAttribute("title"); | 536 WebString value = body_ele.getAttribute("title"); |
541 ASSERT_TRUE(std::string(value.utf8()) == "&<>\"\'"); | 537 ASSERT_TRUE(std::string(value.utf8()) == "&<>\"\'"); |
542 // Do serialization. | 538 // Do serialization. |
543 SerializeDomForURL(file_url, false); | 539 SerializeDomForURL(file_url); |
544 // Compare the serialized contents with original contents. | 540 // Compare the serialized contents with original contents. |
545 ASSERT_TRUE(HasSerializedFrame(file_url)); | 541 ASSERT_TRUE(HasSerializedFrame(file_url)); |
546 const std::string& serialized_contents = | 542 const std::string& serialized_contents = |
547 GetSerializedContentForFrame(file_url); | 543 GetSerializedContentForFrame(file_url); |
548 // Compare the serialized contents with original contents to make sure | 544 // Compare the serialized contents with original contents to make sure |
549 // they are same. | 545 // they are same. |
550 std::string original_str = | 546 std::string original_str = |
551 WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8(); | 547 WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8(); |
552 original_str += original_contents; | 548 original_str += original_contents; |
553 if (!doc.isNull()) { | 549 if (!doc.isNull()) { |
(...skipping 20 matching lines...) Expand all Loading... |
574 // Unescaped string for "%⊅¹'". | 570 // Unescaped string for "%⊅¹'". |
575 static const wchar_t parsed_value[] = { | 571 static const wchar_t parsed_value[] = { |
576 '%', 0x2285, 0x00b9, '\'', 0 | 572 '%', 0x2285, 0x00b9, '\'', 0 |
577 }; | 573 }; |
578 WebString value = body_element.getAttribute("title"); | 574 WebString value = body_element.getAttribute("title"); |
579 WebString content = doc.contentAsTextForTesting(); | 575 WebString content = doc.contentAsTextForTesting(); |
580 ASSERT_TRUE(base::UTF16ToWide(value) == parsed_value); | 576 ASSERT_TRUE(base::UTF16ToWide(value) == parsed_value); |
581 ASSERT_TRUE(base::UTF16ToWide(content) == parsed_value); | 577 ASSERT_TRUE(base::UTF16ToWide(content) == parsed_value); |
582 | 578 |
583 // Do serialization. | 579 // Do serialization. |
584 SerializeDomForURL(file_url, false); | 580 SerializeDomForURL(file_url); |
585 // Check the serialized string. | 581 // Check the serialized string. |
586 ASSERT_TRUE(HasSerializedFrame(file_url)); | 582 ASSERT_TRUE(HasSerializedFrame(file_url)); |
587 const std::string& serialized_contents = | 583 const std::string& serialized_contents = |
588 GetSerializedContentForFrame(file_url); | 584 GetSerializedContentForFrame(file_url); |
589 // Confirm that the serialized string has no non-standard HTML entities. | 585 // Confirm that the serialized string has no non-standard HTML entities. |
590 ASSERT_EQ(std::string::npos, serialized_contents.find("%")); | 586 ASSERT_EQ(std::string::npos, serialized_contents.find("%")); |
591 ASSERT_EQ(std::string::npos, serialized_contents.find("⊅")); | 587 ASSERT_EQ(std::string::npos, serialized_contents.find("⊅")); |
592 ASSERT_EQ(std::string::npos, serialized_contents.find("¹")); | 588 ASSERT_EQ(std::string::npos, serialized_contents.find("¹")); |
593 ASSERT_EQ(std::string::npos, serialized_contents.find("'")); | 589 ASSERT_EQ(std::string::npos, serialized_contents.find("'")); |
594 } | 590 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 } | 623 } |
628 } | 624 } |
629 } | 625 } |
630 ASSERT_EQ(original_base_tag_count, kTotalBaseTagCountInTestFile); | 626 ASSERT_EQ(original_base_tag_count, kTotalBaseTagCountInTestFile); |
631 // Make sure in original document, the base URL is not equal with the | 627 // Make sure in original document, the base URL is not equal with the |
632 // |path_dir_url|. | 628 // |path_dir_url|. |
633 GURL original_base_url(doc.baseURL()); | 629 GURL original_base_url(doc.baseURL()); |
634 ASSERT_NE(original_base_url, path_dir_url); | 630 ASSERT_NE(original_base_url, path_dir_url); |
635 | 631 |
636 // Do serialization. | 632 // Do serialization. |
637 SerializeDomForURL(file_url, false); | 633 SerializeDomForURL(file_url); |
638 | 634 |
639 // Load the serialized contents. | 635 // Load the serialized contents. |
640 ASSERT_TRUE(HasSerializedFrame(file_url)); | 636 ASSERT_TRUE(HasSerializedFrame(file_url)); |
641 const std::string& serialized_contents = | 637 const std::string& serialized_contents = |
642 GetSerializedContentForFrame(file_url); | 638 GetSerializedContentForFrame(file_url); |
643 LoadContents(serialized_contents, file_url, | 639 LoadContents(serialized_contents, file_url, |
644 web_frame->document().encoding()); | 640 web_frame->document().encoding()); |
645 | 641 |
646 // Make sure all links are absolute URLs and doc there are some number of | 642 // Make sure all links are absolute URLs and doc there are some number of |
647 // BASE tags in serialized HTML data. Each of those BASE tags have same base | 643 // BASE tags in serialized HTML data. Each of those BASE tags have same base |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 WebFrame* web_frame = GetMainFrame(); | 693 WebFrame* web_frame = GetMainFrame(); |
698 ASSERT_TRUE(web_frame != NULL); | 694 ASSERT_TRUE(web_frame != NULL); |
699 WebDocument doc = web_frame->document(); | 695 WebDocument doc = web_frame->document(); |
700 ASSERT_TRUE(doc.isHTMLDocument()); | 696 ASSERT_TRUE(doc.isHTMLDocument()); |
701 WebElement head_element = doc.head(); | 697 WebElement head_element = doc.head(); |
702 ASSERT_TRUE(!head_element.isNull()); | 698 ASSERT_TRUE(!head_element.isNull()); |
703 ASSERT_TRUE(!head_element.hasChildNodes()); | 699 ASSERT_TRUE(!head_element.hasChildNodes()); |
704 ASSERT_TRUE(head_element.childNodes().length() == 0); | 700 ASSERT_TRUE(head_element.childNodes().length() == 0); |
705 | 701 |
706 // Do serialization. | 702 // Do serialization. |
707 SerializeDomForURL(file_url, false); | 703 SerializeDomForURL(file_url); |
708 // Make sure the serialized contents have META ; | 704 // Make sure the serialized contents have META ; |
709 ASSERT_TRUE(HasSerializedFrame(file_url)); | 705 ASSERT_TRUE(HasSerializedFrame(file_url)); |
710 const std::string& serialized_contents = | 706 const std::string& serialized_contents = |
711 GetSerializedContentForFrame(file_url); | 707 GetSerializedContentForFrame(file_url); |
712 | 708 |
713 // Reload serialized contents and make sure there is only one META tag. | 709 // Reload serialized contents and make sure there is only one META tag. |
714 LoadContents(serialized_contents, file_url, | 710 LoadContents(serialized_contents, file_url, |
715 web_frame->document().encoding()); | 711 web_frame->document().encoding()); |
716 web_frame = GetMainFrame(); | 712 web_frame = GetMainFrame(); |
717 ASSERT_TRUE(web_frame != NULL); | 713 ASSERT_TRUE(web_frame != NULL); |
(...skipping 15 matching lines...) Expand all Loading... |
733 // Check the body's first node is text node and its contents are | 729 // Check the body's first node is text node and its contents are |
734 // "hello world" | 730 // "hello world" |
735 WebElement body_element = doc.body(); | 731 WebElement body_element = doc.body(); |
736 ASSERT_TRUE(!body_element.isNull()); | 732 ASSERT_TRUE(!body_element.isNull()); |
737 WebNode text_node = body_element.firstChild(); | 733 WebNode text_node = body_element.firstChild(); |
738 ASSERT_TRUE(text_node.isTextNode()); | 734 ASSERT_TRUE(text_node.isTextNode()); |
739 WebString text_node_contents = text_node.nodeValue(); | 735 WebString text_node_contents = text_node.nodeValue(); |
740 ASSERT_TRUE(std::string(text_node_contents.utf8()) == "hello world"); | 736 ASSERT_TRUE(std::string(text_node_contents.utf8()) == "hello world"); |
741 } | 737 } |
742 | 738 |
743 void SerializeDocumentWithDownloadedIFrameOnRenderer(const GURL& file_url) { | |
744 // Do a recursive serialization. We pass if we don't crash. | |
745 SerializeDomForURL(file_url, true); | |
746 } | |
747 | |
748 void SubResourceForElementsInNonHTMLNamespaceOnRenderer( | 739 void SubResourceForElementsInNonHTMLNamespaceOnRenderer( |
749 const GURL& file_url) { | 740 const GURL& file_url) { |
750 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url); | 741 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url); |
751 ASSERT_TRUE(web_frame != NULL); | 742 ASSERT_TRUE(web_frame != NULL); |
752 WebDocument doc = web_frame->document(); | 743 WebDocument doc = web_frame->document(); |
753 WebNode lastNodeInBody = doc.body().lastChild(); | 744 WebNode lastNodeInBody = doc.body().lastChild(); |
754 ASSERT_TRUE(lastNodeInBody.isElementNode()); | 745 ASSERT_TRUE(lastNodeInBody.isElementNode()); |
755 WebString uri = GetSubResourceLinkFromElement( | 746 WebString uri = GetSubResourceLinkFromElement( |
756 lastNodeInBody.to<WebElement>()); | 747 lastNodeInBody.to<WebElement>()); |
757 EXPECT_TRUE(uri.isNull()); | 748 EXPECT_TRUE(uri.isNull()); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 // Need to spin up the renderer and also navigate to a file url so that the | 987 // Need to spin up the renderer and also navigate to a file url so that the |
997 // renderer code doesn't attempt a fork when it sees a load to file scheme | 988 // renderer code doesn't attempt a fork when it sees a load to file scheme |
998 // from non-file scheme. | 989 // from non-file scheme. |
999 NavigateToURL(shell(), GetTestUrl(".", "simple_page.html")); | 990 NavigateToURL(shell(), GetTestUrl(".", "simple_page.html")); |
1000 | 991 |
1001 PostTaskToInProcessRendererAndWait( | 992 PostTaskToInProcessRendererAndWait( |
1002 base::Bind(&DomSerializerTests::SerializeHTMLDOMWithEmptyHeadOnRenderer, | 993 base::Bind(&DomSerializerTests::SerializeHTMLDOMWithEmptyHeadOnRenderer, |
1003 base::Unretained(this))); | 994 base::Unretained(this))); |
1004 } | 995 } |
1005 | 996 |
1006 // Test that we don't crash when the page contains an iframe that | |
1007 // was handled as a download (http://crbug.com/42212). | |
1008 IN_PROC_BROWSER_TEST_F(DomSerializerTests, | |
1009 SerializeDocumentWithDownloadedIFrame) { | |
1010 base::FilePath page_file_path = GetTestFilePath( | |
1011 "dom_serializer", "iframe-src-is-exe.htm"); | |
1012 GURL file_url = net::FilePathToFileURL(page_file_path); | |
1013 ASSERT_TRUE(file_url.SchemeIsFile()); | |
1014 // Load the test file. | |
1015 NavigateToURL(shell(), file_url); | |
1016 | |
1017 PostTaskToInProcessRendererAndWait( | |
1018 base::Bind( | |
1019 &DomSerializerTests:: | |
1020 SerializeDocumentWithDownloadedIFrameOnRenderer, | |
1021 base::Unretained(this), file_url)); | |
1022 } | |
1023 | |
1024 IN_PROC_BROWSER_TEST_F(DomSerializerTests, | 997 IN_PROC_BROWSER_TEST_F(DomSerializerTests, |
1025 SubResourceForElementsInNonHTMLNamespace) { | 998 SubResourceForElementsInNonHTMLNamespace) { |
1026 base::FilePath page_file_path = GetTestFilePath( | 999 base::FilePath page_file_path = GetTestFilePath( |
1027 "dom_serializer", "non_html_namespace.htm"); | 1000 "dom_serializer", "non_html_namespace.htm"); |
1028 GURL file_url = net::FilePathToFileURL(page_file_path); | 1001 GURL file_url = net::FilePathToFileURL(page_file_path); |
1029 NavigateToURL(shell(), file_url); | 1002 NavigateToURL(shell(), file_url); |
1030 | 1003 |
1031 PostTaskToInProcessRendererAndWait( | 1004 PostTaskToInProcessRendererAndWait( |
1032 base::Bind( | 1005 base::Bind( |
1033 &DomSerializerTests:: | 1006 &DomSerializerTests:: |
1034 SubResourceForElementsInNonHTMLNamespaceOnRenderer, | 1007 SubResourceForElementsInNonHTMLNamespaceOnRenderer, |
1035 base::Unretained(this), file_url)); | 1008 base::Unretained(this), file_url)); |
1036 } | 1009 } |
1037 | 1010 |
1038 } // namespace content | 1011 } // namespace content |
OLD | NEW |