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/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 1843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1854 : public DownloadTargetDeterminerTest { | 1854 : public DownloadTargetDeterminerTest { |
1855 public: | 1855 public: |
1856 DownloadTargetDeterminerTestWithPlugin() | 1856 DownloadTargetDeterminerTestWithPlugin() |
1857 : old_plugin_service_filter_(NULL) {} | 1857 : old_plugin_service_filter_(NULL) {} |
1858 | 1858 |
1859 void SetUp() override { | 1859 void SetUp() override { |
1860 DownloadTargetDeterminerTest::SetUp(); | 1860 DownloadTargetDeterminerTest::SetUp(); |
1861 content::PluginService* plugin_service = | 1861 content::PluginService* plugin_service = |
1862 content::PluginService::GetInstance(); | 1862 content::PluginService::GetInstance(); |
1863 plugin_service->Init(); | 1863 plugin_service->Init(); |
1864 plugin_service->DisablePluginsDiscoveryForTesting(); | |
1865 old_plugin_service_filter_ = plugin_service->GetFilter(); | 1864 old_plugin_service_filter_ = plugin_service->GetFilter(); |
1866 plugin_service->SetFilter(&mock_plugin_filter_); | 1865 plugin_service->SetFilter(&mock_plugin_filter_); |
1867 } | 1866 } |
1868 | 1867 |
1869 void TearDown() override { | 1868 void TearDown() override { |
1870 content::PluginService::GetInstance()->SetFilter( | 1869 content::PluginService::GetInstance()->SetFilter( |
1871 old_plugin_service_filter_); | 1870 old_plugin_service_filter_); |
1872 DownloadTargetDeterminerTest::TearDown(); | 1871 DownloadTargetDeterminerTest::TearDown(); |
1873 } | 1872 } |
1874 | 1873 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2012 EXPECT_TRUE(target_info->is_filetype_handled_safely); | 2011 EXPECT_TRUE(target_info->is_filetype_handled_safely); |
2013 | 2012 |
2014 // Try disabling the plugin. Handling should no longer be considered secure. | 2013 // Try disabling the plugin. Handling should no longer be considered secure. |
2015 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(browser_plugin.path())) | 2014 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(browser_plugin.path())) |
2016 .WillRepeatedly(Return(false)); | 2015 .WillRepeatedly(Return(false)); |
2017 target_info = RunDownloadTargetDeterminer( | 2016 target_info = RunDownloadTargetDeterminer( |
2018 GetPathInDownloadDir(kInitialPath), item.get()); | 2017 GetPathInDownloadDir(kInitialPath), item.get()); |
2019 EXPECT_FALSE(target_info->is_filetype_handled_safely); | 2018 EXPECT_FALSE(target_info->is_filetype_handled_safely); |
2020 } | 2019 } |
2021 | 2020 |
2022 // Check if secure handling of filetypes is determined correctly for NPAPI | |
2023 // plugins. | |
2024 TEST_F(DownloadTargetDeterminerTestWithPlugin, | |
2025 TargetDeterminer_CheckForSecureHandling_NPAPI) { | |
2026 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital | |
2027 // path. | |
2028 const base::FilePath::CharType kInitialPath[] = | |
2029 FILE_PATH_LITERAL("some_path/bar.txt"); | |
2030 const char kTestMIMEType[] = "application/x-example-should-not-exist"; | |
2031 | |
2032 DownloadTestCase kSecureHandlingTestCase = { | |
2033 AUTOMATIC, | |
2034 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
2035 download_util::NOT_DANGEROUS, | |
2036 "http://example.com/foo.fakeext", | |
2037 "", | |
2038 FILE_PATH_LITERAL(""), | |
2039 | |
2040 FILE_PATH_LITERAL("foo.fakeext"), | |
2041 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
2042 | |
2043 EXPECT_CRDOWNLOAD}; | |
2044 | |
2045 content::PluginService* plugin_service = | |
2046 content::PluginService::GetInstance(); | |
2047 | |
2048 // Can't run this test if NPAPI isn't supported. | |
2049 if (!plugin_service->NPAPIPluginsSupported()) | |
2050 return; | |
2051 | |
2052 // Verify our test assumptions. | |
2053 { | |
2054 ForceRefreshOfPlugins(); | |
2055 std::vector<content::WebPluginInfo> info; | |
2056 ASSERT_FALSE(plugin_service->GetPluginInfoArray( | |
2057 GURL(), kTestMIMEType, false, &info, NULL)); | |
2058 ASSERT_EQ(0u, info.size()) | |
2059 << "Name: " << info[0].name << ", Path: " << info[0].path.value(); | |
2060 } | |
2061 | |
2062 ON_CALL(*delegate(), GetFileMimeType( | |
2063 GetPathInDownloadDir(FILE_PATH_LITERAL("foo.fakeext")), _)) | |
2064 .WillByDefault(WithArg<1>( | |
2065 ScheduleCallback(kTestMIMEType))); | |
2066 scoped_ptr<content::MockDownloadItem> item( | |
2067 CreateActiveDownloadItem(1, kSecureHandlingTestCase)); | |
2068 scoped_ptr<DownloadTargetInfo> target_info = | |
2069 RunDownloadTargetDeterminer(GetPathInDownloadDir(kInitialPath), | |
2070 item.get()); | |
2071 EXPECT_FALSE(target_info->is_filetype_handled_safely); | |
2072 | |
2073 // Register a NPAPI plugin. This should not count as handling the filetype | |
2074 // securely. | |
2075 ScopedRegisterInternalPlugin npapi_plugin( | |
2076 plugin_service, | |
2077 content::WebPluginInfo::PLUGIN_TYPE_NPAPI, | |
2078 test_download_dir().AppendASCII("npapi"), | |
2079 kTestMIMEType, | |
2080 "fakeext"); | |
2081 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(npapi_plugin.path())) | |
2082 .WillRepeatedly(Return(true)); | |
2083 | |
2084 target_info = RunDownloadTargetDeterminer( | |
2085 GetPathInDownloadDir(kInitialPath), item.get()); | |
2086 EXPECT_FALSE(target_info->is_filetype_handled_safely); | |
2087 } | |
2088 #endif // defined(ENABLE_PLUGINS) | 2021 #endif // defined(ENABLE_PLUGINS) |
2089 | 2022 |
2090 } // namespace | 2023 } // namespace |
OLD | NEW |