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/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.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/observer_list.h" | 9 #include "base/observer_list.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/browser/history/history_types.h" | 22 #include "chrome/browser/history/history_types.h" |
23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
24 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 24 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
25 #include "chrome/test/base/testing_pref_service_syncable.h" | 25 #include "chrome/test/base/testing_pref_service_syncable.h" |
26 #include "chrome/test/base/testing_profile.h" | 26 #include "chrome/test/base/testing_profile.h" |
27 #include "content/public/browser/download_interrupt_reasons.h" | 27 #include "content/public/browser/download_interrupt_reasons.h" |
28 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
30 #include "content/public/browser/web_contents_delegate.h" | 30 #include "content/public/browser/web_contents_delegate.h" |
31 #include "content/public/test/mock_download_item.h" | 31 #include "content/public/test/mock_download_item.h" |
32 #include "content/public/test/test_browser_thread.h" | |
33 #include "content/public/test/test_renderer_host.h" | 32 #include "content/public/test/test_renderer_host.h" |
34 #include "content/public/test/web_contents_tester.h" | 33 #include "content/public/test/web_contents_tester.h" |
35 #include "extensions/common/extension.h" | 34 #include "extensions/common/extension.h" |
36 #include "net/base/mime_util.h" | 35 #include "net/base/mime_util.h" |
37 #include "testing/gmock/include/gmock/gmock.h" | 36 #include "testing/gmock/include/gmock/gmock.h" |
38 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
39 | 38 |
40 #if defined(ENABLE_PLUGINS) | 39 #if defined(ENABLE_PLUGINS) |
41 #include "content/public/browser/plugin_service.h" | 40 #include "content/public/browser/plugin_service.h" |
42 #include "content/public/browser/plugin_service_filter.h" | 41 #include "content/public/browser/plugin_service_filter.h" |
(...skipping 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1549 // type == AUTOMATIC. | 1548 // type == AUTOMATIC. |
1550 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)) | 1549 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)) |
1551 .Times(test_case.test_type == AUTOMATIC ? 1 : 0); | 1550 .Times(test_case.test_type == AUTOMATIC ? 1 : 0); |
1552 EXPECT_CALL(*delegate(), ReserveVirtualPath(_, expected_path, false, _, _)); | 1551 EXPECT_CALL(*delegate(), ReserveVirtualPath(_, expected_path, false, _, _)); |
1553 EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, expected_path, _)) | 1552 EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, expected_path, _)) |
1554 .Times(0); | 1553 .Times(0); |
1555 EXPECT_CALL(*delegate(), DetermineLocalPath(_, expected_path, _)); | 1554 EXPECT_CALL(*delegate(), DetermineLocalPath(_, expected_path, _)); |
1556 EXPECT_CALL(*delegate(), CheckDownloadUrl(_, expected_path, _)); | 1555 EXPECT_CALL(*delegate(), CheckDownloadUrl(_, expected_path, _)); |
1557 RunTestCase(test_case, GetPathInDownloadDir(kInitialPath), item.get()); | 1556 RunTestCase(test_case, GetPathInDownloadDir(kInitialPath), item.get()); |
1558 } | 1557 } |
1559 | |
1560 } | 1558 } |
1561 | 1559 |
1562 // Test that a forced download doesn't prompt, even if the interrupt reason | 1560 // Test that a forced download doesn't prompt, even if the interrupt reason |
1563 // suggests that the target path may not be suitable for downloads. | 1561 // suggests that the target path may not be suitable for downloads. |
1564 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedForcedDownload) { | 1562 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedForcedDownload) { |
1565 const base::FilePath::CharType* kInitialPath = | 1563 const base::FilePath::CharType* kInitialPath = |
1566 FILE_PATH_LITERAL("some_path/bar.txt"); | 1564 FILE_PATH_LITERAL("some_path/bar.txt"); |
1567 const DownloadTestCase kResumedForcedDownload = { | 1565 const DownloadTestCase kResumedForcedDownload = { |
1568 // 3: Forced Safe | 1566 // 3: Forced Safe |
1569 FORCED, | 1567 FORCED, |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1999 | 1997 |
2000 private: | 1998 private: |
2001 content::PluginService* plugin_service_; | 1999 content::PluginService* plugin_service_; |
2002 base::FilePath plugin_path_; | 2000 base::FilePath plugin_path_; |
2003 }; | 2001 }; |
2004 | 2002 |
2005 // We use a slightly different test fixture for tests that touch plugins. SetUp | 2003 // We use a slightly different test fixture for tests that touch plugins. SetUp |
2006 // needs to disable plugin discovery and we need to use a | 2004 // needs to disable plugin discovery and we need to use a |
2007 // ShadowingAtExitManager to discard the tainted PluginService. Unfortunately, | 2005 // ShadowingAtExitManager to discard the tainted PluginService. Unfortunately, |
2008 // PluginService carries global state. | 2006 // PluginService carries global state. |
2009 class DownloadTargetDeterminerTestWithPlugin : | 2007 class DownloadTargetDeterminerTestWithPlugin |
2010 public DownloadTargetDeterminerTest { | 2008 : public DownloadTargetDeterminerTest { |
2011 public: | 2009 public: |
2012 DownloadTargetDeterminerTestWithPlugin() | 2010 DownloadTargetDeterminerTestWithPlugin() |
2013 : old_plugin_service_filter_(NULL) {} | 2011 : old_plugin_service_filter_(NULL) {} |
2014 | 2012 |
2015 virtual void SetUp() OVERRIDE { | 2013 virtual void SetUp() OVERRIDE { |
2016 content::PluginService* plugin_service = | 2014 content::PluginService* plugin_service = |
2017 content::PluginService::GetInstance(); | 2015 content::PluginService::GetInstance(); |
2018 plugin_service->Init(); | 2016 plugin_service->Init(); |
2019 plugin_service->DisablePluginsDiscoveryForTesting(); | 2017 plugin_service->DisablePluginsDiscoveryForTesting(); |
2020 old_plugin_service_filter_ = plugin_service->GetFilter(); | 2018 old_plugin_service_filter_ = plugin_service->GetFilter(); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2178 test_download_dir().AppendASCII("npapi"), | 2176 test_download_dir().AppendASCII("npapi"), |
2179 kTestMIMEType, | 2177 kTestMIMEType, |
2180 "fakeext"); | 2178 "fakeext"); |
2181 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(npapi_plugin.path())) | 2179 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(npapi_plugin.path())) |
2182 .WillRepeatedly(Return(true)); | 2180 .WillRepeatedly(Return(true)); |
2183 | 2181 |
2184 target_info = RunDownloadTargetDeterminer( | 2182 target_info = RunDownloadTargetDeterminer( |
2185 GetPathInDownloadDir(kInitialPath), item.get()); | 2183 GetPathInDownloadDir(kInitialPath), item.get()); |
2186 EXPECT_FALSE(target_info->is_filetype_handled_safely); | 2184 EXPECT_FALSE(target_info->is_filetype_handled_safely); |
2187 } | 2185 } |
2188 #endif // ENABLE_PLUGINS | 2186 #endif // defined(ENABLE_PLUGINS) |
2189 | 2187 |
2190 } // namespace | 2188 } // namespace |
OLD | NEW |