| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 plugin2_(ASCIIToUTF16("plugin2"), FilePath("/tmp/two.plugin"), | 67 plugin2_(ASCIIToUTF16("plugin2"), FilePath("/tmp/two.plugin"), |
| 68 ASCIIToUTF16("2.0"), string16()), | 68 ASCIIToUTF16("2.0"), string16()), |
| 69 plugin3_(ASCIIToUTF16("plugin3"), FilePath("/tmp/three.plugin"), | 69 plugin3_(ASCIIToUTF16("plugin3"), FilePath("/tmp/three.plugin"), |
| 70 ASCIIToUTF16("3.0"), string16()), | 70 ASCIIToUTF16("3.0"), string16()), |
| 71 file_thread_(BrowserThread::FILE, &message_loop_), | 71 file_thread_(BrowserThread::FILE, &message_loop_), |
| 72 io_thread_(BrowserThread::IO, &message_loop_), | 72 io_thread_(BrowserThread::IO, &message_loop_), |
| 73 plugin_loader_(new MockPluginLoaderPosix) { | 73 plugin_loader_(new MockPluginLoaderPosix) { |
| 74 } | 74 } |
| 75 | 75 |
| 76 virtual void SetUp() OVERRIDE { | 76 virtual void SetUp() OVERRIDE { |
| 77 PluginService::GetInstance()->Init(); | 77 PluginServiceImpl::GetInstance()->Init(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 MessageLoop* message_loop() { return &message_loop_; } | 80 MessageLoop* message_loop() { return &message_loop_; } |
| 81 MockPluginLoaderPosix* plugin_loader() { return plugin_loader_.get(); } | 81 MockPluginLoaderPosix* plugin_loader() { return plugin_loader_.get(); } |
| 82 | 82 |
| 83 void AddThreePlugins() { | 83 void AddThreePlugins() { |
| 84 plugin_loader_->canonical_list()->clear(); | 84 plugin_loader_->canonical_list()->clear(); |
| 85 plugin_loader_->canonical_list()->push_back(plugin1_.path); | 85 plugin_loader_->canonical_list()->push_back(plugin1_.path); |
| 86 plugin_loader_->canonical_list()->push_back(plugin2_.path); | 86 plugin_loader_->canonical_list()->push_back(plugin2_.path); |
| 87 plugin_loader_->canonical_list()->push_back(plugin3_.path); | 87 plugin_loader_->canonical_list()->push_back(plugin3_.path); |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Data used for testing. | 90 // Data used for testing. |
| 91 webkit::WebPluginInfo plugin1_; | 91 webkit::WebPluginInfo plugin1_; |
| 92 webkit::WebPluginInfo plugin2_; | 92 webkit::WebPluginInfo plugin2_; |
| 93 webkit::WebPluginInfo plugin3_; | 93 webkit::WebPluginInfo plugin3_; |
| 94 | 94 |
| 95 private: | 95 private: |
| 96 base::ShadowingAtExitManager at_exit_manager_; // Destroys PluginService. | 96 base::ShadowingAtExitManager at_exit_manager_; // Destroys PluginService. |
| 97 | 97 |
| 98 MessageLoopForIO message_loop_; | 98 MessageLoopForIO message_loop_; |
| 99 BrowserThreadImpl file_thread_; | 99 BrowserThreadImpl file_thread_; |
| 100 BrowserThreadImpl io_thread_; | 100 BrowserThreadImpl io_thread_; |
| 101 | 101 |
| 102 scoped_refptr<MockPluginLoaderPosix> plugin_loader_; | 102 scoped_refptr<MockPluginLoaderPosix> plugin_loader_; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 TEST_F(PluginLoaderPosixTest, QueueRequests) { | 105 TEST_F(PluginLoaderPosixTest, QueueRequests) { |
| 106 int did_callback = 0; | 106 int did_callback = 0; |
| 107 PluginService::GetPluginsCallback callback = | 107 content::PluginService::GetPluginsCallback callback = |
| 108 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); | 108 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); |
| 109 | 109 |
| 110 EXPECT_EQ(0u, plugin_loader()->number_of_pending_callbacks()); | 110 EXPECT_EQ(0u, plugin_loader()->number_of_pending_callbacks()); |
| 111 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); | 111 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); |
| 112 EXPECT_EQ(1u, plugin_loader()->number_of_pending_callbacks()); | 112 EXPECT_EQ(1u, plugin_loader()->number_of_pending_callbacks()); |
| 113 | 113 |
| 114 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); | 114 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); |
| 115 EXPECT_EQ(2u, plugin_loader()->number_of_pending_callbacks()); | 115 EXPECT_EQ(2u, plugin_loader()->number_of_pending_callbacks()); |
| 116 | 116 |
| 117 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); | 117 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); |
| 118 message_loop()->RunAllPending(); | 118 message_loop()->RunAllPending(); |
| 119 | 119 |
| 120 plugin_loader()->canonical_list()->clear(); | 120 plugin_loader()->canonical_list()->clear(); |
| 121 plugin_loader()->canonical_list()->push_back(plugin1_.path); | 121 plugin_loader()->canonical_list()->push_back(plugin1_.path); |
| 122 | 122 |
| 123 EXPECT_EQ(0, did_callback); | 123 EXPECT_EQ(0, did_callback); |
| 124 | 124 |
| 125 plugin_loader()->TestOnPluginLoaded(0, plugin1_); | 125 plugin_loader()->TestOnPluginLoaded(0, plugin1_); |
| 126 message_loop()->RunAllPending(); | 126 message_loop()->RunAllPending(); |
| 127 | 127 |
| 128 EXPECT_EQ(2, did_callback); | 128 EXPECT_EQ(2, did_callback); |
| 129 EXPECT_EQ(0u, plugin_loader()->number_of_pending_callbacks()); | 129 EXPECT_EQ(0u, plugin_loader()->number_of_pending_callbacks()); |
| 130 } | 130 } |
| 131 | 131 |
| 132 TEST_F(PluginLoaderPosixTest, ThreeSuccessfulLoads) { | 132 TEST_F(PluginLoaderPosixTest, ThreeSuccessfulLoads) { |
| 133 int did_callback = 0; | 133 int did_callback = 0; |
| 134 PluginService::GetPluginsCallback callback = | 134 content::PluginService::GetPluginsCallback callback = |
| 135 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); | 135 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); |
| 136 | 136 |
| 137 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); | 137 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); |
| 138 | 138 |
| 139 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); | 139 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); |
| 140 message_loop()->RunAllPending(); | 140 message_loop()->RunAllPending(); |
| 141 | 141 |
| 142 AddThreePlugins(); | 142 AddThreePlugins(); |
| 143 | 143 |
| 144 EXPECT_EQ(0u, plugin_loader()->next_load_index()); | 144 EXPECT_EQ(0u, plugin_loader()->next_load_index()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 165 plugin_loader()->TestOnPluginLoaded(2, plugin3_); | 165 plugin_loader()->TestOnPluginLoaded(2, plugin3_); |
| 166 EXPECT_EQ(3u, plugins.size()); | 166 EXPECT_EQ(3u, plugins.size()); |
| 167 EXPECT_EQ(plugin3_.name, plugins[2].name); | 167 EXPECT_EQ(plugin3_.name, plugins[2].name); |
| 168 | 168 |
| 169 message_loop()->RunAllPending(); | 169 message_loop()->RunAllPending(); |
| 170 EXPECT_EQ(1, did_callback); | 170 EXPECT_EQ(1, did_callback); |
| 171 } | 171 } |
| 172 | 172 |
| 173 TEST_F(PluginLoaderPosixTest, TwoFailures) { | 173 TEST_F(PluginLoaderPosixTest, TwoFailures) { |
| 174 int did_callback = 0; | 174 int did_callback = 0; |
| 175 PluginService::GetPluginsCallback callback = | 175 content::PluginService::GetPluginsCallback callback = |
| 176 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); | 176 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); |
| 177 | 177 |
| 178 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); | 178 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); |
| 179 | 179 |
| 180 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); | 180 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); |
| 181 message_loop()->RunAllPending(); | 181 message_loop()->RunAllPending(); |
| 182 | 182 |
| 183 AddThreePlugins(); | 183 AddThreePlugins(); |
| 184 | 184 |
| 185 EXPECT_EQ(0u, plugin_loader()->next_load_index()); | 185 EXPECT_EQ(0u, plugin_loader()->next_load_index()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 204 | 204 |
| 205 plugin_loader()->TestOnPluginLoadFailed(2, plugin3_.path); | 205 plugin_loader()->TestOnPluginLoadFailed(2, plugin3_.path); |
| 206 EXPECT_EQ(1u, plugins.size()); | 206 EXPECT_EQ(1u, plugins.size()); |
| 207 | 207 |
| 208 message_loop()->RunAllPending(); | 208 message_loop()->RunAllPending(); |
| 209 EXPECT_EQ(1, did_callback); | 209 EXPECT_EQ(1, did_callback); |
| 210 } | 210 } |
| 211 | 211 |
| 212 TEST_F(PluginLoaderPosixTest, CrashedProcess) { | 212 TEST_F(PluginLoaderPosixTest, CrashedProcess) { |
| 213 int did_callback = 0; | 213 int did_callback = 0; |
| 214 PluginService::GetPluginsCallback callback = | 214 content::PluginService::GetPluginsCallback callback = |
| 215 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); | 215 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); |
| 216 | 216 |
| 217 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); | 217 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); |
| 218 | 218 |
| 219 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); | 219 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); |
| 220 message_loop()->RunAllPending(); | 220 message_loop()->RunAllPending(); |
| 221 | 221 |
| 222 AddThreePlugins(); | 222 AddThreePlugins(); |
| 223 | 223 |
| 224 EXPECT_EQ(0u, plugin_loader()->next_load_index()); | 224 EXPECT_EQ(0u, plugin_loader()->next_load_index()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 237 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); | 237 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); |
| 238 plugin_loader()->OnProcessCrashed(42); | 238 plugin_loader()->OnProcessCrashed(42); |
| 239 EXPECT_EQ(1u, plugin_loader()->canonical_list()->size()); | 239 EXPECT_EQ(1u, plugin_loader()->canonical_list()->size()); |
| 240 EXPECT_EQ(0u, plugin_loader()->next_load_index()); | 240 EXPECT_EQ(0u, plugin_loader()->next_load_index()); |
| 241 EXPECT_EQ(plugin3_.path.value(), | 241 EXPECT_EQ(plugin3_.path.value(), |
| 242 plugin_loader()->canonical_list()->at(0).value()); | 242 plugin_loader()->canonical_list()->at(0).value()); |
| 243 } | 243 } |
| 244 | 244 |
| 245 TEST_F(PluginLoaderPosixTest, InternalPlugin) { | 245 TEST_F(PluginLoaderPosixTest, InternalPlugin) { |
| 246 int did_callback = 0; | 246 int did_callback = 0; |
| 247 PluginService::GetPluginsCallback callback = | 247 content::PluginService::GetPluginsCallback callback = |
| 248 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); | 248 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); |
| 249 | 249 |
| 250 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); | 250 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); |
| 251 | 251 |
| 252 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); | 252 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); |
| 253 message_loop()->RunAllPending(); | 253 message_loop()->RunAllPending(); |
| 254 | 254 |
| 255 plugin2_.path = FilePath("/internal/plugin.plugin"); | 255 plugin2_.path = FilePath("/internal/plugin.plugin"); |
| 256 | 256 |
| 257 AddThreePlugins(); | 257 AddThreePlugins(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 286 plugin_loader()->TestOnPluginLoaded(2, plugin3_); | 286 plugin_loader()->TestOnPluginLoaded(2, plugin3_); |
| 287 EXPECT_EQ(3u, plugins.size()); | 287 EXPECT_EQ(3u, plugins.size()); |
| 288 EXPECT_EQ(plugin3_.name, plugins[2].name); | 288 EXPECT_EQ(plugin3_.name, plugins[2].name); |
| 289 | 289 |
| 290 message_loop()->RunAllPending(); | 290 message_loop()->RunAllPending(); |
| 291 EXPECT_EQ(1, did_callback); | 291 EXPECT_EQ(1, did_callback); |
| 292 } | 292 } |
| 293 | 293 |
| 294 TEST_F(PluginLoaderPosixTest, AllCrashed) { | 294 TEST_F(PluginLoaderPosixTest, AllCrashed) { |
| 295 int did_callback = 0; | 295 int did_callback = 0; |
| 296 PluginService::GetPluginsCallback callback = | 296 content::PluginService::GetPluginsCallback callback = |
| 297 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); | 297 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); |
| 298 | 298 |
| 299 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); | 299 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); |
| 300 | 300 |
| 301 // Spin the loop so that the canonical list of plugins can be set. | 301 // Spin the loop so that the canonical list of plugins can be set. |
| 302 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); | 302 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); |
| 303 message_loop()->RunAllPending(); | 303 message_loop()->RunAllPending(); |
| 304 AddThreePlugins(); | 304 AddThreePlugins(); |
| 305 | 305 |
| 306 EXPECT_EQ(0u, plugin_loader()->next_load_index()); | 306 EXPECT_EQ(0u, plugin_loader()->next_load_index()); |
| 307 | 307 |
| 308 // Mock the first two calls like normal. | 308 // Mock the first two calls like normal. |
| 309 testing::Expectation first = | 309 testing::Expectation first = |
| 310 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(2); | 310 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(2); |
| 311 // On the last call, go through the default impl. | 311 // On the last call, go through the default impl. |
| 312 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()) | 312 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()) |
| 313 .After(first) | 313 .After(first) |
| 314 .WillOnce( | 314 .WillOnce( |
| 315 testing::Invoke(plugin_loader(), | 315 testing::Invoke(plugin_loader(), |
| 316 &MockPluginLoaderPosix::RealLoadPluginsInternal)); | 316 &MockPluginLoaderPosix::RealLoadPluginsInternal)); |
| 317 plugin_loader()->OnProcessCrashed(42); | 317 plugin_loader()->OnProcessCrashed(42); |
| 318 plugin_loader()->OnProcessCrashed(42); | 318 plugin_loader()->OnProcessCrashed(42); |
| 319 plugin_loader()->OnProcessCrashed(42); | 319 plugin_loader()->OnProcessCrashed(42); |
| 320 | 320 |
| 321 message_loop()->RunAllPending(); | 321 message_loop()->RunAllPending(); |
| 322 EXPECT_EQ(1, did_callback); | 322 EXPECT_EQ(1, did_callback); |
| 323 | 323 |
| 324 EXPECT_EQ(0u, plugin_loader()->loaded_plugins().size()); | 324 EXPECT_EQ(0u, plugin_loader()->loaded_plugins().size()); |
| 325 } | 325 } |
| OLD | NEW |