| 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 "content/browser/plugin_loader_posix.h" | 5 #include "content/browser/plugin_loader_posix.h" |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "content/browser/browser_thread_impl.h" | 13 #include "content/browser/browser_thread_impl.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "webkit/plugins/webplugininfo.h" | |
| 17 | 16 |
| 18 namespace content { | 17 namespace content { |
| 19 | 18 |
| 20 class MockPluginLoaderPosix : public PluginLoaderPosix { | 19 class MockPluginLoaderPosix : public PluginLoaderPosix { |
| 21 public: | 20 public: |
| 22 MOCK_METHOD0(LoadPluginsInternal, void(void)); | 21 MOCK_METHOD0(LoadPluginsInternal, void(void)); |
| 23 | 22 |
| 24 size_t number_of_pending_callbacks() { | 23 size_t number_of_pending_callbacks() { |
| 25 return callbacks_.size(); | 24 return callbacks_.size(); |
| 26 } | 25 } |
| 27 | 26 |
| 28 std::vector<base::FilePath>* canonical_list() { | 27 std::vector<base::FilePath>* canonical_list() { |
| 29 return &canonical_list_; | 28 return &canonical_list_; |
| 30 } | 29 } |
| 31 | 30 |
| 32 size_t next_load_index() { | 31 size_t next_load_index() { |
| 33 return next_load_index_; | 32 return next_load_index_; |
| 34 } | 33 } |
| 35 | 34 |
| 36 const std::vector<webkit::WebPluginInfo>& loaded_plugins() { | 35 const std::vector<WebPluginInfo>& loaded_plugins() { |
| 37 return loaded_plugins_; | 36 return loaded_plugins_; |
| 38 } | 37 } |
| 39 | 38 |
| 40 std::vector<webkit::WebPluginInfo>* internal_plugins() { | 39 std::vector<WebPluginInfo>* internal_plugins() { |
| 41 return &internal_plugins_; | 40 return &internal_plugins_; |
| 42 } | 41 } |
| 43 | 42 |
| 44 void RealLoadPluginsInternal() { | 43 void RealLoadPluginsInternal() { |
| 45 PluginLoaderPosix::LoadPluginsInternal(); | 44 PluginLoaderPosix::LoadPluginsInternal(); |
| 46 } | 45 } |
| 47 | 46 |
| 48 void TestOnPluginLoaded(uint32 index, const webkit::WebPluginInfo& plugin) { | 47 void TestOnPluginLoaded(uint32 index, const WebPluginInfo& plugin) { |
| 49 OnPluginLoaded(index, plugin); | 48 OnPluginLoaded(index, plugin); |
| 50 } | 49 } |
| 51 | 50 |
| 52 void TestOnPluginLoadFailed(uint32 index, const base::FilePath& path) { | 51 void TestOnPluginLoadFailed(uint32 index, const base::FilePath& path) { |
| 53 OnPluginLoadFailed(index, path); | 52 OnPluginLoadFailed(index, path); |
| 54 } | 53 } |
| 55 | 54 |
| 56 protected: | 55 protected: |
| 57 virtual ~MockPluginLoaderPosix() {} | 56 virtual ~MockPluginLoaderPosix() {} |
| 58 }; | 57 }; |
| 59 | 58 |
| 60 void VerifyCallback(int* run_count, const std::vector<webkit::WebPluginInfo>&) { | 59 void VerifyCallback(int* run_count, const std::vector<WebPluginInfo>&) { |
| 61 ++(*run_count); | 60 ++(*run_count); |
| 62 } | 61 } |
| 63 | 62 |
| 64 class PluginLoaderPosixTest : public testing::Test { | 63 class PluginLoaderPosixTest : public testing::Test { |
| 65 public: | 64 public: |
| 66 PluginLoaderPosixTest() | 65 PluginLoaderPosixTest() |
| 67 : plugin1_(ASCIIToUTF16("plugin1"), base::FilePath("/tmp/one.plugin"), | 66 : plugin1_(ASCIIToUTF16("plugin1"), base::FilePath("/tmp/one.plugin"), |
| 68 ASCIIToUTF16("1.0"), string16()), | 67 ASCIIToUTF16("1.0"), string16()), |
| 69 plugin2_(ASCIIToUTF16("plugin2"), base::FilePath("/tmp/two.plugin"), | 68 plugin2_(ASCIIToUTF16("plugin2"), base::FilePath("/tmp/two.plugin"), |
| 70 ASCIIToUTF16("2.0"), string16()), | 69 ASCIIToUTF16("2.0"), string16()), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 83 MockPluginLoaderPosix* plugin_loader() { return plugin_loader_.get(); } | 82 MockPluginLoaderPosix* plugin_loader() { return plugin_loader_.get(); } |
| 84 | 83 |
| 85 void AddThreePlugins() { | 84 void AddThreePlugins() { |
| 86 plugin_loader_->canonical_list()->clear(); | 85 plugin_loader_->canonical_list()->clear(); |
| 87 plugin_loader_->canonical_list()->push_back(plugin1_.path); | 86 plugin_loader_->canonical_list()->push_back(plugin1_.path); |
| 88 plugin_loader_->canonical_list()->push_back(plugin2_.path); | 87 plugin_loader_->canonical_list()->push_back(plugin2_.path); |
| 89 plugin_loader_->canonical_list()->push_back(plugin3_.path); | 88 plugin_loader_->canonical_list()->push_back(plugin3_.path); |
| 90 } | 89 } |
| 91 | 90 |
| 92 // Data used for testing. | 91 // Data used for testing. |
| 93 webkit::WebPluginInfo plugin1_; | 92 WebPluginInfo plugin1_; |
| 94 webkit::WebPluginInfo plugin2_; | 93 WebPluginInfo plugin2_; |
| 95 webkit::WebPluginInfo plugin3_; | 94 WebPluginInfo plugin3_; |
| 96 | 95 |
| 97 private: | 96 private: |
| 98 base::ShadowingAtExitManager at_exit_manager_; // Destroys PluginService. | 97 base::ShadowingAtExitManager at_exit_manager_; // Destroys PluginService. |
| 99 | 98 |
| 100 base::MessageLoopForIO message_loop_; | 99 base::MessageLoopForIO message_loop_; |
| 101 BrowserThreadImpl file_thread_; | 100 BrowserThreadImpl file_thread_; |
| 102 BrowserThreadImpl io_thread_; | 101 BrowserThreadImpl io_thread_; |
| 103 | 102 |
| 104 scoped_refptr<MockPluginLoaderPosix> plugin_loader_; | 103 scoped_refptr<MockPluginLoaderPosix> plugin_loader_; |
| 105 }; | 104 }; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 144 |
| 146 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); | 145 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); |
| 147 | 146 |
| 148 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); | 147 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); |
| 149 message_loop()->RunUntilIdle(); | 148 message_loop()->RunUntilIdle(); |
| 150 | 149 |
| 151 AddThreePlugins(); | 150 AddThreePlugins(); |
| 152 | 151 |
| 153 EXPECT_EQ(0u, plugin_loader()->next_load_index()); | 152 EXPECT_EQ(0u, plugin_loader()->next_load_index()); |
| 154 | 153 |
| 155 const std::vector<webkit::WebPluginInfo>& plugins( | 154 const std::vector<WebPluginInfo>& plugins(plugin_loader()->loaded_plugins()); |
| 156 plugin_loader()->loaded_plugins()); | |
| 157 | 155 |
| 158 plugin_loader()->TestOnPluginLoaded(0, plugin1_); | 156 plugin_loader()->TestOnPluginLoaded(0, plugin1_); |
| 159 EXPECT_EQ(1u, plugin_loader()->next_load_index()); | 157 EXPECT_EQ(1u, plugin_loader()->next_load_index()); |
| 160 EXPECT_EQ(1u, plugins.size()); | 158 EXPECT_EQ(1u, plugins.size()); |
| 161 EXPECT_EQ(plugin1_.name, plugins[0].name); | 159 EXPECT_EQ(plugin1_.name, plugins[0].name); |
| 162 | 160 |
| 163 message_loop()->RunUntilIdle(); | 161 message_loop()->RunUntilIdle(); |
| 164 EXPECT_EQ(0, did_callback); | 162 EXPECT_EQ(0, did_callback); |
| 165 | 163 |
| 166 plugin_loader()->TestOnPluginLoaded(1, plugin2_); | 164 plugin_loader()->TestOnPluginLoaded(1, plugin2_); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 186 | 184 |
| 187 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); | 185 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); |
| 188 | 186 |
| 189 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(2); | 187 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(2); |
| 190 message_loop()->RunUntilIdle(); | 188 message_loop()->RunUntilIdle(); |
| 191 | 189 |
| 192 AddThreePlugins(); | 190 AddThreePlugins(); |
| 193 | 191 |
| 194 EXPECT_EQ(0u, plugin_loader()->next_load_index()); | 192 EXPECT_EQ(0u, plugin_loader()->next_load_index()); |
| 195 | 193 |
| 196 const std::vector<webkit::WebPluginInfo>& plugins( | 194 const std::vector<WebPluginInfo>& plugins(plugin_loader()->loaded_plugins()); |
| 197 plugin_loader()->loaded_plugins()); | |
| 198 | 195 |
| 199 plugin_loader()->TestOnPluginLoaded(0, plugin1_); | 196 plugin_loader()->TestOnPluginLoaded(0, plugin1_); |
| 200 EXPECT_EQ(1u, plugin_loader()->next_load_index()); | 197 EXPECT_EQ(1u, plugin_loader()->next_load_index()); |
| 201 EXPECT_EQ(1u, plugins.size()); | 198 EXPECT_EQ(1u, plugins.size()); |
| 202 EXPECT_EQ(plugin1_.name, plugins[0].name); | 199 EXPECT_EQ(plugin1_.name, plugins[0].name); |
| 203 | 200 |
| 204 message_loop()->RunUntilIdle(); | 201 message_loop()->RunUntilIdle(); |
| 205 EXPECT_EQ(0, did_callback); | 202 EXPECT_EQ(0, did_callback); |
| 206 | 203 |
| 207 plugin_loader()->TestOnPluginLoaded(1, plugin2_); | 204 plugin_loader()->TestOnPluginLoaded(1, plugin2_); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 229 | 226 |
| 230 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); | 227 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); |
| 231 | 228 |
| 232 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); | 229 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); |
| 233 message_loop()->RunUntilIdle(); | 230 message_loop()->RunUntilIdle(); |
| 234 | 231 |
| 235 AddThreePlugins(); | 232 AddThreePlugins(); |
| 236 | 233 |
| 237 EXPECT_EQ(0u, plugin_loader()->next_load_index()); | 234 EXPECT_EQ(0u, plugin_loader()->next_load_index()); |
| 238 | 235 |
| 239 const std::vector<webkit::WebPluginInfo>& plugins( | 236 const std::vector<WebPluginInfo>& plugins(plugin_loader()->loaded_plugins()); |
| 240 plugin_loader()->loaded_plugins()); | |
| 241 | 237 |
| 242 plugin_loader()->TestOnPluginLoadFailed(0, plugin1_.path); | 238 plugin_loader()->TestOnPluginLoadFailed(0, plugin1_.path); |
| 243 EXPECT_EQ(1u, plugin_loader()->next_load_index()); | 239 EXPECT_EQ(1u, plugin_loader()->next_load_index()); |
| 244 EXPECT_EQ(0u, plugins.size()); | 240 EXPECT_EQ(0u, plugins.size()); |
| 245 | 241 |
| 246 message_loop()->RunUntilIdle(); | 242 message_loop()->RunUntilIdle(); |
| 247 EXPECT_EQ(0, did_callback); | 243 EXPECT_EQ(0, did_callback); |
| 248 | 244 |
| 249 plugin_loader()->TestOnPluginLoaded(1, plugin2_); | 245 plugin_loader()->TestOnPluginLoaded(1, plugin2_); |
| 250 EXPECT_EQ(2u, plugin_loader()->next_load_index()); | 246 EXPECT_EQ(2u, plugin_loader()->next_load_index()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 268 | 264 |
| 269 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); | 265 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); |
| 270 | 266 |
| 271 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); | 267 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); |
| 272 message_loop()->RunUntilIdle(); | 268 message_loop()->RunUntilIdle(); |
| 273 | 269 |
| 274 AddThreePlugins(); | 270 AddThreePlugins(); |
| 275 | 271 |
| 276 EXPECT_EQ(0u, plugin_loader()->next_load_index()); | 272 EXPECT_EQ(0u, plugin_loader()->next_load_index()); |
| 277 | 273 |
| 278 const std::vector<webkit::WebPluginInfo>& plugins( | 274 const std::vector<WebPluginInfo>& plugins(plugin_loader()->loaded_plugins()); |
| 279 plugin_loader()->loaded_plugins()); | |
| 280 | 275 |
| 281 plugin_loader()->TestOnPluginLoaded(0, plugin1_); | 276 plugin_loader()->TestOnPluginLoaded(0, plugin1_); |
| 282 EXPECT_EQ(1u, plugin_loader()->next_load_index()); | 277 EXPECT_EQ(1u, plugin_loader()->next_load_index()); |
| 283 EXPECT_EQ(1u, plugins.size()); | 278 EXPECT_EQ(1u, plugins.size()); |
| 284 EXPECT_EQ(plugin1_.name, plugins[0].name); | 279 EXPECT_EQ(plugin1_.name, plugins[0].name); |
| 285 | 280 |
| 286 message_loop()->RunUntilIdle(); | 281 message_loop()->RunUntilIdle(); |
| 287 EXPECT_EQ(0, did_callback); | 282 EXPECT_EQ(0, did_callback); |
| 288 | 283 |
| 289 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); | 284 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 306 | 301 |
| 307 plugin2_.path = base::FilePath("/internal/plugin.plugin"); | 302 plugin2_.path = base::FilePath("/internal/plugin.plugin"); |
| 308 | 303 |
| 309 AddThreePlugins(); | 304 AddThreePlugins(); |
| 310 | 305 |
| 311 plugin_loader()->internal_plugins()->clear(); | 306 plugin_loader()->internal_plugins()->clear(); |
| 312 plugin_loader()->internal_plugins()->push_back(plugin2_); | 307 plugin_loader()->internal_plugins()->push_back(plugin2_); |
| 313 | 308 |
| 314 EXPECT_EQ(0u, plugin_loader()->next_load_index()); | 309 EXPECT_EQ(0u, plugin_loader()->next_load_index()); |
| 315 | 310 |
| 316 const std::vector<webkit::WebPluginInfo>& plugins( | 311 const std::vector<WebPluginInfo>& plugins(plugin_loader()->loaded_plugins()); |
| 317 plugin_loader()->loaded_plugins()); | |
| 318 | 312 |
| 319 plugin_loader()->TestOnPluginLoaded(0, plugin1_); | 313 plugin_loader()->TestOnPluginLoaded(0, plugin1_); |
| 320 EXPECT_EQ(1u, plugin_loader()->next_load_index()); | 314 EXPECT_EQ(1u, plugin_loader()->next_load_index()); |
| 321 EXPECT_EQ(1u, plugins.size()); | 315 EXPECT_EQ(1u, plugins.size()); |
| 322 EXPECT_EQ(plugin1_.name, plugins[0].name); | 316 EXPECT_EQ(plugin1_.name, plugins[0].name); |
| 323 | 317 |
| 324 message_loop()->RunUntilIdle(); | 318 message_loop()->RunUntilIdle(); |
| 325 EXPECT_EQ(0, did_callback); | 319 EXPECT_EQ(0, did_callback); |
| 326 | 320 |
| 327 // Internal plugins can fail to load if they're built-in with manual | 321 // Internal plugins can fail to load if they're built-in with manual |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 plugin_loader()->OnProcessCrashed(42); | 364 plugin_loader()->OnProcessCrashed(42); |
| 371 plugin_loader()->OnProcessCrashed(42); | 365 plugin_loader()->OnProcessCrashed(42); |
| 372 | 366 |
| 373 message_loop()->RunUntilIdle(); | 367 message_loop()->RunUntilIdle(); |
| 374 EXPECT_EQ(1, did_callback); | 368 EXPECT_EQ(1, did_callback); |
| 375 | 369 |
| 376 EXPECT_EQ(0u, plugin_loader()->loaded_plugins().size()); | 370 EXPECT_EQ(0u, plugin_loader()->loaded_plugins().size()); |
| 377 } | 371 } |
| 378 | 372 |
| 379 } // namespace content | 373 } // namespace content |
| OLD | NEW |