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

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

Issue 8603012: Fix race in PluginDataRemoverImpl going away while it's still being used on the IO thread... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Move Context class to cc file Created 9 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_service.cc ('k') | no next file » | 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) 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_service.h" 5 #include "content/browser/plugin_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/test/base/in_process_browser_test.h" 11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "chrome/test/base/testing_profile.h" 12 #include "chrome/test/base/testing_profile.h"
13 #include "chrome/test/base/ui_test_utils.h" 13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/browser/resource_context.h" 14 #include "content/browser/resource_context.h"
15 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
16 #include "content/test/test_browser_thread.h" 16 #include "content/test/test_browser_thread.h"
17 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "webkit/plugins/npapi/plugin_list.h" 18 #include "webkit/plugins/npapi/plugin_list.h"
19 19
20 using content::BrowserThread; 20 using content::BrowserThread;
21 21
22 namespace { 22 namespace {
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) {
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
28 // Start opening the channel
29 PluginService::GetInstance()->OpenChannelToNpapiPlugin(
30 0, 0, GURL(), GURL(), kNPAPITestPluginMimeType, client);
31 }
32
26 // 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
27 // communication channel with the plugin. 34 // communication channel with the plugin.
28 class MockPluginProcessHostClient : public PluginProcessHost::Client, 35 class MockPluginProcessHostClient : public PluginProcessHost::Client,
29 public IPC::Channel::Listener { 36 public IPC::Channel::Listener {
30 public: 37 public:
31 MockPluginProcessHostClient(const content::ResourceContext& context) 38 MockPluginProcessHostClient(const content::ResourceContext& context)
32 : context_(context), 39 : context_(context),
33 channel_(NULL), 40 channel_(NULL),
34 set_plugin_info_called_(false) { 41 set_plugin_info_called_(false) {
35 } 42 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 browser_directory.AppendASCII("plugins")); 100 browser_directory.AppendASCII("plugins"));
94 #endif 101 #endif
95 } 102 }
96 }; 103 };
97 104
98 // Try to open a channel to the test plugin. Minimal plugin process spawning 105 // Try to open a channel to the test plugin. Minimal plugin process spawning
99 // test for the PluginService interface. 106 // test for the PluginService interface.
100 IN_PROC_BROWSER_TEST_F(PluginServiceTest, OpenChannelToPlugin) { 107 IN_PROC_BROWSER_TEST_F(PluginServiceTest, OpenChannelToPlugin) {
101 ::testing::StrictMock<MockPluginProcessHostClient> mock_client( 108 ::testing::StrictMock<MockPluginProcessHostClient> mock_client(
102 browser()->profile()->GetResourceContext()); 109 browser()->profile()->GetResourceContext());
103 PluginService::GetInstance()->OpenChannelToNpapiPlugin( 110 BrowserThread::PostTask(
104 0, 0, GURL(), GURL(), kNPAPITestPluginMimeType, &mock_client); 111 BrowserThread::IO, FROM_HERE,
112 base::Bind(OpenChannel, &mock_client));
105 ui_test_utils::RunMessageLoop(); 113 ui_test_utils::RunMessageLoop();
106 } 114 }
107 115
108 // A strict mock that fails if any of the methods are called. They shouldn't be 116 // A strict mock that fails if any of the methods are called. They shouldn't be
109 // called since the request should get canceled before then. 117 // called since the request should get canceled before then.
110 class MockCanceledPluginServiceClient : public PluginProcessHost::Client { 118 class MockCanceledPluginServiceClient : public PluginProcessHost::Client {
111 public: 119 public:
112 MockCanceledPluginServiceClient(const content::ResourceContext& context) 120 MockCanceledPluginServiceClient(const content::ResourceContext& context)
113 : context_(context), 121 : context_(context),
114 get_resource_context_called_(false) { 122 get_resource_context_called_(false) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 PluginProcessHost* host() const { return host_; } 235 PluginProcessHost* host() const { return host_; }
228 236
229 private: 237 private:
230 bool set_plugin_info_called_; 238 bool set_plugin_info_called_;
231 bool on_found_plugin_process_host_called_; 239 bool on_found_plugin_process_host_called_;
232 PluginProcessHost* host_; 240 PluginProcessHost* host_;
233 241
234 DISALLOW_COPY_AND_ASSIGN(MockCanceledBeforeSentPluginProcessHostClient); 242 DISALLOW_COPY_AND_ASSIGN(MockCanceledBeforeSentPluginProcessHostClient);
235 }; 243 };
236 244
237 void OpenChannel(PluginProcessHost::Client* client) {
238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
239 // Start opening the channel
240 PluginService::GetInstance()->OpenChannelToNpapiPlugin(
241 0, 0, GURL(), GURL(), kNPAPITestPluginMimeType, client);
242 }
243
244 IN_PROC_BROWSER_TEST_F( 245 IN_PROC_BROWSER_TEST_F(
245 PluginServiceTest, CancelBeforeSentOpenChannelToPluginProcessHost) { 246 PluginServiceTest, CancelBeforeSentOpenChannelToPluginProcessHost) {
246 ::testing::StrictMock<MockCanceledBeforeSentPluginProcessHostClient> 247 ::testing::StrictMock<MockCanceledBeforeSentPluginProcessHostClient>
247 mock_client(browser()->profile()->GetResourceContext()); 248 mock_client(browser()->profile()->GetResourceContext());
248 BrowserThread::PostTask( 249 BrowserThread::PostTask(
249 BrowserThread::IO, FROM_HERE, 250 BrowserThread::IO, FROM_HERE,
250 base::Bind(OpenChannel, &mock_client)); 251 base::Bind(OpenChannel, &mock_client));
251 ui_test_utils::RunMessageLoop(); 252 ui_test_utils::RunMessageLoop();
252 EXPECT_TRUE(mock_client.get_resource_context_called()); 253 EXPECT_TRUE(mock_client.get_resource_context_called());
253 EXPECT_TRUE(mock_client.set_plugin_info_called()); 254 EXPECT_TRUE(mock_client.set_plugin_info_called());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 BrowserThread::IO, FROM_HERE, 302 BrowserThread::IO, FROM_HERE,
302 base::Bind(OpenChannel, &mock_client)); 303 base::Bind(OpenChannel, &mock_client));
303 ui_test_utils::RunMessageLoop(); 304 ui_test_utils::RunMessageLoop();
304 EXPECT_TRUE(mock_client.get_resource_context_called()); 305 EXPECT_TRUE(mock_client.get_resource_context_called());
305 EXPECT_TRUE(mock_client.set_plugin_info_called()); 306 EXPECT_TRUE(mock_client.set_plugin_info_called());
306 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called()); 307 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called());
307 EXPECT_TRUE(mock_client.on_sent_plugin_channel_request_called()); 308 EXPECT_TRUE(mock_client.on_sent_plugin_channel_request_called());
308 } 309 }
309 310
310 } // namespace 311 } // namespace
OLDNEW
« no previous file with comments | « content/browser/plugin_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698