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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 prefs::kDownloadDefaultDirectory, save_dir_.path()); | 294 prefs::kDownloadDefaultDirectory, save_dir_.path()); |
295 browser()->profile()->GetPrefs()->SetFilePath( | 295 browser()->profile()->GetPrefs()->SetFilePath( |
296 prefs::kSaveFileDefaultDirectory, save_dir_.path()); | 296 prefs::kSaveFileDefaultDirectory, save_dir_.path()); |
297 BrowserThread::PostTask( | 297 BrowserThread::PostTask( |
298 BrowserThread::IO, FROM_HERE, | 298 BrowserThread::IO, FROM_HERE, |
299 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 299 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
300 } | 300 } |
301 | 301 |
302 GURL NavigateToMockURL(const std::string& prefix) { | 302 GURL NavigateToMockURL(const std::string& prefix) { |
303 GURL url = URLRequestMockHTTPJob::GetMockUrl( | 303 GURL url = URLRequestMockHTTPJob::GetMockUrl( |
304 base::FilePath(kTestDir).AppendASCII(prefix + ".htm")); | 304 "save_page/" + prefix + ".htm"); |
305 ui_test_utils::NavigateToURL(browser(), url); | 305 ui_test_utils::NavigateToURL(browser(), url); |
306 return url; | 306 return url; |
307 } | 307 } |
308 | 308 |
309 // Returns full paths of destination file and directory. | 309 // Returns full paths of destination file and directory. |
310 void GetDestinationPaths(const std::string& prefix, | 310 void GetDestinationPaths(const std::string& prefix, |
311 base::FilePath* full_file_name, | 311 base::FilePath* full_file_name, |
312 base::FilePath* dir) { | 312 base::FilePath* dir) { |
313 *full_file_name = save_dir_.path().AppendASCII(prefix + ".htm"); | 313 *full_file_name = save_dir_.path().AppendASCII(prefix + ".htm"); |
314 *dir = save_dir_.path().AppendASCII(prefix + "_files"); | 314 *dir = save_dir_.path().AppendASCII(prefix + "_files"); |
315 } | 315 } |
316 | 316 |
317 WebContents* GetCurrentTab(Browser* browser) const { | 317 WebContents* GetCurrentTab(Browser* browser) const { |
318 WebContents* current_tab = | 318 WebContents* current_tab = |
319 browser->tab_strip_model()->GetActiveWebContents(); | 319 browser->tab_strip_model()->GetActiveWebContents(); |
320 EXPECT_TRUE(current_tab); | 320 EXPECT_TRUE(current_tab); |
321 return current_tab; | 321 return current_tab; |
322 } | 322 } |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 EXPECT_FALSE(base::PathExists(dir)); | 503 EXPECT_FALSE(base::PathExists(dir)); |
504 } | 504 } |
505 | 505 |
506 // Disabled on Windows due to flakiness. http://crbug.com/162323 | 506 // Disabled on Windows due to flakiness. http://crbug.com/162323 |
507 #if defined(OS_WIN) | 507 #if defined(OS_WIN) |
508 #define MAYBE_SaveViewSourceHTMLOnly DISABLED_SaveViewSourceHTMLOnly | 508 #define MAYBE_SaveViewSourceHTMLOnly DISABLED_SaveViewSourceHTMLOnly |
509 #else | 509 #else |
510 #define MAYBE_SaveViewSourceHTMLOnly SaveViewSourceHTMLOnly | 510 #define MAYBE_SaveViewSourceHTMLOnly SaveViewSourceHTMLOnly |
511 #endif | 511 #endif |
512 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveViewSourceHTMLOnly) { | 512 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveViewSourceHTMLOnly) { |
513 base::FilePath file_name(FILE_PATH_LITERAL("a.htm")); | 513 GURL mock_url = URLRequestMockHTTPJob::GetMockUrl("save_page/a.htm"); |
514 GURL mock_url = URLRequestMockHTTPJob::GetMockUrl( | |
515 base::FilePath(kTestDir).Append(file_name)); | |
516 GURL view_source_url = | 514 GURL view_source_url = |
517 GURL(content::kViewSourceScheme + std::string(":") + mock_url.spec()); | 515 GURL(content::kViewSourceScheme + std::string(":") + mock_url.spec()); |
518 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( | 516 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( |
519 base::FilePath(kTestDir).Append(file_name)); | 517 "save_page/a.htm"); |
520 ui_test_utils::NavigateToURL(browser(), view_source_url); | 518 ui_test_utils::NavigateToURL(browser(), view_source_url); |
521 | 519 |
522 base::FilePath full_file_name, dir; | 520 base::FilePath full_file_name, dir; |
523 SaveCurrentTab(actual_page_url, content::SAVE_PAGE_TYPE_AS_ONLY_HTML, "a", 1, | 521 SaveCurrentTab(actual_page_url, content::SAVE_PAGE_TYPE_AS_ONLY_HTML, "a", 1, |
524 &dir, &full_file_name); | 522 &dir, &full_file_name); |
525 ASSERT_FALSE(HasFailure()); | 523 ASSERT_FALSE(HasFailure()); |
526 | 524 |
525 base::FilePath file_name(FILE_PATH_LITERAL("a.htm")); | |
527 EXPECT_TRUE(base::PathExists(full_file_name)); | 526 EXPECT_TRUE(base::PathExists(full_file_name)); |
528 EXPECT_FALSE(base::PathExists(dir)); | 527 EXPECT_FALSE(base::PathExists(dir)); |
529 EXPECT_TRUE(base::ContentsEqual( | 528 EXPECT_TRUE(base::ContentsEqual( |
530 test_dir_.Append(base::FilePath(kTestDir)).Append(file_name), | 529 test_dir_.Append(base::FilePath(kTestDir)).Append(file_name), |
mmenke
2015/10/14 16:43:20
Maybe AppendASCII and get rid of file_name?
tfarina
2015/10/17 22:24:44
Done.
| |
531 full_file_name)); | 530 full_file_name)); |
532 } | 531 } |
533 | 532 |
534 // Disabled on Windows due to flakiness. http://crbug.com/162323 | 533 // Disabled on Windows due to flakiness. http://crbug.com/162323 |
535 #if defined(OS_WIN) | 534 #if defined(OS_WIN) |
536 #define MAYBE_SaveCompleteHTML DISABLED_SaveCompleteHTML | 535 #define MAYBE_SaveCompleteHTML DISABLED_SaveCompleteHTML |
537 #else | 536 #else |
538 #define MAYBE_SaveCompleteHTML SaveCompleteHTML | 537 #define MAYBE_SaveCompleteHTML SaveCompleteHTML |
539 #endif | 538 #endif |
540 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_SaveCompleteHTML) { | 539 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_SaveCompleteHTML) { |
(...skipping 29 matching lines...) Expand all Loading... | |
570 MAYBE_SaveDuringInitialNavigationIncognito) { | 569 MAYBE_SaveDuringInitialNavigationIncognito) { |
571 // Open an Incognito window. | 570 // Open an Incognito window. |
572 Browser* incognito = CreateIncognitoBrowser(); // Waits. | 571 Browser* incognito = CreateIncognitoBrowser(); // Waits. |
573 ASSERT_TRUE(incognito); | 572 ASSERT_TRUE(incognito); |
574 | 573 |
575 // Create a download item creation waiter on that window. | 574 // Create a download item creation waiter on that window. |
576 DownloadItemCreatedObserver creation_observer( | 575 DownloadItemCreatedObserver creation_observer( |
577 BrowserContext::GetDownloadManager(incognito->profile())); | 576 BrowserContext::GetDownloadManager(incognito->profile())); |
578 | 577 |
579 // Navigate, unblocking with new tab. | 578 // Navigate, unblocking with new tab. |
580 GURL url = URLRequestMockHTTPJob::GetMockUrl( | 579 GURL url = URLRequestMockHTTPJob::GetMockUrl("save_page/b.htm"); |
581 base::FilePath(kTestDir).AppendASCII("b.htm")); | |
582 NavigateToURLWithDisposition(incognito, url, NEW_FOREGROUND_TAB, | 580 NavigateToURLWithDisposition(incognito, url, NEW_FOREGROUND_TAB, |
583 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 581 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
584 | 582 |
585 // Save the page before completion. | 583 // Save the page before completion. |
586 base::FilePath full_file_name, dir; | 584 base::FilePath full_file_name, dir; |
587 GetDestinationPaths("b", &full_file_name, &dir); | 585 GetDestinationPaths("b", &full_file_name, &dir); |
588 scoped_refptr<content::MessageLoopRunner> loop_runner( | 586 scoped_refptr<content::MessageLoopRunner> loop_runner( |
589 new content::MessageLoopRunner); | 587 new content::MessageLoopRunner); |
590 SavePackageFinishedObserver observer( | 588 SavePackageFinishedObserver observer( |
591 content::BrowserContext::GetDownloadManager(incognito->profile()), | 589 content::BrowserContext::GetDownloadManager(incognito->profile()), |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 EXPECT_FALSE(base::PathExists(dir)); | 675 EXPECT_FALSE(base::PathExists(dir)); |
678 EXPECT_TRUE(base::ContentsEqual(test_dir_.Append(base::FilePath( | 676 EXPECT_TRUE(base::ContentsEqual(test_dir_.Append(base::FilePath( |
679 kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), full_file_name)); | 677 kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), full_file_name)); |
680 } | 678 } |
681 | 679 |
682 // This tests that a webpage with the title "test.exe" is saved as | 680 // This tests that a webpage with the title "test.exe" is saved as |
683 // "test.exe.htm". | 681 // "test.exe.htm". |
684 // We probably don't care to handle this on Linux or Mac. | 682 // We probably don't care to handle this on Linux or Mac. |
685 #if defined(OS_WIN) | 683 #if defined(OS_WIN) |
686 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, CleanFilenameFromPageTitle) { | 684 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, CleanFilenameFromPageTitle) { |
687 const base::FilePath file_name(FILE_PATH_LITERAL("c.htm")); | |
688 base::FilePath download_dir = | 685 base::FilePath download_dir = |
689 DownloadPrefs::FromDownloadManager(GetDownloadManager())-> | 686 DownloadPrefs::FromDownloadManager(GetDownloadManager())-> |
690 DownloadPath(); | 687 DownloadPath(); |
691 base::FilePath full_file_name = | 688 base::FilePath full_file_name = |
692 download_dir.AppendASCII(std::string("test.exe") + kAppendedExtension); | 689 download_dir.AppendASCII(std::string("test.exe") + kAppendedExtension); |
693 base::FilePath dir = download_dir.AppendASCII("test.exe_files"); | 690 base::FilePath dir = download_dir.AppendASCII("test.exe_files"); |
694 | 691 |
695 EXPECT_FALSE(base::PathExists(full_file_name)); | 692 EXPECT_FALSE(base::PathExists(full_file_name)); |
696 GURL url = URLRequestMockHTTPJob::GetMockUrl( | 693 GURL url = URLRequestMockHTTPJob::GetMockUrl("save_page/c.htm"); |
697 base::FilePath(kTestDir).Append(file_name)); | |
698 ui_test_utils::NavigateToURL(browser(), url); | 694 ui_test_utils::NavigateToURL(browser(), url); |
699 | 695 |
700 SavePackageFilePicker::SetShouldPromptUser(false); | 696 SavePackageFilePicker::SetShouldPromptUser(false); |
701 scoped_refptr<content::MessageLoopRunner> loop_runner( | 697 scoped_refptr<content::MessageLoopRunner> loop_runner( |
702 new content::MessageLoopRunner); | 698 new content::MessageLoopRunner); |
703 SavePackageFinishedObserver observer( | 699 SavePackageFinishedObserver observer( |
704 content::BrowserContext::GetDownloadManager(browser()->profile()), | 700 content::BrowserContext::GetDownloadManager(browser()->profile()), |
705 loop_runner->QuitClosure()); | 701 loop_runner->QuitClosure()); |
706 chrome::SavePage(browser()); | 702 chrome::SavePage(browser()); |
707 loop_runner->Run(); | 703 loop_runner->Run(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
773 std::string contents; | 769 std::string contents; |
774 EXPECT_TRUE(base::ReadFileToString(filename, &contents)); | 770 EXPECT_TRUE(base::ReadFileToString(filename, &contents)); |
775 EXPECT_EQ("foo", contents); | 771 EXPECT_EQ("foo", contents); |
776 } | 772 } |
777 | 773 |
778 // Test that we don't crash when the page contains an iframe that | 774 // Test that we don't crash when the page contains an iframe that |
779 // was handled as a download (http://crbug.com/42212). | 775 // was handled as a download (http://crbug.com/42212). |
780 // Flaky: https://crbug.com/537530. | 776 // Flaky: https://crbug.com/537530. |
781 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_SaveDownloadableIFrame) { | 777 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_SaveDownloadableIFrame) { |
782 GURL url = URLRequestMockHTTPJob::GetMockUrl( | 778 GURL url = URLRequestMockHTTPJob::GetMockUrl( |
783 base::FilePath(FILE_PATH_LITERAL("downloads")) | 779 "downloads/iframe-src-is-a-download.htm"); |
784 .AppendASCII("iframe-src-is-a-download.htm")); | |
785 ui_test_utils::NavigateToURL(browser(), url); | 780 ui_test_utils::NavigateToURL(browser(), url); |
786 | 781 |
787 // Wait for and then dismiss the non-save-page-as-related download item | 782 // Wait for and then dismiss the non-save-page-as-related download item |
788 // (the one associated with downloading of "thisdayinhistory.xls" file). | 783 // (the one associated with downloading of "thisdayinhistory.xls" file). |
789 VerifySavePackageExpectations(browser(), url); | 784 VerifySavePackageExpectations(browser(), url); |
790 GetDownloadManager()->RemoveAllDownloads(); | 785 GetDownloadManager()->RemoveAllDownloads(); |
791 | 786 |
792 base::FilePath full_file_name, dir; | 787 base::FilePath full_file_name, dir; |
793 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, | 788 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, |
794 "iframe-src-is-a-download", 2, &dir, &full_file_name); | 789 "iframe-src-is-a-download", 2, &dir, &full_file_name); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
866 ASSERT_TRUE(base::ReadFileToString(full_file_name, &main_contents)); | 861 ASSERT_TRUE(base::ReadFileToString(full_file_name, &main_contents)); |
867 EXPECT_THAT(main_contents, | 862 EXPECT_THAT(main_contents, |
868 HasSubstr("<iframe src=\"./iframes_files/a.html\"></iframe>")); | 863 HasSubstr("<iframe src=\"./iframes_files/a.html\"></iframe>")); |
869 EXPECT_THAT(main_contents, | 864 EXPECT_THAT(main_contents, |
870 HasSubstr("<iframe src=\"./iframes_files/b.html\"></iframe>")); | 865 HasSubstr("<iframe src=\"./iframes_files/b.html\"></iframe>")); |
871 EXPECT_THAT(main_contents, | 866 EXPECT_THAT(main_contents, |
872 HasSubstr("<img src=\"./iframes_files/1.png\">")); | 867 HasSubstr("<img src=\"./iframes_files/1.png\">")); |
873 } | 868 } |
874 | 869 |
875 } // namespace | 870 } // namespace |
OLD | NEW |