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/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/observer_list.h" | 8 #include "base/observer_list.h" |
9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 EXPECT_CALL(*download_manager_, GetAllDownloads(_)).WillRepeatedly(Return()); | 297 EXPECT_CALL(*download_manager_, GetAllDownloads(_)).WillRepeatedly(Return()); |
298 EXPECT_CALL(*download_manager_, AddObserver(_)).WillRepeatedly(Return()); | 298 EXPECT_CALL(*download_manager_, AddObserver(_)).WillRepeatedly(Return()); |
299 EXPECT_CALL(*download_manager_, RemoveObserver(_)).WillRepeatedly(Return()); | 299 EXPECT_CALL(*download_manager_, RemoveObserver(_)).WillRepeatedly(Return()); |
300 } | 300 } |
301 | 301 |
302 void ChromeDownloadManagerDelegateTest::SetUp() { | 302 void ChromeDownloadManagerDelegateTest::SetUp() { |
303 ChromeRenderViewHostTestHarness::SetUp(); | 303 ChromeRenderViewHostTestHarness::SetUp(); |
304 | 304 |
305 CHECK(profile()); | 305 CHECK(profile()); |
306 delegate_ = new TestChromeDownloadManagerDelegate(profile()); | 306 delegate_ = new TestChromeDownloadManagerDelegate(profile()); |
| 307 EXPECT_CALL(*download_manager_.get(), GetAllDownloads(_)) |
| 308 .WillRepeatedly(Return()); |
| 309 EXPECT_CALL(*download_manager_.get(), AddObserver(_)) |
| 310 .WillRepeatedly(Return()); |
307 delegate_->SetDownloadManager(download_manager_.get()); | 311 delegate_->SetDownloadManager(download_manager_.get()); |
308 pref_service_ = profile()->GetTestingPrefService(); | 312 pref_service_ = profile()->GetTestingPrefService(); |
309 contents()->SetDelegate(&web_contents_delegate_); | 313 contents()->SetDelegate(&web_contents_delegate_); |
310 | 314 |
311 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); | 315 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); |
312 SetDefaultDownloadPath(test_download_dir_.path()); | 316 SetDefaultDownloadPath(test_download_dir_.path()); |
313 } | 317 } |
314 | 318 |
315 void ChromeDownloadManagerDelegateTest::TearDown() { | 319 void ChromeDownloadManagerDelegateTest::TearDown() { |
316 message_loop_.RunAllPending(); | 320 message_loop_.RunAllPending(); |
317 delegate_->Shutdown(); | 321 delegate_->Shutdown(); |
318 ChromeRenderViewHostTestHarness::TearDown(); | 322 ChromeRenderViewHostTestHarness::TearDown(); |
319 } | 323 } |
320 | 324 |
321 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() { | 325 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() { |
322 ::testing::Mock::VerifyAndClearExpectations(delegate_); | 326 ::testing::Mock::VerifyAndClearExpectations(delegate_); |
323 ::testing::Mock::VerifyAndClearExpectations(download_manager_); | 327 ::testing::Mock::VerifyAndClearExpectations(download_manager_); |
324 EXPECT_CALL(*download_manager_, RemoveObserver(_)).WillRepeatedly(Return()); | 328 EXPECT_CALL(*download_manager_, RemoveObserver(_)).WillRepeatedly(Return()); |
325 EXPECT_CALL(*download_manager_, GetAllDownloads(_)) | 329 EXPECT_CALL(*download_manager_, GetAllDownloads(_)) |
326 .WillRepeatedly(Return()); | 330 .WillRepeatedly(Return()); |
327 } | 331 } |
328 | 332 |
329 content::MockDownloadItem* | 333 content::MockDownloadItem* |
330 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32 id) { | 334 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32 id) { |
331 content::MockDownloadItem* item = | 335 content::MockDownloadItem* item = |
332 new ::testing::NiceMock<content::MockDownloadItem>(); | 336 new ::testing::NiceMock<content::MockDownloadItem>(); |
| 337 EXPECT_CALL(*item, GetState()) |
| 338 .WillRepeatedly(Return(DownloadItem::IN_PROGRESS)); |
| 339 EXPECT_CALL(*item, AddObserver(_)) |
| 340 .WillRepeatedly(Return()); |
| 341 EXPECT_CALL(*item, RemoveObserver(_)) |
| 342 .WillRepeatedly(Return()); |
333 ON_CALL(*item, GetFullPath()) | 343 ON_CALL(*item, GetFullPath()) |
334 .WillByDefault(ReturnRefOfCopy(FilePath())); | 344 .WillByDefault(ReturnRefOfCopy(FilePath())); |
335 ON_CALL(*item, GetHash()) | 345 ON_CALL(*item, GetHash()) |
336 .WillByDefault(ReturnRefOfCopy(std::string())); | 346 .WillByDefault(ReturnRefOfCopy(std::string())); |
337 ON_CALL(*item, GetReferrerUrl()) | 347 ON_CALL(*item, GetReferrerUrl()) |
338 .WillByDefault(ReturnRefOfCopy(GURL())); | 348 .WillByDefault(ReturnRefOfCopy(GURL())); |
339 ON_CALL(*item, GetTransitionType()) | 349 ON_CALL(*item, GetTransitionType()) |
340 .WillByDefault(Return(content::PAGE_TRANSITION_LINK)); | 350 .WillByDefault(Return(content::PAGE_TRANSITION_LINK)); |
341 ON_CALL(*item, HasUserGesture()) | 351 ON_CALL(*item, HasUserGesture()) |
342 .WillByDefault(Return(false)); | 352 .WillByDefault(Return(false)); |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 }; | 955 }; |
946 | 956 |
947 RunTestCases(kWebIntentsTestCases, arraysize(kWebIntentsTestCases)); | 957 RunTestCases(kWebIntentsTestCases, arraysize(kWebIntentsTestCases)); |
948 } | 958 } |
949 | 959 |
950 // TODO(asanka): Add more tests. | 960 // TODO(asanka): Add more tests. |
951 // * Default download path is not writable. | 961 // * Default download path is not writable. |
952 // * Download path doesn't exist. | 962 // * Download path doesn't exist. |
953 // * IsDangerousFile(). | 963 // * IsDangerousFile(). |
954 // * Filename generation. | 964 // * Filename generation. |
OLD | NEW |