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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 DownloadItem* download, const base::FilePath& suggested_path, | 187 DownloadItem* download, const base::FilePath& suggested_path, |
188 const FileSelectedCallback& callback); | 188 const FileSelectedCallback& callback); |
189 static void NullDetermineLocalPath( | 189 static void NullDetermineLocalPath( |
190 DownloadItem* download, const base::FilePath& virtual_path, | 190 DownloadItem* download, const base::FilePath& virtual_path, |
191 const LocalPathCallback& callback); | 191 const LocalPathCallback& callback); |
192 }; | 192 }; |
193 | 193 |
194 class DownloadTargetDeterminerTest : public ChromeRenderViewHostTestHarness { | 194 class DownloadTargetDeterminerTest : public ChromeRenderViewHostTestHarness { |
195 public: | 195 public: |
196 // ::testing::Test | 196 // ::testing::Test |
197 virtual void SetUp() override; | 197 void SetUp() override; |
198 virtual void TearDown() override; | 198 void TearDown() override; |
199 | 199 |
200 // Creates MockDownloadItem and sets up default expectations. | 200 // Creates MockDownloadItem and sets up default expectations. |
201 content::MockDownloadItem* CreateActiveDownloadItem( | 201 content::MockDownloadItem* CreateActiveDownloadItem( |
202 int32 id, | 202 int32 id, |
203 const DownloadTestCase& test_case); | 203 const DownloadTestCase& test_case); |
204 | 204 |
205 // Sets the AutoOpenBasedOnExtension user preference for |path|. | 205 // Sets the AutoOpenBasedOnExtension user preference for |path|. |
206 void EnableAutoOpenBasedOnExtension(const base::FilePath& path); | 206 void EnableAutoOpenBasedOnExtension(const base::FilePath& path); |
207 | 207 |
208 // Set the kDownloadDefaultDirectory managed preference to |path|. | 208 // Set the kDownloadDefaultDirectory managed preference to |path|. |
(...skipping 1736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1945 run_loop.Run(); | 1945 run_loop.Run(); |
1946 #if !defined(OS_WIN) | 1946 #if !defined(OS_WIN) |
1947 content::RenderProcessHost::SetRunRendererInProcess(false); | 1947 content::RenderProcessHost::SetRunRendererInProcess(false); |
1948 #endif | 1948 #endif |
1949 } | 1949 } |
1950 | 1950 |
1951 class MockPluginServiceFilter : public content::PluginServiceFilter { | 1951 class MockPluginServiceFilter : public content::PluginServiceFilter { |
1952 public: | 1952 public: |
1953 MOCK_METHOD1(MockPluginAvailable, bool(const base::FilePath&)); | 1953 MOCK_METHOD1(MockPluginAvailable, bool(const base::FilePath&)); |
1954 | 1954 |
1955 virtual bool IsPluginAvailable(int render_process_id, | 1955 bool IsPluginAvailable(int render_process_id, |
1956 int render_view_id, | 1956 int render_view_id, |
1957 const void* context, | 1957 const void* context, |
1958 const GURL& url, | 1958 const GURL& url, |
1959 const GURL& policy_url, | 1959 const GURL& policy_url, |
1960 content::WebPluginInfo* plugin) override { | 1960 content::WebPluginInfo* plugin) override { |
1961 return MockPluginAvailable(plugin->path); | 1961 return MockPluginAvailable(plugin->path); |
1962 } | 1962 } |
1963 | 1963 |
1964 virtual bool CanLoadPlugin(int render_process_id, | 1964 bool CanLoadPlugin(int render_process_id, |
1965 const base::FilePath& path) override { | 1965 const base::FilePath& path) override { |
1966 return true; | 1966 return true; |
1967 } | 1967 } |
1968 }; | 1968 }; |
1969 | 1969 |
1970 class ScopedRegisterInternalPlugin { | 1970 class ScopedRegisterInternalPlugin { |
1971 public: | 1971 public: |
1972 ScopedRegisterInternalPlugin(content::PluginService* plugin_service, | 1972 ScopedRegisterInternalPlugin(content::PluginService* plugin_service, |
1973 content::WebPluginInfo::PluginType type, | 1973 content::WebPluginInfo::PluginType type, |
1974 const base::FilePath& path, | 1974 const base::FilePath& path, |
1975 const char* mime_type, | 1975 const char* mime_type, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2007 // We use a slightly different test fixture for tests that touch plugins. SetUp | 2007 // We use a slightly different test fixture for tests that touch plugins. SetUp |
2008 // needs to disable plugin discovery and we need to use a | 2008 // needs to disable plugin discovery and we need to use a |
2009 // ShadowingAtExitManager to discard the tainted PluginService. Unfortunately, | 2009 // ShadowingAtExitManager to discard the tainted PluginService. Unfortunately, |
2010 // PluginService carries global state. | 2010 // PluginService carries global state. |
2011 class DownloadTargetDeterminerTestWithPlugin | 2011 class DownloadTargetDeterminerTestWithPlugin |
2012 : public DownloadTargetDeterminerTest { | 2012 : public DownloadTargetDeterminerTest { |
2013 public: | 2013 public: |
2014 DownloadTargetDeterminerTestWithPlugin() | 2014 DownloadTargetDeterminerTestWithPlugin() |
2015 : old_plugin_service_filter_(NULL) {} | 2015 : old_plugin_service_filter_(NULL) {} |
2016 | 2016 |
2017 virtual void SetUp() override { | 2017 void SetUp() override { |
2018 content::PluginService* plugin_service = | 2018 content::PluginService* plugin_service = |
2019 content::PluginService::GetInstance(); | 2019 content::PluginService::GetInstance(); |
2020 plugin_service->Init(); | 2020 plugin_service->Init(); |
2021 plugin_service->DisablePluginsDiscoveryForTesting(); | 2021 plugin_service->DisablePluginsDiscoveryForTesting(); |
2022 old_plugin_service_filter_ = plugin_service->GetFilter(); | 2022 old_plugin_service_filter_ = plugin_service->GetFilter(); |
2023 plugin_service->SetFilter(&mock_plugin_filter_); | 2023 plugin_service->SetFilter(&mock_plugin_filter_); |
2024 DownloadTargetDeterminerTest::SetUp(); | 2024 DownloadTargetDeterminerTest::SetUp(); |
2025 } | 2025 } |
2026 | 2026 |
2027 virtual void TearDown() override { | 2027 void TearDown() override { |
2028 content::PluginService::GetInstance()->SetFilter( | 2028 content::PluginService::GetInstance()->SetFilter( |
2029 old_plugin_service_filter_); | 2029 old_plugin_service_filter_); |
2030 DownloadTargetDeterminerTest::TearDown(); | 2030 DownloadTargetDeterminerTest::TearDown(); |
2031 } | 2031 } |
2032 | 2032 |
2033 protected: | 2033 protected: |
2034 content::PluginServiceFilter* old_plugin_service_filter_; | 2034 content::PluginServiceFilter* old_plugin_service_filter_; |
2035 testing::StrictMock<MockPluginServiceFilter> mock_plugin_filter_; | 2035 testing::StrictMock<MockPluginServiceFilter> mock_plugin_filter_; |
2036 // The ShadowingAtExitManager destroys the tainted PluginService instance. | 2036 // The ShadowingAtExitManager destroys the tainted PluginService instance. |
2037 base::ShadowingAtExitManager at_exit_manager_; | 2037 base::ShadowingAtExitManager at_exit_manager_; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2167 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(npapi_plugin.path())) | 2167 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(npapi_plugin.path())) |
2168 .WillRepeatedly(Return(true)); | 2168 .WillRepeatedly(Return(true)); |
2169 | 2169 |
2170 target_info = RunDownloadTargetDeterminer( | 2170 target_info = RunDownloadTargetDeterminer( |
2171 GetPathInDownloadDir(kInitialPath), item.get()); | 2171 GetPathInDownloadDir(kInitialPath), item.get()); |
2172 EXPECT_FALSE(target_info->is_filetype_handled_safely); | 2172 EXPECT_FALSE(target_info->is_filetype_handled_safely); |
2173 } | 2173 } |
2174 #endif // defined(ENABLE_PLUGINS) | 2174 #endif // defined(ENABLE_PLUGINS) |
2175 | 2175 |
2176 } // namespace | 2176 } // namespace |
OLD | NEW |