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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "build/build_config.h" |
15 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 16 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
16 #include "chrome/browser/download/download_item_model.h" | 17 #include "chrome/browser/download/download_item_model.h" |
17 #include "chrome/browser/download/download_prefs.h" | 18 #include "chrome/browser/download/download_prefs.h" |
18 #include "chrome/browser/download/download_target_info.h" | 19 #include "chrome/browser/download/download_target_info.h" |
19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
20 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 21 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
21 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
22 #include "components/prefs/pref_service.h" | 23 #include "components/prefs/pref_service.h" |
23 #include "components/syncable_prefs/testing_pref_service_syncable.h" | 24 #include "components/syncable_prefs/testing_pref_service_syncable.h" |
24 #include "content/public/browser/download_interrupt_reasons.h" | 25 #include "content/public/browser/download_interrupt_reasons.h" |
25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
26 #include "content/public/browser/web_contents_delegate.h" | 27 #include "content/public/browser/web_contents_delegate.h" |
27 #include "content/public/test/mock_download_item.h" | 28 #include "content/public/test/mock_download_item.h" |
28 #include "content/public/test/mock_download_manager.h" | 29 #include "content/public/test/mock_download_manager.h" |
29 #include "content/public/test/test_renderer_host.h" | 30 #include "content/public/test/test_renderer_host.h" |
30 #include "content/public/test/web_contents_tester.h" | 31 #include "content/public/test/web_contents_tester.h" |
31 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
33 | 34 |
34 #if defined(FULL_SAFE_BROWSING) | 35 #if defined(FULL_SAFE_BROWSING) |
35 #include "chrome/browser/safe_browsing/download_protection_service.h" | 36 #include "chrome/browser/safe_browsing/download_protection_service.h" |
36 #endif | 37 #endif |
37 | 38 |
| 39 #if !defined(OS_ANDROID) |
| 40 #include "content/public/browser/plugin_service.h" |
| 41 #endif |
| 42 |
38 using ::testing::AtMost; | 43 using ::testing::AtMost; |
39 using ::testing::Invoke; | 44 using ::testing::Invoke; |
40 using ::testing::Ref; | 45 using ::testing::Ref; |
41 using ::testing::Return; | 46 using ::testing::Return; |
42 using ::testing::ReturnPointee; | 47 using ::testing::ReturnPointee; |
43 using ::testing::ReturnRef; | 48 using ::testing::ReturnRef; |
44 using ::testing::ReturnRefOfCopy; | 49 using ::testing::ReturnRefOfCopy; |
45 using ::testing::SetArgPointee; | 50 using ::testing::SetArgPointee; |
46 using ::testing::WithArg; | 51 using ::testing::WithArg; |
47 using ::testing::_; | 52 using ::testing::_; |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 EXPECT_CALL(*delegate(), | 403 EXPECT_CALL(*delegate(), |
399 MockPromptUserForDownloadPath(save_as_download.get(), | 404 MockPromptUserForDownloadPath(save_as_download.get(), |
400 expected_prompt_path, _)) | 405 expected_prompt_path, _)) |
401 .WillOnce(Return(base::FilePath())); | 406 .WillOnce(Return(base::FilePath())); |
402 DetermineDownloadTarget(save_as_download.get(), &result); | 407 DetermineDownloadTarget(save_as_download.get(), &result); |
403 VerifyAndClearExpectations(); | 408 VerifyAndClearExpectations(); |
404 } | 409 } |
405 } | 410 } |
406 | 411 |
407 TEST_F(ChromeDownloadManagerDelegateTest, MaybeDangerousContent) { | 412 TEST_F(ChromeDownloadManagerDelegateTest, MaybeDangerousContent) { |
| 413 #if !defined(OS_ANDROID) |
| 414 content::PluginService::GetInstance()->Init(); |
| 415 #endif |
| 416 |
408 GURL url("http://example.com/foo"); | 417 GURL url("http://example.com/foo"); |
409 | 418 |
410 std::unique_ptr<content::MockDownloadItem> download_item = | 419 std::unique_ptr<content::MockDownloadItem> download_item = |
411 CreateActiveDownloadItem(0); | 420 CreateActiveDownloadItem(0); |
412 EXPECT_CALL(*download_item, GetURL()).WillRepeatedly(ReturnRef(url)); | 421 EXPECT_CALL(*download_item, GetURL()).WillRepeatedly(ReturnRef(url)); |
413 EXPECT_CALL(*download_item, GetTargetDisposition()) | 422 EXPECT_CALL(*download_item, GetTargetDisposition()) |
414 .WillRepeatedly(Return(DownloadItem::TARGET_DISPOSITION_OVERWRITE)); | 423 .WillRepeatedly(Return(DownloadItem::TARGET_DISPOSITION_OVERWRITE)); |
415 EXPECT_CALL(*delegate(), MockCheckDownloadUrl(_, _)) | 424 EXPECT_CALL(*delegate(), MockCheckDownloadUrl(_, _)) |
416 .WillRepeatedly( | 425 .WillRepeatedly( |
417 Return(content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT)); | 426 Return(content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT)); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 EXPECT_CALL(*download_item, OnContentCheckCompleted(_)).Times(0); | 675 EXPECT_CALL(*download_item, OnContentCheckCompleted(_)).Times(0); |
667 } | 676 } |
668 | 677 |
669 base::RunLoop run_loop; | 678 base::RunLoop run_loop; |
670 ASSERT_FALSE(delegate()->ShouldCompleteDownload(download_item.get(), | 679 ASSERT_FALSE(delegate()->ShouldCompleteDownload(download_item.get(), |
671 run_loop.QuitClosure())); | 680 run_loop.QuitClosure())); |
672 run_loop.Run(); | 681 run_loop.Run(); |
673 } | 682 } |
674 | 683 |
675 #endif // FULL_SAFE_BROWSING | 684 #endif // FULL_SAFE_BROWSING |
OLD | NEW |