Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: content/browser/plugin_loader_posix_unittest.cc

Issue 128773002: Restart plugin loading only if the plugin list has actually become stale. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/plugin_loader_posix.cc ('k') | content/browser/plugin_service_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/common/plugin_list.h"
14 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 using base::ASCIIToUTF16; 18 using base::ASCIIToUTF16;
18 19
19 namespace content { 20 namespace content {
20 21
21 class MockPluginLoaderPosix : public PluginLoaderPosix { 22 class MockPluginLoaderPosix : public PluginLoaderPosix {
22 public: 23 public:
23 MOCK_METHOD0(LoadPluginsInternal, void(void)); 24 MOCK_METHOD0(LoadPluginsInternal, void(void));
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 plugin_loader_->canonical_list()->push_back(plugin2_.path); 90 plugin_loader_->canonical_list()->push_back(plugin2_.path);
90 plugin_loader_->canonical_list()->push_back(plugin3_.path); 91 plugin_loader_->canonical_list()->push_back(plugin3_.path);
91 } 92 }
92 93
93 // Data used for testing. 94 // Data used for testing.
94 WebPluginInfo plugin1_; 95 WebPluginInfo plugin1_;
95 WebPluginInfo plugin2_; 96 WebPluginInfo plugin2_;
96 WebPluginInfo plugin3_; 97 WebPluginInfo plugin3_;
97 98
98 private: 99 private:
99 base::ShadowingAtExitManager at_exit_manager_; // Destroys PluginService. 100 // Destroys PluginService and PluginList.
101 base::ShadowingAtExitManager at_exit_manager_;
100 102
101 base::MessageLoopForIO message_loop_; 103 base::MessageLoopForIO message_loop_;
102 BrowserThreadImpl file_thread_; 104 BrowserThreadImpl file_thread_;
103 BrowserThreadImpl io_thread_; 105 BrowserThreadImpl io_thread_;
104 106
105 scoped_refptr<MockPluginLoaderPosix> plugin_loader_; 107 scoped_refptr<MockPluginLoaderPosix> plugin_loader_;
106 }; 108 };
107 109
108 TEST_F(PluginLoaderPosixTest, QueueRequests) { 110 TEST_F(PluginLoaderPosixTest, QueueRequests) {
109 int did_callback = 0; 111 int did_callback = 0;
110 PluginService::GetPluginsCallback callback = 112 PluginService::GetPluginsCallback callback =
111 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); 113 base::Bind(&VerifyCallback, base::Unretained(&did_callback));
112 114
113 EXPECT_EQ(0u, plugin_loader()->number_of_pending_callbacks()); 115 plugin_loader()->GetPlugins(callback);
114 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); 116 plugin_loader()->GetPlugins(callback);
115 EXPECT_EQ(1u, plugin_loader()->number_of_pending_callbacks());
116 117
117 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); 118 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1);
118 EXPECT_EQ(2u, plugin_loader()->number_of_pending_callbacks());
119
120 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(2);
121 message_loop()->RunUntilIdle(); 119 message_loop()->RunUntilIdle();
122 120
123 EXPECT_EQ(0, did_callback); 121 EXPECT_EQ(0, did_callback);
124 122
125 plugin_loader()->canonical_list()->clear(); 123 plugin_loader()->canonical_list()->clear();
126 plugin_loader()->canonical_list()->push_back(plugin1_.path); 124 plugin_loader()->canonical_list()->push_back(plugin1_.path);
127 plugin_loader()->TestOnPluginLoaded(0, plugin1_); 125 plugin_loader()->TestOnPluginLoaded(0, plugin1_);
128 message_loop()->RunUntilIdle(); 126 message_loop()->RunUntilIdle();
129 127
130 EXPECT_EQ(1, did_callback); 128 EXPECT_EQ(2, did_callback);
131 EXPECT_EQ(1u, plugin_loader()->number_of_pending_callbacks()); 129 }
130
131 TEST_F(PluginLoaderPosixTest, QueueRequestsAndInvalidate) {
132 int did_callback = 0;
133 PluginService::GetPluginsCallback callback =
134 base::Bind(&VerifyCallback, base::Unretained(&did_callback));
135
136 plugin_loader()->GetPlugins(callback);
137
138 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1);
139 message_loop()->RunUntilIdle();
140
141 EXPECT_EQ(0, did_callback);
142 ::testing::Mock::VerifyAndClearExpectations(plugin_loader());
143
144 // Invalidate the plugin list, then queue up another request.
145 PluginList::Singleton()->RefreshPlugins();
146 plugin_loader()->GetPlugins(callback);
147
148 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1);
132 149
133 plugin_loader()->canonical_list()->clear(); 150 plugin_loader()->canonical_list()->clear();
134 plugin_loader()->canonical_list()->push_back(plugin1_.path); 151 plugin_loader()->canonical_list()->push_back(plugin1_.path);
152 plugin_loader()->TestOnPluginLoaded(0, plugin1_);
153 message_loop()->RunUntilIdle();
154
155 // Only the first request should have been fulfilled.
156 EXPECT_EQ(1, did_callback);
157
158 plugin_loader()->canonical_list()->clear();
159 plugin_loader()->canonical_list()->push_back(plugin1_.path);
135 plugin_loader()->TestOnPluginLoaded(0, plugin1_); 160 plugin_loader()->TestOnPluginLoaded(0, plugin1_);
136 message_loop()->RunUntilIdle(); 161 message_loop()->RunUntilIdle();
137 162
138 EXPECT_EQ(2, did_callback); 163 EXPECT_EQ(2, did_callback);
139 EXPECT_EQ(0u, plugin_loader()->number_of_pending_callbacks());
140 } 164 }
141 165
142 TEST_F(PluginLoaderPosixTest, ThreeSuccessfulLoads) { 166 TEST_F(PluginLoaderPosixTest, ThreeSuccessfulLoads) {
143 int did_callback = 0; 167 int did_callback = 0;
144 PluginService::GetPluginsCallback callback = 168 PluginService::GetPluginsCallback callback =
145 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); 169 base::Bind(&VerifyCallback, base::Unretained(&did_callback));
146 170
147 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); 171 plugin_loader()->GetPlugins(callback);
148 172
149 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); 173 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1);
150 message_loop()->RunUntilIdle(); 174 message_loop()->RunUntilIdle();
151 175
152 AddThreePlugins(); 176 AddThreePlugins();
153 177
154 EXPECT_EQ(0u, plugin_loader()->next_load_index()); 178 EXPECT_EQ(0u, plugin_loader()->next_load_index());
155 179
156 const std::vector<WebPluginInfo>& plugins(plugin_loader()->loaded_plugins()); 180 const std::vector<WebPluginInfo>& plugins(plugin_loader()->loaded_plugins());
157 181
(...skipping 19 matching lines...) Expand all
177 201
178 message_loop()->RunUntilIdle(); 202 message_loop()->RunUntilIdle();
179 EXPECT_EQ(1, did_callback); 203 EXPECT_EQ(1, did_callback);
180 } 204 }
181 205
182 TEST_F(PluginLoaderPosixTest, ThreeSuccessfulLoadsThenCrash) { 206 TEST_F(PluginLoaderPosixTest, ThreeSuccessfulLoadsThenCrash) {
183 int did_callback = 0; 207 int did_callback = 0;
184 PluginService::GetPluginsCallback callback = 208 PluginService::GetPluginsCallback callback =
185 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); 209 base::Bind(&VerifyCallback, base::Unretained(&did_callback));
186 210
187 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); 211 plugin_loader()->GetPlugins(callback);
188 212
189 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(2); 213 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(2);
190 message_loop()->RunUntilIdle(); 214 message_loop()->RunUntilIdle();
191 215
192 AddThreePlugins(); 216 AddThreePlugins();
193 217
194 EXPECT_EQ(0u, plugin_loader()->next_load_index()); 218 EXPECT_EQ(0u, plugin_loader()->next_load_index());
195 219
196 const std::vector<WebPluginInfo>& plugins(plugin_loader()->loaded_plugins()); 220 const std::vector<WebPluginInfo>& plugins(plugin_loader()->loaded_plugins());
197 221
(...skipping 21 matching lines...) Expand all
219 EXPECT_EQ(1, did_callback); 243 EXPECT_EQ(1, did_callback);
220 244
221 plugin_loader()->OnProcessCrashed(42); 245 plugin_loader()->OnProcessCrashed(42);
222 } 246 }
223 247
224 TEST_F(PluginLoaderPosixTest, TwoFailures) { 248 TEST_F(PluginLoaderPosixTest, TwoFailures) {
225 int did_callback = 0; 249 int did_callback = 0;
226 PluginService::GetPluginsCallback callback = 250 PluginService::GetPluginsCallback callback =
227 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); 251 base::Bind(&VerifyCallback, base::Unretained(&did_callback));
228 252
229 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); 253 plugin_loader()->GetPlugins(callback);
230 254
231 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); 255 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1);
232 message_loop()->RunUntilIdle(); 256 message_loop()->RunUntilIdle();
233 257
234 AddThreePlugins(); 258 AddThreePlugins();
235 259
236 EXPECT_EQ(0u, plugin_loader()->next_load_index()); 260 EXPECT_EQ(0u, plugin_loader()->next_load_index());
237 261
238 const std::vector<WebPluginInfo>& plugins(plugin_loader()->loaded_plugins()); 262 const std::vector<WebPluginInfo>& plugins(plugin_loader()->loaded_plugins());
239 263
(...skipping 17 matching lines...) Expand all
257 281
258 message_loop()->RunUntilIdle(); 282 message_loop()->RunUntilIdle();
259 EXPECT_EQ(1, did_callback); 283 EXPECT_EQ(1, did_callback);
260 } 284 }
261 285
262 TEST_F(PluginLoaderPosixTest, CrashedProcess) { 286 TEST_F(PluginLoaderPosixTest, CrashedProcess) {
263 int did_callback = 0; 287 int did_callback = 0;
264 PluginService::GetPluginsCallback callback = 288 PluginService::GetPluginsCallback callback =
265 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); 289 base::Bind(&VerifyCallback, base::Unretained(&did_callback));
266 290
267 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); 291 plugin_loader()->GetPlugins(callback);
268 292
269 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); 293 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1);
270 message_loop()->RunUntilIdle(); 294 message_loop()->RunUntilIdle();
271 295
272 AddThreePlugins(); 296 AddThreePlugins();
273 297
274 EXPECT_EQ(0u, plugin_loader()->next_load_index()); 298 EXPECT_EQ(0u, plugin_loader()->next_load_index());
275 299
276 const std::vector<WebPluginInfo>& plugins(plugin_loader()->loaded_plugins()); 300 const std::vector<WebPluginInfo>& plugins(plugin_loader()->loaded_plugins());
277 301
(...skipping 11 matching lines...) Expand all
289 EXPECT_EQ(0u, plugin_loader()->next_load_index()); 313 EXPECT_EQ(0u, plugin_loader()->next_load_index());
290 EXPECT_EQ(plugin3_.path.value(), 314 EXPECT_EQ(plugin3_.path.value(),
291 plugin_loader()->canonical_list()->at(0).value()); 315 plugin_loader()->canonical_list()->at(0).value());
292 } 316 }
293 317
294 TEST_F(PluginLoaderPosixTest, InternalPlugin) { 318 TEST_F(PluginLoaderPosixTest, InternalPlugin) {
295 int did_callback = 0; 319 int did_callback = 0;
296 PluginService::GetPluginsCallback callback = 320 PluginService::GetPluginsCallback callback =
297 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); 321 base::Bind(&VerifyCallback, base::Unretained(&did_callback));
298 322
299 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); 323 plugin_loader()->GetPlugins(callback);
300 324
301 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); 325 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1);
302 message_loop()->RunUntilIdle(); 326 message_loop()->RunUntilIdle();
303 327
304 plugin2_.path = base::FilePath("/internal/plugin.plugin"); 328 plugin2_.path = base::FilePath("/internal/plugin.plugin");
305 329
306 AddThreePlugins(); 330 AddThreePlugins();
307 331
308 plugin_loader()->internal_plugins()->clear(); 332 plugin_loader()->internal_plugins()->clear();
309 plugin_loader()->internal_plugins()->push_back(plugin2_); 333 plugin_loader()->internal_plugins()->push_back(plugin2_);
(...skipping 27 matching lines...) Expand all
337 361
338 message_loop()->RunUntilIdle(); 362 message_loop()->RunUntilIdle();
339 EXPECT_EQ(1, did_callback); 363 EXPECT_EQ(1, did_callback);
340 } 364 }
341 365
342 TEST_F(PluginLoaderPosixTest, AllCrashed) { 366 TEST_F(PluginLoaderPosixTest, AllCrashed) {
343 int did_callback = 0; 367 int did_callback = 0;
344 PluginService::GetPluginsCallback callback = 368 PluginService::GetPluginsCallback callback =
345 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); 369 base::Bind(&VerifyCallback, base::Unretained(&did_callback));
346 370
347 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); 371 plugin_loader()->GetPlugins(callback);
348 372
349 // Spin the loop so that the canonical list of plugins can be set. 373 // Spin the loop so that the canonical list of plugins can be set.
350 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); 374 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1);
351 message_loop()->RunUntilIdle(); 375 message_loop()->RunUntilIdle();
352 AddThreePlugins(); 376 AddThreePlugins();
353 377
354 EXPECT_EQ(0u, plugin_loader()->next_load_index()); 378 EXPECT_EQ(0u, plugin_loader()->next_load_index());
355 379
356 // Mock the first two calls like normal. 380 // Mock the first two calls like normal.
357 testing::Expectation first = 381 testing::Expectation first =
358 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(2); 382 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(2);
359 // On the last call, go through the default impl. 383 // On the last call, go through the default impl.
360 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()) 384 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal())
361 .After(first) 385 .After(first)
362 .WillOnce( 386 .WillOnce(
363 testing::Invoke(plugin_loader(), 387 testing::Invoke(plugin_loader(),
364 &MockPluginLoaderPosix::RealLoadPluginsInternal)); 388 &MockPluginLoaderPosix::RealLoadPluginsInternal));
365 plugin_loader()->OnProcessCrashed(42); 389 plugin_loader()->OnProcessCrashed(42);
366 plugin_loader()->OnProcessCrashed(42); 390 plugin_loader()->OnProcessCrashed(42);
367 plugin_loader()->OnProcessCrashed(42); 391 plugin_loader()->OnProcessCrashed(42);
368 392
369 message_loop()->RunUntilIdle(); 393 message_loop()->RunUntilIdle();
370 EXPECT_EQ(1, did_callback); 394 EXPECT_EQ(1, did_callback);
371 395
372 EXPECT_EQ(0u, plugin_loader()->loaded_plugins().size()); 396 EXPECT_EQ(0u, plugin_loader()->loaded_plugins().size());
373 } 397 }
374 398
375 } // namespace content 399 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/plugin_loader_posix.cc ('k') | content/browser/plugin_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698