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

Side by Side Diff: content/public/test/download_test_observer.h

Issue 10855116: Move DownloadTestObserver and friends down into content. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
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 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ 5 #ifndef CONTENT_TEST_DOWNLOAD_TEST_OBSERVER_H_
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ 6 #define CONTENT_TEST_DOWNLOAD_TEST_OBSERVER_H_
7 7
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "content/public/browser/download_item.h" 13 #include "content/public/browser/download_item.h"
14 #include "content/public/browser/download_manager.h" 14 #include "content/public/browser/download_manager.h"
15 #include "content/public/browser/download_url_parameters.h" 15 #include "content/public/browser/download_url_parameters.h"
16 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
17 17
18 namespace internal { 18 namespace content {
19 class MockFileChooserDownloadManagerDelegate;
20 }
21
22 class Profile;
23 19
24 // Detects changes to the downloads after construction. 20 // Detects changes to the downloads after construction.
25 // Finishes when one of the following happens: 21 // Finishes when one of the following happens:
26 // - A specified number of downloads change to a terminal state (defined 22 // - A specified number of downloads change to a terminal state (defined
27 // in derived classes). 23 // in derived classes).
28 // - Specific events, such as a select file dialog. 24 // - Specific events, such as a select file dialog.
29 // Callers may either probe for the finished state, or wait on it. 25 // Callers may either probe for the finished state, or wait on it.
30 // 26 //
31 // TODO(rdsmith): Detect manager going down, remove pointer to 27 // TODO(rdsmith): Detect manager going down, remove pointer to
32 // DownloadManager, transition to finished. (For right now we 28 // DownloadManager, transition to finished. (For right now we
33 // just use a scoped_refptr<> to keep it around, but that may cause 29 // just use a scoped_refptr<> to keep it around, but that may cause
34 // timeouts on waiting if a DownloadManager::Shutdown() occurs which 30 // timeouts on waiting if a DownloadManager::Shutdown() occurs which
35 // cancels our in-progress downloads.) 31 // cancels our in-progress downloads.)
36 class DownloadTestObserver : public content::DownloadManager::Observer, 32 class DownloadTestObserver : public content::DownloadManager::Observer,
jam 2012/08/13 16:00:21 nit: get rid of content:: everywhere
Randy Smith (Not in Mondays) 2012/08/13 18:57:49 Done.
37 public content::DownloadItem::Observer { 33 public content::DownloadItem::Observer {
38 public: 34 public:
39 // Action an observer should take if a dangerous download is encountered. 35 // Action an observer should take if a dangerous download is encountered.
40 enum DangerousDownloadAction { 36 enum DangerousDownloadAction {
41 ON_DANGEROUS_DOWNLOAD_ACCEPT, // Accept the download 37 ON_DANGEROUS_DOWNLOAD_ACCEPT, // Accept the download
42 ON_DANGEROUS_DOWNLOAD_DENY, // Deny the download 38 ON_DANGEROUS_DOWNLOAD_DENY, // Deny the download
43 ON_DANGEROUS_DOWNLOAD_FAIL // Fail if a dangerous download is seen 39 ON_DANGEROUS_DOWNLOAD_FAIL // Fail if a dangerous download is seen
44 }; 40 };
45 41
46 // Create an object that will be considered finished when |wait_count| 42 // Create an object that will be considered finished when |wait_count|
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 255
260 // Count of callbacks. 256 // Count of callbacks.
261 size_t called_back_count_; 257 size_t called_back_count_;
262 258
263 // We are in the message loop. 259 // We are in the message loop.
264 bool waiting_; 260 bool waiting_;
265 261
266 DISALLOW_COPY_AND_ASSIGN(DownloadTestItemCreationObserver); 262 DISALLOW_COPY_AND_ASSIGN(DownloadTestItemCreationObserver);
267 }; 263 };
268 264
269 // Observes and overrides file chooser activity for a profile. By default, once 265 } // namespace content`
270 // attached to a profile, this class overrides the default file chooser by
271 // replacing the ChromeDownloadManagerDelegate associated with |profile|.
272 // NOTE: Again, this overrides the ChromeDownloadManagerDelegate for |profile|.
273 class DownloadTestFileChooserObserver {
274 public:
275 // Attaches to |profile|. By default file chooser dialogs will be disabled
276 // once attached. Call EnableFileChooser() to re-enable.
277 explicit DownloadTestFileChooserObserver(Profile* profile);
278 ~DownloadTestFileChooserObserver();
279 266
280 // Sets whether the file chooser dialog is enabled. If |enable| is false, any 267 #endif // CONTENT_TEST_DOWNLOAD_TEST_OBSERVER_H_
281 // attempt to display a file chooser dialog will cause the download to be
282 // canceled. Otherwise, attempting to display a file chooser dialog will
283 // result in the download continuing with the suggested path.
284 void EnableFileChooser(bool enable);
285
286 // Returns true if a file chooser dialog was displayed since the last time
287 // this method was called.
288 bool TestAndResetDidShowFileChooser();
289
290 private:
291 scoped_refptr<internal::MockFileChooserDownloadManagerDelegate>
292 test_delegate_;
293 };
294
295 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698