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

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

Issue 12047039: download: Remove DownloadManager::MockDownloadOpenForTesting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and comment fix Created 7 years, 10 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) 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 "chrome/browser/download/download_test_file_chooser_observer.h" 5 #include "chrome/browser/download/download_test_file_activity_observer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "chrome/browser/download/chrome_download_manager_delegate.h" 9 #include "chrome/browser/download/chrome_download_manager_delegate.h"
10 #include "chrome/browser/download/download_service.h" 10 #include "chrome/browser/download/download_service.h"
11 #include "chrome/browser/download/download_service_factory.h" 11 #include "chrome/browser/download/download_service_factory.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 13
14 namespace content { 14 namespace content {
15 class DownloadItem; 15 class DownloadItem;
16 } 16 }
17 17
18 namespace internal {
19
20 // Test ChromeDownloadManagerDelegate that controls whether how file chooser 18 // Test ChromeDownloadManagerDelegate that controls whether how file chooser
21 // dialogs are handled. By default, file chooser dialogs are disabled. 19 // dialogs are handled, and how files are opend.
22 class MockFileChooserDownloadManagerDelegate 20 // By default, file chooser dialogs are disabled.
21 class DownloadTestFileActivityObserver::MockDownloadManagerDelegate
23 : public ChromeDownloadManagerDelegate { 22 : public ChromeDownloadManagerDelegate {
24 public: 23 public:
25 explicit MockFileChooserDownloadManagerDelegate(Profile* profile) 24 explicit MockDownloadManagerDelegate(Profile* profile)
26 : ChromeDownloadManagerDelegate(profile), 25 : ChromeDownloadManagerDelegate(profile),
27 file_chooser_enabled_(false), 26 file_chooser_enabled_(false),
28 file_chooser_displayed_(false) {} 27 file_chooser_displayed_(false) {}
29 28
30 void EnableFileChooser(bool enable) { 29 void EnableFileChooser(bool enable) {
31 file_chooser_enabled_ = enable; 30 file_chooser_enabled_ = enable;
32 } 31 }
33 32
34 bool TestAndResetDidShowFileChooser() { 33 bool TestAndResetDidShowFileChooser() {
35 bool did_show = file_chooser_displayed_; 34 bool did_show = file_chooser_displayed_;
36 file_chooser_displayed_ = false; 35 file_chooser_displayed_ = false;
37 return did_show; 36 return did_show;
38 } 37 }
39 38
40 protected: 39 protected:
41 40
42 virtual void ChooseDownloadPath(content::DownloadItem* item, 41 virtual void ChooseDownloadPath(content::DownloadItem* item,
43 const FilePath& suggested_path, 42 const FilePath& suggested_path,
44 const FileSelectedCallback& 43 const FileSelectedCallback&
45 callback) OVERRIDE { 44 callback) OVERRIDE {
46 file_chooser_displayed_ = true; 45 file_chooser_displayed_ = true;
47 MessageLoop::current()->PostTask( 46 MessageLoop::current()->PostTask(
48 FROM_HERE, 47 FROM_HERE,
49 base::Bind(callback, 48 base::Bind(callback,
50 (file_chooser_enabled_ ? suggested_path : FilePath()))); 49 (file_chooser_enabled_ ? suggested_path : FilePath())));
51 } 50 }
52 51
52 virtual void OpenDownload(content::DownloadItem* item) OVERRIDE {}
53
53 private: 54 private:
54 virtual ~MockFileChooserDownloadManagerDelegate() {} 55 virtual ~MockDownloadManagerDelegate() {}
55 56
56 bool file_chooser_enabled_; 57 bool file_chooser_enabled_;
57 bool file_chooser_displayed_; 58 bool file_chooser_displayed_;
58 }; 59 };
59 60
60 } // namespace internal 61 DownloadTestFileActivityObserver::DownloadTestFileActivityObserver(
61
62 DownloadTestFileChooserObserver::DownloadTestFileChooserObserver(
63 Profile* profile) { 62 Profile* profile) {
64 test_delegate_ = 63 test_delegate_ = new MockDownloadManagerDelegate(profile);
65 new internal::MockFileChooserDownloadManagerDelegate(profile);
66 DownloadServiceFactory::GetForProfile(profile)-> 64 DownloadServiceFactory::GetForProfile(profile)->
67 SetDownloadManagerDelegateForTesting(test_delegate_.get()); 65 SetDownloadManagerDelegateForTesting(test_delegate_.get());
68 } 66 }
69 67
70 DownloadTestFileChooserObserver::~DownloadTestFileChooserObserver() { 68 DownloadTestFileActivityObserver::~DownloadTestFileActivityObserver() {
71 } 69 }
72 70
73 void DownloadTestFileChooserObserver::EnableFileChooser(bool enable) { 71 void DownloadTestFileActivityObserver::EnableFileChooser(bool enable) {
74 test_delegate_->EnableFileChooser(enable); 72 test_delegate_->EnableFileChooser(enable);
75 } 73 }
76 74
77 bool DownloadTestFileChooserObserver::TestAndResetDidShowFileChooser() { 75 bool DownloadTestFileActivityObserver::TestAndResetDidShowFileChooser() {
78 return test_delegate_->TestAndResetDidShowFileChooser(); 76 return test_delegate_->TestAndResetDidShowFileChooser();
79 } 77 }
80
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698