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

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: Added URLRequestMockHTTPJob.test_dir_ and URLRequestMockHTTPJob.temp_dir_ 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
239 file_dialog_ids_.insert(id); 240 file_dialog_ids_.insert(id);
240 } 241 }
241 242
242 bool ShowedFileDialogForId(int32 id) { 243 bool ShowedFileDialogForId(int32 id) {
243 return file_dialog_ids_.find(id) != file_dialog_ids_.end(); 244 return file_dialog_ids_.find(id) != file_dialog_ids_.end();
244 } 245 }
245 246
246 private: 247 private:
247 std::set<int32> file_dialog_ids_; 248 std::set<int32> file_dialog_ids_;
248 scoped_refptr<DownloadManager> download_manager_; 249 scoped_refptr<DownloadManager> download_manager_;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 DownloadItem* tracked_; 286 DownloadItem* tracked_;
286 int states_hit_; 287 int states_hit_;
287 bool was_updated_; 288 bool was_updated_;
288 bool was_opened_; 289 bool was_opened_;
289 }; 290 };
290 291
291 } // namespace 292 } // namespace
292 293
293 TEST_F(DownloadManagerTest, StartDownload) { 294 TEST_F(DownloadManagerTest, StartDownload) {
294 BrowserThread io_thread(BrowserThread::IO, &message_loop_); 295 BrowserThread io_thread(BrowserThread::IO, &message_loop_);
296 ScopedTempDir download_save_dir;
297 ASSERT_TRUE(download_save_dir.CreateUniqueTempDir());
295 PrefService* prefs = profile_->GetPrefs(); 298 PrefService* prefs = profile_->GetPrefs();
296 prefs->SetFilePath(prefs::kDownloadDefaultDirectory, FilePath()); 299 prefs->SetFilePath(prefs::kDownloadDefaultDirectory,
300 download_save_dir.path());
297 download_manager_->download_prefs()->EnableAutoOpenBasedOnExtension( 301 download_manager_->download_prefs()->EnableAutoOpenBasedOnExtension(
298 FilePath(FILE_PATH_LITERAL("example.pdf"))); 302 FilePath(FILE_PATH_LITERAL("example.pdf")));
299 303
300 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kStartDownloadCases); ++i) { 304 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kStartDownloadCases); ++i) {
301 prefs->SetBoolean(prefs::kPromptForDownload, 305 prefs->SetBoolean(prefs::kPromptForDownload,
302 kStartDownloadCases[i].prompt_for_download); 306 kStartDownloadCases[i].prompt_for_download);
303 307
304 SelectFileObserver observer(download_manager_); 308 SelectFileObserver observer(download_manager_);
305 // Normally, the download system takes ownership of info, and is 309 // Normally, the download system takes ownership of info, and is
306 // responsible for deleting it. In these unit tests, however, we 310 // responsible for deleting it. In these unit tests, however, we
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); 712 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING));
709 EXPECT_TRUE(observer->was_updated()); 713 EXPECT_TRUE(observer->was_updated());
710 EXPECT_FALSE(observer->was_opened()); 714 EXPECT_FALSE(observer->was_opened());
711 EXPECT_TRUE(download->file_externally_removed()); 715 EXPECT_TRUE(download->file_externally_removed());
712 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); 716 EXPECT_EQ(DownloadItem::COMPLETE, download->state());
713 EXPECT_EQ(download_item_model->GetStatusText(), 717 EXPECT_EQ(download_item_model->GetStatusText(),
714 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); 718 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED));
715 719
716 EXPECT_FALSE(file_util::PathExists(new_path)); 720 EXPECT_FALSE(file_util::PathExists(new_path));
717 } 721 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698