OLD | NEW |
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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 67 } |
68 | 68 |
69 // Subclass of the ChromeDownloadManagerDelegate that uses a mock | 69 // Subclass of the ChromeDownloadManagerDelegate that uses a mock |
70 // DownloadProtectionService. | 70 // DownloadProtectionService. |
71 class TestChromeDownloadManagerDelegate : public ChromeDownloadManagerDelegate { | 71 class TestChromeDownloadManagerDelegate : public ChromeDownloadManagerDelegate { |
72 public: | 72 public: |
73 explicit TestChromeDownloadManagerDelegate(Profile* profile) | 73 explicit TestChromeDownloadManagerDelegate(Profile* profile) |
74 : ChromeDownloadManagerDelegate(profile) { | 74 : ChromeDownloadManagerDelegate(profile) { |
75 } | 75 } |
76 | 76 |
77 virtual ~TestChromeDownloadManagerDelegate() {} | 77 ~TestChromeDownloadManagerDelegate() override {} |
78 | 78 |
79 virtual safe_browsing::DownloadProtectionService* | 79 safe_browsing::DownloadProtectionService* |
80 GetDownloadProtectionService() override { | 80 GetDownloadProtectionService() override { |
81 return NULL; | 81 return NULL; |
82 } | 82 } |
83 | 83 |
84 virtual void NotifyExtensions( | 84 void NotifyExtensions(content::DownloadItem* download, |
85 content::DownloadItem* download, | 85 const base::FilePath& suggested_virtual_path, |
86 const base::FilePath& suggested_virtual_path, | 86 const NotifyExtensionsCallback& callback) override { |
87 const NotifyExtensionsCallback& callback) override { | |
88 callback.Run(base::FilePath(), | 87 callback.Run(base::FilePath(), |
89 DownloadPathReservationTracker::UNIQUIFY); | 88 DownloadPathReservationTracker::UNIQUIFY); |
90 } | 89 } |
91 | 90 |
92 virtual void ReserveVirtualPath( | 91 void ReserveVirtualPath( |
93 content::DownloadItem* download, | 92 content::DownloadItem* download, |
94 const base::FilePath& virtual_path, | 93 const base::FilePath& virtual_path, |
95 bool create_directory, | 94 bool create_directory, |
96 DownloadPathReservationTracker::FilenameConflictAction conflict_action, | 95 DownloadPathReservationTracker::FilenameConflictAction conflict_action, |
97 const DownloadPathReservationTracker::ReservedPathCallback& callback) | 96 const DownloadPathReservationTracker::ReservedPathCallback& callback) |
98 override { | 97 override { |
99 // Pretend the path reservation succeeded without any change to | 98 // Pretend the path reservation succeeded without any change to |
100 // |target_path|. | 99 // |target_path|. |
101 base::MessageLoop::current()->PostTask( | 100 base::MessageLoop::current()->PostTask( |
102 FROM_HERE, base::Bind(callback, virtual_path, true)); | 101 FROM_HERE, base::Bind(callback, virtual_path, true)); |
103 } | 102 } |
104 | 103 |
105 virtual void PromptUserForDownloadPath( | 104 void PromptUserForDownloadPath( |
106 DownloadItem* download, | 105 DownloadItem* download, |
107 const base::FilePath& suggested_path, | 106 const base::FilePath& suggested_path, |
108 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) | 107 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) |
109 override { | 108 override { |
110 base::FilePath return_path = MockPromptUserForDownloadPath(download, | 109 base::FilePath return_path = MockPromptUserForDownloadPath(download, |
111 suggested_path, | 110 suggested_path, |
112 callback); | 111 callback); |
113 callback.Run(return_path); | 112 callback.Run(return_path); |
114 } | 113 } |
115 | 114 |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 CreateActiveDownloadItem(1)); | 391 CreateActiveDownloadItem(1)); |
393 EXPECT_CALL(*download_item, GetTargetFilePath()) | 392 EXPECT_CALL(*download_item, GetTargetFilePath()) |
394 .WillRepeatedly(ReturnRef(existing_path)); | 393 .WillRepeatedly(ReturnRef(existing_path)); |
395 EXPECT_TRUE(CheckForFileExistence(download_item.get())); | 394 EXPECT_TRUE(CheckForFileExistence(download_item.get())); |
396 | 395 |
397 download_item.reset(CreateActiveDownloadItem(1)); | 396 download_item.reset(CreateActiveDownloadItem(1)); |
398 EXPECT_CALL(*download_item, GetTargetFilePath()) | 397 EXPECT_CALL(*download_item, GetTargetFilePath()) |
399 .WillRepeatedly(ReturnRef(non_existent_path)); | 398 .WillRepeatedly(ReturnRef(non_existent_path)); |
400 EXPECT_FALSE(CheckForFileExistence(download_item.get())); | 399 EXPECT_FALSE(CheckForFileExistence(download_item.get())); |
401 } | 400 } |
OLD | NEW |