| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 DownloadItem* download, const base::FilePath& suggested_path, | 184 DownloadItem* download, const base::FilePath& suggested_path, |
| 185 const FileSelectedCallback& callback); | 185 const FileSelectedCallback& callback); |
| 186 static void NullDetermineLocalPath( | 186 static void NullDetermineLocalPath( |
| 187 DownloadItem* download, const base::FilePath& virtual_path, | 187 DownloadItem* download, const base::FilePath& virtual_path, |
| 188 const LocalPathCallback& callback); | 188 const LocalPathCallback& callback); |
| 189 }; | 189 }; |
| 190 | 190 |
| 191 class DownloadTargetDeterminerTest : public ChromeRenderViewHostTestHarness { | 191 class DownloadTargetDeterminerTest : public ChromeRenderViewHostTestHarness { |
| 192 public: | 192 public: |
| 193 // ::testing::Test | 193 // ::testing::Test |
| 194 virtual void SetUp() OVERRIDE; | 194 virtual void SetUp() override; |
| 195 virtual void TearDown() OVERRIDE; | 195 virtual void TearDown() override; |
| 196 | 196 |
| 197 // Creates MockDownloadItem and sets up default expectations. | 197 // Creates MockDownloadItem and sets up default expectations. |
| 198 content::MockDownloadItem* CreateActiveDownloadItem( | 198 content::MockDownloadItem* CreateActiveDownloadItem( |
| 199 int32 id, | 199 int32 id, |
| 200 const DownloadTestCase& test_case); | 200 const DownloadTestCase& test_case); |
| 201 | 201 |
| 202 // Sets the AutoOpenBasedOnExtension user preference for |path|. | 202 // Sets the AutoOpenBasedOnExtension user preference for |path|. |
| 203 void EnableAutoOpenBasedOnExtension(const base::FilePath& path); | 203 void EnableAutoOpenBasedOnExtension(const base::FilePath& path); |
| 204 | 204 |
| 205 // Set the kDownloadDefaultDirectory managed preference to |path|. | 205 // Set the kDownloadDefaultDirectory managed preference to |path|. |
| (...skipping 1740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1946 | 1946 |
| 1947 class MockPluginServiceFilter : public content::PluginServiceFilter { | 1947 class MockPluginServiceFilter : public content::PluginServiceFilter { |
| 1948 public: | 1948 public: |
| 1949 MOCK_METHOD1(MockPluginAvailable, bool(const base::FilePath&)); | 1949 MOCK_METHOD1(MockPluginAvailable, bool(const base::FilePath&)); |
| 1950 | 1950 |
| 1951 virtual bool IsPluginAvailable(int render_process_id, | 1951 virtual bool IsPluginAvailable(int render_process_id, |
| 1952 int render_view_id, | 1952 int render_view_id, |
| 1953 const void* context, | 1953 const void* context, |
| 1954 const GURL& url, | 1954 const GURL& url, |
| 1955 const GURL& policy_url, | 1955 const GURL& policy_url, |
| 1956 content::WebPluginInfo* plugin) OVERRIDE { | 1956 content::WebPluginInfo* plugin) override { |
| 1957 return MockPluginAvailable(plugin->path); | 1957 return MockPluginAvailable(plugin->path); |
| 1958 } | 1958 } |
| 1959 | 1959 |
| 1960 virtual bool CanLoadPlugin(int render_process_id, | 1960 virtual bool CanLoadPlugin(int render_process_id, |
| 1961 const base::FilePath& path) OVERRIDE { | 1961 const base::FilePath& path) override { |
| 1962 return true; | 1962 return true; |
| 1963 } | 1963 } |
| 1964 }; | 1964 }; |
| 1965 | 1965 |
| 1966 class ScopedRegisterInternalPlugin { | 1966 class ScopedRegisterInternalPlugin { |
| 1967 public: | 1967 public: |
| 1968 ScopedRegisterInternalPlugin(content::PluginService* plugin_service, | 1968 ScopedRegisterInternalPlugin(content::PluginService* plugin_service, |
| 1969 content::WebPluginInfo::PluginType type, | 1969 content::WebPluginInfo::PluginType type, |
| 1970 const base::FilePath& path, | 1970 const base::FilePath& path, |
| 1971 const char* mime_type, | 1971 const char* mime_type, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2003 // 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 |
| 2004 // needs to disable plugin discovery and we need to use a | 2004 // needs to disable plugin discovery and we need to use a |
| 2005 // ShadowingAtExitManager to discard the tainted PluginService. Unfortunately, | 2005 // ShadowingAtExitManager to discard the tainted PluginService. Unfortunately, |
| 2006 // PluginService carries global state. | 2006 // PluginService carries global state. |
| 2007 class DownloadTargetDeterminerTestWithPlugin | 2007 class DownloadTargetDeterminerTestWithPlugin |
| 2008 : public DownloadTargetDeterminerTest { | 2008 : public DownloadTargetDeterminerTest { |
| 2009 public: | 2009 public: |
| 2010 DownloadTargetDeterminerTestWithPlugin() | 2010 DownloadTargetDeterminerTestWithPlugin() |
| 2011 : old_plugin_service_filter_(NULL) {} | 2011 : old_plugin_service_filter_(NULL) {} |
| 2012 | 2012 |
| 2013 virtual void SetUp() OVERRIDE { | 2013 virtual void SetUp() override { |
| 2014 content::PluginService* plugin_service = | 2014 content::PluginService* plugin_service = |
| 2015 content::PluginService::GetInstance(); | 2015 content::PluginService::GetInstance(); |
| 2016 plugin_service->Init(); | 2016 plugin_service->Init(); |
| 2017 plugin_service->DisablePluginsDiscoveryForTesting(); | 2017 plugin_service->DisablePluginsDiscoveryForTesting(); |
| 2018 old_plugin_service_filter_ = plugin_service->GetFilter(); | 2018 old_plugin_service_filter_ = plugin_service->GetFilter(); |
| 2019 plugin_service->SetFilter(&mock_plugin_filter_); | 2019 plugin_service->SetFilter(&mock_plugin_filter_); |
| 2020 DownloadTargetDeterminerTest::SetUp(); | 2020 DownloadTargetDeterminerTest::SetUp(); |
| 2021 } | 2021 } |
| 2022 | 2022 |
| 2023 virtual void TearDown() OVERRIDE { | 2023 virtual void TearDown() override { |
| 2024 content::PluginService::GetInstance()->SetFilter( | 2024 content::PluginService::GetInstance()->SetFilter( |
| 2025 old_plugin_service_filter_); | 2025 old_plugin_service_filter_); |
| 2026 DownloadTargetDeterminerTest::TearDown(); | 2026 DownloadTargetDeterminerTest::TearDown(); |
| 2027 } | 2027 } |
| 2028 | 2028 |
| 2029 protected: | 2029 protected: |
| 2030 content::PluginServiceFilter* old_plugin_service_filter_; | 2030 content::PluginServiceFilter* old_plugin_service_filter_; |
| 2031 testing::StrictMock<MockPluginServiceFilter> mock_plugin_filter_; | 2031 testing::StrictMock<MockPluginServiceFilter> mock_plugin_filter_; |
| 2032 // The ShadowingAtExitManager destroys the tainted PluginService instance. | 2032 // The ShadowingAtExitManager destroys the tainted PluginService instance. |
| 2033 base::ShadowingAtExitManager at_exit_manager_; | 2033 base::ShadowingAtExitManager at_exit_manager_; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2179 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(npapi_plugin.path())) | 2179 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(npapi_plugin.path())) |
| 2180 .WillRepeatedly(Return(true)); | 2180 .WillRepeatedly(Return(true)); |
| 2181 | 2181 |
| 2182 target_info = RunDownloadTargetDeterminer( | 2182 target_info = RunDownloadTargetDeterminer( |
| 2183 GetPathInDownloadDir(kInitialPath), item.get()); | 2183 GetPathInDownloadDir(kInitialPath), item.get()); |
| 2184 EXPECT_FALSE(target_info->is_filetype_handled_safely); | 2184 EXPECT_FALSE(target_info->is_filetype_handled_safely); |
| 2185 } | 2185 } |
| 2186 #endif // defined(ENABLE_PLUGINS) | 2186 #endif // defined(ENABLE_PLUGINS) |
| 2187 | 2187 |
| 2188 } // namespace | 2188 } // namespace |
| OLD | NEW |