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 2088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2099 EXPECT_TRUE(target_info->is_filetype_handled_safely); | 2099 EXPECT_TRUE(target_info->is_filetype_handled_safely); |
2100 | 2100 |
2101 // Try disabling the plugin. Handling should no longer be considered secure. | 2101 // Try disabling the plugin. Handling should no longer be considered secure. |
2102 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(ppapi_plugin.path())) | 2102 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(ppapi_plugin.path())) |
2103 .WillRepeatedly(Return(false)); | 2103 .WillRepeatedly(Return(false)); |
2104 target_info = RunDownloadTargetDeterminer( | 2104 target_info = RunDownloadTargetDeterminer( |
2105 GetPathInDownloadDir(kInitialPath), item.get()); | 2105 GetPathInDownloadDir(kInitialPath), item.get()); |
2106 EXPECT_FALSE(target_info->is_filetype_handled_safely); | 2106 EXPECT_FALSE(target_info->is_filetype_handled_safely); |
2107 } | 2107 } |
2108 | 2108 |
| 2109 // Check if secure handling of filetypes is determined correctly for |
| 2110 // BrowserPlugins. |
| 2111 TEST_F(DownloadTargetDeterminerTestWithPlugin, |
| 2112 TargetDeterminer_CheckForSecureHandling_BrowserPlugin) { |
| 2113 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital |
| 2114 // path. |
| 2115 const base::FilePath::CharType kInitialPath[] = |
| 2116 FILE_PATH_LITERAL("some_path/bar.txt"); |
| 2117 const char kTestMIMEType[] = "application/x-example-should-not-exist"; |
| 2118 |
| 2119 DownloadTestCase kSecureHandlingTestCase = { |
| 2120 AUTOMATIC, |
| 2121 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 2122 "http://example.com/foo.fakeext", "", |
| 2123 FILE_PATH_LITERAL(""), |
| 2124 |
| 2125 FILE_PATH_LITERAL("foo.fakeext"), |
| 2126 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 2127 |
| 2128 EXPECT_CRDOWNLOAD |
| 2129 }; |
| 2130 |
| 2131 content::PluginService* plugin_service = |
| 2132 content::PluginService::GetInstance(); |
| 2133 |
| 2134 // Verify our test assumptions. |
| 2135 { |
| 2136 ForceRefreshOfPlugins(); |
| 2137 std::vector<content::WebPluginInfo> info; |
| 2138 ASSERT_FALSE(plugin_service->GetPluginInfoArray( |
| 2139 GURL(), kTestMIMEType, false, &info, NULL)); |
| 2140 ASSERT_EQ(0u, info.size()) |
| 2141 << "Name: " << info[0].name << ", Path: " << info[0].path.value(); |
| 2142 } |
| 2143 |
| 2144 ON_CALL(*delegate(), GetFileMimeType( |
| 2145 GetPathInDownloadDir(FILE_PATH_LITERAL("foo.fakeext")), _)) |
| 2146 .WillByDefault(WithArg<1>( |
| 2147 ScheduleCallback(kTestMIMEType))); |
| 2148 scoped_ptr<content::MockDownloadItem> item( |
| 2149 CreateActiveDownloadItem(1, kSecureHandlingTestCase)); |
| 2150 scoped_ptr<DownloadTargetInfo> target_info = |
| 2151 RunDownloadTargetDeterminer(GetPathInDownloadDir(kInitialPath), |
| 2152 item.get()); |
| 2153 EXPECT_FALSE(target_info->is_filetype_handled_safely); |
| 2154 |
| 2155 // Register a BrowserPlugin. This should count as handling the filetype |
| 2156 // securely. |
| 2157 ScopedRegisterInternalPlugin browser_plugin( |
| 2158 plugin_service, |
| 2159 content::WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN, |
| 2160 test_download_dir().AppendASCII("browser_plugin"), |
| 2161 kTestMIMEType, |
| 2162 "fakeext"); |
| 2163 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(browser_plugin.path())) |
| 2164 .WillRepeatedly(Return(true)); |
| 2165 |
| 2166 target_info = RunDownloadTargetDeterminer( |
| 2167 GetPathInDownloadDir(kInitialPath), item.get()); |
| 2168 EXPECT_TRUE(target_info->is_filetype_handled_safely); |
| 2169 |
| 2170 // Try disabling the plugin. Handling should no longer be considered secure. |
| 2171 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(browser_plugin.path())) |
| 2172 .WillRepeatedly(Return(false)); |
| 2173 target_info = RunDownloadTargetDeterminer( |
| 2174 GetPathInDownloadDir(kInitialPath), item.get()); |
| 2175 EXPECT_FALSE(target_info->is_filetype_handled_safely); |
| 2176 } |
| 2177 |
2109 // Check if secure handling of filetypes is determined correctly for NPAPI | 2178 // Check if secure handling of filetypes is determined correctly for NPAPI |
2110 // plugins. | 2179 // plugins. |
2111 TEST_F(DownloadTargetDeterminerTestWithPlugin, | 2180 TEST_F(DownloadTargetDeterminerTestWithPlugin, |
2112 TargetDeterminer_CheckForSecureHandling_NPAPI) { | 2181 TargetDeterminer_CheckForSecureHandling_NPAPI) { |
2113 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital | 2182 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital |
2114 // path. | 2183 // path. |
2115 const base::FilePath::CharType kInitialPath[] = | 2184 const base::FilePath::CharType kInitialPath[] = |
2116 FILE_PATH_LITERAL("some_path/bar.txt"); | 2185 FILE_PATH_LITERAL("some_path/bar.txt"); |
2117 const char kTestMIMEType[] = "application/x-example-should-not-exist"; | 2186 const char kTestMIMEType[] = "application/x-example-should-not-exist"; |
2118 | 2187 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2167 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(npapi_plugin.path())) | 2236 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(npapi_plugin.path())) |
2168 .WillRepeatedly(Return(true)); | 2237 .WillRepeatedly(Return(true)); |
2169 | 2238 |
2170 target_info = RunDownloadTargetDeterminer( | 2239 target_info = RunDownloadTargetDeterminer( |
2171 GetPathInDownloadDir(kInitialPath), item.get()); | 2240 GetPathInDownloadDir(kInitialPath), item.get()); |
2172 EXPECT_FALSE(target_info->is_filetype_handled_safely); | 2241 EXPECT_FALSE(target_info->is_filetype_handled_safely); |
2173 } | 2242 } |
2174 #endif // defined(ENABLE_PLUGINS) | 2243 #endif // defined(ENABLE_PLUGINS) |
2175 | 2244 |
2176 } // namespace | 2245 } // namespace |
OLD | NEW |