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