| 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/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/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" | 16 #include "webkit/plugins/webplugininfo.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 class MockPluginLoaderPosix : public PluginLoaderPosix { | 20 class MockPluginLoaderPosix : public PluginLoaderPosix { |
| 21 public: | 21 public: |
| 22 MOCK_METHOD0(LoadPluginsInternal, void(void)); | 22 MOCK_METHOD0(LoadPluginsInternal, void(void)); |
| 23 | 23 |
| 24 size_t number_of_pending_callbacks() { | 24 size_t number_of_pending_callbacks() { |
| 25 return callbacks_.size(); | 25 return callbacks_.size(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 std::vector<FilePath>* canonical_list() { | 28 std::vector<base::FilePath>* canonical_list() { |
| 29 return &canonical_list_; | 29 return &canonical_list_; |
| 30 } | 30 } |
| 31 | 31 |
| 32 size_t next_load_index() { | 32 size_t next_load_index() { |
| 33 return next_load_index_; | 33 return next_load_index_; |
| 34 } | 34 } |
| 35 | 35 |
| 36 const std::vector<webkit::WebPluginInfo>& loaded_plugins() { | 36 const std::vector<webkit::WebPluginInfo>& loaded_plugins() { |
| 37 return loaded_plugins_; | 37 return loaded_plugins_; |
| 38 } | 38 } |
| 39 | 39 |
| 40 std::vector<webkit::WebPluginInfo>* internal_plugins() { | 40 std::vector<webkit::WebPluginInfo>* internal_plugins() { |
| 41 return &internal_plugins_; | 41 return &internal_plugins_; |
| 42 } | 42 } |
| 43 | 43 |
| 44 void RealLoadPluginsInternal() { | 44 void RealLoadPluginsInternal() { |
| 45 PluginLoaderPosix::LoadPluginsInternal(); | 45 PluginLoaderPosix::LoadPluginsInternal(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void TestOnPluginLoaded(uint32 index, const webkit::WebPluginInfo& plugin) { | 48 void TestOnPluginLoaded(uint32 index, const webkit::WebPluginInfo& plugin) { |
| 49 OnPluginLoaded(index, plugin); | 49 OnPluginLoaded(index, plugin); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void TestOnPluginLoadFailed(uint32 index, const FilePath& path) { | 52 void TestOnPluginLoadFailed(uint32 index, const base::FilePath& path) { |
| 53 OnPluginLoadFailed(index, path); | 53 OnPluginLoadFailed(index, path); |
| 54 } | 54 } |
| 55 | 55 |
| 56 protected: | 56 protected: |
| 57 virtual ~MockPluginLoaderPosix() {} | 57 virtual ~MockPluginLoaderPosix() {} |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 void VerifyCallback(int* run_count, const std::vector<webkit::WebPluginInfo>&) { | 60 void VerifyCallback(int* run_count, const std::vector<webkit::WebPluginInfo>&) { |
| 61 ++(*run_count); | 61 ++(*run_count); |
| 62 } | 62 } |
| 63 | 63 |
| 64 class PluginLoaderPosixTest : public testing::Test { | 64 class PluginLoaderPosixTest : public testing::Test { |
| 65 public: | 65 public: |
| 66 PluginLoaderPosixTest() | 66 PluginLoaderPosixTest() |
| 67 : plugin1_(ASCIIToUTF16("plugin1"), FilePath("/tmp/one.plugin"), | 67 : plugin1_(ASCIIToUTF16("plugin1"), base::FilePath("/tmp/one.plugin"), |
| 68 ASCIIToUTF16("1.0"), string16()), | 68 ASCIIToUTF16("1.0"), string16()), |
| 69 plugin2_(ASCIIToUTF16("plugin2"), FilePath("/tmp/two.plugin"), | 69 plugin2_(ASCIIToUTF16("plugin2"), base::FilePath("/tmp/two.plugin"), |
| 70 ASCIIToUTF16("2.0"), string16()), | 70 ASCIIToUTF16("2.0"), string16()), |
| 71 plugin3_(ASCIIToUTF16("plugin3"), FilePath("/tmp/three.plugin"), | 71 plugin3_(ASCIIToUTF16("plugin3"), base::FilePath("/tmp/three.plugin"), |
| 72 ASCIIToUTF16("3.0"), string16()), | 72 ASCIIToUTF16("3.0"), string16()), |
| 73 file_thread_(BrowserThread::FILE, &message_loop_), | 73 file_thread_(BrowserThread::FILE, &message_loop_), |
| 74 io_thread_(BrowserThread::IO, &message_loop_), | 74 io_thread_(BrowserThread::IO, &message_loop_), |
| 75 plugin_loader_(new MockPluginLoaderPosix) { | 75 plugin_loader_(new MockPluginLoaderPosix) { |
| 76 } | 76 } |
| 77 | 77 |
| 78 virtual void SetUp() OVERRIDE { | 78 virtual void SetUp() OVERRIDE { |
| 79 PluginServiceImpl::GetInstance()->Init(); | 79 PluginServiceImpl::GetInstance()->Init(); |
| 80 } | 80 } |
| 81 | 81 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 TEST_F(PluginLoaderPosixTest, InternalPlugin) { | 297 TEST_F(PluginLoaderPosixTest, InternalPlugin) { |
| 298 int did_callback = 0; | 298 int did_callback = 0; |
| 299 PluginService::GetPluginsCallback callback = | 299 PluginService::GetPluginsCallback callback = |
| 300 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); | 300 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); |
| 301 | 301 |
| 302 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); | 302 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); |
| 303 | 303 |
| 304 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); | 304 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); |
| 305 message_loop()->RunUntilIdle(); | 305 message_loop()->RunUntilIdle(); |
| 306 | 306 |
| 307 plugin2_.path = FilePath("/internal/plugin.plugin"); | 307 plugin2_.path = base::FilePath("/internal/plugin.plugin"); |
| 308 | 308 |
| 309 AddThreePlugins(); | 309 AddThreePlugins(); |
| 310 | 310 |
| 311 plugin_loader()->internal_plugins()->clear(); | 311 plugin_loader()->internal_plugins()->clear(); |
| 312 plugin_loader()->internal_plugins()->push_back(plugin2_); | 312 plugin_loader()->internal_plugins()->push_back(plugin2_); |
| 313 | 313 |
| 314 EXPECT_EQ(0u, plugin_loader()->next_load_index()); | 314 EXPECT_EQ(0u, plugin_loader()->next_load_index()); |
| 315 | 315 |
| 316 const std::vector<webkit::WebPluginInfo>& plugins( | 316 const std::vector<webkit::WebPluginInfo>& plugins( |
| 317 plugin_loader()->loaded_plugins()); | 317 plugin_loader()->loaded_plugins()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 plugin_loader()->OnProcessCrashed(42); | 370 plugin_loader()->OnProcessCrashed(42); |
| 371 plugin_loader()->OnProcessCrashed(42); | 371 plugin_loader()->OnProcessCrashed(42); |
| 372 | 372 |
| 373 message_loop()->RunUntilIdle(); | 373 message_loop()->RunUntilIdle(); |
| 374 EXPECT_EQ(1, did_callback); | 374 EXPECT_EQ(1, did_callback); |
| 375 | 375 |
| 376 EXPECT_EQ(0u, plugin_loader()->loaded_plugins().size()); | 376 EXPECT_EQ(0u, plugin_loader()->loaded_plugins().size()); |
| 377 } | 377 } |
| 378 | 378 |
| 379 } // namespace content | 379 } // namespace content |
| OLD | NEW |