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

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

Issue 11235068: Move the remaning files in content\common to the content namespace. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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_process_host.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/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 using content::BrowserThread; 18 namespace content {
19 using content::BrowserThreadImpl;
20 19
21 class MockPluginLoaderPosix : public PluginLoaderPosix { 20 class MockPluginLoaderPosix : public PluginLoaderPosix {
22 public: 21 public:
23 MOCK_METHOD0(LoadPluginsInternal, void(void)); 22 MOCK_METHOD0(LoadPluginsInternal, void(void));
24 23
25 size_t number_of_pending_callbacks() { 24 size_t number_of_pending_callbacks() {
26 return callbacks_.size(); 25 return callbacks_.size();
27 } 26 }
28 27
29 std::vector<FilePath>* canonical_list() { 28 std::vector<FilePath>* canonical_list() {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 99
101 MessageLoopForIO message_loop_; 100 MessageLoopForIO message_loop_;
102 BrowserThreadImpl file_thread_; 101 BrowserThreadImpl file_thread_;
103 BrowserThreadImpl io_thread_; 102 BrowserThreadImpl io_thread_;
104 103
105 scoped_refptr<MockPluginLoaderPosix> plugin_loader_; 104 scoped_refptr<MockPluginLoaderPosix> plugin_loader_;
106 }; 105 };
107 106
108 TEST_F(PluginLoaderPosixTest, QueueRequests) { 107 TEST_F(PluginLoaderPosixTest, QueueRequests) {
109 int did_callback = 0; 108 int did_callback = 0;
110 content::PluginService::GetPluginsCallback callback = 109 PluginService::GetPluginsCallback callback =
111 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); 110 base::Bind(&VerifyCallback, base::Unretained(&did_callback));
112 111
113 EXPECT_EQ(0u, plugin_loader()->number_of_pending_callbacks()); 112 EXPECT_EQ(0u, plugin_loader()->number_of_pending_callbacks());
114 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); 113 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback);
115 EXPECT_EQ(1u, plugin_loader()->number_of_pending_callbacks()); 114 EXPECT_EQ(1u, plugin_loader()->number_of_pending_callbacks());
116 115
117 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); 116 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback);
118 EXPECT_EQ(2u, plugin_loader()->number_of_pending_callbacks()); 117 EXPECT_EQ(2u, plugin_loader()->number_of_pending_callbacks());
119 118
120 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(2); 119 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(2);
(...skipping 13 matching lines...) Expand all
134 plugin_loader()->canonical_list()->push_back(plugin1_.path); 133 plugin_loader()->canonical_list()->push_back(plugin1_.path);
135 plugin_loader()->TestOnPluginLoaded(0, plugin1_); 134 plugin_loader()->TestOnPluginLoaded(0, plugin1_);
136 message_loop()->RunAllPending(); 135 message_loop()->RunAllPending();
137 136
138 EXPECT_EQ(2, did_callback); 137 EXPECT_EQ(2, did_callback);
139 EXPECT_EQ(0u, plugin_loader()->number_of_pending_callbacks()); 138 EXPECT_EQ(0u, plugin_loader()->number_of_pending_callbacks());
140 } 139 }
141 140
142 TEST_F(PluginLoaderPosixTest, ThreeSuccessfulLoads) { 141 TEST_F(PluginLoaderPosixTest, ThreeSuccessfulLoads) {
143 int did_callback = 0; 142 int did_callback = 0;
144 content::PluginService::GetPluginsCallback callback = 143 PluginService::GetPluginsCallback callback =
145 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); 144 base::Bind(&VerifyCallback, base::Unretained(&did_callback));
146 145
147 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); 146 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback);
148 147
149 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); 148 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1);
150 message_loop()->RunAllPending(); 149 message_loop()->RunAllPending();
151 150
152 AddThreePlugins(); 151 AddThreePlugins();
153 152
154 EXPECT_EQ(0u, plugin_loader()->next_load_index()); 153 EXPECT_EQ(0u, plugin_loader()->next_load_index());
(...skipping 20 matching lines...) Expand all
175 plugin_loader()->TestOnPluginLoaded(2, plugin3_); 174 plugin_loader()->TestOnPluginLoaded(2, plugin3_);
176 EXPECT_EQ(3u, plugins.size()); 175 EXPECT_EQ(3u, plugins.size());
177 EXPECT_EQ(plugin3_.name, plugins[2].name); 176 EXPECT_EQ(plugin3_.name, plugins[2].name);
178 177
179 message_loop()->RunAllPending(); 178 message_loop()->RunAllPending();
180 EXPECT_EQ(1, did_callback); 179 EXPECT_EQ(1, did_callback);
181 } 180 }
182 181
183 TEST_F(PluginLoaderPosixTest, ThreeSuccessfulLoadsThenCrash) { 182 TEST_F(PluginLoaderPosixTest, ThreeSuccessfulLoadsThenCrash) {
184 int did_callback = 0; 183 int did_callback = 0;
185 content::PluginService::GetPluginsCallback callback = 184 PluginService::GetPluginsCallback callback =
186 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); 185 base::Bind(&VerifyCallback, base::Unretained(&did_callback));
187 186
188 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); 187 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback);
189 188
190 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(2); 189 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(2);
191 message_loop()->RunAllPending(); 190 message_loop()->RunAllPending();
192 191
193 AddThreePlugins(); 192 AddThreePlugins();
194 193
195 EXPECT_EQ(0u, plugin_loader()->next_load_index()); 194 EXPECT_EQ(0u, plugin_loader()->next_load_index());
(...skipping 22 matching lines...) Expand all
218 EXPECT_EQ(plugin3_.name, plugins[2].name); 217 EXPECT_EQ(plugin3_.name, plugins[2].name);
219 218
220 message_loop()->RunAllPending(); 219 message_loop()->RunAllPending();
221 EXPECT_EQ(1, did_callback); 220 EXPECT_EQ(1, did_callback);
222 221
223 plugin_loader()->OnProcessCrashed(42); 222 plugin_loader()->OnProcessCrashed(42);
224 } 223 }
225 224
226 TEST_F(PluginLoaderPosixTest, TwoFailures) { 225 TEST_F(PluginLoaderPosixTest, TwoFailures) {
227 int did_callback = 0; 226 int did_callback = 0;
228 content::PluginService::GetPluginsCallback callback = 227 PluginService::GetPluginsCallback callback =
229 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); 228 base::Bind(&VerifyCallback, base::Unretained(&did_callback));
230 229
231 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); 230 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback);
232 231
233 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); 232 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1);
234 message_loop()->RunAllPending(); 233 message_loop()->RunAllPending();
235 234
236 AddThreePlugins(); 235 AddThreePlugins();
237 236
238 EXPECT_EQ(0u, plugin_loader()->next_load_index()); 237 EXPECT_EQ(0u, plugin_loader()->next_load_index());
(...skipping 18 matching lines...) Expand all
257 256
258 plugin_loader()->TestOnPluginLoadFailed(2, plugin3_.path); 257 plugin_loader()->TestOnPluginLoadFailed(2, plugin3_.path);
259 EXPECT_EQ(1u, plugins.size()); 258 EXPECT_EQ(1u, plugins.size());
260 259
261 message_loop()->RunAllPending(); 260 message_loop()->RunAllPending();
262 EXPECT_EQ(1, did_callback); 261 EXPECT_EQ(1, did_callback);
263 } 262 }
264 263
265 TEST_F(PluginLoaderPosixTest, CrashedProcess) { 264 TEST_F(PluginLoaderPosixTest, CrashedProcess) {
266 int did_callback = 0; 265 int did_callback = 0;
267 content::PluginService::GetPluginsCallback callback = 266 PluginService::GetPluginsCallback callback =
268 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); 267 base::Bind(&VerifyCallback, base::Unretained(&did_callback));
269 268
270 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); 269 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback);
271 270
272 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); 271 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1);
273 message_loop()->RunAllPending(); 272 message_loop()->RunAllPending();
274 273
275 AddThreePlugins(); 274 AddThreePlugins();
276 275
277 EXPECT_EQ(0u, plugin_loader()->next_load_index()); 276 EXPECT_EQ(0u, plugin_loader()->next_load_index());
(...skipping 12 matching lines...) Expand all
290 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); 289 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1);
291 plugin_loader()->OnProcessCrashed(42); 290 plugin_loader()->OnProcessCrashed(42);
292 EXPECT_EQ(1u, plugin_loader()->canonical_list()->size()); 291 EXPECT_EQ(1u, plugin_loader()->canonical_list()->size());
293 EXPECT_EQ(0u, plugin_loader()->next_load_index()); 292 EXPECT_EQ(0u, plugin_loader()->next_load_index());
294 EXPECT_EQ(plugin3_.path.value(), 293 EXPECT_EQ(plugin3_.path.value(),
295 plugin_loader()->canonical_list()->at(0).value()); 294 plugin_loader()->canonical_list()->at(0).value());
296 } 295 }
297 296
298 TEST_F(PluginLoaderPosixTest, InternalPlugin) { 297 TEST_F(PluginLoaderPosixTest, InternalPlugin) {
299 int did_callback = 0; 298 int did_callback = 0;
300 content::PluginService::GetPluginsCallback callback = 299 PluginService::GetPluginsCallback callback =
301 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); 300 base::Bind(&VerifyCallback, base::Unretained(&did_callback));
302 301
303 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); 302 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback);
304 303
305 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); 304 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1);
306 message_loop()->RunAllPending(); 305 message_loop()->RunAllPending();
307 306
308 plugin2_.path = FilePath("/internal/plugin.plugin"); 307 plugin2_.path = FilePath("/internal/plugin.plugin");
309 308
310 AddThreePlugins(); 309 AddThreePlugins();
(...skipping 28 matching lines...) Expand all
339 plugin_loader()->TestOnPluginLoaded(2, plugin3_); 338 plugin_loader()->TestOnPluginLoaded(2, plugin3_);
340 EXPECT_EQ(3u, plugins.size()); 339 EXPECT_EQ(3u, plugins.size());
341 EXPECT_EQ(plugin3_.name, plugins[2].name); 340 EXPECT_EQ(plugin3_.name, plugins[2].name);
342 341
343 message_loop()->RunAllPending(); 342 message_loop()->RunAllPending();
344 EXPECT_EQ(1, did_callback); 343 EXPECT_EQ(1, did_callback);
345 } 344 }
346 345
347 TEST_F(PluginLoaderPosixTest, AllCrashed) { 346 TEST_F(PluginLoaderPosixTest, AllCrashed) {
348 int did_callback = 0; 347 int did_callback = 0;
349 content::PluginService::GetPluginsCallback callback = 348 PluginService::GetPluginsCallback callback =
350 base::Bind(&VerifyCallback, base::Unretained(&did_callback)); 349 base::Bind(&VerifyCallback, base::Unretained(&did_callback));
351 350
352 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback); 351 plugin_loader()->LoadPlugins(message_loop()->message_loop_proxy(), callback);
353 352
354 // Spin the loop so that the canonical list of plugins can be set. 353 // Spin the loop so that the canonical list of plugins can be set.
355 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1); 354 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(1);
356 message_loop()->RunAllPending(); 355 message_loop()->RunAllPending();
357 AddThreePlugins(); 356 AddThreePlugins();
358 357
359 EXPECT_EQ(0u, plugin_loader()->next_load_index()); 358 EXPECT_EQ(0u, plugin_loader()->next_load_index());
360 359
361 // Mock the first two calls like normal. 360 // Mock the first two calls like normal.
362 testing::Expectation first = 361 testing::Expectation first =
363 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(2); 362 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()).Times(2);
364 // On the last call, go through the default impl. 363 // On the last call, go through the default impl.
365 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal()) 364 EXPECT_CALL(*plugin_loader(), LoadPluginsInternal())
366 .After(first) 365 .After(first)
367 .WillOnce( 366 .WillOnce(
368 testing::Invoke(plugin_loader(), 367 testing::Invoke(plugin_loader(),
369 &MockPluginLoaderPosix::RealLoadPluginsInternal)); 368 &MockPluginLoaderPosix::RealLoadPluginsInternal));
370 plugin_loader()->OnProcessCrashed(42); 369 plugin_loader()->OnProcessCrashed(42);
371 plugin_loader()->OnProcessCrashed(42); 370 plugin_loader()->OnProcessCrashed(42);
372 plugin_loader()->OnProcessCrashed(42); 371 plugin_loader()->OnProcessCrashed(42);
373 372
374 message_loop()->RunAllPending(); 373 message_loop()->RunAllPending();
375 EXPECT_EQ(1, did_callback); 374 EXPECT_EQ(1, did_callback);
376 375
377 EXPECT_EQ(0u, plugin_loader()->loaded_plugins().size()); 376 EXPECT_EQ(0u, plugin_loader()->loaded_plugins().size());
378 } 377 }
378
379 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/plugin_loader_posix.cc ('k') | content/browser/plugin_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698