| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
| 6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/hash_tables.h" | 8 #include "base/hash_tables.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 // Get actual charset info. | 274 // Get actual charset info. |
| 275 charset_info = content.substr(start_pos, end_pos - start_pos); | 275 charset_info = content.substr(start_pos, end_pos - start_pos); |
| 276 return true; | 276 return true; |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 return true; | 279 return true; |
| 280 } | 280 } |
| 281 | 281 |
| 282 // If original contents have document type, the serialized contents also have | 282 // If original contents have document type, the serialized contents also have |
| 283 // document type. | 283 // document type. |
| 284 TEST_F(DomSerializerTests, SerialzeHTMLDOMWithDocType) { | 284 TEST_F(DomSerializerTests, SerializeHTMLDOMWithDocType) { |
| 285 FilePath page_file_path = data_dir_; | 285 FilePath page_file_path = data_dir_; |
| 286 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 286 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
| 287 page_file_path = page_file_path.AppendASCII("youtube_1.htm"); | 287 page_file_path = page_file_path.AppendASCII("youtube_1.htm"); |
| 288 GURL file_url = net::FilePathToFileURL(page_file_path); | 288 GURL file_url = net::FilePathToFileURL(page_file_path); |
| 289 ASSERT_TRUE(file_url.SchemeIsFile()); | 289 ASSERT_TRUE(file_url.SchemeIsFile()); |
| 290 // Load the test file. | 290 // Load the test file. |
| 291 LoadPageFromURL(file_url); | 291 LoadPageFromURL(file_url); |
| 292 // Make sure original contents have document type. | 292 // Make sure original contents have document type. |
| 293 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); | 293 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); |
| 294 ASSERT_TRUE(web_frame != NULL); | 294 ASSERT_TRUE(web_frame != NULL); |
| 295 WebDocument doc = web_frame->document(); | 295 WebDocument doc = web_frame->document(); |
| 296 ASSERT_TRUE(HasDocType(doc)); | 296 ASSERT_TRUE(HasDocType(doc)); |
| 297 // Do serialization. | 297 // Do serialization. |
| 298 SerializeDomForURL(file_url, false); | 298 SerializeDomForURL(file_url, false); |
| 299 // Load the serialized contents. | 299 // Load the serialized contents. |
| 300 ASSERT_TRUE(HasSerializedFrame(file_url)); | 300 ASSERT_TRUE(HasSerializedFrame(file_url)); |
| 301 const std::string& serialized_contents = | 301 const std::string& serialized_contents = |
| 302 GetSerializedContentForFrame(file_url); | 302 GetSerializedContentForFrame(file_url); |
| 303 LoadContents(serialized_contents, file_url, | 303 LoadContents(serialized_contents, file_url, |
| 304 web_frame->encoding()); | 304 web_frame->encoding()); |
| 305 // Make sure serialized contents still have document type. | 305 // Make sure serialized contents still have document type. |
| 306 web_frame = test_shell_->webView()->mainFrame(); | 306 web_frame = test_shell_->webView()->mainFrame(); |
| 307 doc = web_frame->document(); | 307 doc = web_frame->document(); |
| 308 ASSERT_TRUE(HasDocType(doc)); | 308 ASSERT_TRUE(HasDocType(doc)); |
| 309 } | 309 } |
| 310 | 310 |
| 311 // If original contents do not have document type, the serialized contents | 311 // If original contents do not have document type, the serialized contents |
| 312 // also do not have document type. | 312 // also do not have document type. |
| 313 TEST_F(DomSerializerTests, SerialzeHTMLDOMWithoutDocType) { | 313 TEST_F(DomSerializerTests, SerializeHTMLDOMWithoutDocType) { |
| 314 FilePath page_file_path = data_dir_; | 314 FilePath page_file_path = data_dir_; |
| 315 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 315 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
| 316 page_file_path = page_file_path.AppendASCII("youtube_2.htm"); | 316 page_file_path = page_file_path.AppendASCII("youtube_2.htm"); |
| 317 GURL file_url = net::FilePathToFileURL(page_file_path); | 317 GURL file_url = net::FilePathToFileURL(page_file_path); |
| 318 ASSERT_TRUE(file_url.SchemeIsFile()); | 318 ASSERT_TRUE(file_url.SchemeIsFile()); |
| 319 // Load the test file. | 319 // Load the test file. |
| 320 LoadPageFromURL(file_url); | 320 LoadPageFromURL(file_url); |
| 321 // Make sure original contents do not have document type. | 321 // Make sure original contents do not have document type. |
| 322 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); | 322 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); |
| 323 ASSERT_TRUE(web_frame != NULL); | 323 ASSERT_TRUE(web_frame != NULL); |
| 324 WebDocument doc = web_frame->document(); | 324 WebDocument doc = web_frame->document(); |
| 325 ASSERT_TRUE(!HasDocType(doc)); | 325 ASSERT_TRUE(!HasDocType(doc)); |
| 326 // Do serialization. | 326 // Do serialization. |
| 327 SerializeDomForURL(file_url, false); | 327 SerializeDomForURL(file_url, false); |
| 328 // Load the serialized contents. | 328 // Load the serialized contents. |
| 329 ASSERT_TRUE(HasSerializedFrame(file_url)); | 329 ASSERT_TRUE(HasSerializedFrame(file_url)); |
| 330 const std::string& serialized_contents = | 330 const std::string& serialized_contents = |
| 331 GetSerializedContentForFrame(file_url); | 331 GetSerializedContentForFrame(file_url); |
| 332 LoadContents(serialized_contents, file_url, | 332 LoadContents(serialized_contents, file_url, |
| 333 web_frame->encoding()); | 333 web_frame->encoding()); |
| 334 // Make sure serialized contents do not have document type. | 334 // Make sure serialized contents do not have document type. |
| 335 web_frame = test_shell_->webView()->mainFrame(); | 335 web_frame = test_shell_->webView()->mainFrame(); |
| 336 doc = web_frame->document(); | 336 doc = web_frame->document(); |
| 337 ASSERT_TRUE(!HasDocType(doc)); | 337 ASSERT_TRUE(!HasDocType(doc)); |
| 338 } | 338 } |
| 339 | 339 |
| 340 // Serialize XML document which has all 5 built-in entities. After | 340 // Serialize XML document which has all 5 built-in entities. After |
| 341 // finishing serialization, the serialized contents should be same | 341 // finishing serialization, the serialized contents should be same |
| 342 // with original XML document. | 342 // with original XML document. |
| 343 TEST_F(DomSerializerTests, SerialzeXMLDocWithBuiltInEntities) { | 343 TEST_F(DomSerializerTests, SerializeXMLDocWithBuiltInEntities) { |
| 344 FilePath page_file_path = data_dir_; | 344 FilePath page_file_path = data_dir_; |
| 345 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 345 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
| 346 page_file_path = page_file_path.AppendASCII("note.xml"); | 346 page_file_path = page_file_path.AppendASCII("note.xml"); |
| 347 // Read original contents for later comparison. | 347 // Read original contents for later comparison. |
| 348 std::string original_contents; | 348 std::string original_contents; |
| 349 ASSERT_TRUE(file_util::ReadFileToString(page_file_path, &original_contents)); | 349 ASSERT_TRUE(file_util::ReadFileToString(page_file_path, &original_contents)); |
| 350 // Get file URL. | 350 // Get file URL. |
| 351 GURL file_url = net::FilePathToFileURL(page_file_path); | 351 GURL file_url = net::FilePathToFileURL(page_file_path); |
| 352 ASSERT_TRUE(file_url.SchemeIsFile()); | 352 ASSERT_TRUE(file_url.SchemeIsFile()); |
| 353 // Load the test file. | 353 // Load the test file. |
| 354 LoadPageFromURL(file_url); | 354 LoadPageFromURL(file_url); |
| 355 // Do serialization. | 355 // Do serialization. |
| 356 SerializeDomForURL(file_url, false); | 356 SerializeDomForURL(file_url, false); |
| 357 // Compare the serialized contents with original contents. | 357 // Compare the serialized contents with original contents. |
| 358 ASSERT_TRUE(HasSerializedFrame(file_url)); | 358 ASSERT_TRUE(HasSerializedFrame(file_url)); |
| 359 const std::string& serialized_contents = | 359 const std::string& serialized_contents = |
| 360 GetSerializedContentForFrame(file_url); | 360 GetSerializedContentForFrame(file_url); |
| 361 ASSERT_EQ(original_contents, serialized_contents); | 361 ASSERT_EQ(original_contents, serialized_contents); |
| 362 } | 362 } |
| 363 | 363 |
| 364 // When serializing DOM, we add MOTW declaration before html tag. | 364 // When serializing DOM, we add MOTW declaration before html tag. |
| 365 TEST_F(DomSerializerTests, SerialzeHTMLDOMWithAddingMOTW) { | 365 TEST_F(DomSerializerTests, SerializeHTMLDOMWithAddingMOTW) { |
| 366 FilePath page_file_path = data_dir_; | 366 FilePath page_file_path = data_dir_; |
| 367 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 367 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
| 368 page_file_path = page_file_path.AppendASCII("youtube_2.htm"); | 368 page_file_path = page_file_path.AppendASCII("youtube_2.htm"); |
| 369 // Read original contents for later comparison . | 369 // Read original contents for later comparison . |
| 370 std::string original_contents; | 370 std::string original_contents; |
| 371 ASSERT_TRUE(file_util::ReadFileToString(page_file_path, &original_contents)); | 371 ASSERT_TRUE(file_util::ReadFileToString(page_file_path, &original_contents)); |
| 372 // Get file URL. | 372 // Get file URL. |
| 373 GURL file_url = net::FilePathToFileURL(page_file_path); | 373 GURL file_url = net::FilePathToFileURL(page_file_path); |
| 374 ASSERT_TRUE(file_url.SchemeIsFile()); | 374 ASSERT_TRUE(file_url.SchemeIsFile()); |
| 375 // Make sure original contents does not have MOTW; | 375 // Make sure original contents does not have MOTW; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 389 const std::string& serialized_contents = | 389 const std::string& serialized_contents = |
| 390 GetSerializedContentForFrame(file_url); | 390 GetSerializedContentForFrame(file_url); |
| 391 ASSERT_FALSE(std::string::npos == | 391 ASSERT_FALSE(std::string::npos == |
| 392 serialized_contents.find(motw_declaration)); | 392 serialized_contents.find(motw_declaration)); |
| 393 } | 393 } |
| 394 | 394 |
| 395 // When serializing DOM, we will add the META which have correct charset | 395 // When serializing DOM, we will add the META which have correct charset |
| 396 // declaration as first child of HEAD element for resolving WebKit bug: | 396 // declaration as first child of HEAD element for resolving WebKit bug: |
| 397 // http://bugs.webkit.org/show_bug.cgi?id=16621 even the original document | 397 // http://bugs.webkit.org/show_bug.cgi?id=16621 even the original document |
| 398 // does not have META charset declaration. | 398 // does not have META charset declaration. |
| 399 TEST_F(DomSerializerTests, SerialzeHTMLDOMWithNoMetaCharsetInOriginalDoc) { | 399 TEST_F(DomSerializerTests, SerializeHTMLDOMWithNoMetaCharsetInOriginalDoc) { |
| 400 FilePath page_file_path = data_dir_; | 400 FilePath page_file_path = data_dir_; |
| 401 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 401 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
| 402 page_file_path = page_file_path.AppendASCII("youtube_1.htm"); | 402 page_file_path = page_file_path.AppendASCII("youtube_1.htm"); |
| 403 // Get file URL. | 403 // Get file URL. |
| 404 GURL file_url = net::FilePathToFileURL(page_file_path); | 404 GURL file_url = net::FilePathToFileURL(page_file_path); |
| 405 ASSERT_TRUE(file_url.SchemeIsFile()); | 405 ASSERT_TRUE(file_url.SchemeIsFile()); |
| 406 // Load the test file. | 406 // Load the test file. |
| 407 LoadPageFromURL(file_url); | 407 LoadPageFromURL(file_url); |
| 408 | 408 |
| 409 // Make sure there is no META charset declaration in original document. | 409 // Make sure there is no META charset declaration in original document. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 if (IsMetaElement(child, charset_info)) | 452 if (IsMetaElement(child, charset_info)) |
| 453 ASSERT_TRUE(charset_info.empty()); | 453 ASSERT_TRUE(charset_info.empty()); |
| 454 } | 454 } |
| 455 } | 455 } |
| 456 | 456 |
| 457 // When serializing DOM, if the original document has multiple META charset | 457 // When serializing DOM, if the original document has multiple META charset |
| 458 // declaration, we will add the META which have correct charset declaration | 458 // declaration, we will add the META which have correct charset declaration |
| 459 // as first child of HEAD element and remove all original META charset | 459 // as first child of HEAD element and remove all original META charset |
| 460 // declarations. | 460 // declarations. |
| 461 TEST_F(DomSerializerTests, | 461 TEST_F(DomSerializerTests, |
| 462 SerialzeHTMLDOMWithMultipleMetaCharsetInOriginalDoc) { | 462 SerializeHTMLDOMWithMultipleMetaCharsetInOriginalDoc) { |
| 463 FilePath page_file_path = data_dir_; | 463 FilePath page_file_path = data_dir_; |
| 464 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 464 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
| 465 page_file_path = page_file_path.AppendASCII("youtube_2.htm"); | 465 page_file_path = page_file_path.AppendASCII("youtube_2.htm"); |
| 466 // Get file URL. | 466 // Get file URL. |
| 467 GURL file_url = net::FilePathToFileURL(page_file_path); | 467 GURL file_url = net::FilePathToFileURL(page_file_path); |
| 468 ASSERT_TRUE(file_url.SchemeIsFile()); | 468 ASSERT_TRUE(file_url.SchemeIsFile()); |
| 469 // Load the test file. | 469 // Load the test file. |
| 470 LoadPageFromURL(file_url); | 470 LoadPageFromURL(file_url); |
| 471 | 471 |
| 472 // Make sure there are multiple META charset declarations in original | 472 // Make sure there are multiple META charset declarations in original |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 // Make sure no more additional META tags which have charset declaration. | 516 // Make sure no more additional META tags which have charset declaration. |
| 517 for (WebNode child = meta_node.nextSibling(); !child.isNull(); | 517 for (WebNode child = meta_node.nextSibling(); !child.isNull(); |
| 518 child = child.nextSibling()) { | 518 child = child.nextSibling()) { |
| 519 std::string charset_info; | 519 std::string charset_info; |
| 520 if (IsMetaElement(child, charset_info)) | 520 if (IsMetaElement(child, charset_info)) |
| 521 ASSERT_TRUE(charset_info.empty()); | 521 ASSERT_TRUE(charset_info.empty()); |
| 522 } | 522 } |
| 523 } | 523 } |
| 524 | 524 |
| 525 // Test situation of html entities in text when serializing HTML DOM. | 525 // Test situation of html entities in text when serializing HTML DOM. |
| 526 TEST_F(DomSerializerTests, SerialzeHTMLDOMWithEntitiesInText) { | 526 TEST_F(DomSerializerTests, SerializeHTMLDOMWithEntitiesInText) { |
| 527 FilePath page_file_path = data_dir_; | 527 FilePath page_file_path = data_dir_; |
| 528 page_file_path = page_file_path.AppendASCII( | 528 page_file_path = page_file_path.AppendASCII( |
| 529 "dom_serializer/htmlentities_in_text.htm"); | 529 "dom_serializer/htmlentities_in_text.htm"); |
| 530 // Get file URL. The URL is dummy URL to identify the following loading | 530 // Get file URL. The URL is dummy URL to identify the following loading |
| 531 // actions. The test content is in constant:original_contents. | 531 // actions. The test content is in constant:original_contents. |
| 532 GURL file_url = net::FilePathToFileURL(page_file_path); | 532 GURL file_url = net::FilePathToFileURL(page_file_path); |
| 533 ASSERT_TRUE(file_url.SchemeIsFile()); | 533 ASSERT_TRUE(file_url.SchemeIsFile()); |
| 534 // Test contents. | 534 // Test contents. |
| 535 static const char* const original_contents = | 535 static const char* const original_contents = |
| 536 "<HTML><BODY>&<>\"\'</BODY></HTML>"; | 536 "<html><body>&<>\"\'</body></html>"; |
| 537 // Load the test contents. | 537 // Load the test contents. |
| 538 LoadContents(original_contents, file_url, WebString()); | 538 LoadContents(original_contents, file_url, WebString()); |
| 539 | 539 |
| 540 // Get BODY's text content in DOM. | 540 // Get BODY's text content in DOM. |
| 541 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); | 541 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); |
| 542 ASSERT_TRUE(web_frame != NULL); | 542 ASSERT_TRUE(web_frame != NULL); |
| 543 WebDocument doc = web_frame->document(); | 543 WebDocument doc = web_frame->document(); |
| 544 ASSERT_TRUE(doc.isHTMLDocument()); | 544 ASSERT_TRUE(doc.isHTMLDocument()); |
| 545 WebElement body_ele = doc.body(); | 545 WebElement body_ele = doc.body(); |
| 546 ASSERT_TRUE(!body_ele.isNull()); | 546 ASSERT_TRUE(!body_ele.isNull()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 560 // need to add MOTW to original_contents. | 560 // need to add MOTW to original_contents. |
| 561 std::string original_str = | 561 std::string original_str = |
| 562 WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8(); | 562 WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8(); |
| 563 original_str += original_contents; | 563 original_str += original_contents; |
| 564 // Since WebCore now inserts a new HEAD element if there is no HEAD element | 564 // Since WebCore now inserts a new HEAD element if there is no HEAD element |
| 565 // when creating BODY element. (Please see HTMLParser::bodyCreateErrorCheck.) | 565 // when creating BODY element. (Please see HTMLParser::bodyCreateErrorCheck.) |
| 566 // We need to append the HEAD content and corresponding META content if we | 566 // We need to append the HEAD content and corresponding META content if we |
| 567 // find WebCore-generated HEAD element. | 567 // find WebCore-generated HEAD element. |
| 568 if (!doc.head().isNull()) { | 568 if (!doc.head().isNull()) { |
| 569 WebString encoding = web_frame->encoding(); | 569 WebString encoding = web_frame->encoding(); |
| 570 std::string htmlTag("<HTML>"); | 570 std::string htmlTag("<html>"); |
| 571 std::string::size_type pos = original_str.find(htmlTag); | 571 std::string::size_type pos = original_str.find(htmlTag); |
| 572 ASSERT_NE(std::string::npos, pos); | 572 ASSERT_NE(std::string::npos, pos); |
| 573 pos += htmlTag.length(); | 573 pos += htmlTag.length(); |
| 574 std::string head_part("<HEAD>"); | 574 std::string head_part("<head>"); |
| 575 head_part += | 575 head_part += |
| 576 WebPageSerializer::generateMetaCharsetDeclaration(encoding).utf8(); | 576 WebPageSerializer::generateMetaCharsetDeclaration(encoding).utf8(); |
| 577 head_part += "</HEAD>"; | 577 head_part += "</head>"; |
| 578 original_str.insert(pos, head_part); | 578 original_str.insert(pos, head_part); |
| 579 } | 579 } |
| 580 ASSERT_EQ(original_str, serialized_contents); | 580 ASSERT_EQ(original_str, serialized_contents); |
| 581 } | 581 } |
| 582 | 582 |
| 583 // Test situation of html entities in attribute value when serializing | 583 // Test situation of html entities in attribute value when serializing |
| 584 // HTML DOM. | 584 // HTML DOM. |
| 585 TEST_F(DomSerializerTests, SerialzeHTMLDOMWithEntitiesInAttributeValue) { | 585 TEST_F(DomSerializerTests, SerializeHTMLDOMWithEntitiesInAttributeValue) { |
| 586 FilePath page_file_path = data_dir_; | 586 FilePath page_file_path = data_dir_; |
| 587 page_file_path = page_file_path.AppendASCII( | 587 page_file_path = page_file_path.AppendASCII( |
| 588 "dom_serializer/htmlentities_in_attribute_value.htm"); | 588 "dom_serializer/htmlentities_in_attribute_value.htm"); |
| 589 // Get file URL. The URL is dummy URL to identify the following loading | 589 // Get file URL. The URL is dummy URL to identify the following loading |
| 590 // actions. The test content is in constant:original_contents. | 590 // actions. The test content is in constant:original_contents. |
| 591 GURL file_url = net::FilePathToFileURL(page_file_path); | 591 GURL file_url = net::FilePathToFileURL(page_file_path); |
| 592 ASSERT_TRUE(file_url.SchemeIsFile()); | 592 ASSERT_TRUE(file_url.SchemeIsFile()); |
| 593 // Test contents. | 593 // Test contents. |
| 594 static const char* const original_contents = | 594 static const char* const original_contents = |
| 595 "<HTML><BODY title=\"&<>"'\"></BODY></HTML>"; | 595 "<HTML><BODY title=\"&<>"'\"></BODY></HTML>"; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 624 std::string head_part("<HEAD>"); | 624 std::string head_part("<HEAD>"); |
| 625 head_part += | 625 head_part += |
| 626 WebPageSerializer::generateMetaCharsetDeclaration(encoding).utf8(); | 626 WebPageSerializer::generateMetaCharsetDeclaration(encoding).utf8(); |
| 627 head_part += "</HEAD>"; | 627 head_part += "</HEAD>"; |
| 628 original_str.insert(pos, head_part); | 628 original_str.insert(pos, head_part); |
| 629 } | 629 } |
| 630 ASSERT_EQ(original_str, serialized_contents); | 630 ASSERT_EQ(original_str, serialized_contents); |
| 631 } | 631 } |
| 632 | 632 |
| 633 // Test situation of non-standard HTML entities when serializing HTML DOM. | 633 // Test situation of non-standard HTML entities when serializing HTML DOM. |
| 634 TEST_F(DomSerializerTests, SerialzeHTMLDOMWithNonStandardEntities) { | 634 TEST_F(DomSerializerTests, SerializeHTMLDOMWithNonStandardEntities) { |
| 635 // Make a test file URL and load it. | 635 // Make a test file URL and load it. |
| 636 FilePath page_file_path = data_dir_; | 636 FilePath page_file_path = data_dir_; |
| 637 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 637 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
| 638 page_file_path = page_file_path.AppendASCII("nonstandard_htmlentities.htm"); | 638 page_file_path = page_file_path.AppendASCII("nonstandard_htmlentities.htm"); |
| 639 GURL file_url = net::FilePathToFileURL(page_file_path); | 639 GURL file_url = net::FilePathToFileURL(page_file_path); |
| 640 LoadPageFromURL(file_url); | 640 LoadPageFromURL(file_url); |
| 641 | 641 |
| 642 // Get value of BODY's title attribute in DOM. | 642 // Get value of BODY's title attribute in DOM. |
| 643 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); | 643 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); |
| 644 WebDocument doc = web_frame->document(); | 644 WebDocument doc = web_frame->document(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 665 ASSERT_EQ(std::string::npos, serialized_contents.find("%")); | 665 ASSERT_EQ(std::string::npos, serialized_contents.find("%")); |
| 666 ASSERT_EQ(std::string::npos, serialized_contents.find("⊅")); | 666 ASSERT_EQ(std::string::npos, serialized_contents.find("⊅")); |
| 667 ASSERT_EQ(std::string::npos, serialized_contents.find("&supl;")); | 667 ASSERT_EQ(std::string::npos, serialized_contents.find("&supl;")); |
| 668 ASSERT_EQ(std::string::npos, serialized_contents.find("'")); | 668 ASSERT_EQ(std::string::npos, serialized_contents.find("'")); |
| 669 } | 669 } |
| 670 | 670 |
| 671 // Test situation of BASE tag in original document when serializing HTML DOM. | 671 // Test situation of BASE tag in original document when serializing HTML DOM. |
| 672 // When serializing, we should comment the BASE tag, append a new BASE tag. | 672 // When serializing, we should comment the BASE tag, append a new BASE tag. |
| 673 // rewrite all the savable URLs to relative local path, and change other URLs | 673 // rewrite all the savable URLs to relative local path, and change other URLs |
| 674 // to absolute URLs. | 674 // to absolute URLs. |
| 675 TEST_F(DomSerializerTests, SerialzeHTMLDOMWithBaseTag) { | 675 TEST_F(DomSerializerTests, SerializeHTMLDOMWithBaseTag) { |
| 676 // There are total 2 available base tags in this test file. | 676 // There are total 2 available base tags in this test file. |
| 677 const int kTotalBaseTagCountInTestFile = 2; | 677 const int kTotalBaseTagCountInTestFile = 2; |
| 678 | 678 |
| 679 FilePath page_file_path = data_dir_.AppendASCII("dom_serializer"); | 679 FilePath page_file_path = data_dir_.AppendASCII("dom_serializer"); |
| 680 file_util::EnsureEndsWithSeparator(&page_file_path); | 680 file_util::EnsureEndsWithSeparator(&page_file_path); |
| 681 | 681 |
| 682 // Get page dir URL which is base URL of this file. | 682 // Get page dir URL which is base URL of this file. |
| 683 GURL path_dir_url = net::FilePathToFileURL(page_file_path); | 683 GURL path_dir_url = net::FilePathToFileURL(page_file_path); |
| 684 // Get file path. | 684 // Get file path. |
| 685 page_file_path = | 685 page_file_path = |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 } | 772 } |
| 773 } | 773 } |
| 774 // We have one more added BASE tag which is generated by JavaScript. | 774 // We have one more added BASE tag which is generated by JavaScript. |
| 775 ASSERT_EQ(new_base_tag_count, original_base_tag_count + 1); | 775 ASSERT_EQ(new_base_tag_count, original_base_tag_count + 1); |
| 776 // Make sure in new document, the base URL is equal with the |path_dir_url|. | 776 // Make sure in new document, the base URL is equal with the |path_dir_url|. |
| 777 GURL new_base_url(doc.baseURL()); | 777 GURL new_base_url(doc.baseURL()); |
| 778 ASSERT_EQ(new_base_url, path_dir_url); | 778 ASSERT_EQ(new_base_url, path_dir_url); |
| 779 } | 779 } |
| 780 | 780 |
| 781 // Serializing page which has an empty HEAD tag. | 781 // Serializing page which has an empty HEAD tag. |
| 782 TEST_F(DomSerializerTests, SerialzeHTMLDOMWithEmptyHead) { | 782 TEST_F(DomSerializerTests, SerializeHTMLDOMWithEmptyHead) { |
| 783 FilePath page_file_path = data_dir_; | 783 FilePath page_file_path = data_dir_; |
| 784 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 784 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
| 785 page_file_path = page_file_path.AppendASCII("empty_head.htm"); | 785 page_file_path = page_file_path.AppendASCII("empty_head.htm"); |
| 786 GURL file_url = net::FilePathToFileURL(page_file_path); | 786 GURL file_url = net::FilePathToFileURL(page_file_path); |
| 787 ASSERT_TRUE(file_url.SchemeIsFile()); | 787 ASSERT_TRUE(file_url.SchemeIsFile()); |
| 788 | 788 |
| 789 // Load the test html content. | 789 // Load the test html content. |
| 790 static const char* const empty_head_contents = | 790 static const char* const empty_head_contents = |
| 791 "<HTML><HEAD></HEAD><BODY>hello world</BODY></HTML>"; | 791 "<html><head></head><body>hello world</body></html>"; |
| 792 LoadContents(empty_head_contents, file_url, WebString()); | 792 LoadContents(empty_head_contents, file_url, WebString()); |
| 793 | 793 |
| 794 // Make sure the head tag is empty. | 794 // Make sure the head tag is empty. |
| 795 WebFrame* web_frame = test_shell_->webView()->mainFrame(); | 795 WebFrame* web_frame = test_shell_->webView()->mainFrame(); |
| 796 ASSERT_TRUE(web_frame != NULL); | 796 ASSERT_TRUE(web_frame != NULL); |
| 797 WebDocument doc = web_frame->document(); | 797 WebDocument doc = web_frame->document(); |
| 798 ASSERT_TRUE(doc.isHTMLDocument()); | 798 ASSERT_TRUE(doc.isHTMLDocument()); |
| 799 WebElement head_element = doc.head(); | 799 WebElement head_element = doc.head(); |
| 800 ASSERT_TRUE(!head_element.isNull()); | 800 ASSERT_TRUE(!head_element.isNull()); |
| 801 ASSERT_TRUE(!head_element.hasChildNodes()); | 801 ASSERT_TRUE(!head_element.hasChildNodes()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 830 // "hello world" | 830 // "hello world" |
| 831 WebElement body_element = doc.body(); | 831 WebElement body_element = doc.body(); |
| 832 ASSERT_TRUE(!body_element.isNull()); | 832 ASSERT_TRUE(!body_element.isNull()); |
| 833 WebNode text_node = body_element.firstChild(); | 833 WebNode text_node = body_element.firstChild(); |
| 834 ASSERT_TRUE(text_node.isTextNode()); | 834 ASSERT_TRUE(text_node.isTextNode()); |
| 835 WebString text_node_contents = text_node.nodeValue(); | 835 WebString text_node_contents = text_node.nodeValue(); |
| 836 ASSERT_TRUE(std::string(text_node_contents.utf8()) == "hello world"); | 836 ASSERT_TRUE(std::string(text_node_contents.utf8()) == "hello world"); |
| 837 } | 837 } |
| 838 | 838 |
| 839 } // namespace | 839 } // namespace |
| OLD | NEW |