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

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

Issue 9369009: Make content::ResourceContext be a real interface like the rest of the Content API (i.e. don't ha... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 8 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_service_impl.cc ('k') | content/browser/ppapi_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) 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_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
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::Channel::Listener { 37 public IPC::Channel::Listener {
38 public: 38 public:
39 MockPluginProcessHostClient(const content::ResourceContext& context) 39 MockPluginProcessHostClient(content::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
50 // Client implementation. 50 // Client implementation.
51 virtual int ID() OVERRIDE { return 42; } 51 virtual int ID() OVERRIDE { return 42; }
52 virtual bool OffTheRecord() OVERRIDE { return false; } 52 virtual bool OffTheRecord() OVERRIDE { return false; }
53 virtual const content::ResourceContext& GetResourceContext() OVERRIDE { 53 virtual content::ResourceContext* GetResourceContext() OVERRIDE {
54 return context_; 54 return context_;
55 } 55 }
56 virtual void OnFoundPluginProcessHost(PluginProcessHost* host) OVERRIDE {} 56 virtual void OnFoundPluginProcessHost(PluginProcessHost* host) OVERRIDE {}
57 virtual void OnSentPluginChannelRequest() OVERRIDE {} 57 virtual void OnSentPluginChannelRequest() OVERRIDE {}
58 58
59 virtual void OnChannelOpened(const IPC::ChannelHandle& handle) OVERRIDE { 59 virtual void OnChannelOpened(const IPC::ChannelHandle& handle) OVERRIDE {
60 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 60 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
61 ASSERT_TRUE(set_plugin_info_called_); 61 ASSERT_TRUE(set_plugin_info_called_);
62 ASSERT_TRUE(!channel_); 62 ASSERT_TRUE(!channel_);
63 channel_ = new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this); 63 channel_ = new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this);
(...skipping 12 matching lines...) Expand all
76 MOCK_METHOD1(OnMessageReceived, bool(const IPC::Message& message)); 76 MOCK_METHOD1(OnMessageReceived, bool(const IPC::Message& message));
77 void OnChannelConnected(int32 peer_pid) OVERRIDE { 77 void OnChannelConnected(int32 peer_pid) OVERRIDE {
78 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 78 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
79 MessageLoop::QuitClosure()); 79 MessageLoop::QuitClosure());
80 } 80 }
81 MOCK_METHOD0(OnChannelError, void()); 81 MOCK_METHOD0(OnChannelError, void());
82 MOCK_METHOD0(OnChannelDenied, void()); 82 MOCK_METHOD0(OnChannelDenied, void());
83 MOCK_METHOD0(OnChannelListenError, void()); 83 MOCK_METHOD0(OnChannelListenError, void());
84 84
85 private: 85 private:
86 const content::ResourceContext& context_; 86 content::ResourceContext* context_;
87 IPC::Channel* channel_; 87 IPC::Channel* channel_;
88 bool set_plugin_info_called_; 88 bool set_plugin_info_called_;
89 DISALLOW_COPY_AND_ASSIGN(MockPluginProcessHostClient); 89 DISALLOW_COPY_AND_ASSIGN(MockPluginProcessHostClient);
90 }; 90 };
91 91
92 class PluginServiceTest : public InProcessBrowserTest { 92 class PluginServiceTest : public InProcessBrowserTest {
93 public: 93 public:
94 PluginServiceTest() : InProcessBrowserTest() { } 94 PluginServiceTest() : InProcessBrowserTest() { }
95 95
96 virtual void SetUpCommandLine(CommandLine* command_line) { 96 virtual void SetUpCommandLine(CommandLine* command_line) {
(...skipping 14 matching lines...) Expand all
111 BrowserThread::PostTask( 111 BrowserThread::PostTask(
112 BrowserThread::IO, FROM_HERE, 112 BrowserThread::IO, FROM_HERE,
113 base::Bind(&OpenChannel, &mock_client)); 113 base::Bind(&OpenChannel, &mock_client));
114 ui_test_utils::RunMessageLoop(); 114 ui_test_utils::RunMessageLoop();
115 } 115 }
116 116
117 // A strict mock that fails if any of the methods are called. They shouldn't be 117 // A strict mock that fails if any of the methods are called. They shouldn't be
118 // called since the request should get canceled before then. 118 // called since the request should get canceled before then.
119 class MockCanceledPluginServiceClient : public PluginProcessHost::Client { 119 class MockCanceledPluginServiceClient : public PluginProcessHost::Client {
120 public: 120 public:
121 MockCanceledPluginServiceClient(const content::ResourceContext& context) 121 MockCanceledPluginServiceClient(content::ResourceContext* context)
122 : context_(context), 122 : context_(context),
123 get_resource_context_called_(false) { 123 get_resource_context_called_(false) {
124 } 124 }
125 125
126 virtual ~MockCanceledPluginServiceClient() {} 126 virtual ~MockCanceledPluginServiceClient() {}
127 127
128 // Client implementation. 128 // Client implementation.
129 MOCK_METHOD0(ID, int()); 129 MOCK_METHOD0(ID, int());
130 virtual const content::ResourceContext& GetResourceContext() OVERRIDE { 130 virtual content::ResourceContext* GetResourceContext() OVERRIDE {
131 get_resource_context_called_ = true; 131 get_resource_context_called_ = true;
132 return context_; 132 return context_;
133 } 133 }
134 MOCK_METHOD0(OffTheRecord, bool()); 134 MOCK_METHOD0(OffTheRecord, bool());
135 MOCK_METHOD1(OnFoundPluginProcessHost, void(PluginProcessHost* host)); 135 MOCK_METHOD1(OnFoundPluginProcessHost, void(PluginProcessHost* host));
136 MOCK_METHOD0(OnSentPluginChannelRequest, void()); 136 MOCK_METHOD0(OnSentPluginChannelRequest, void());
137 MOCK_METHOD1(OnChannelOpened, void(const IPC::ChannelHandle& handle)); 137 MOCK_METHOD1(OnChannelOpened, void(const IPC::ChannelHandle& handle));
138 MOCK_METHOD1(SetPluginInfo, void(const webkit::WebPluginInfo& info)); 138 MOCK_METHOD1(SetPluginInfo, void(const webkit::WebPluginInfo& info));
139 MOCK_METHOD0(OnError, void()); 139 MOCK_METHOD0(OnError, void());
140 140
141 bool get_resource_context_called() const { 141 bool get_resource_context_called() const {
142 return get_resource_context_called_; 142 return get_resource_context_called_;
143 } 143 }
144 144
145 private: 145 private:
146 const content::ResourceContext& context_; 146 content::ResourceContext* context_;
147 bool get_resource_context_called_; 147 bool get_resource_context_called_;
148 148
149 DISALLOW_COPY_AND_ASSIGN(MockCanceledPluginServiceClient); 149 DISALLOW_COPY_AND_ASSIGN(MockCanceledPluginServiceClient);
150 }; 150 };
151 151
152 void QuitUIMessageLoopFromIOThread() { 152 void QuitUIMessageLoopFromIOThread() {
153 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 153 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
154 MessageLoop::QuitClosure()); 154 MessageLoop::QuitClosure());
155 } 155 }
156 156
(...skipping 21 matching lines...) Expand all
178 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 178 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
179 base::Bind(OpenChannelAndThenCancel, &mock_client)); 179 base::Bind(OpenChannelAndThenCancel, &mock_client));
180 ui_test_utils::RunMessageLoop(); 180 ui_test_utils::RunMessageLoop();
181 EXPECT_TRUE(mock_client.get_resource_context_called()); 181 EXPECT_TRUE(mock_client.get_resource_context_called());
182 } 182 }
183 183
184 class MockCanceledBeforeSentPluginProcessHostClient 184 class MockCanceledBeforeSentPluginProcessHostClient
185 : public MockCanceledPluginServiceClient { 185 : public MockCanceledPluginServiceClient {
186 public: 186 public:
187 MockCanceledBeforeSentPluginProcessHostClient( 187 MockCanceledBeforeSentPluginProcessHostClient(
188 const content::ResourceContext& context) 188 content::ResourceContext* context)
189 : MockCanceledPluginServiceClient(context), 189 : MockCanceledPluginServiceClient(context),
190 set_plugin_info_called_(false), 190 set_plugin_info_called_(false),
191 on_found_plugin_process_host_called_(false), 191 on_found_plugin_process_host_called_(false),
192 host_(NULL) {} 192 host_(NULL) {}
193 193
194 virtual ~MockCanceledBeforeSentPluginProcessHostClient() {} 194 virtual ~MockCanceledBeforeSentPluginProcessHostClient() {}
195 195
196 // Client implementation. 196 // Client implementation.
197 virtual void SetPluginInfo(const webkit::WebPluginInfo& info) OVERRIDE { 197 virtual void SetPluginInfo(const webkit::WebPluginInfo& info) OVERRIDE {
198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 ui_test_utils::RunMessageLoop(); 251 ui_test_utils::RunMessageLoop();
252 EXPECT_TRUE(mock_client.get_resource_context_called()); 252 EXPECT_TRUE(mock_client.get_resource_context_called());
253 EXPECT_TRUE(mock_client.set_plugin_info_called()); 253 EXPECT_TRUE(mock_client.set_plugin_info_called());
254 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called()); 254 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called());
255 } 255 }
256 256
257 class MockCanceledAfterSentPluginProcessHostClient 257 class MockCanceledAfterSentPluginProcessHostClient
258 : public MockCanceledBeforeSentPluginProcessHostClient { 258 : public MockCanceledBeforeSentPluginProcessHostClient {
259 public: 259 public:
260 MockCanceledAfterSentPluginProcessHostClient( 260 MockCanceledAfterSentPluginProcessHostClient(
261 const content::ResourceContext& context) 261 content::ResourceContext* context)
262 : MockCanceledBeforeSentPluginProcessHostClient(context), 262 : MockCanceledBeforeSentPluginProcessHostClient(context),
263 on_sent_plugin_channel_request_called_(false) {} 263 on_sent_plugin_channel_request_called_(false) {}
264 virtual ~MockCanceledAfterSentPluginProcessHostClient() {} 264 virtual ~MockCanceledAfterSentPluginProcessHostClient() {}
265 265
266 // Client implementation. 266 // Client implementation.
267 267
268 virtual int ID() OVERRIDE { return 42; } 268 virtual int ID() OVERRIDE { return 42; }
269 virtual bool OffTheRecord() OVERRIDE { return false; } 269 virtual bool OffTheRecord() OVERRIDE { return false; }
270 270
271 // We override this guy again since we don't want to cancel yet. 271 // We override this guy again since we don't want to cancel yet.
(...skipping 29 matching lines...) Expand all
301 BrowserThread::IO, FROM_HERE, 301 BrowserThread::IO, FROM_HERE,
302 base::Bind(&OpenChannel, &mock_client)); 302 base::Bind(&OpenChannel, &mock_client));
303 ui_test_utils::RunMessageLoop(); 303 ui_test_utils::RunMessageLoop();
304 EXPECT_TRUE(mock_client.get_resource_context_called()); 304 EXPECT_TRUE(mock_client.get_resource_context_called());
305 EXPECT_TRUE(mock_client.set_plugin_info_called()); 305 EXPECT_TRUE(mock_client.set_plugin_info_called());
306 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called()); 306 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called());
307 EXPECT_TRUE(mock_client.on_sent_plugin_channel_request_called()); 307 EXPECT_TRUE(mock_client.on_sent_plugin_channel_request_called());
308 } 308 }
309 309
310 } // namespace 310 } // namespace
OLDNEW
« no previous file with comments | « content/browser/plugin_service_impl.cc ('k') | content/browser/ppapi_plugin_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698