Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1455)

Side by Side Diff: chrome/browser/download/download_manager_unittest.cc

Issue 6973052: When the download folder does not exist, change the download folder to a user's "Downloads" (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Redirect "http://mock.testfile.http/<random path>" to "chrome/test/data/a.htm" Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 download_manager_->AddObserver(this); 233 download_manager_->AddObserver(this);
234 } 234 }
235 235
236 ~SelectFileObserver() { 236 ~SelectFileObserver() {
237 download_manager_->RemoveObserver(this); 237 download_manager_->RemoveObserver(this);
238 } 238 }
239 239
240 // Downloadmanager::Observer functions. 240 // Downloadmanager::Observer functions.
241 virtual void ModelChanged() {} 241 virtual void ModelChanged() {}
242 virtual void ManagerGoingDown() {} 242 virtual void ManagerGoingDown() {}
243 virtual void SelectFileDialogDisplayed(int32 id) { 243 virtual void SelectFileDialogDisplayed(int32 id,
244 const FilePath& suggested_path) {
244 file_dialog_ids_.insert(id); 245 file_dialog_ids_.insert(id);
245 } 246 }
246 247
247 bool ShowedFileDialogForId(int32 id) { 248 bool ShowedFileDialogForId(int32 id) {
248 return file_dialog_ids_.find(id) != file_dialog_ids_.end(); 249 return file_dialog_ids_.find(id) != file_dialog_ids_.end();
249 } 250 }
250 251
251 private: 252 private:
252 std::set<int32> file_dialog_ids_; 253 std::set<int32> file_dialog_ids_;
253 scoped_refptr<DownloadManager> download_manager_; 254 scoped_refptr<DownloadManager> download_manager_;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 DownloadItem* tracked_; 291 DownloadItem* tracked_;
291 int states_hit_; 292 int states_hit_;
292 bool was_updated_; 293 bool was_updated_;
293 bool was_opened_; 294 bool was_opened_;
294 }; 295 };
295 296
296 } // namespace 297 } // namespace
297 298
298 TEST_F(DownloadManagerTest, StartDownload) { 299 TEST_F(DownloadManagerTest, StartDownload) {
299 BrowserThread io_thread(BrowserThread::IO, &message_loop_); 300 BrowserThread io_thread(BrowserThread::IO, &message_loop_);
301 ScopedTempDir download_save_dir;
302 ASSERT_TRUE(download_save_dir.CreateUniqueTempDir());
300 PrefService* prefs = profile_->GetPrefs(); 303 PrefService* prefs = profile_->GetPrefs();
301 prefs->SetFilePath(prefs::kDownloadDefaultDirectory, FilePath()); 304 prefs->SetFilePath(prefs::kDownloadDefaultDirectory,
305 download_save_dir.path());
302 download_manager_->download_prefs()->EnableAutoOpenBasedOnExtension( 306 download_manager_->download_prefs()->EnableAutoOpenBasedOnExtension(
303 FilePath(FILE_PATH_LITERAL("example.pdf"))); 307 FilePath(FILE_PATH_LITERAL("example.pdf")));
304 308
305 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kStartDownloadCases); ++i) { 309 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kStartDownloadCases); ++i) {
306 prefs->SetBoolean(prefs::kPromptForDownload, 310 prefs->SetBoolean(prefs::kPromptForDownload,
307 kStartDownloadCases[i].prompt_for_download); 311 kStartDownloadCases[i].prompt_for_download);
308 312
309 SelectFileObserver observer(download_manager_); 313 SelectFileObserver observer(download_manager_);
310 // Normally, the download system takes ownership of info, and is 314 // Normally, the download system takes ownership of info, and is
311 // responsible for deleting it. In these unit tests, however, we 315 // responsible for deleting it. In these unit tests, however, we
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); 717 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING));
714 EXPECT_TRUE(observer->was_updated()); 718 EXPECT_TRUE(observer->was_updated());
715 EXPECT_FALSE(observer->was_opened()); 719 EXPECT_FALSE(observer->was_opened());
716 EXPECT_TRUE(download->file_externally_removed()); 720 EXPECT_TRUE(download->file_externally_removed());
717 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); 721 EXPECT_EQ(DownloadItem::COMPLETE, download->state());
718 EXPECT_EQ(download_item_model->GetStatusText(), 722 EXPECT_EQ(download_item_model->GetStatusText(),
719 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); 723 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED));
720 724
721 EXPECT_FALSE(file_util::PathExists(new_path)); 725 EXPECT_FALSE(file_util::PathExists(new_path));
722 } 726 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698