| 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" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // Start opening the channel | 29 // Start opening the channel |
| 30 PluginServiceImpl::GetInstance()->OpenChannelToNpapiPlugin( | 30 PluginServiceImpl::GetInstance()->OpenChannelToNpapiPlugin( |
| 31 0, 0, GURL(), GURL(), kNPAPITestPluginMimeType, client); | 31 0, 0, GURL(), GURL(), kNPAPITestPluginMimeType, client); |
| 32 } | 32 } |
| 33 | 33 |
| 34 // Mock up of the Client and the Listener classes that would supply the | 34 // Mock up of the Client and the Listener classes that would supply the |
| 35 // communication channel with the plugin. | 35 // communication channel with the plugin. |
| 36 class MockPluginProcessHostClient : public PluginProcessHost::Client, | 36 class MockPluginProcessHostClient : public PluginProcessHost::Client, |
| 37 public IPC::Listener { | 37 public IPC::Listener { |
| 38 public: | 38 public: |
| 39 MockPluginProcessHostClient(ResourceContext* context) | 39 explicit MockPluginProcessHostClient(ResourceContext* context) |
| 40 : context_(context), | 40 : context_(context), |
| 41 channel_(NULL), | 41 channel_(NULL), |
| 42 set_plugin_info_called_(false) { | 42 set_plugin_info_called_(false) { |
| 43 } | 43 } |
| 44 | 44 |
| 45 virtual ~MockPluginProcessHostClient() { | 45 virtual ~MockPluginProcessHostClient() { |
| 46 if (channel_) | 46 if (channel_) |
| 47 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, channel_); | 47 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, channel_); |
| 48 } | 48 } |
| 49 | 49 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 BrowserThread::PostTask( | 144 BrowserThread::PostTask( |
| 145 BrowserThread::IO, FROM_HERE, | 145 BrowserThread::IO, FROM_HERE, |
| 146 base::Bind(&OpenChannel, &mock_client)); | 146 base::Bind(&OpenChannel, &mock_client)); |
| 147 RunMessageLoop(); | 147 RunMessageLoop(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 // A strict mock that fails if any of the methods are called. They shouldn't be | 150 // A strict mock that fails if any of the methods are called. They shouldn't be |
| 151 // called since the request should get canceled before then. | 151 // called since the request should get canceled before then. |
| 152 class MockCanceledPluginServiceClient : public PluginProcessHost::Client { | 152 class MockCanceledPluginServiceClient : public PluginProcessHost::Client { |
| 153 public: | 153 public: |
| 154 MockCanceledPluginServiceClient(ResourceContext* context) | 154 explicit MockCanceledPluginServiceClient(ResourceContext* context) |
| 155 : context_(context), | 155 : context_(context), |
| 156 get_resource_context_called_(false) { | 156 get_resource_context_called_(false) { |
| 157 } | 157 } |
| 158 | 158 |
| 159 virtual ~MockCanceledPluginServiceClient() {} | 159 virtual ~MockCanceledPluginServiceClient() {} |
| 160 | 160 |
| 161 // Client implementation. | 161 // Client implementation. |
| 162 MOCK_METHOD0(ID, int()); | 162 MOCK_METHOD0(ID, int()); |
| 163 virtual ResourceContext* GetResourceContext() OVERRIDE { | 163 virtual ResourceContext* GetResourceContext() OVERRIDE { |
| 164 get_resource_context_called_ = true; | 164 get_resource_context_called_ = true; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 GetResourceContext()); | 207 GetResourceContext()); |
| 208 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 208 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 209 base::Bind(OpenChannelAndThenCancel, &mock_client)); | 209 base::Bind(OpenChannelAndThenCancel, &mock_client)); |
| 210 RunMessageLoop(); | 210 RunMessageLoop(); |
| 211 EXPECT_TRUE(mock_client.get_resource_context_called()); | 211 EXPECT_TRUE(mock_client.get_resource_context_called()); |
| 212 } | 212 } |
| 213 | 213 |
| 214 class MockCanceledBeforeSentPluginProcessHostClient | 214 class MockCanceledBeforeSentPluginProcessHostClient |
| 215 : public MockCanceledPluginServiceClient { | 215 : public MockCanceledPluginServiceClient { |
| 216 public: | 216 public: |
| 217 MockCanceledBeforeSentPluginProcessHostClient( | 217 explicit MockCanceledBeforeSentPluginProcessHostClient( |
| 218 ResourceContext* context) | 218 ResourceContext* context) |
| 219 : MockCanceledPluginServiceClient(context), | 219 : MockCanceledPluginServiceClient(context), |
| 220 set_plugin_info_called_(false), | 220 set_plugin_info_called_(false), |
| 221 on_found_plugin_process_host_called_(false), | 221 on_found_plugin_process_host_called_(false), |
| 222 host_(NULL) {} | 222 host_(NULL) {} |
| 223 | 223 |
| 224 virtual ~MockCanceledBeforeSentPluginProcessHostClient() {} | 224 virtual ~MockCanceledBeforeSentPluginProcessHostClient() {} |
| 225 | 225 |
| 226 // Client implementation. | 226 // Client implementation. |
| 227 virtual void SetPluginInfo(const webkit::WebPluginInfo& info) OVERRIDE { | 227 virtual void SetPluginInfo(const webkit::WebPluginInfo& info) OVERRIDE { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 base::Bind(&OpenChannel, &mock_client)); | 282 base::Bind(&OpenChannel, &mock_client)); |
| 283 RunMessageLoop(); | 283 RunMessageLoop(); |
| 284 EXPECT_TRUE(mock_client.get_resource_context_called()); | 284 EXPECT_TRUE(mock_client.get_resource_context_called()); |
| 285 EXPECT_TRUE(mock_client.set_plugin_info_called()); | 285 EXPECT_TRUE(mock_client.set_plugin_info_called()); |
| 286 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called()); | 286 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called()); |
| 287 } | 287 } |
| 288 | 288 |
| 289 class MockCanceledAfterSentPluginProcessHostClient | 289 class MockCanceledAfterSentPluginProcessHostClient |
| 290 : public MockCanceledBeforeSentPluginProcessHostClient { | 290 : public MockCanceledBeforeSentPluginProcessHostClient { |
| 291 public: | 291 public: |
| 292 MockCanceledAfterSentPluginProcessHostClient( | 292 explicit MockCanceledAfterSentPluginProcessHostClient( |
| 293 ResourceContext* context) | 293 ResourceContext* context) |
| 294 : MockCanceledBeforeSentPluginProcessHostClient(context), | 294 : MockCanceledBeforeSentPluginProcessHostClient(context), |
| 295 on_sent_plugin_channel_request_called_(false) {} | 295 on_sent_plugin_channel_request_called_(false) {} |
| 296 virtual ~MockCanceledAfterSentPluginProcessHostClient() {} | 296 virtual ~MockCanceledAfterSentPluginProcessHostClient() {} |
| 297 | 297 |
| 298 // Client implementation. | 298 // Client implementation. |
| 299 | 299 |
| 300 virtual int ID() OVERRIDE { return 42; } | 300 virtual int ID() OVERRIDE { return 42; } |
| 301 virtual bool OffTheRecord() OVERRIDE { return false; } | 301 virtual bool OffTheRecord() OVERRIDE { return false; } |
| 302 | 302 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 BrowserThread::IO, FROM_HERE, | 335 BrowserThread::IO, FROM_HERE, |
| 336 base::Bind(&OpenChannel, &mock_client)); | 336 base::Bind(&OpenChannel, &mock_client)); |
| 337 RunMessageLoop(); | 337 RunMessageLoop(); |
| 338 EXPECT_TRUE(mock_client.get_resource_context_called()); | 338 EXPECT_TRUE(mock_client.get_resource_context_called()); |
| 339 EXPECT_TRUE(mock_client.set_plugin_info_called()); | 339 EXPECT_TRUE(mock_client.set_plugin_info_called()); |
| 340 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called()); | 340 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called()); |
| 341 EXPECT_TRUE(mock_client.on_sent_plugin_channel_request_called()); | 341 EXPECT_TRUE(mock_client.on_sent_plugin_channel_request_called()); |
| 342 } | 342 } |
| 343 | 343 |
| 344 } // namespace content | 344 } // namespace content |
| OLD | NEW |