OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
6 #include <set> | 6 #include <set> |
7 | 7 |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/i18n/number_formatting.h" | 9 #include "base/i18n/number_formatting.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 download_manager_->AddObserver(this); | 228 download_manager_->AddObserver(this); |
229 } | 229 } |
230 | 230 |
231 ~SelectFileObserver() { | 231 ~SelectFileObserver() { |
232 download_manager_->RemoveObserver(this); | 232 download_manager_->RemoveObserver(this); |
233 } | 233 } |
234 | 234 |
235 // Downloadmanager::Observer functions. | 235 // Downloadmanager::Observer functions. |
236 virtual void ModelChanged() {} | 236 virtual void ModelChanged() {} |
237 virtual void ManagerGoingDown() {} | 237 virtual void ManagerGoingDown() {} |
238 virtual void SelectFileDialogDisplayed(int32 id, | 238 virtual void SelectFileDialogDisplayed(int32 id) { |
239 const FilePath& suggested_path) { | |
240 file_dialog_ids_.insert(id); | 239 file_dialog_ids_.insert(id); |
241 } | 240 } |
242 | 241 |
243 bool ShowedFileDialogForId(int32 id) { | 242 bool ShowedFileDialogForId(int32 id) { |
244 return file_dialog_ids_.find(id) != file_dialog_ids_.end(); | 243 return file_dialog_ids_.find(id) != file_dialog_ids_.end(); |
245 } | 244 } |
246 | 245 |
247 private: | 246 private: |
248 std::set<int32> file_dialog_ids_; | 247 std::set<int32> file_dialog_ids_; |
249 scoped_refptr<DownloadManager> download_manager_; | 248 scoped_refptr<DownloadManager> download_manager_; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 DownloadItem* tracked_; | 285 DownloadItem* tracked_; |
287 int states_hit_; | 286 int states_hit_; |
288 bool was_updated_; | 287 bool was_updated_; |
289 bool was_opened_; | 288 bool was_opened_; |
290 }; | 289 }; |
291 | 290 |
292 } // namespace | 291 } // namespace |
293 | 292 |
294 TEST_F(DownloadManagerTest, StartDownload) { | 293 TEST_F(DownloadManagerTest, StartDownload) { |
295 BrowserThread io_thread(BrowserThread::IO, &message_loop_); | 294 BrowserThread io_thread(BrowserThread::IO, &message_loop_); |
296 ScopedTempDir download_save_dir; | |
297 ASSERT_TRUE(download_save_dir.CreateUniqueTempDir()); | |
298 PrefService* prefs = profile_->GetPrefs(); | 295 PrefService* prefs = profile_->GetPrefs(); |
299 prefs->SetFilePath(prefs::kDownloadDefaultDirectory, | 296 prefs->SetFilePath(prefs::kDownloadDefaultDirectory, FilePath()); |
300 download_save_dir.path()); | |
301 download_manager_->download_prefs()->EnableAutoOpenBasedOnExtension( | 297 download_manager_->download_prefs()->EnableAutoOpenBasedOnExtension( |
302 FilePath(FILE_PATH_LITERAL("example.pdf"))); | 298 FilePath(FILE_PATH_LITERAL("example.pdf"))); |
303 | 299 |
304 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kStartDownloadCases); ++i) { | 300 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kStartDownloadCases); ++i) { |
305 prefs->SetBoolean(prefs::kPromptForDownload, | 301 prefs->SetBoolean(prefs::kPromptForDownload, |
306 kStartDownloadCases[i].prompt_for_download); | 302 kStartDownloadCases[i].prompt_for_download); |
307 | 303 |
308 SelectFileObserver observer(download_manager_); | 304 SelectFileObserver observer(download_manager_); |
309 // Normally, the download system takes ownership of info, and is | 305 // Normally, the download system takes ownership of info, and is |
310 // responsible for deleting it. In these unit tests, however, we | 306 // responsible for deleting it. In these unit tests, however, we |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 708 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
713 EXPECT_TRUE(observer->was_updated()); | 709 EXPECT_TRUE(observer->was_updated()); |
714 EXPECT_FALSE(observer->was_opened()); | 710 EXPECT_FALSE(observer->was_opened()); |
715 EXPECT_TRUE(download->file_externally_removed()); | 711 EXPECT_TRUE(download->file_externally_removed()); |
716 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); | 712 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); |
717 EXPECT_EQ(download_item_model->GetStatusText(), | 713 EXPECT_EQ(download_item_model->GetStatusText(), |
718 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); | 714 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); |
719 | 715 |
720 EXPECT_FALSE(file_util::PathExists(new_path)); | 716 EXPECT_FALSE(file_util::PathExists(new_path)); |
721 } | 717 } |
OLD | NEW |