| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 // Path to directory containing test data. | 390 // Path to directory containing test data. |
| 391 base::FilePath test_dir_; | 391 base::FilePath test_dir_; |
| 392 | 392 |
| 393 // Temporary directory we will save pages to. | 393 // Temporary directory we will save pages to. |
| 394 base::ScopedTempDir save_dir_; | 394 base::ScopedTempDir save_dir_; |
| 395 | 395 |
| 396 private: | 396 private: |
| 397 DISALLOW_COPY_AND_ASSIGN(SavePageBrowserTest); | 397 DISALLOW_COPY_AND_ASSIGN(SavePageBrowserTest); |
| 398 }; | 398 }; |
| 399 | 399 |
| 400 // Disabled on Windows due to flakiness. http://crbug.com/162323 | 400 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { |
| 401 #if defined(OS_WIN) | |
| 402 #define MAYBE_SaveHTMLOnly DISABLED_SaveHTMLOnly | |
| 403 #else | |
| 404 #define MAYBE_SaveHTMLOnly SaveHTMLOnly | |
| 405 #endif | |
| 406 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveHTMLOnly) { | |
| 407 GURL url = NavigateToMockURL("a"); | 401 GURL url = NavigateToMockURL("a"); |
| 408 | 402 |
| 409 base::FilePath full_file_name, dir; | 403 base::FilePath full_file_name, dir; |
| 410 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_ONLY_HTML, "a", 1, &dir, | 404 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_ONLY_HTML, "a", 1, &dir, |
| 411 &full_file_name); | 405 &full_file_name); |
| 412 ASSERT_FALSE(HasFailure()); | 406 ASSERT_FALSE(HasFailure()); |
| 413 | 407 |
| 414 EXPECT_TRUE(base::PathExists(full_file_name)); | 408 EXPECT_TRUE(base::PathExists(full_file_name)); |
| 415 EXPECT_FALSE(base::PathExists(dir)); | 409 EXPECT_FALSE(base::PathExists(dir)); |
| 416 EXPECT_TRUE(base::ContentsEqual(test_dir_.Append(base::FilePath( | 410 EXPECT_TRUE(base::ContentsEqual(test_dir_.Append(base::FilePath( |
| 417 kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), full_file_name)); | 411 kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), full_file_name)); |
| 418 } | 412 } |
| 419 | 413 |
| 420 // http://crbug.com/162323 | 414 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { |
| 421 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_SaveHTMLOnlyCancel) { | |
| 422 GURL url = NavigateToMockURL("a"); | 415 GURL url = NavigateToMockURL("a"); |
| 423 DownloadManager* manager(GetDownloadManager()); | 416 DownloadManager* manager(GetDownloadManager()); |
| 424 std::vector<DownloadItem*> downloads; | 417 std::vector<DownloadItem*> downloads; |
| 425 manager->GetAllDownloads(&downloads); | 418 manager->GetAllDownloads(&downloads); |
| 426 ASSERT_EQ(0u, downloads.size()); | 419 ASSERT_EQ(0u, downloads.size()); |
| 427 | 420 |
| 428 base::FilePath full_file_name, dir; | 421 base::FilePath full_file_name, dir; |
| 429 GetDestinationPaths("a", &full_file_name, &dir); | 422 GetDestinationPaths("a", &full_file_name, &dir); |
| 430 DownloadItemCreatedObserver creation_observer(manager); | 423 DownloadItemCreatedObserver creation_observer(manager); |
| 431 DownloadPersistedObserver persisted(browser()->profile(), base::Bind( | 424 DownloadPersistedObserver persisted(browser()->profile(), base::Bind( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 461 bool ShouldCompleteDownload( | 454 bool ShouldCompleteDownload( |
| 462 content::DownloadItem* item, | 455 content::DownloadItem* item, |
| 463 const base::Closure& user_complete_callback) override { | 456 const base::Closure& user_complete_callback) override { |
| 464 return false; | 457 return false; |
| 465 } | 458 } |
| 466 | 459 |
| 467 private: | 460 private: |
| 468 DISALLOW_COPY_AND_ASSIGN(DelayingDownloadManagerDelegate); | 461 DISALLOW_COPY_AND_ASSIGN(DelayingDownloadManagerDelegate); |
| 469 }; | 462 }; |
| 470 | 463 |
| 471 // Disabled on Windows due to flakiness. http://crbug.com/162323 | 464 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyTabDestroy) { |
| 472 #if defined(OS_WIN) | |
| 473 #define MAYBE_SaveHTMLOnlyTabDestroy DISABLED_SaveHTMLOnlyTabDestroy | |
| 474 #else | |
| 475 #define MAYBE_SaveHTMLOnlyTabDestroy SaveHTMLOnlyTabDestroy | |
| 476 #endif | |
| 477 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveHTMLOnlyTabDestroy) { | |
| 478 GURL url = NavigateToMockURL("a"); | 465 GURL url = NavigateToMockURL("a"); |
| 479 scoped_ptr<DelayingDownloadManagerDelegate> delaying_delegate( | 466 scoped_ptr<DelayingDownloadManagerDelegate> delaying_delegate( |
| 480 new DelayingDownloadManagerDelegate(browser()->profile())); | 467 new DelayingDownloadManagerDelegate(browser()->profile())); |
| 481 delaying_delegate->GetDownloadIdReceiverCallback().Run( | 468 delaying_delegate->GetDownloadIdReceiverCallback().Run( |
| 482 content::DownloadItem::kInvalidId + 1); | 469 content::DownloadItem::kInvalidId + 1); |
| 483 DownloadServiceFactory::GetForBrowserContext(browser()->profile()) | 470 DownloadServiceFactory::GetForBrowserContext(browser()->profile()) |
| 484 ->SetDownloadManagerDelegateForTesting(delaying_delegate.Pass()); | 471 ->SetDownloadManagerDelegateForTesting(delaying_delegate.Pass()); |
| 485 DownloadManager* manager(GetDownloadManager()); | 472 DownloadManager* manager(GetDownloadManager()); |
| 486 std::vector<DownloadItem*> downloads; | 473 std::vector<DownloadItem*> downloads; |
| 487 manager->GetAllDownloads(&downloads); | 474 manager->GetAllDownloads(&downloads); |
| 488 ASSERT_EQ(0u, downloads.size()); | 475 ASSERT_EQ(0u, downloads.size()); |
| 489 | 476 |
| 490 base::FilePath full_file_name, dir; | 477 base::FilePath full_file_name, dir; |
| 491 GetDestinationPaths("a", &full_file_name, &dir); | 478 GetDestinationPaths("a", &full_file_name, &dir); |
| 492 DownloadItemCreatedObserver creation_observer(manager); | 479 DownloadItemCreatedObserver creation_observer(manager); |
| 493 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, | 480 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, |
| 494 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 481 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
| 495 std::vector<DownloadItem*> items; | 482 std::vector<DownloadItem*> items; |
| 496 creation_observer.WaitForDownloadItem(&items); | 483 creation_observer.WaitForDownloadItem(&items); |
| 497 ASSERT_TRUE(items.size() == 1); | 484 ASSERT_TRUE(items.size() == 1); |
| 498 | 485 |
| 499 // Close the tab; does this cancel the download? | 486 // Close the tab; does this cancel the download? |
| 500 GetCurrentTab(browser())->Close(); | 487 GetCurrentTab(browser())->Close(); |
| 501 EXPECT_EQ(DownloadItem::CANCELLED, items[0]->GetState()); | 488 EXPECT_EQ(DownloadItem::CANCELLED, items[0]->GetState()); |
| 502 | 489 |
| 503 EXPECT_FALSE(base::PathExists(full_file_name)); | 490 EXPECT_FALSE(base::PathExists(full_file_name)); |
| 504 EXPECT_FALSE(base::PathExists(dir)); | 491 EXPECT_FALSE(base::PathExists(dir)); |
| 505 } | 492 } |
| 506 | 493 |
| 507 // Disabled on Windows due to flakiness. http://crbug.com/162323 | 494 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) { |
| 508 #if defined(OS_WIN) | |
| 509 #define MAYBE_SaveViewSourceHTMLOnly DISABLED_SaveViewSourceHTMLOnly | |
| 510 #else | |
| 511 #define MAYBE_SaveViewSourceHTMLOnly SaveViewSourceHTMLOnly | |
| 512 #endif | |
| 513 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveViewSourceHTMLOnly) { | |
| 514 GURL mock_url = URLRequestMockHTTPJob::GetMockUrl("save_page/a.htm"); | 495 GURL mock_url = URLRequestMockHTTPJob::GetMockUrl("save_page/a.htm"); |
| 515 GURL view_source_url = | 496 GURL view_source_url = |
| 516 GURL(content::kViewSourceScheme + std::string(":") + mock_url.spec()); | 497 GURL(content::kViewSourceScheme + std::string(":") + mock_url.spec()); |
| 517 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( | 498 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( |
| 518 "save_page/a.htm"); | 499 "save_page/a.htm"); |
| 519 ui_test_utils::NavigateToURL(browser(), view_source_url); | 500 ui_test_utils::NavigateToURL(browser(), view_source_url); |
| 520 | 501 |
| 521 base::FilePath full_file_name, dir; | 502 base::FilePath full_file_name, dir; |
| 522 SaveCurrentTab(actual_page_url, content::SAVE_PAGE_TYPE_AS_ONLY_HTML, "a", 1, | 503 SaveCurrentTab(actual_page_url, content::SAVE_PAGE_TYPE_AS_ONLY_HTML, "a", 1, |
| 523 &dir, &full_file_name); | 504 &dir, &full_file_name); |
| 524 ASSERT_FALSE(HasFailure()); | 505 ASSERT_FALSE(HasFailure()); |
| 525 | 506 |
| 526 EXPECT_TRUE(base::PathExists(full_file_name)); | 507 EXPECT_TRUE(base::PathExists(full_file_name)); |
| 527 EXPECT_FALSE(base::PathExists(dir)); | 508 EXPECT_FALSE(base::PathExists(dir)); |
| 528 EXPECT_TRUE(base::ContentsEqual( | 509 EXPECT_TRUE(base::ContentsEqual( |
| 529 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("a.htm"), | 510 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("a.htm"), |
| 530 full_file_name)); | 511 full_file_name)); |
| 531 } | 512 } |
| 532 | 513 |
| 533 // Disabled on Windows due to flakiness. http://crbug.com/162323 | 514 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { |
| 534 #if defined(OS_WIN) | |
| 535 #define MAYBE_SaveCompleteHTML DISABLED_SaveCompleteHTML | |
| 536 #else | |
| 537 #define MAYBE_SaveCompleteHTML SaveCompleteHTML | |
| 538 #endif | |
| 539 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_SaveCompleteHTML) { | |
| 540 GURL url = NavigateToMockURL("b"); | 515 GURL url = NavigateToMockURL("b"); |
| 541 | 516 |
| 542 base::FilePath full_file_name, dir; | 517 base::FilePath full_file_name, dir; |
| 543 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, "b", 3, &dir, | 518 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, "b", 3, &dir, |
| 544 &full_file_name); | 519 &full_file_name); |
| 545 ASSERT_FALSE(HasFailure()); | 520 ASSERT_FALSE(HasFailure()); |
| 546 | 521 |
| 547 EXPECT_TRUE(base::PathExists(full_file_name)); | 522 EXPECT_TRUE(base::PathExists(full_file_name)); |
| 548 EXPECT_TRUE(base::PathExists(dir)); | 523 EXPECT_TRUE(base::PathExists(dir)); |
| 549 EXPECT_TRUE(base::TextContentsEqual( | 524 EXPECT_TRUE(base::TextContentsEqual( |
| 550 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("b.saved1.htm"), | 525 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("b.saved1.htm"), |
| 551 full_file_name)); | 526 full_file_name)); |
| 552 EXPECT_TRUE(base::ContentsEqual( | 527 EXPECT_TRUE(base::ContentsEqual( |
| 553 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.png"), | 528 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.png"), |
| 554 dir.AppendASCII("1.png"))); | 529 dir.AppendASCII("1.png"))); |
| 555 EXPECT_TRUE(base::ContentsEqual( | 530 EXPECT_TRUE(base::ContentsEqual( |
| 556 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.css"), | 531 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.css"), |
| 557 dir.AppendASCII("1.css"))); | 532 dir.AppendASCII("1.css"))); |
| 558 } | 533 } |
| 559 | 534 |
| 560 // Invoke a save page during the initial navigation. | |
| 561 // (Regression test for http://crbug.com/156538). | |
| 562 // Disabled on Windows due to flakiness. http://crbug.com/162323 | |
| 563 #if defined(OS_WIN) | |
| 564 #define MAYBE_SaveDuringInitialNavigationIncognito DISABLED_SaveDuringInitialNav
igationIncognito | |
| 565 #else | |
| 566 #define MAYBE_SaveDuringInitialNavigationIncognito SaveDuringInitialNavigationIn
cognito | |
| 567 #endif | |
| 568 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, | 535 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, |
| 569 MAYBE_SaveDuringInitialNavigationIncognito) { | 536 SaveDuringInitialNavigationIncognito) { |
| 570 // Open an Incognito window. | 537 // Open an Incognito window. |
| 571 Browser* incognito = CreateIncognitoBrowser(); // Waits. | 538 Browser* incognito = CreateIncognitoBrowser(); // Waits. |
| 572 ASSERT_TRUE(incognito); | 539 ASSERT_TRUE(incognito); |
| 573 | 540 |
| 574 // Create a download item creation waiter on that window. | 541 // Create a download item creation waiter on that window. |
| 575 DownloadItemCreatedObserver creation_observer( | 542 DownloadItemCreatedObserver creation_observer( |
| 576 BrowserContext::GetDownloadManager(incognito->profile())); | 543 BrowserContext::GetDownloadManager(incognito->profile())); |
| 577 | 544 |
| 578 // Navigate, unblocking with new tab. | 545 // Navigate, unblocking with new tab. |
| 579 GURL url = URLRequestMockHTTPJob::GetMockUrl("save_page/b.htm"); | 546 GURL url = URLRequestMockHTTPJob::GetMockUrl("save_page/b.htm"); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 599 // might have completed. If the page load lost the race, then | 566 // might have completed. If the page load lost the race, then |
| 600 // SavePackage will cancel because there aren't any resources to | 567 // SavePackage will cancel because there aren't any resources to |
| 601 // save. | 568 // save. |
| 602 } | 569 } |
| 603 | 570 |
| 604 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, NoSave) { | 571 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, NoSave) { |
| 605 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); | 572 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); |
| 606 EXPECT_FALSE(chrome::CanSavePage(browser())); | 573 EXPECT_FALSE(chrome::CanSavePage(browser())); |
| 607 } | 574 } |
| 608 | 575 |
| 609 // Disabled on Windows due to flakiness. http://crbug.com/162323 | 576 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, FileNameFromPageTitle) { |
| 610 #if defined(OS_WIN) | |
| 611 #define MAYBE_FileNameFromPageTitle DISABLED_FileNameFromPageTitle | |
| 612 #else | |
| 613 #define MAYBE_FileNameFromPageTitle FileNameFromPageTitle | |
| 614 #endif | |
| 615 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_FileNameFromPageTitle) { | |
| 616 GURL url = NavigateToMockURL("b"); | 577 GURL url = NavigateToMockURL("b"); |
| 617 | 578 |
| 618 base::FilePath full_file_name = save_dir_.path().AppendASCII( | 579 base::FilePath full_file_name = save_dir_.path().AppendASCII( |
| 619 std::string("Test page for saving page feature") + kAppendedExtension); | 580 std::string("Test page for saving page feature") + kAppendedExtension); |
| 620 base::FilePath dir = save_dir_.path().AppendASCII( | 581 base::FilePath dir = save_dir_.path().AppendASCII( |
| 621 "Test page for saving page feature_files"); | 582 "Test page for saving page feature_files"); |
| 622 DownloadPersistedObserver persisted(browser()->profile(), base::Bind( | 583 DownloadPersistedObserver persisted(browser()->profile(), base::Bind( |
| 623 &DownloadStoredProperly, url, full_file_name, 3, | 584 &DownloadStoredProperly, url, full_file_name, 3, |
| 624 history::DownloadState::COMPLETE)); | 585 history::DownloadState::COMPLETE)); |
| 625 scoped_refptr<content::MessageLoopRunner> loop_runner( | 586 scoped_refptr<content::MessageLoopRunner> loop_runner( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 640 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("b.saved2.htm"), | 601 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("b.saved2.htm"), |
| 641 full_file_name)); | 602 full_file_name)); |
| 642 EXPECT_TRUE(base::ContentsEqual( | 603 EXPECT_TRUE(base::ContentsEqual( |
| 643 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.png"), | 604 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.png"), |
| 644 dir.AppendASCII("1.png"))); | 605 dir.AppendASCII("1.png"))); |
| 645 EXPECT_TRUE(base::ContentsEqual( | 606 EXPECT_TRUE(base::ContentsEqual( |
| 646 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.css"), | 607 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.css"), |
| 647 dir.AppendASCII("1.css"))); | 608 dir.AppendASCII("1.css"))); |
| 648 } | 609 } |
| 649 | 610 |
| 650 // Disabled on Windows due to flakiness. http://crbug.com/162323 | 611 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { |
| 651 #if defined(OS_WIN) | |
| 652 #define MAYBE_RemoveFromList DISABLED_RemoveFromList | |
| 653 #else | |
| 654 #define MAYBE_RemoveFromList RemoveFromList | |
| 655 #endif | |
| 656 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_RemoveFromList) { | |
| 657 GURL url = NavigateToMockURL("a"); | 612 GURL url = NavigateToMockURL("a"); |
| 658 | 613 |
| 659 base::FilePath full_file_name, dir; | 614 base::FilePath full_file_name, dir; |
| 660 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_ONLY_HTML, "a", 1, &dir, | 615 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_ONLY_HTML, "a", 1, &dir, |
| 661 &full_file_name); | 616 &full_file_name); |
| 662 ASSERT_FALSE(HasFailure()); | 617 ASSERT_FALSE(HasFailure()); |
| 663 | 618 |
| 664 DownloadManager* manager(GetDownloadManager()); | 619 DownloadManager* manager(GetDownloadManager()); |
| 665 std::vector<DownloadItem*> downloads; | 620 std::vector<DownloadItem*> downloads; |
| 666 manager->GetAllDownloads(&downloads); | 621 manager->GetAllDownloads(&downloads); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 pos = mhtml.find("Content-Type: image/png", pos); | 884 pos = mhtml.find("Content-Type: image/png", pos); |
| 930 if (pos == std::string::npos) | 885 if (pos == std::string::npos) |
| 931 break; | 886 break; |
| 932 count++; | 887 count++; |
| 933 pos++; | 888 pos++; |
| 934 } | 889 } |
| 935 EXPECT_EQ(1, count) << "Verify number of image/png parts in the mhtml output"; | 890 EXPECT_EQ(1, count) << "Verify number of image/png parts in the mhtml output"; |
| 936 } | 891 } |
| 937 | 892 |
| 938 } // namespace | 893 } // namespace |
| OLD | NEW |