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/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/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 SerializationFinishStatusMap serialization_finish_status_; | 198 SerializationFinishStatusMap serialization_finish_status_; |
199 // Flag indicates whether the process of serializing DOM is finished or not. | 199 // Flag indicates whether the process of serializing DOM is finished or not. |
200 bool serialized_; | 200 bool serialized_; |
201 // The links_ contain dummy original URLs of all saved links. | 201 // The links_ contain dummy original URLs of all saved links. |
202 WebVector<WebURL> links_; | 202 WebVector<WebURL> links_; |
203 // The local_paths_ contain dummy corresponding local file paths of all saved | 203 // The local_paths_ contain dummy corresponding local file paths of all saved |
204 // links, which matched links_ one by one. | 204 // links, which matched links_ one by one. |
205 WebVector<WebString> local_paths_; | 205 WebVector<WebString> local_paths_; |
206 // The local_directory_name_ is dummy relative path of directory which | 206 // The local_directory_name_ is dummy relative path of directory which |
207 // contain all saved auxiliary files included all sub frames and resources. | 207 // contain all saved auxiliary files included all sub frames and resources. |
208 const FilePath local_directory_name_; | 208 const base::FilePath local_directory_name_; |
209 | 209 |
210 protected: | 210 protected: |
211 // testing::Test | 211 // testing::Test |
212 virtual void SetUp() { | 212 virtual void SetUp() { |
213 TestShellTest::SetUp(); | 213 TestShellTest::SetUp(); |
214 serialized_ = false; | 214 serialized_ = false; |
215 } | 215 } |
216 | 216 |
217 virtual void TearDown() { | 217 virtual void TearDown() { |
218 TestShellTest::TearDown(); | 218 TestShellTest::TearDown(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 charset_info = content.substr(start_pos, end_pos - start_pos); | 276 charset_info = content.substr(start_pos, end_pos - start_pos); |
277 return true; | 277 return true; |
278 } | 278 } |
279 } | 279 } |
280 return true; | 280 return true; |
281 } | 281 } |
282 | 282 |
283 // If original contents have document type, the serialized contents also have | 283 // If original contents have document type, the serialized contents also have |
284 // document type. | 284 // document type. |
285 TEST_F(DomSerializerTests, SerializeHTMLDOMWithDocType) { | 285 TEST_F(DomSerializerTests, SerializeHTMLDOMWithDocType) { |
286 FilePath page_file_path = data_dir_; | 286 base::FilePath page_file_path = data_dir_; |
287 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 287 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
288 page_file_path = page_file_path.AppendASCII("youtube_1.htm"); | 288 page_file_path = page_file_path.AppendASCII("youtube_1.htm"); |
289 GURL file_url = net::FilePathToFileURL(page_file_path); | 289 GURL file_url = net::FilePathToFileURL(page_file_path); |
290 ASSERT_TRUE(file_url.SchemeIsFile()); | 290 ASSERT_TRUE(file_url.SchemeIsFile()); |
291 // Load the test file. | 291 // Load the test file. |
292 LoadPageFromURL(file_url); | 292 LoadPageFromURL(file_url); |
293 // Make sure original contents have document type. | 293 // Make sure original contents have document type. |
294 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); | 294 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); |
295 ASSERT_TRUE(web_frame != NULL); | 295 ASSERT_TRUE(web_frame != NULL); |
296 WebDocument doc = web_frame->document(); | 296 WebDocument doc = web_frame->document(); |
297 ASSERT_TRUE(HasDocType(doc)); | 297 ASSERT_TRUE(HasDocType(doc)); |
298 // Do serialization. | 298 // Do serialization. |
299 SerializeDomForURL(file_url, false); | 299 SerializeDomForURL(file_url, false); |
300 // Load the serialized contents. | 300 // Load the serialized contents. |
301 ASSERT_TRUE(HasSerializedFrame(file_url)); | 301 ASSERT_TRUE(HasSerializedFrame(file_url)); |
302 const std::string& serialized_contents = | 302 const std::string& serialized_contents = |
303 GetSerializedContentForFrame(file_url); | 303 GetSerializedContentForFrame(file_url); |
304 LoadContents(serialized_contents, file_url, | 304 LoadContents(serialized_contents, file_url, |
305 web_frame->document().encoding()); | 305 web_frame->document().encoding()); |
306 // Make sure serialized contents still have document type. | 306 // Make sure serialized contents still have document type. |
307 web_frame = test_shell_->webView()->mainFrame(); | 307 web_frame = test_shell_->webView()->mainFrame(); |
308 doc = web_frame->document(); | 308 doc = web_frame->document(); |
309 ASSERT_TRUE(HasDocType(doc)); | 309 ASSERT_TRUE(HasDocType(doc)); |
310 } | 310 } |
311 | 311 |
312 // If original contents do not have document type, the serialized contents | 312 // If original contents do not have document type, the serialized contents |
313 // also do not have document type. | 313 // also do not have document type. |
314 TEST_F(DomSerializerTests, SerializeHTMLDOMWithoutDocType) { | 314 TEST_F(DomSerializerTests, SerializeHTMLDOMWithoutDocType) { |
315 FilePath page_file_path = data_dir_; | 315 base::FilePath page_file_path = data_dir_; |
316 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 316 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
317 page_file_path = page_file_path.AppendASCII("youtube_2.htm"); | 317 page_file_path = page_file_path.AppendASCII("youtube_2.htm"); |
318 GURL file_url = net::FilePathToFileURL(page_file_path); | 318 GURL file_url = net::FilePathToFileURL(page_file_path); |
319 ASSERT_TRUE(file_url.SchemeIsFile()); | 319 ASSERT_TRUE(file_url.SchemeIsFile()); |
320 // Load the test file. | 320 // Load the test file. |
321 LoadPageFromURL(file_url); | 321 LoadPageFromURL(file_url); |
322 // Make sure original contents do not have document type. | 322 // Make sure original contents do not have document type. |
323 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); | 323 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); |
324 ASSERT_TRUE(web_frame != NULL); | 324 ASSERT_TRUE(web_frame != NULL); |
325 WebDocument doc = web_frame->document(); | 325 WebDocument doc = web_frame->document(); |
326 ASSERT_TRUE(!HasDocType(doc)); | 326 ASSERT_TRUE(!HasDocType(doc)); |
327 // Do serialization. | 327 // Do serialization. |
328 SerializeDomForURL(file_url, false); | 328 SerializeDomForURL(file_url, false); |
329 // Load the serialized contents. | 329 // Load the serialized contents. |
330 ASSERT_TRUE(HasSerializedFrame(file_url)); | 330 ASSERT_TRUE(HasSerializedFrame(file_url)); |
331 const std::string& serialized_contents = | 331 const std::string& serialized_contents = |
332 GetSerializedContentForFrame(file_url); | 332 GetSerializedContentForFrame(file_url); |
333 LoadContents(serialized_contents, file_url, | 333 LoadContents(serialized_contents, file_url, |
334 web_frame->document().encoding()); | 334 web_frame->document().encoding()); |
335 // Make sure serialized contents do not have document type. | 335 // Make sure serialized contents do not have document type. |
336 web_frame = test_shell_->webView()->mainFrame(); | 336 web_frame = test_shell_->webView()->mainFrame(); |
337 doc = web_frame->document(); | 337 doc = web_frame->document(); |
338 ASSERT_TRUE(!HasDocType(doc)); | 338 ASSERT_TRUE(!HasDocType(doc)); |
339 } | 339 } |
340 | 340 |
341 // Serialize XML document which has all 5 built-in entities. After | 341 // Serialize XML document which has all 5 built-in entities. After |
342 // finishing serialization, the serialized contents should be same | 342 // finishing serialization, the serialized contents should be same |
343 // with original XML document. | 343 // with original XML document. |
344 TEST_F(DomSerializerTests, SerializeXMLDocWithBuiltInEntities) { | 344 TEST_F(DomSerializerTests, SerializeXMLDocWithBuiltInEntities) { |
345 FilePath page_file_path = data_dir_; | 345 base::FilePath page_file_path = data_dir_; |
346 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 346 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
347 page_file_path = page_file_path.AppendASCII("note.xml"); | 347 page_file_path = page_file_path.AppendASCII("note.xml"); |
348 // Read original contents for later comparison. | 348 // Read original contents for later comparison. |
349 std::string original_contents; | 349 std::string original_contents; |
350 ASSERT_TRUE(file_util::ReadFileToString(page_file_path, &original_contents)); | 350 ASSERT_TRUE(file_util::ReadFileToString(page_file_path, &original_contents)); |
351 // Get file URL. | 351 // Get file URL. |
352 GURL file_url = net::FilePathToFileURL(page_file_path); | 352 GURL file_url = net::FilePathToFileURL(page_file_path); |
353 ASSERT_TRUE(file_url.SchemeIsFile()); | 353 ASSERT_TRUE(file_url.SchemeIsFile()); |
354 // Load the test file. | 354 // Load the test file. |
355 LoadPageFromURL(file_url); | 355 LoadPageFromURL(file_url); |
356 // Do serialization. | 356 // Do serialization. |
357 SerializeDomForURL(file_url, false); | 357 SerializeDomForURL(file_url, false); |
358 // Compare the serialized contents with original contents. | 358 // Compare the serialized contents with original contents. |
359 ASSERT_TRUE(HasSerializedFrame(file_url)); | 359 ASSERT_TRUE(HasSerializedFrame(file_url)); |
360 const std::string& serialized_contents = | 360 const std::string& serialized_contents = |
361 GetSerializedContentForFrame(file_url); | 361 GetSerializedContentForFrame(file_url); |
362 ASSERT_EQ(original_contents, serialized_contents); | 362 ASSERT_EQ(original_contents, serialized_contents); |
363 } | 363 } |
364 | 364 |
365 // When serializing DOM, we add MOTW declaration before html tag. | 365 // When serializing DOM, we add MOTW declaration before html tag. |
366 TEST_F(DomSerializerTests, SerializeHTMLDOMWithAddingMOTW) { | 366 TEST_F(DomSerializerTests, SerializeHTMLDOMWithAddingMOTW) { |
367 FilePath page_file_path = data_dir_; | 367 base::FilePath page_file_path = data_dir_; |
368 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 368 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
369 page_file_path = page_file_path.AppendASCII("youtube_2.htm"); | 369 page_file_path = page_file_path.AppendASCII("youtube_2.htm"); |
370 // Read original contents for later comparison . | 370 // Read original contents for later comparison . |
371 std::string original_contents; | 371 std::string original_contents; |
372 ASSERT_TRUE(file_util::ReadFileToString(page_file_path, &original_contents)); | 372 ASSERT_TRUE(file_util::ReadFileToString(page_file_path, &original_contents)); |
373 // Get file URL. | 373 // Get file URL. |
374 GURL file_url = net::FilePathToFileURL(page_file_path); | 374 GURL file_url = net::FilePathToFileURL(page_file_path); |
375 ASSERT_TRUE(file_url.SchemeIsFile()); | 375 ASSERT_TRUE(file_url.SchemeIsFile()); |
376 // Make sure original contents does not have MOTW; | 376 // Make sure original contents does not have MOTW; |
377 std::string motw_declaration = | 377 std::string motw_declaration = |
(...skipping 13 matching lines...) Expand all Loading... |
391 GetSerializedContentForFrame(file_url); | 391 GetSerializedContentForFrame(file_url); |
392 ASSERT_FALSE(std::string::npos == | 392 ASSERT_FALSE(std::string::npos == |
393 serialized_contents.find(motw_declaration)); | 393 serialized_contents.find(motw_declaration)); |
394 } | 394 } |
395 | 395 |
396 // When serializing DOM, we will add the META which have correct charset | 396 // When serializing DOM, we will add the META which have correct charset |
397 // declaration as first child of HEAD element for resolving WebKit bug: | 397 // declaration as first child of HEAD element for resolving WebKit bug: |
398 // http://bugs.webkit.org/show_bug.cgi?id=16621 even the original document | 398 // http://bugs.webkit.org/show_bug.cgi?id=16621 even the original document |
399 // does not have META charset declaration. | 399 // does not have META charset declaration. |
400 TEST_F(DomSerializerTests, SerializeHTMLDOMWithNoMetaCharsetInOriginalDoc) { | 400 TEST_F(DomSerializerTests, SerializeHTMLDOMWithNoMetaCharsetInOriginalDoc) { |
401 FilePath page_file_path = data_dir_; | 401 base::FilePath page_file_path = data_dir_; |
402 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 402 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
403 page_file_path = page_file_path.AppendASCII("youtube_1.htm"); | 403 page_file_path = page_file_path.AppendASCII("youtube_1.htm"); |
404 // Get file URL. | 404 // Get file URL. |
405 GURL file_url = net::FilePathToFileURL(page_file_path); | 405 GURL file_url = net::FilePathToFileURL(page_file_path); |
406 ASSERT_TRUE(file_url.SchemeIsFile()); | 406 ASSERT_TRUE(file_url.SchemeIsFile()); |
407 // Load the test file. | 407 // Load the test file. |
408 LoadPageFromURL(file_url); | 408 LoadPageFromURL(file_url); |
409 | 409 |
410 // Make sure there is no META charset declaration in original document. | 410 // Make sure there is no META charset declaration in original document. |
411 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); | 411 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 ASSERT_TRUE(charset_info.empty()); | 455 ASSERT_TRUE(charset_info.empty()); |
456 } | 456 } |
457 } | 457 } |
458 | 458 |
459 // When serializing DOM, if the original document has multiple META charset | 459 // When serializing DOM, if the original document has multiple META charset |
460 // declaration, we will add the META which have correct charset declaration | 460 // declaration, we will add the META which have correct charset declaration |
461 // as first child of HEAD element and remove all original META charset | 461 // as first child of HEAD element and remove all original META charset |
462 // declarations. | 462 // declarations. |
463 TEST_F(DomSerializerTests, | 463 TEST_F(DomSerializerTests, |
464 SerializeHTMLDOMWithMultipleMetaCharsetInOriginalDoc) { | 464 SerializeHTMLDOMWithMultipleMetaCharsetInOriginalDoc) { |
465 FilePath page_file_path = data_dir_; | 465 base::FilePath page_file_path = data_dir_; |
466 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 466 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
467 page_file_path = page_file_path.AppendASCII("youtube_2.htm"); | 467 page_file_path = page_file_path.AppendASCII("youtube_2.htm"); |
468 // Get file URL. | 468 // Get file URL. |
469 GURL file_url = net::FilePathToFileURL(page_file_path); | 469 GURL file_url = net::FilePathToFileURL(page_file_path); |
470 ASSERT_TRUE(file_url.SchemeIsFile()); | 470 ASSERT_TRUE(file_url.SchemeIsFile()); |
471 // Load the test file. | 471 // Load the test file. |
472 LoadPageFromURL(file_url); | 472 LoadPageFromURL(file_url); |
473 | 473 |
474 // Make sure there are multiple META charset declarations in original | 474 // Make sure there are multiple META charset declarations in original |
475 // document. | 475 // document. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 for (WebNode child = meta_node.nextSibling(); !child.isNull(); | 520 for (WebNode child = meta_node.nextSibling(); !child.isNull(); |
521 child = child.nextSibling()) { | 521 child = child.nextSibling()) { |
522 std::string charset_info; | 522 std::string charset_info; |
523 if (IsMetaElement(child, charset_info)) | 523 if (IsMetaElement(child, charset_info)) |
524 ASSERT_TRUE(charset_info.empty()); | 524 ASSERT_TRUE(charset_info.empty()); |
525 } | 525 } |
526 } | 526 } |
527 | 527 |
528 // Test situation of html entities in text when serializing HTML DOM. | 528 // Test situation of html entities in text when serializing HTML DOM. |
529 TEST_F(DomSerializerTests, SerializeHTMLDOMWithEntitiesInText) { | 529 TEST_F(DomSerializerTests, SerializeHTMLDOMWithEntitiesInText) { |
530 FilePath page_file_path = data_dir_; | 530 base::FilePath page_file_path = data_dir_; |
531 page_file_path = page_file_path.AppendASCII( | 531 page_file_path = page_file_path.AppendASCII( |
532 "dom_serializer/htmlentities_in_text.htm"); | 532 "dom_serializer/htmlentities_in_text.htm"); |
533 // Get file URL. The URL is dummy URL to identify the following loading | 533 // Get file URL. The URL is dummy URL to identify the following loading |
534 // actions. The test content is in constant:original_contents. | 534 // actions. The test content is in constant:original_contents. |
535 GURL file_url = net::FilePathToFileURL(page_file_path); | 535 GURL file_url = net::FilePathToFileURL(page_file_path); |
536 ASSERT_TRUE(file_url.SchemeIsFile()); | 536 ASSERT_TRUE(file_url.SchemeIsFile()); |
537 // Test contents. | 537 // Test contents. |
538 static const char* const original_contents = | 538 static const char* const original_contents = |
539 "<html><body>&<>\"\'</body></html>"; | 539 "<html><body>&<>\"\'</body></html>"; |
540 // Load the test contents. | 540 // Load the test contents. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 head_part += "</head>"; | 580 head_part += "</head>"; |
581 original_str.insert(pos, head_part); | 581 original_str.insert(pos, head_part); |
582 } | 582 } |
583 ASSERT_EQ(original_str, serialized_contents); | 583 ASSERT_EQ(original_str, serialized_contents); |
584 } | 584 } |
585 | 585 |
586 // Test situation of html entities in attribute value when serializing | 586 // Test situation of html entities in attribute value when serializing |
587 // HTML DOM. | 587 // HTML DOM. |
588 // This test started to fail at WebKit r65388. See http://crbug.com/52279. | 588 // This test started to fail at WebKit r65388. See http://crbug.com/52279. |
589 TEST_F(DomSerializerTests, SerializeHTMLDOMWithEntitiesInAttributeValue) { | 589 TEST_F(DomSerializerTests, SerializeHTMLDOMWithEntitiesInAttributeValue) { |
590 FilePath page_file_path = data_dir_; | 590 base::FilePath page_file_path = data_dir_; |
591 page_file_path = page_file_path.AppendASCII( | 591 page_file_path = page_file_path.AppendASCII( |
592 "dom_serializer/htmlentities_in_attribute_value.htm"); | 592 "dom_serializer/htmlentities_in_attribute_value.htm"); |
593 // Get file URL. The URL is dummy URL to identify the following loading | 593 // Get file URL. The URL is dummy URL to identify the following loading |
594 // actions. The test content is in constant:original_contents. | 594 // actions. The test content is in constant:original_contents. |
595 GURL file_url = net::FilePathToFileURL(page_file_path); | 595 GURL file_url = net::FilePathToFileURL(page_file_path); |
596 ASSERT_TRUE(file_url.SchemeIsFile()); | 596 ASSERT_TRUE(file_url.SchemeIsFile()); |
597 // Test contents. | 597 // Test contents. |
598 static const char* const original_contents = | 598 static const char* const original_contents = |
599 "<html><body title=\"&<>"'\"></body></html>"; | 599 "<html><body title=\"&<>"'\"></body></html>"; |
600 // Load the test contents. | 600 // Load the test contents. |
(...skipping 30 matching lines...) Expand all Loading... |
631 head_part += "</head>"; | 631 head_part += "</head>"; |
632 original_str.insert(pos, head_part); | 632 original_str.insert(pos, head_part); |
633 } | 633 } |
634 ASSERT_EQ(original_str, serialized_contents); | 634 ASSERT_EQ(original_str, serialized_contents); |
635 } | 635 } |
636 | 636 |
637 // Test situation of non-standard HTML entities when serializing HTML DOM. | 637 // Test situation of non-standard HTML entities when serializing HTML DOM. |
638 // This test started to fail at WebKit r65351. See http://crbug.com/52279. | 638 // This test started to fail at WebKit r65351. See http://crbug.com/52279. |
639 TEST_F(DomSerializerTests, SerializeHTMLDOMWithNonStandardEntities) { | 639 TEST_F(DomSerializerTests, SerializeHTMLDOMWithNonStandardEntities) { |
640 // Make a test file URL and load it. | 640 // Make a test file URL and load it. |
641 FilePath page_file_path = data_dir_; | 641 base::FilePath page_file_path = data_dir_; |
642 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 642 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
643 page_file_path = page_file_path.AppendASCII("nonstandard_htmlentities.htm"); | 643 page_file_path = page_file_path.AppendASCII("nonstandard_htmlentities.htm"); |
644 GURL file_url = net::FilePathToFileURL(page_file_path); | 644 GURL file_url = net::FilePathToFileURL(page_file_path); |
645 LoadPageFromURL(file_url); | 645 LoadPageFromURL(file_url); |
646 | 646 |
647 // Get value of BODY's title attribute in DOM. | 647 // Get value of BODY's title attribute in DOM. |
648 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); | 648 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); |
649 WebDocument doc = web_frame->document(); | 649 WebDocument doc = web_frame->document(); |
650 ASSERT_TRUE(doc.isHTMLDocument()); | 650 ASSERT_TRUE(doc.isHTMLDocument()); |
651 WebElement body_element = doc.body(); | 651 WebElement body_element = doc.body(); |
(...skipping 19 matching lines...) Expand all Loading... |
671 } | 671 } |
672 | 672 |
673 // Test situation of BASE tag in original document when serializing HTML DOM. | 673 // Test situation of BASE tag in original document when serializing HTML DOM. |
674 // When serializing, we should comment the BASE tag, append a new BASE tag. | 674 // When serializing, we should comment the BASE tag, append a new BASE tag. |
675 // rewrite all the savable URLs to relative local path, and change other URLs | 675 // rewrite all the savable URLs to relative local path, and change other URLs |
676 // to absolute URLs. | 676 // to absolute URLs. |
677 TEST_F(DomSerializerTests, SerializeHTMLDOMWithBaseTag) { | 677 TEST_F(DomSerializerTests, SerializeHTMLDOMWithBaseTag) { |
678 // There are total 2 available base tags in this test file. | 678 // There are total 2 available base tags in this test file. |
679 const int kTotalBaseTagCountInTestFile = 2; | 679 const int kTotalBaseTagCountInTestFile = 2; |
680 | 680 |
681 FilePath page_file_path = data_dir_.AppendASCII("dom_serializer"); | 681 base::FilePath page_file_path = data_dir_.AppendASCII("dom_serializer"); |
682 file_util::EnsureEndsWithSeparator(&page_file_path); | 682 file_util::EnsureEndsWithSeparator(&page_file_path); |
683 | 683 |
684 // Get page dir URL which is base URL of this file. | 684 // Get page dir URL which is base URL of this file. |
685 GURL path_dir_url = net::FilePathToFileURL(page_file_path); | 685 GURL path_dir_url = net::FilePathToFileURL(page_file_path); |
686 // Get file path. | 686 // Get file path. |
687 page_file_path = | 687 page_file_path = |
688 page_file_path.AppendASCII("html_doc_has_base_tag.htm"); | 688 page_file_path.AppendASCII("html_doc_has_base_tag.htm"); |
689 // Get file URL. | 689 // Get file URL. |
690 GURL file_url = net::FilePathToFileURL(page_file_path); | 690 GURL file_url = net::FilePathToFileURL(page_file_path); |
691 ASSERT_TRUE(file_url.SchemeIsFile()); | 691 ASSERT_TRUE(file_url.SchemeIsFile()); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 } | 775 } |
776 // We have one more added BASE tag which is generated by JavaScript. | 776 // We have one more added BASE tag which is generated by JavaScript. |
777 ASSERT_EQ(new_base_tag_count, original_base_tag_count + 1); | 777 ASSERT_EQ(new_base_tag_count, original_base_tag_count + 1); |
778 // Make sure in new document, the base URL is equal with the |path_dir_url|. | 778 // Make sure in new document, the base URL is equal with the |path_dir_url|. |
779 GURL new_base_url(doc.baseURL()); | 779 GURL new_base_url(doc.baseURL()); |
780 ASSERT_EQ(new_base_url, path_dir_url); | 780 ASSERT_EQ(new_base_url, path_dir_url); |
781 } | 781 } |
782 | 782 |
783 // Serializing page which has an empty HEAD tag. | 783 // Serializing page which has an empty HEAD tag. |
784 TEST_F(DomSerializerTests, SerializeHTMLDOMWithEmptyHead) { | 784 TEST_F(DomSerializerTests, SerializeHTMLDOMWithEmptyHead) { |
785 FilePath page_file_path = data_dir_; | 785 base::FilePath page_file_path = data_dir_; |
786 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 786 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
787 page_file_path = page_file_path.AppendASCII("empty_head.htm"); | 787 page_file_path = page_file_path.AppendASCII("empty_head.htm"); |
788 GURL file_url = net::FilePathToFileURL(page_file_path); | 788 GURL file_url = net::FilePathToFileURL(page_file_path); |
789 ASSERT_TRUE(file_url.SchemeIsFile()); | 789 ASSERT_TRUE(file_url.SchemeIsFile()); |
790 | 790 |
791 // Load the test html content. | 791 // Load the test html content. |
792 static const char* const empty_head_contents = | 792 static const char* const empty_head_contents = |
793 "<html><head></head><body>hello world</body></html>"; | 793 "<html><head></head><body>hello world</body></html>"; |
794 LoadContents(empty_head_contents, file_url, WebString()); | 794 LoadContents(empty_head_contents, file_url, WebString()); |
795 | 795 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 ASSERT_TRUE(!body_element.isNull()); | 835 ASSERT_TRUE(!body_element.isNull()); |
836 WebNode text_node = body_element.firstChild(); | 836 WebNode text_node = body_element.firstChild(); |
837 ASSERT_TRUE(text_node.isTextNode()); | 837 ASSERT_TRUE(text_node.isTextNode()); |
838 WebString text_node_contents = text_node.nodeValue(); | 838 WebString text_node_contents = text_node.nodeValue(); |
839 ASSERT_TRUE(std::string(text_node_contents.utf8()) == "hello world"); | 839 ASSERT_TRUE(std::string(text_node_contents.utf8()) == "hello world"); |
840 } | 840 } |
841 | 841 |
842 // Test that we don't crash when the page contains an iframe that | 842 // Test that we don't crash when the page contains an iframe that |
843 // was handled as a download (http://crbug.com/42212). | 843 // was handled as a download (http://crbug.com/42212). |
844 TEST_F(DomSerializerTests, SerializeDocumentWithDownloadedIFrame) { | 844 TEST_F(DomSerializerTests, SerializeDocumentWithDownloadedIFrame) { |
845 FilePath page_file_path = data_dir_; | 845 base::FilePath page_file_path = data_dir_; |
846 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 846 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
847 page_file_path = page_file_path.AppendASCII("iframe-src-is-exe.htm"); | 847 page_file_path = page_file_path.AppendASCII("iframe-src-is-exe.htm"); |
848 GURL file_url = net::FilePathToFileURL(page_file_path); | 848 GURL file_url = net::FilePathToFileURL(page_file_path); |
849 ASSERT_TRUE(file_url.SchemeIsFile()); | 849 ASSERT_TRUE(file_url.SchemeIsFile()); |
850 // Load the test file. | 850 // Load the test file. |
851 LoadPageFromURL(file_url); | 851 LoadPageFromURL(file_url); |
852 // Do a recursive serialization. We pass if we don't crash. | 852 // Do a recursive serialization. We pass if we don't crash. |
853 SerializeDomForURL(file_url, true); | 853 SerializeDomForURL(file_url, true); |
854 } | 854 } |
855 | 855 |
856 TEST_F(DomSerializerTests, SubResourceForElementsInNonHTMLNamespace) { | 856 TEST_F(DomSerializerTests, SubResourceForElementsInNonHTMLNamespace) { |
857 FilePath page_file_path = data_dir_; | 857 base::FilePath page_file_path = data_dir_; |
858 page_file_path = page_file_path.AppendASCII("dom_serializer"); | 858 page_file_path = page_file_path.AppendASCII("dom_serializer"); |
859 page_file_path = page_file_path.AppendASCII("non_html_namespace.htm"); | 859 page_file_path = page_file_path.AppendASCII("non_html_namespace.htm"); |
860 GURL file_url = net::FilePathToFileURL(page_file_path); | 860 GURL file_url = net::FilePathToFileURL(page_file_path); |
861 LoadPageFromURL(file_url); | 861 LoadPageFromURL(file_url); |
862 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); | 862 WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url); |
863 ASSERT_TRUE(web_frame != NULL); | 863 ASSERT_TRUE(web_frame != NULL); |
864 WebDocument doc = web_frame->document(); | 864 WebDocument doc = web_frame->document(); |
865 WebNode lastNodeInBody = doc.body().lastChild(); | 865 WebNode lastNodeInBody = doc.body().lastChild(); |
866 ASSERT_EQ(WebNode::ElementNode, lastNodeInBody.nodeType()); | 866 ASSERT_EQ(WebNode::ElementNode, lastNodeInBody.nodeType()); |
867 WebString uri = webkit_glue::GetSubResourceLinkFromElement( | 867 WebString uri = webkit_glue::GetSubResourceLinkFromElement( |
868 lastNodeInBody.to<WebElement>()); | 868 lastNodeInBody.to<WebElement>()); |
869 EXPECT_TRUE(uri.isNull()); | 869 EXPECT_TRUE(uri.isNull()); |
870 } | 870 } |
871 | 871 |
872 } // namespace | 872 } // namespace |
OLD | NEW |