OLD | NEW |
---|---|
(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 private: | |
41 virtual ~MockFileChooserDownloadManagerDelegate() {} | |
42 | |
43 virtual void ChooseDownloadPath(content::DownloadItem* item, | |
benjhayden
2012/08/13 16:35:18
Why is this private?
Randy Smith (Not in Mondays)
2012/08/13 18:57:49
I didn't write the code, but I suspect the answer
| |
44 const FilePath& suggested_path, | |
45 const FileSelectedCallback& | |
46 callback) OVERRIDE { | |
47 file_chooser_displayed_ = true; | |
48 MessageLoop::current()->PostTask( | |
49 FROM_HERE, | |
50 base::Bind(callback, | |
51 (file_chooser_enabled_ ? suggested_path : FilePath()))); | |
52 } | |
53 | |
54 bool file_chooser_enabled_; | |
55 bool file_chooser_displayed_; | |
56 }; | |
57 | |
58 } // namespace internal | |
59 | |
60 DownloadTestFileChooserObserver::DownloadTestFileChooserObserver( | |
61 Profile* profile) { | |
62 test_delegate_ = | |
63 new internal::MockFileChooserDownloadManagerDelegate(profile); | |
64 DownloadServiceFactory::GetForProfile(profile)-> | |
65 SetDownloadManagerDelegateForTesting(test_delegate_.get()); | |
66 } | |
67 | |
68 DownloadTestFileChooserObserver::~DownloadTestFileChooserObserver() { | |
69 } | |
70 | |
71 void DownloadTestFileChooserObserver::EnableFileChooser(bool enable) { | |
72 test_delegate_->EnableFileChooser(enable); | |
73 } | |
74 | |
75 bool DownloadTestFileChooserObserver::TestAndResetDidShowFileChooser() { | |
76 return test_delegate_->TestAndResetDidShowFileChooser(); | |
77 } | |
78 | |
OLD | NEW |