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

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

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

Powered by Google App Engine
This is Rietveld 408576698