| 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/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 Loading... |
| 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 | |
| 35 using ::testing::AtMost; | 31 using ::testing::AtMost; |
| 36 using ::testing::Invoke; | 32 using ::testing::Invoke; |
| 37 using ::testing::Ref; | 33 using ::testing::Ref; |
| 38 using ::testing::Return; | 34 using ::testing::Return; |
| 39 using ::testing::ReturnPointee; | 35 using ::testing::ReturnPointee; |
| 40 using ::testing::ReturnRef; | 36 using ::testing::ReturnRef; |
| 41 using ::testing::ReturnRefOfCopy; | 37 using ::testing::ReturnRefOfCopy; |
| 42 using ::testing::SetArgPointee; | 38 using ::testing::SetArgPointee; |
| 43 using ::testing::WithArg; | 39 using ::testing::WithArg; |
| 44 using ::testing::_; | 40 using ::testing::_; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 TestChromeDownloadManagerDelegate* delegate(); | 159 TestChromeDownloadManagerDelegate* delegate(); |
| 164 content::MockDownloadManager* download_manager(); | 160 content::MockDownloadManager* download_manager(); |
| 165 DownloadPrefs* download_prefs(); | 161 DownloadPrefs* download_prefs(); |
| 166 | 162 |
| 167 private: | 163 private: |
| 168 TestingPrefServiceSyncable* pref_service_; | 164 TestingPrefServiceSyncable* pref_service_; |
| 169 base::ScopedTempDir test_download_dir_; | 165 base::ScopedTempDir test_download_dir_; |
| 170 scoped_ptr<content::MockDownloadManager> download_manager_; | 166 scoped_ptr<content::MockDownloadManager> download_manager_; |
| 171 scoped_ptr<TestChromeDownloadManagerDelegate> delegate_; | 167 scoped_ptr<TestChromeDownloadManagerDelegate> delegate_; |
| 172 MockWebContentsDelegate web_contents_delegate_; | 168 MockWebContentsDelegate web_contents_delegate_; |
| 173 #if defined(OS_ANDROID) | |
| 174 chrome::android::MockDownloadControllerAndroid download_controller_; | |
| 175 #endif | |
| 176 | 169 |
| 177 }; | 170 }; |
| 178 | 171 |
| 179 ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest() | 172 ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest() |
| 180 : download_manager_(new ::testing::NiceMock<content::MockDownloadManager>) { | 173 : download_manager_(new ::testing::NiceMock<content::MockDownloadManager>) { |
| 181 } | 174 } |
| 182 | 175 |
| 183 void ChromeDownloadManagerDelegateTest::SetUp() { | 176 void ChromeDownloadManagerDelegateTest::SetUp() { |
| 184 ChromeRenderViewHostTestHarness::SetUp(); | 177 ChromeRenderViewHostTestHarness::SetUp(); |
| 185 | 178 |
| 186 CHECK(profile()); | 179 CHECK(profile()); |
| 187 delegate_.reset(new TestChromeDownloadManagerDelegate(profile())); | 180 delegate_.reset(new TestChromeDownloadManagerDelegate(profile())); |
| 188 delegate_->SetDownloadManager(download_manager_.get()); | 181 delegate_->SetDownloadManager(download_manager_.get()); |
| 189 pref_service_ = profile()->GetTestingPrefService(); | 182 pref_service_ = profile()->GetTestingPrefService(); |
| 190 web_contents()->SetDelegate(&web_contents_delegate_); | 183 web_contents()->SetDelegate(&web_contents_delegate_); |
| 191 | 184 |
| 192 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); | 185 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); |
| 193 SetDefaultDownloadPath(test_download_dir_.path()); | 186 SetDefaultDownloadPath(test_download_dir_.path()); |
| 194 #if defined(OS_ANDROID) | |
| 195 content::DownloadControllerAndroid::SetDownloadControllerAndroid( | |
| 196 &download_controller_); | |
| 197 #endif | |
| 198 } | 187 } |
| 199 | 188 |
| 200 void ChromeDownloadManagerDelegateTest::TearDown() { | 189 void ChromeDownloadManagerDelegateTest::TearDown() { |
| 201 base::RunLoop().RunUntilIdle(); | 190 base::RunLoop().RunUntilIdle(); |
| 202 delegate_->Shutdown(); | 191 delegate_->Shutdown(); |
| 203 #if defined(OS_ANDROID) | |
| 204 content::DownloadControllerAndroid::SetDownloadControllerAndroid(nullptr); | |
| 205 #endif | |
| 206 ChromeRenderViewHostTestHarness::TearDown(); | 192 ChromeRenderViewHostTestHarness::TearDown(); |
| 207 } | 193 } |
| 208 | 194 |
| 209 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() { | 195 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() { |
| 210 ::testing::Mock::VerifyAndClearExpectations(delegate_.get()); | 196 ::testing::Mock::VerifyAndClearExpectations(delegate_.get()); |
| 211 } | 197 } |
| 212 | 198 |
| 213 content::MockDownloadItem* | 199 content::MockDownloadItem* |
| 214 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32 id) { | 200 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32 id) { |
| 215 content::MockDownloadItem* item = | 201 content::MockDownloadItem* item = |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 CreateActiveDownloadItem(1)); | 395 CreateActiveDownloadItem(1)); |
| 410 EXPECT_CALL(*download_item, GetTargetFilePath()) | 396 EXPECT_CALL(*download_item, GetTargetFilePath()) |
| 411 .WillRepeatedly(ReturnRef(existing_path)); | 397 .WillRepeatedly(ReturnRef(existing_path)); |
| 412 EXPECT_TRUE(CheckForFileExistence(download_item.get())); | 398 EXPECT_TRUE(CheckForFileExistence(download_item.get())); |
| 413 | 399 |
| 414 download_item.reset(CreateActiveDownloadItem(1)); | 400 download_item.reset(CreateActiveDownloadItem(1)); |
| 415 EXPECT_CALL(*download_item, GetTargetFilePath()) | 401 EXPECT_CALL(*download_item, GetTargetFilePath()) |
| 416 .WillRepeatedly(ReturnRef(non_existent_path)); | 402 .WillRepeatedly(ReturnRef(non_existent_path)); |
| 417 EXPECT_FALSE(CheckForFileExistence(download_item.get())); | 403 EXPECT_FALSE(CheckForFileExistence(download_item.get())); |
| 418 } | 404 } |
| OLD | NEW |