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

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

Issue 1217223006: Prompt user for file access permission before download starts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 5 years, 5 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
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 #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/location.h" 8 #include "base/location.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 10 matching lines...) Expand all
21 #include "content/public/browser/download_interrupt_reasons.h" 21 #include "content/public/browser/download_interrupt_reasons.h"
22 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
23 #include "content/public/browser/web_contents_delegate.h" 23 #include "content/public/browser/web_contents_delegate.h"
24 #include "content/public/test/mock_download_item.h" 24 #include "content/public/test/mock_download_item.h"
25 #include "content/public/test/mock_download_manager.h" 25 #include "content/public/test/mock_download_manager.h"
26 #include "content/public/test/test_renderer_host.h" 26 #include "content/public/test/test_renderer_host.h"
27 #include "content/public/test/web_contents_tester.h" 27 #include "content/public/test/web_contents_tester.h"
28 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
30 30
31 #if defined(OS_ANDROID)
32 #include "chrome/browser/android/download/mock_download_controller_android.h"
33 #endif
34
31 using ::testing::AtMost; 35 using ::testing::AtMost;
32 using ::testing::Invoke; 36 using ::testing::Invoke;
33 using ::testing::Ref; 37 using ::testing::Ref;
34 using ::testing::Return; 38 using ::testing::Return;
35 using ::testing::ReturnPointee; 39 using ::testing::ReturnPointee;
36 using ::testing::ReturnRef; 40 using ::testing::ReturnRef;
37 using ::testing::ReturnRefOfCopy; 41 using ::testing::ReturnRefOfCopy;
38 using ::testing::SetArgPointee; 42 using ::testing::SetArgPointee;
39 using ::testing::WithArg; 43 using ::testing::WithArg;
40 using ::testing::_; 44 using ::testing::_;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 TestChromeDownloadManagerDelegate* delegate(); 163 TestChromeDownloadManagerDelegate* delegate();
160 content::MockDownloadManager* download_manager(); 164 content::MockDownloadManager* download_manager();
161 DownloadPrefs* download_prefs(); 165 DownloadPrefs* download_prefs();
162 166
163 private: 167 private:
164 TestingPrefServiceSyncable* pref_service_; 168 TestingPrefServiceSyncable* pref_service_;
165 base::ScopedTempDir test_download_dir_; 169 base::ScopedTempDir test_download_dir_;
166 scoped_ptr<content::MockDownloadManager> download_manager_; 170 scoped_ptr<content::MockDownloadManager> download_manager_;
167 scoped_ptr<TestChromeDownloadManagerDelegate> delegate_; 171 scoped_ptr<TestChromeDownloadManagerDelegate> delegate_;
168 MockWebContentsDelegate web_contents_delegate_; 172 MockWebContentsDelegate web_contents_delegate_;
173 #if defined(OS_ANDROID)
174 chrome::android::MockDownloadControllerAndroid download_controller_;
175 #endif
176
169 }; 177 };
170 178
171 ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest() 179 ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest()
172 : download_manager_(new ::testing::NiceMock<content::MockDownloadManager>) { 180 : download_manager_(new ::testing::NiceMock<content::MockDownloadManager>) {
173 } 181 }
174 182
175 void ChromeDownloadManagerDelegateTest::SetUp() { 183 void ChromeDownloadManagerDelegateTest::SetUp() {
176 ChromeRenderViewHostTestHarness::SetUp(); 184 ChromeRenderViewHostTestHarness::SetUp();
177 185
178 CHECK(profile()); 186 CHECK(profile());
179 delegate_.reset(new TestChromeDownloadManagerDelegate(profile())); 187 delegate_.reset(new TestChromeDownloadManagerDelegate(profile()));
180 delegate_->SetDownloadManager(download_manager_.get()); 188 delegate_->SetDownloadManager(download_manager_.get());
181 pref_service_ = profile()->GetTestingPrefService(); 189 pref_service_ = profile()->GetTestingPrefService();
182 web_contents()->SetDelegate(&web_contents_delegate_); 190 web_contents()->SetDelegate(&web_contents_delegate_);
183 191
184 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); 192 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir());
185 SetDefaultDownloadPath(test_download_dir_.path()); 193 SetDefaultDownloadPath(test_download_dir_.path());
194 #if defined(OS_ANDROID)
195 content::DownloadControllerAndroid::SetDownloadControllerAndroid(
196 &download_controller_);
197 #endif
186 } 198 }
187 199
188 void ChromeDownloadManagerDelegateTest::TearDown() { 200 void ChromeDownloadManagerDelegateTest::TearDown() {
189 base::RunLoop().RunUntilIdle(); 201 base::RunLoop().RunUntilIdle();
190 delegate_->Shutdown(); 202 delegate_->Shutdown();
203 #if defined(OS_ANDROID)
204 content::DownloadControllerAndroid::SetDownloadControllerAndroid(nullptr);
205 #endif
191 ChromeRenderViewHostTestHarness::TearDown(); 206 ChromeRenderViewHostTestHarness::TearDown();
192 } 207 }
193 208
194 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() { 209 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() {
195 ::testing::Mock::VerifyAndClearExpectations(delegate_.get()); 210 ::testing::Mock::VerifyAndClearExpectations(delegate_.get());
196 } 211 }
197 212
198 content::MockDownloadItem* 213 content::MockDownloadItem*
199 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32 id) { 214 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32 id) {
200 content::MockDownloadItem* item = 215 content::MockDownloadItem* item =
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 CreateActiveDownloadItem(1)); 409 CreateActiveDownloadItem(1));
395 EXPECT_CALL(*download_item, GetTargetFilePath()) 410 EXPECT_CALL(*download_item, GetTargetFilePath())
396 .WillRepeatedly(ReturnRef(existing_path)); 411 .WillRepeatedly(ReturnRef(existing_path));
397 EXPECT_TRUE(CheckForFileExistence(download_item.get())); 412 EXPECT_TRUE(CheckForFileExistence(download_item.get()));
398 413
399 download_item.reset(CreateActiveDownloadItem(1)); 414 download_item.reset(CreateActiveDownloadItem(1));
400 EXPECT_CALL(*download_item, GetTargetFilePath()) 415 EXPECT_CALL(*download_item, GetTargetFilePath())
401 .WillRepeatedly(ReturnRef(non_existent_path)); 416 .WillRepeatedly(ReturnRef(non_existent_path));
402 EXPECT_FALSE(CheckForFileExistence(download_item.get())); 417 EXPECT_FALSE(CheckForFileExistence(download_item.get()));
403 } 418 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698