| 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_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 bool WaitForPersisted() { | 79 bool WaitForPersisted() { |
| 80 if (persisted_) | 80 if (persisted_) |
| 81 return true; | 81 return true; |
| 82 waiting_ = true; | 82 waiting_ = true; |
| 83 content::RunMessageLoop(); | 83 content::RunMessageLoop(); |
| 84 waiting_ = false; | 84 waiting_ = false; |
| 85 return persisted_; | 85 return persisted_; |
| 86 } | 86 } |
| 87 | 87 |
| 88 virtual void OnDownloadStored(DownloadItem* item, | 88 virtual void OnDownloadStored(DownloadItem* item, |
| 89 const history::DownloadRow& info) { | 89 const history::DownloadRow& info) OVERRIDE { |
| 90 persisted_ = filter_.Run(item, info); | 90 persisted_ = filter_.Run(item, info); |
| 91 if (persisted_ && waiting_) | 91 if (persisted_ && waiting_) |
| 92 MessageLoopForUI::current()->Quit(); | 92 MessageLoopForUI::current()->Quit(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 private: | 95 private: |
| 96 Profile* profile_; | 96 Profile* profile_; |
| 97 DownloadItem* item_; | 97 DownloadItem* item_; |
| 98 PersistedFilter filter_; | 98 PersistedFilter filter_; |
| 99 bool waiting_; | 99 bool waiting_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 116 bool WaitForRemoved() { | 116 bool WaitForRemoved() { |
| 117 if (removed_) | 117 if (removed_) |
| 118 return true; | 118 return true; |
| 119 waiting_ = true; | 119 waiting_ = true; |
| 120 content::RunMessageLoop(); | 120 content::RunMessageLoop(); |
| 121 waiting_ = false; | 121 waiting_ = false; |
| 122 return removed_; | 122 return removed_; |
| 123 } | 123 } |
| 124 | 124 |
| 125 virtual void OnDownloadStored(DownloadItem* item, | 125 virtual void OnDownloadStored(DownloadItem* item, |
| 126 const history::DownloadRow& info) { | 126 const history::DownloadRow& info) OVERRIDE { |
| 127 } | 127 } |
| 128 | 128 |
| 129 virtual void OnDownloadsRemoved(const DownloadHistory::IdSet& ids) { | 129 virtual void OnDownloadsRemoved(const DownloadHistory::IdSet& ids) OVERRIDE { |
| 130 removed_ = ids.find(download_id_) != ids.end(); | 130 removed_ = ids.find(download_id_) != ids.end(); |
| 131 if (removed_ && waiting_) | 131 if (removed_ && waiting_) |
| 132 MessageLoopForUI::current()->Quit(); | 132 MessageLoopForUI::current()->Quit(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 private: | 135 private: |
| 136 bool removed_; | 136 bool removed_; |
| 137 bool waiting_; | 137 bool waiting_; |
| 138 int32 download_id_; | 138 int32 download_id_; |
| 139 | 139 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 #endif | 188 #endif |
| 189 | 189 |
| 190 // Loosely based on logic in DownloadTestObserver. | 190 // Loosely based on logic in DownloadTestObserver. |
| 191 class DownloadItemCreatedObserver : public DownloadManager::Observer { | 191 class DownloadItemCreatedObserver : public DownloadManager::Observer { |
| 192 public: | 192 public: |
| 193 explicit DownloadItemCreatedObserver(DownloadManager* manager) | 193 explicit DownloadItemCreatedObserver(DownloadManager* manager) |
| 194 : waiting_(false), manager_(manager) { | 194 : waiting_(false), manager_(manager) { |
| 195 manager->AddObserver(this); | 195 manager->AddObserver(this); |
| 196 } | 196 } |
| 197 | 197 |
| 198 ~DownloadItemCreatedObserver() { | 198 virtual ~DownloadItemCreatedObserver() { |
| 199 if (manager_) | 199 if (manager_) |
| 200 manager_->RemoveObserver(this); | 200 manager_->RemoveObserver(this); |
| 201 } | 201 } |
| 202 | 202 |
| 203 // Wait for the first download item created after object creation. | 203 // Wait for the first download item created after object creation. |
| 204 // Note that this class provides no protection against the download | 204 // Note that this class provides no protection against the download |
| 205 // being destroyed between creation and return of WaitForNewDownloadItem(); | 205 // being destroyed between creation and return of WaitForNewDownloadItem(); |
| 206 // the caller must guarantee that in some other fashion. | 206 // the caller must guarantee that in some other fashion. |
| 207 void WaitForDownloadItem(std::vector<DownloadItem*>* items_seen) { | 207 void WaitForDownloadItem(std::vector<DownloadItem*>* items_seen) { |
| 208 if (!manager_) { | 208 if (!manager_) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 277 |
| 278 DISALLOW_COPY_AND_ASSIGN(SavePackageFinishedObserver); | 278 DISALLOW_COPY_AND_ASSIGN(SavePackageFinishedObserver); |
| 279 }; | 279 }; |
| 280 | 280 |
| 281 class SavePageBrowserTest : public InProcessBrowserTest { | 281 class SavePageBrowserTest : public InProcessBrowserTest { |
| 282 public: | 282 public: |
| 283 SavePageBrowserTest() {} | 283 SavePageBrowserTest() {} |
| 284 virtual ~SavePageBrowserTest(); | 284 virtual ~SavePageBrowserTest(); |
| 285 | 285 |
| 286 protected: | 286 protected: |
| 287 void SetUp() OVERRIDE { | 287 virtual void SetUp() OVERRIDE { |
| 288 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); | 288 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); |
| 289 ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); | 289 ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); |
| 290 InProcessBrowserTest::SetUp(); | 290 InProcessBrowserTest::SetUp(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 void SetUpOnMainThread() OVERRIDE { | 293 virtual void SetUpOnMainThread() OVERRIDE { |
| 294 browser()->profile()->GetPrefs()->SetFilePath( | 294 browser()->profile()->GetPrefs()->SetFilePath( |
| 295 prefs::kDownloadDefaultDirectory, save_dir_.path()); | 295 prefs::kDownloadDefaultDirectory, save_dir_.path()); |
| 296 BrowserThread::PostTask( | 296 BrowserThread::PostTask( |
| 297 BrowserThread::IO, FROM_HERE, | 297 BrowserThread::IO, FROM_HERE, |
| 298 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 298 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
| 299 } | 299 } |
| 300 | 300 |
| 301 GURL NavigateToMockURL(const std::string& prefix) { | 301 GURL NavigateToMockURL(const std::string& prefix) { |
| 302 GURL url = URLRequestMockHTTPJob::GetMockUrl( | 302 GURL url = URLRequestMockHTTPJob::GetMockUrl( |
| 303 FilePath(kTestDir).AppendASCII(prefix + ".htm")); | 303 FilePath(kTestDir).AppendASCII(prefix + ".htm")); |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 persisted.WaitForPersisted(); | 769 persisted.WaitForPersisted(); |
| 770 | 770 |
| 771 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 771 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 772 int64 actual_file_size = -1; | 772 int64 actual_file_size = -1; |
| 773 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); | 773 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); |
| 774 EXPECT_LE(kFileSizeMin, actual_file_size); | 774 EXPECT_LE(kFileSizeMin, actual_file_size); |
| 775 } | 775 } |
| 776 | 776 |
| 777 } // namespace | 777 } // namespace |
| 778 | 778 |
| OLD | NEW |