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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 virtual ~TestChromeDownloadManagerDelegate() {} |
78 | 78 |
79 virtual safe_browsing::DownloadProtectionService* | 79 virtual safe_browsing::DownloadProtectionService* |
80 GetDownloadProtectionService() OVERRIDE { | 80 GetDownloadProtectionService() override { |
81 return NULL; | 81 return NULL; |
82 } | 82 } |
83 | 83 |
84 virtual void NotifyExtensions( | 84 virtual void NotifyExtensions( |
85 content::DownloadItem* download, | 85 content::DownloadItem* download, |
86 const base::FilePath& suggested_virtual_path, | 86 const base::FilePath& suggested_virtual_path, |
87 const NotifyExtensionsCallback& callback) OVERRIDE { | 87 const NotifyExtensionsCallback& callback) override { |
88 callback.Run(base::FilePath(), | 88 callback.Run(base::FilePath(), |
89 DownloadPathReservationTracker::UNIQUIFY); | 89 DownloadPathReservationTracker::UNIQUIFY); |
90 } | 90 } |
91 | 91 |
92 virtual void ReserveVirtualPath( | 92 virtual void ReserveVirtualPath( |
93 content::DownloadItem* download, | 93 content::DownloadItem* download, |
94 const base::FilePath& virtual_path, | 94 const base::FilePath& virtual_path, |
95 bool create_directory, | 95 bool create_directory, |
96 DownloadPathReservationTracker::FilenameConflictAction conflict_action, | 96 DownloadPathReservationTracker::FilenameConflictAction conflict_action, |
97 const DownloadPathReservationTracker::ReservedPathCallback& callback) | 97 const DownloadPathReservationTracker::ReservedPathCallback& callback) |
98 OVERRIDE { | 98 override { |
99 // Pretend the path reservation succeeded without any change to | 99 // Pretend the path reservation succeeded without any change to |
100 // |target_path|. | 100 // |target_path|. |
101 base::MessageLoop::current()->PostTask( | 101 base::MessageLoop::current()->PostTask( |
102 FROM_HERE, base::Bind(callback, virtual_path, true)); | 102 FROM_HERE, base::Bind(callback, virtual_path, true)); |
103 } | 103 } |
104 | 104 |
105 virtual void PromptUserForDownloadPath( | 105 virtual void PromptUserForDownloadPath( |
106 DownloadItem* download, | 106 DownloadItem* download, |
107 const base::FilePath& suggested_path, | 107 const base::FilePath& suggested_path, |
108 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) | 108 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) |
109 OVERRIDE { | 109 override { |
110 base::FilePath return_path = MockPromptUserForDownloadPath(download, | 110 base::FilePath return_path = MockPromptUserForDownloadPath(download, |
111 suggested_path, | 111 suggested_path, |
112 callback); | 112 callback); |
113 callback.Run(return_path); | 113 callback.Run(return_path); |
114 } | 114 } |
115 | 115 |
116 MOCK_METHOD3( | 116 MOCK_METHOD3( |
117 MockPromptUserForDownloadPath, | 117 MockPromptUserForDownloadPath, |
118 base::FilePath( | 118 base::FilePath( |
119 content::DownloadItem*, | 119 content::DownloadItem*, |
120 const base::FilePath&, | 120 const base::FilePath&, |
121 const DownloadTargetDeterminerDelegate::FileSelectedCallback&)); | 121 const DownloadTargetDeterminerDelegate::FileSelectedCallback&)); |
122 }; | 122 }; |
123 | 123 |
124 class ChromeDownloadManagerDelegateTest | 124 class ChromeDownloadManagerDelegateTest |
125 : public ChromeRenderViewHostTestHarness { | 125 : public ChromeRenderViewHostTestHarness { |
126 public: | 126 public: |
127 ChromeDownloadManagerDelegateTest(); | 127 ChromeDownloadManagerDelegateTest(); |
128 | 128 |
129 // ::testing::Test | 129 // ::testing::Test |
130 virtual void SetUp() OVERRIDE; | 130 virtual void SetUp() override; |
131 virtual void TearDown() OVERRIDE; | 131 virtual void TearDown() override; |
132 | 132 |
133 // Verifies and clears test expectations for |delegate_| and | 133 // Verifies and clears test expectations for |delegate_| and |
134 // |download_manager_|. | 134 // |download_manager_|. |
135 void VerifyAndClearExpectations(); | 135 void VerifyAndClearExpectations(); |
136 | 136 |
137 // Creates MockDownloadItem and sets up default expectations. | 137 // Creates MockDownloadItem and sets up default expectations. |
138 content::MockDownloadItem* CreateActiveDownloadItem(int32 id); | 138 content::MockDownloadItem* CreateActiveDownloadItem(int32 id); |
139 | 139 |
140 // Given the relative path |path|, returns the full path under the temporary | 140 // Given the relative path |path|, returns the full path under the temporary |
141 // downloads directory. | 141 // downloads directory. |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 CreateActiveDownloadItem(1)); | 392 CreateActiveDownloadItem(1)); |
393 EXPECT_CALL(*download_item, GetTargetFilePath()) | 393 EXPECT_CALL(*download_item, GetTargetFilePath()) |
394 .WillRepeatedly(ReturnRef(existing_path)); | 394 .WillRepeatedly(ReturnRef(existing_path)); |
395 EXPECT_TRUE(CheckForFileExistence(download_item.get())); | 395 EXPECT_TRUE(CheckForFileExistence(download_item.get())); |
396 | 396 |
397 download_item.reset(CreateActiveDownloadItem(1)); | 397 download_item.reset(CreateActiveDownloadItem(1)); |
398 EXPECT_CALL(*download_item, GetTargetFilePath()) | 398 EXPECT_CALL(*download_item, GetTargetFilePath()) |
399 .WillRepeatedly(ReturnRef(non_existent_path)); | 399 .WillRepeatedly(ReturnRef(non_existent_path)); |
400 EXPECT_FALSE(CheckForFileExistence(download_item.get())); | 400 EXPECT_FALSE(CheckForFileExistence(download_item.get())); |
401 } | 401 } |
OLD | NEW |