Chromium Code Reviews| 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/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| 11 #include "base/test/test_file_util.h" | 11 #include "base/test/test_file_util.h" |
| 12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 13 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 13 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 14 #include "chrome/browser/download/download_history.h" | 14 #include "chrome/browser/download/download_history.h" |
| 15 #include "chrome/browser/download/download_prefs.h" | 15 #include "chrome/browser/download/download_prefs.h" |
| 16 #include "chrome/browser/download/download_service.h" | 16 #include "chrome/browser/download/download_service.h" |
| 17 #include "chrome/browser/download/download_service_factory.h" | 17 #include "chrome/browser/download/download_service_factory.h" |
| 18 #include "chrome/browser/download/save_package_file_picker.h" | 18 #include "chrome/browser/download/save_package_file_picker.h" |
| 19 #include "chrome/browser/net/url_request_mock_util.h" | 19 #include "chrome/browser/net/url_request_mock_util.h" |
| 20 #include "chrome/browser/prefs/pref_member.h" | |
| 21 #include "chrome/browser/prefs/pref_service.h" | |
| 20 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
| 23 #include "chrome/browser/ui/webui/chromeos/active_downloads_ui.h" | 25 #include "chrome/browser/ui/webui/chromeos/active_downloads_ui.h" |
| 24 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
| 27 #include "chrome/common/pref_names.h" | |
| 25 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 26 #include "chrome/test/base/in_process_browser_test.h" | 29 #include "chrome/test/base/in_process_browser_test.h" |
| 27 #include "chrome/test/base/ui_test_utils.h" | 30 #include "chrome/test/base/ui_test_utils.h" |
| 28 #include "content/public/browser/download_item.h" | 31 #include "content/public/browser/download_item.h" |
| 29 #include "content/public/browser/download_manager.h" | 32 #include "content/public/browser/download_manager.h" |
| 30 #include "content/public/browser/download_persistent_store_info.h" | 33 #include "content/public/browser/download_persistent_store_info.h" |
| 31 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
| 32 #include "content/public/browser/notification_types.h" | 35 #include "content/public/browser/notification_types.h" |
| 33 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 34 #include "content/test/net/url_request_mock_http_job.h" | 37 #include "content/test/net/url_request_mock_http_job.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 55 | 58 |
| 56 class SavePageBrowserTest : public InProcessBrowserTest { | 59 class SavePageBrowserTest : public InProcessBrowserTest { |
| 57 protected: | 60 protected: |
| 58 void SetUp() OVERRIDE { | 61 void SetUp() OVERRIDE { |
| 59 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); | 62 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); |
| 60 ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); | 63 ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); |
| 61 InProcessBrowserTest::SetUp(); | 64 InProcessBrowserTest::SetUp(); |
| 62 } | 65 } |
| 63 | 66 |
| 64 void SetUpOnMainThread() OVERRIDE { | 67 void SetUpOnMainThread() OVERRIDE { |
| 68 browser()->profile()->GetPrefs()->SetFilePath( | |
| 69 prefs::kDownloadDefaultDirectory, save_dir_.path()); | |
|
Randy Smith (Not in Mondays)
2012/04/16 17:45:47
What's the context for this change?
benjhayden
2012/04/16 19:08:06
I noticed it was leaving files in my ~/Downloads/.
| |
| 65 BrowserThread::PostTask( | 70 BrowserThread::PostTask( |
| 66 BrowserThread::IO, FROM_HERE, | 71 BrowserThread::IO, FROM_HERE, |
| 67 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 72 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
| 68 } | 73 } |
| 69 | 74 |
| 70 GURL NavigateToMockURL(const std::string& prefix) { | 75 GURL NavigateToMockURL(const std::string& prefix) { |
| 71 GURL url = URLRequestMockHTTPJob::GetMockUrl( | 76 GURL url = URLRequestMockHTTPJob::GetMockUrl( |
| 72 FilePath(kTestDir).AppendASCII(prefix + ".htm")); | 77 FilePath(kTestDir).AppendASCII(prefix + ".htm")); |
| 73 ui_test_utils::NavigateToURL(browser(), url); | 78 ui_test_utils::NavigateToURL(browser(), url); |
| 74 return url; | 79 return url; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 info.state == DownloadItem::COMPLETE; | 182 info.state == DownloadItem::COMPLETE; |
| 178 } | 183 } |
| 179 | 184 |
| 180 GURL url_; | 185 GURL url_; |
| 181 FilePath path_; | 186 FilePath path_; |
| 182 int64 num_files_; | 187 int64 num_files_; |
| 183 }; | 188 }; |
| 184 | 189 |
| 185 void CheckDownloadHistory(const GURL& url, | 190 void CheckDownloadHistory(const GURL& url, |
| 186 const FilePath& path, | 191 const FilePath& path, |
| 187 int64 num_files_) { | 192 int64 num_files) { |
| 188 QueryDownloadHistory(); | 193 QueryDownloadHistory(); |
| 189 | 194 |
| 190 EXPECT_NE(std::find_if(history_entries_.begin(), history_entries_.end(), | 195 EXPECT_NE(std::find_if(history_entries_.begin(), history_entries_.end(), |
| 191 DownloadPersistentStoreInfoMatch(url, path, num_files_)), | 196 DownloadPersistentStoreInfoMatch(url, path, num_files)), |
| 192 history_entries_.end()); | 197 history_entries_.end()); |
| 193 } | 198 } |
| 194 | 199 |
| 195 std::vector<DownloadPersistentStoreInfo> history_entries_; | 200 std::vector<DownloadPersistentStoreInfo> history_entries_; |
| 196 | 201 |
| 197 // Path to directory containing test data. | 202 // Path to directory containing test data. |
| 198 FilePath test_dir_; | 203 FilePath test_dir_; |
| 199 | 204 |
| 200 // Temporary directory we will save pages to. | 205 // Temporary directory we will save pages to. |
| 201 ScopedTempDir save_dir_; | 206 ScopedTempDir save_dir_; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 content::NotificationService::AllSources()); | 367 content::NotificationService::AllSources()); |
| 363 browser()->SavePage(); | 368 browser()->SavePage(); |
| 364 observer.Wait(); | 369 observer.Wait(); |
| 365 | 370 |
| 366 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 371 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 367 | 372 |
| 368 EXPECT_TRUE(file_util::DieFileDie(full_file_name, false)); | 373 EXPECT_TRUE(file_util::DieFileDie(full_file_name, false)); |
| 369 EXPECT_TRUE(file_util::DieFileDie(dir, true)); | 374 EXPECT_TRUE(file_util::DieFileDie(dir, true)); |
| 370 } | 375 } |
| 371 #endif | 376 #endif |
| 377 | |
| 378 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SavePageAsMHTML) { | |
| 379 GURL url = NavigateToMockURL("b"); | |
| 380 FilePath download_dir = DownloadPrefs::FromDownloadManager( | |
| 381 GetDownloadManager())->download_path(); | |
| 382 FilePath full_file_name = download_dir.AppendASCII(std::string( | |
| 383 "Test page for saving page feature.mht")); | |
| 384 SavePackageFilePicker::SetShouldPromptUser(false); | |
| 385 browser()->profile()->GetPrefs()->SetInteger( | |
| 386 prefs::kSaveFileType, content::SAVE_PAGE_TYPE_AS_MHTML); | |
| 387 ui_test_utils::WindowedNotificationObserver observer( | |
| 388 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | |
| 389 content::NotificationService::AllSources()); | |
| 390 browser()->SavePage(); | |
| 391 observer.Wait(); | |
| 392 CheckDownloadUI(full_file_name); | |
| 393 CheckDownloadHistory(url, full_file_name, 2760); | |
| 394 | |
| 395 EXPECT_TRUE(file_util::PathExists(full_file_name)); | |
| 396 int64 actual_file_size = -1; | |
| 397 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); | |
| 398 EXPECT_EQ(2760, actual_file_size); | |
| 399 } | |
| OLD | NEW |