| 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/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/prefs/pref_member.h" | 12 #include "base/prefs/pref_member.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/test/test_file_util.h" | 14 #include "base/test/test_file_util.h" |
| 15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
| 16 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 16 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 17 #include "chrome/browser/download/download_history.h" | 17 #include "chrome/browser/download/download_history.h" |
| 18 #include "chrome/browser/download/download_prefs.h" | 18 #include "chrome/browser/download/download_prefs.h" |
| 19 #include "chrome/browser/download/download_service.h" | 19 #include "chrome/browser/download/download_service.h" |
| 20 #include "chrome/browser/download/download_service_factory.h" | 20 #include "chrome/browser/download/download_service_factory.h" |
| 21 #include "chrome/browser/download/save_package_file_picker.h" |
| 21 #include "chrome/browser/history/download_row.h" | 22 #include "chrome/browser/history/download_row.h" |
| 22 #include "chrome/browser/net/url_request_mock_util.h" | 23 #include "chrome/browser/net/url_request_mock_util.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_commands.h" | 26 #include "chrome/browser/ui/browser_commands.h" |
| 26 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
| 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 28 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
| 29 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 32 #include "chrome/test/base/in_process_browser_test.h" | 33 #include "chrome/test/base/in_process_browser_test.h" |
| 33 #include "chrome/test/base/ui_test_utils.h" | 34 #include "chrome/test/base/ui_test_utils.h" |
| 34 #include "content/public/browser/download_item.h" | 35 #include "content/public/browser/download_item.h" |
| 35 #include "content/public/browser/download_manager.h" | 36 #include "content/public/browser/download_manager.h" |
| 36 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| 37 #include "content/public/browser/notification_types.h" | 38 #include "content/public/browser/notification_types.h" |
| 38 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
| 39 #include "content/public/test/test_utils.h" | 40 #include "content/public/test/test_utils.h" |
| 40 #include "content/test/net/url_request_mock_http_job.h" | 41 #include "content/test/net/url_request_mock_http_job.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
| 42 | 43 |
| 43 #if defined(OS_CHROMEOS) | |
| 44 #include "chrome/browser/download/save_package_file_picker_chromeos.h" | |
| 45 #else | |
| 46 #include "chrome/browser/download/save_package_file_picker.h" | |
| 47 #endif | |
| 48 | |
| 49 using content::BrowserContext; | 44 using content::BrowserContext; |
| 50 using content::BrowserThread; | 45 using content::BrowserThread; |
| 51 using content::DownloadItem; | 46 using content::DownloadItem; |
| 52 using content::DownloadManager; | 47 using content::DownloadManager; |
| 53 using content::URLRequestMockHTTPJob; | 48 using content::URLRequestMockHTTPJob; |
| 54 using content::WebContents; | 49 using content::WebContents; |
| 55 | 50 |
| 56 namespace { | 51 namespace { |
| 57 | 52 |
| 58 // Waits for an item record in the downloads database to match |filter|. See | 53 // Waits for an item record in the downloads database to match |filter|. See |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 SavePageAsMHTMLBrowserTest::~SavePageAsMHTMLBrowserTest() { | 742 SavePageAsMHTMLBrowserTest::~SavePageAsMHTMLBrowserTest() { |
| 748 } | 743 } |
| 749 | 744 |
| 750 IN_PROC_BROWSER_TEST_F(SavePageAsMHTMLBrowserTest, SavePageAsMHTML) { | 745 IN_PROC_BROWSER_TEST_F(SavePageAsMHTMLBrowserTest, SavePageAsMHTML) { |
| 751 static const int64 kFileSizeMin = 2758; | 746 static const int64 kFileSizeMin = 2758; |
| 752 GURL url = NavigateToMockURL("b"); | 747 GURL url = NavigateToMockURL("b"); |
| 753 base::FilePath download_dir = DownloadPrefs::FromDownloadManager( | 748 base::FilePath download_dir = DownloadPrefs::FromDownloadManager( |
| 754 GetDownloadManager())->DownloadPath(); | 749 GetDownloadManager())->DownloadPath(); |
| 755 base::FilePath full_file_name = download_dir.AppendASCII(std::string( | 750 base::FilePath full_file_name = download_dir.AppendASCII(std::string( |
| 756 "Test page for saving page feature.mhtml")); | 751 "Test page for saving page feature.mhtml")); |
| 757 #if defined(OS_CHROMEOS) | |
| 758 SavePackageFilePickerChromeOS::SetShouldPromptUser(false); | |
| 759 #else | |
| 760 SavePackageFilePicker::SetShouldPromptUser(false); | 752 SavePackageFilePicker::SetShouldPromptUser(false); |
| 761 #endif | |
| 762 DownloadPersistedObserver persisted(browser()->profile(), base::Bind( | 753 DownloadPersistedObserver persisted(browser()->profile(), base::Bind( |
| 763 &DownloadStoredProperly, url, full_file_name, -1, | 754 &DownloadStoredProperly, url, full_file_name, -1, |
| 764 DownloadItem::COMPLETE)); | 755 DownloadItem::COMPLETE)); |
| 765 scoped_refptr<content::MessageLoopRunner> loop_runner( | 756 scoped_refptr<content::MessageLoopRunner> loop_runner( |
| 766 new content::MessageLoopRunner); | 757 new content::MessageLoopRunner); |
| 767 SavePackageFinishedObserver observer( | 758 SavePackageFinishedObserver observer( |
| 768 content::BrowserContext::GetDownloadManager(browser()->profile()), | 759 content::BrowserContext::GetDownloadManager(browser()->profile()), |
| 769 loop_runner->QuitClosure()); | 760 loop_runner->QuitClosure()); |
| 770 chrome::SavePage(browser()); | 761 chrome::SavePage(browser()); |
| 771 loop_runner->Run(); | 762 loop_runner->Run(); |
| 772 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); | 763 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); |
| 773 persisted.WaitForPersisted(); | 764 persisted.WaitForPersisted(); |
| 774 | 765 |
| 775 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 766 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 776 int64 actual_file_size = -1; | 767 int64 actual_file_size = -1; |
| 777 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); | 768 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); |
| 778 EXPECT_LE(kFileSizeMin, actual_file_size); | 769 EXPECT_LE(kFileSizeMin, actual_file_size); |
| 779 } | 770 } |
| 780 | 771 |
| 781 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SavePageBrowserTest_NonMHTML) { | 772 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SavePageBrowserTest_NonMHTML) { |
| 782 #if defined(OS_CHROMEOS) | |
| 783 SavePackageFilePickerChromeOS::SetShouldPromptUser(false); | |
| 784 #else | |
| 785 SavePackageFilePicker::SetShouldPromptUser(false); | 773 SavePackageFilePicker::SetShouldPromptUser(false); |
| 786 #endif | |
| 787 GURL url("data:text/plain,foo"); | 774 GURL url("data:text/plain,foo"); |
| 788 ui_test_utils::NavigateToURL(browser(), url); | 775 ui_test_utils::NavigateToURL(browser(), url); |
| 789 scoped_refptr<content::MessageLoopRunner> loop_runner( | 776 scoped_refptr<content::MessageLoopRunner> loop_runner( |
| 790 new content::MessageLoopRunner); | 777 new content::MessageLoopRunner); |
| 791 SavePackageFinishedObserver observer( | 778 SavePackageFinishedObserver observer( |
| 792 content::BrowserContext::GetDownloadManager(browser()->profile()), | 779 content::BrowserContext::GetDownloadManager(browser()->profile()), |
| 793 loop_runner->QuitClosure()); | 780 loop_runner->QuitClosure()); |
| 794 chrome::SavePage(browser()); | 781 chrome::SavePage(browser()); |
| 795 loop_runner->Run(); | 782 loop_runner->Run(); |
| 796 base::FilePath download_dir = DownloadPrefs::FromDownloadManager( | 783 base::FilePath download_dir = DownloadPrefs::FromDownloadManager( |
| 797 GetDownloadManager())->DownloadPath(); | 784 GetDownloadManager())->DownloadPath(); |
| 798 base::FilePath filename = download_dir.AppendASCII("dataurl.txt"); | 785 base::FilePath filename = download_dir.AppendASCII("dataurl.txt"); |
| 799 EXPECT_TRUE(file_util::PathExists(filename)); | 786 EXPECT_TRUE(file_util::PathExists(filename)); |
| 800 std::string contents; | 787 std::string contents; |
| 801 EXPECT_TRUE(file_util::ReadFileToString(filename, &contents)); | 788 EXPECT_TRUE(file_util::ReadFileToString(filename, &contents)); |
| 802 EXPECT_EQ("foo", contents); | 789 EXPECT_EQ("foo", contents); |
| 803 } | 790 } |
| 804 | 791 |
| 805 } // namespace | 792 } // namespace |
| 806 | 793 |
| OLD | NEW |