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

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

Issue 667943003: Standardize usage of virtual/override/final in content/browser/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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_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 24 matching lines...) Expand all
35 class MockPluginProcessHostClient : public PluginProcessHost::Client, 35 class MockPluginProcessHostClient : public PluginProcessHost::Client,
36 public IPC::Listener { 36 public IPC::Listener {
37 public: 37 public:
38 MockPluginProcessHostClient(ResourceContext* context, bool expect_fail) 38 MockPluginProcessHostClient(ResourceContext* context, bool expect_fail)
39 : context_(context), 39 : context_(context),
40 channel_(NULL), 40 channel_(NULL),
41 set_plugin_info_called_(false), 41 set_plugin_info_called_(false),
42 expect_fail_(expect_fail) { 42 expect_fail_(expect_fail) {
43 } 43 }
44 44
45 virtual ~MockPluginProcessHostClient() { 45 ~MockPluginProcessHostClient() override {
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 // PluginProcessHost::Client implementation. 50 // PluginProcessHost::Client implementation.
51 virtual int ID() override { return 42; } 51 int ID() override { return 42; }
52 virtual bool OffTheRecord() override { return false; } 52 bool OffTheRecord() override { return false; }
53 virtual ResourceContext* GetResourceContext() override { 53 ResourceContext* GetResourceContext() override { return context_; }
54 return context_; 54 void OnFoundPluginProcessHost(PluginProcessHost* host) override {}
55 } 55 void OnSentPluginChannelRequest() override {}
56 virtual void OnFoundPluginProcessHost(PluginProcessHost* host) override {}
57 virtual void OnSentPluginChannelRequest() override {}
58 56
59 virtual void OnChannelOpened(const IPC::ChannelHandle& handle) override { 57 void OnChannelOpened(const IPC::ChannelHandle& handle) override {
60 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 58 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
61 ASSERT_TRUE(set_plugin_info_called_); 59 ASSERT_TRUE(set_plugin_info_called_);
62 ASSERT_TRUE(!channel_); 60 ASSERT_TRUE(!channel_);
63 channel_ = IPC::Channel::CreateClient(handle, this).release(); 61 channel_ = IPC::Channel::CreateClient(handle, this).release();
64 ASSERT_TRUE(channel_->Connect()); 62 ASSERT_TRUE(channel_->Connect());
65 } 63 }
66 64
67 virtual void SetPluginInfo(const WebPluginInfo& info) override { 65 void SetPluginInfo(const WebPluginInfo& info) override {
68 ASSERT_TRUE(info.mime_types.size()); 66 ASSERT_TRUE(info.mime_types.size());
69 ASSERT_EQ(kNPAPITestPluginMimeType, info.mime_types[0].mime_type); 67 ASSERT_EQ(kNPAPITestPluginMimeType, info.mime_types[0].mime_type);
70 set_plugin_info_called_ = true; 68 set_plugin_info_called_ = true;
71 } 69 }
72 70
73 virtual void OnError() override { 71 void OnError() override { Fail(); }
74 Fail();
75 }
76 72
77 // IPC::Listener implementation. 73 // IPC::Listener implementation.
78 virtual bool OnMessageReceived(const IPC::Message& message) override { 74 bool OnMessageReceived(const IPC::Message& message) override {
79 Fail(); 75 Fail();
80 return false; 76 return false;
81 } 77 }
82 virtual void OnChannelConnected(int32 peer_pid) override { 78 void OnChannelConnected(int32 peer_pid) override {
83 if (expect_fail_) 79 if (expect_fail_)
84 FAIL(); 80 FAIL();
85 QuitMessageLoop(); 81 QuitMessageLoop();
86 } 82 }
87 virtual void OnChannelError() override { 83 void OnChannelError() override { Fail(); }
88 Fail();
89 }
90 #if defined(OS_POSIX) 84 #if defined(OS_POSIX)
91 virtual void OnChannelDenied() override { 85 void OnChannelDenied() override { Fail(); }
92 Fail(); 86 void OnChannelListenError() override { Fail(); }
93 }
94 virtual void OnChannelListenError() override {
95 Fail();
96 }
97 #endif 87 #endif
98 88
99 private: 89 private:
100 void Fail() { 90 void Fail() {
101 if (!expect_fail_) 91 if (!expect_fail_)
102 FAIL(); 92 FAIL();
103 QuitMessageLoop(); 93 QuitMessageLoop();
104 } 94 }
105 95
106 void QuitMessageLoop() { 96 void QuitMessageLoop() {
107 BrowserThread::PostTask( 97 BrowserThread::PostTask(
108 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure()); 98 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure());
109 } 99 }
110 100
111 ResourceContext* context_; 101 ResourceContext* context_;
112 IPC::Channel* channel_; 102 IPC::Channel* channel_;
113 bool set_plugin_info_called_; 103 bool set_plugin_info_called_;
114 bool expect_fail_; 104 bool expect_fail_;
115 DISALLOW_COPY_AND_ASSIGN(MockPluginProcessHostClient); 105 DISALLOW_COPY_AND_ASSIGN(MockPluginProcessHostClient);
116 }; 106 };
117 107
118 class MockPluginServiceFilter : public content::PluginServiceFilter { 108 class MockPluginServiceFilter : public content::PluginServiceFilter {
119 public: 109 public:
120 MockPluginServiceFilter() {} 110 MockPluginServiceFilter() {}
121 111
122 virtual bool IsPluginAvailable( 112 bool IsPluginAvailable(int render_process_id,
123 int render_process_id, 113 int render_view_id,
124 int render_view_id, 114 const void* context,
125 const void* context, 115 const GURL& url,
126 const GURL& url, 116 const GURL& policy_url,
127 const GURL& policy_url, 117 WebPluginInfo* plugin) override {
128 WebPluginInfo* plugin) override { return true; } 118 return true;
119 }
129 120
130 virtual bool CanLoadPlugin( 121 bool CanLoadPlugin(int render_process_id,
131 int render_process_id, 122 const base::FilePath& path) override {
132 const base::FilePath& path) override { return false; } 123 return false;
124 }
133 }; 125 };
134 126
135 class PluginServiceTest : public ContentBrowserTest { 127 class PluginServiceTest : public ContentBrowserTest {
136 public: 128 public:
137 PluginServiceTest() {} 129 PluginServiceTest() {}
138 130
139 ResourceContext* GetResourceContext() { 131 ResourceContext* GetResourceContext() {
140 return shell()->web_contents()->GetBrowserContext()->GetResourceContext(); 132 return shell()->web_contents()->GetBrowserContext()->GetResourceContext();
141 } 133 }
142 134
143 virtual void SetUpCommandLine(CommandLine* command_line) override { 135 void SetUpCommandLine(CommandLine* command_line) override {
144 #if defined(OS_MACOSX) 136 #if defined(OS_MACOSX)
145 base::FilePath browser_directory; 137 base::FilePath browser_directory;
146 PathService::Get(base::DIR_MODULE, &browser_directory); 138 PathService::Get(base::DIR_MODULE, &browser_directory);
147 command_line->AppendSwitchPath(switches::kExtraPluginDir, 139 command_line->AppendSwitchPath(switches::kExtraPluginDir,
148 browser_directory.AppendASCII("plugins")); 140 browser_directory.AppendASCII("plugins"));
149 #endif 141 #endif
150 // TODO(jam): since these plugin tests are running under Chrome, we need to 142 // TODO(jam): since these plugin tests are running under Chrome, we need to
151 // tell it to disable its security features for old plugins. Once this is 143 // tell it to disable its security features for old plugins. Once this is
152 // running under content_browsertests, these flags won't be needed. 144 // running under content_browsertests, these flags won't be needed.
153 // http://crbug.com/90448 145 // http://crbug.com/90448
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 class MockCanceledBeforeSentPluginProcessHostClient 239 class MockCanceledBeforeSentPluginProcessHostClient
248 : public MockCanceledPluginServiceClient { 240 : public MockCanceledPluginServiceClient {
249 public: 241 public:
250 MockCanceledBeforeSentPluginProcessHostClient( 242 MockCanceledBeforeSentPluginProcessHostClient(
251 ResourceContext* context) 243 ResourceContext* context)
252 : MockCanceledPluginServiceClient(context), 244 : MockCanceledPluginServiceClient(context),
253 set_plugin_info_called_(false), 245 set_plugin_info_called_(false),
254 on_found_plugin_process_host_called_(false), 246 on_found_plugin_process_host_called_(false),
255 host_(NULL) {} 247 host_(NULL) {}
256 248
257 virtual ~MockCanceledBeforeSentPluginProcessHostClient() {} 249 ~MockCanceledBeforeSentPluginProcessHostClient() override {}
258 250
259 // Client implementation. 251 // Client implementation.
260 virtual void SetPluginInfo(const WebPluginInfo& info) override { 252 void SetPluginInfo(const WebPluginInfo& info) override {
261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
262 ASSERT_TRUE(info.mime_types.size()); 254 ASSERT_TRUE(info.mime_types.size());
263 ASSERT_EQ(kNPAPITestPluginMimeType, info.mime_types[0].mime_type); 255 ASSERT_EQ(kNPAPITestPluginMimeType, info.mime_types[0].mime_type);
264 set_plugin_info_called_ = true; 256 set_plugin_info_called_ = true;
265 } 257 }
266 virtual void OnFoundPluginProcessHost(PluginProcessHost* host) override { 258 void OnFoundPluginProcessHost(PluginProcessHost* host) override {
267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
268 set_on_found_plugin_process_host_called(); 260 set_on_found_plugin_process_host_called();
269 set_host(host); 261 set_host(host);
270 // This gets called right before we request the plugin<=>renderer channel, 262 // This gets called right before we request the plugin<=>renderer channel,
271 // so we have to post a task to cancel it. 263 // so we have to post a task to cancel it.
272 base::MessageLoop::current()->PostTask( 264 base::MessageLoop::current()->PostTask(
273 FROM_HERE, 265 FROM_HERE,
274 base::Bind(&PluginProcessHost::CancelPendingRequest, 266 base::Bind(&PluginProcessHost::CancelPendingRequest,
275 base::Unretained(host), 267 base::Unretained(host),
276 this)); 268 this));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called()); 311 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called());
320 } 312 }
321 313
322 class MockCanceledAfterSentPluginProcessHostClient 314 class MockCanceledAfterSentPluginProcessHostClient
323 : public MockCanceledBeforeSentPluginProcessHostClient { 315 : public MockCanceledBeforeSentPluginProcessHostClient {
324 public: 316 public:
325 MockCanceledAfterSentPluginProcessHostClient( 317 MockCanceledAfterSentPluginProcessHostClient(
326 ResourceContext* context) 318 ResourceContext* context)
327 : MockCanceledBeforeSentPluginProcessHostClient(context), 319 : MockCanceledBeforeSentPluginProcessHostClient(context),
328 on_sent_plugin_channel_request_called_(false) {} 320 on_sent_plugin_channel_request_called_(false) {}
329 virtual ~MockCanceledAfterSentPluginProcessHostClient() {} 321 ~MockCanceledAfterSentPluginProcessHostClient() override {}
330 322
331 // Client implementation. 323 // Client implementation.
332 324
333 virtual int ID() override { return 42; } 325 int ID() override { return 42; }
334 virtual bool OffTheRecord() override { return false; } 326 bool OffTheRecord() override { return false; }
335 327
336 // 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.
337 virtual void OnFoundPluginProcessHost(PluginProcessHost* host) override { 329 void OnFoundPluginProcessHost(PluginProcessHost* host) override {
338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
339 set_on_found_plugin_process_host_called(); 331 set_on_found_plugin_process_host_called();
340 set_host(host); 332 set_host(host);
341 } 333 }
342 334
343 virtual void OnSentPluginChannelRequest() override { 335 void OnSentPluginChannelRequest() override {
344 on_sent_plugin_channel_request_called_ = true; 336 on_sent_plugin_channel_request_called_ = true;
345 host()->CancelSentRequest(this); 337 host()->CancelSentRequest(this);
346 BrowserThread::PostTask( 338 BrowserThread::PostTask(
347 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure()); 339 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure());
348 } 340 }
349 341
350 bool on_sent_plugin_channel_request_called() const { 342 bool on_sent_plugin_channel_request_called() const {
351 return on_sent_plugin_channel_request_called_; 343 return on_sent_plugin_channel_request_called_;
352 } 344 }
353 345
(...skipping 14 matching lines...) Expand all
368 BrowserThread::IO, FROM_HERE, 360 BrowserThread::IO, FROM_HERE,
369 base::Bind(&OpenChannel, &mock_client)); 361 base::Bind(&OpenChannel, &mock_client));
370 RunMessageLoop(); 362 RunMessageLoop();
371 EXPECT_TRUE(mock_client.get_resource_context_called()); 363 EXPECT_TRUE(mock_client.get_resource_context_called());
372 EXPECT_TRUE(mock_client.set_plugin_info_called()); 364 EXPECT_TRUE(mock_client.set_plugin_info_called());
373 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called()); 365 EXPECT_TRUE(mock_client.on_found_plugin_process_host_called());
374 EXPECT_TRUE(mock_client.on_sent_plugin_channel_request_called()); 366 EXPECT_TRUE(mock_client.on_sent_plugin_channel_request_called());
375 } 367 }
376 368
377 } // namespace content 369 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/plugin_service_impl.h ('k') | content/browser/power_monitor_message_broadcaster.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698