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_service_impl.h" | 5 #include "content/browser/plugin_service_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "content/public/browser/browser_context.h" | 11 #include "content/public/browser/browser_context.h" |
12 #include "content/public/browser/plugin_service_filter.h" | 12 #include "content/public/browser/plugin_service_filter.h" |
13 #include "content/public/browser/resource_context.h" | 13 #include "content/public/browser/resource_context.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
16 #include "content/public/test/content_browser_test.h" | 16 #include "content/public/test/content_browser_test.h" |
17 #include "content/public/test/test_browser_thread.h" | 17 #include "content/public/test/test_browser_thread.h" |
18 #include "content/public/test/test_utils.h" | 18 #include "content/public/test/test_utils.h" |
19 #include "content/shell/browser/shell.h" | 19 #include "content/shell/browser/shell.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 | 23 |
24 const char kNPAPITestPluginMimeType[] = "application/vnd.npapi-test"; | 24 const char kNPAPITestPluginMimeType[] = "application/vnd.npapi-test"; |
25 | 25 |
26 void OpenChannel(PluginProcessHost::Client* client) { | 26 void OpenChannel(PluginProcessHost::Client* client) { |
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 27 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
28 // Start opening the channel | 28 // Start opening the channel |
29 PluginServiceImpl::GetInstance()->OpenChannelToNpapiPlugin( | 29 PluginServiceImpl::GetInstance()->OpenChannelToNpapiPlugin( |
30 0, 0, GURL(), GURL(), kNPAPITestPluginMimeType, client); | 30 0, 0, GURL(), GURL(), kNPAPITestPluginMimeType, client); |
31 } | 31 } |
32 | 32 |
33 // Mock up of the Client and the Listener classes that would supply the | 33 // Mock up of the Client and the Listener classes that would supply the |
34 // communication channel with the plugin. | 34 // communication channel with the plugin. |
35 class MockPluginProcessHostClient : public PluginProcessHost::Client, | 35 class MockPluginProcessHostClient : public PluginProcessHost::Client, |
36 public IPC::Listener { | 36 public IPC::Listener { |
37 public: | 37 public: |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 ResourceContext* context) | 243 ResourceContext* context) |
244 : MockCanceledPluginServiceClient(context), | 244 : MockCanceledPluginServiceClient(context), |
245 set_plugin_info_called_(false), | 245 set_plugin_info_called_(false), |
246 on_found_plugin_process_host_called_(false), | 246 on_found_plugin_process_host_called_(false), |
247 host_(NULL) {} | 247 host_(NULL) {} |
248 | 248 |
249 ~MockCanceledBeforeSentPluginProcessHostClient() override {} | 249 ~MockCanceledBeforeSentPluginProcessHostClient() override {} |
250 | 250 |
251 // Client implementation. | 251 // Client implementation. |
252 void SetPluginInfo(const WebPluginInfo& info) override { | 252 void SetPluginInfo(const WebPluginInfo& info) override { |
253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 253 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
254 ASSERT_TRUE(info.mime_types.size()); | 254 ASSERT_TRUE(info.mime_types.size()); |
255 ASSERT_EQ(kNPAPITestPluginMimeType, info.mime_types[0].mime_type); | 255 ASSERT_EQ(kNPAPITestPluginMimeType, info.mime_types[0].mime_type); |
256 set_plugin_info_called_ = true; | 256 set_plugin_info_called_ = true; |
257 } | 257 } |
258 void OnFoundPluginProcessHost(PluginProcessHost* host) override { | 258 void OnFoundPluginProcessHost(PluginProcessHost* host) override { |
259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 259 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
260 set_on_found_plugin_process_host_called(); | 260 set_on_found_plugin_process_host_called(); |
261 set_host(host); | 261 set_host(host); |
262 // This gets called right before we request the plugin<=>renderer channel, | 262 // This gets called right before we request the plugin<=>renderer channel, |
263 // so we have to post a task to cancel it. | 263 // so we have to post a task to cancel it. |
264 base::MessageLoop::current()->PostTask( | 264 base::MessageLoop::current()->PostTask( |
265 FROM_HERE, | 265 FROM_HERE, |
266 base::Bind(&PluginProcessHost::CancelPendingRequest, | 266 base::Bind(&PluginProcessHost::CancelPendingRequest, |
267 base::Unretained(host), | 267 base::Unretained(host), |
268 this)); | 268 this)); |
269 base::MessageLoop::current()->PostTask( | 269 base::MessageLoop::current()->PostTask( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 on_sent_plugin_channel_request_called_(false) {} | 320 on_sent_plugin_channel_request_called_(false) {} |
321 ~MockCanceledAfterSentPluginProcessHostClient() override {} | 321 ~MockCanceledAfterSentPluginProcessHostClient() override {} |
322 | 322 |
323 // Client implementation. | 323 // Client implementation. |
324 | 324 |
325 int ID() override { return 42; } | 325 int ID() override { return 42; } |
326 bool OffTheRecord() override { return false; } | 326 bool OffTheRecord() override { return false; } |
327 | 327 |
328 // We override this guy again since we don't want to cancel yet. | 328 // We override this guy again since we don't want to cancel yet. |
329 void OnFoundPluginProcessHost(PluginProcessHost* host) override { | 329 void OnFoundPluginProcessHost(PluginProcessHost* host) override { |
330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 330 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
331 set_on_found_plugin_process_host_called(); | 331 set_on_found_plugin_process_host_called(); |
332 set_host(host); | 332 set_host(host); |
333 } | 333 } |
334 | 334 |
335 void OnSentPluginChannelRequest() override { | 335 void OnSentPluginChannelRequest() override { |
336 on_sent_plugin_channel_request_called_ = true; | 336 on_sent_plugin_channel_request_called_ = true; |
337 host()->CancelSentRequest(this); | 337 host()->CancelSentRequest(this); |
338 BrowserThread::PostTask( | 338 BrowserThread::PostTask( |
339 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure()); | 339 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure()); |
340 } | 340 } |
(...skipping 19 matching lines...) Expand all Loading... |
360 BrowserThread::IO, FROM_HERE, | 360 BrowserThread::IO, FROM_HERE, |
361 base::Bind(&OpenChannel, &mock_client)); | 361 base::Bind(&OpenChannel, &mock_client)); |
362 RunMessageLoop(); | 362 RunMessageLoop(); |
363 EXPECT_TRUE(mock_client.get_resource_context_called()); | 363 EXPECT_TRUE(mock_client.get_resource_context_called()); |
364 EXPECT_TRUE(mock_client.set_plugin_info_called()); | 364 EXPECT_TRUE(mock_client.set_plugin_info_called()); |
365 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called()); | 365 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called()); |
366 EXPECT_TRUE(mock_client.on_sent_plugin_channel_request_called()); | 366 EXPECT_TRUE(mock_client.on_sent_plugin_channel_request_called()); |
367 } | 367 } |
368 | 368 |
369 } // namespace content | 369 } // namespace content |
OLD | NEW |