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

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

Issue 7387010: Add PluginServiceFilter interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unit test Created 9 years, 3 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.cc ('k') | content/browser/plugin_service_filter.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.h" 5 #include "content/browser/plugin_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "chrome/browser/ui/browser.h"
9 #include "chrome/test/base/in_process_browser_test.h" 10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/testing_profile.h"
10 #include "chrome/test/base/ui_test_utils.h" 12 #include "chrome/test/base/ui_test_utils.h"
11 #include "content/browser/browser_thread.h" 13 #include "content/browser/browser_thread.h"
14 #include "content/browser/resource_context.h"
12 #include "content/common/content_switches.h" 15 #include "content/common/content_switches.h"
13 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
14 #include "webkit/plugins/npapi/plugin_list.h" 17 #include "webkit/plugins/npapi/plugin_list.h"
15 18
16 namespace { 19 namespace {
17 20
18 const char* kNPAPITestPluginMimeType = "application/vnd.npapi-test"; 21 const char* kNPAPITestPluginMimeType = "application/vnd.npapi-test";
19 22
20 // Mock up of the Client and the Listener classes that would supply the 23 // Mock up of the Client and the Listener classes that would supply the
21 // communication channel with the plugin. 24 // communication channel with the plugin.
22 class MockPluginProcessHostClient : public PluginProcessHost::Client, 25 class MockPluginProcessHostClient : public PluginProcessHost::Client,
23 public IPC::Channel::Listener { 26 public IPC::Channel::Listener {
24 public: 27 public:
25 MockPluginProcessHostClient() 28 MockPluginProcessHostClient(const content::ResourceContext& context)
26 : channel_(NULL), 29 : context_(context),
30 channel_(NULL),
27 set_plugin_info_called_(false) { 31 set_plugin_info_called_(false) {
28 } 32 }
29 33
30 virtual ~MockPluginProcessHostClient() { 34 virtual ~MockPluginProcessHostClient() {
31 if (channel_) 35 if (channel_)
32 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, channel_); 36 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, channel_);
33 } 37 }
34 38
35 // Client implementation. 39 // Client implementation.
36 int ID() { return 42; } 40 virtual int ID() OVERRIDE { return 42; }
37 bool OffTheRecord() { return false; } 41 virtual bool OffTheRecord() OVERRIDE { return false; }
42 virtual const content::ResourceContext& GetResourceContext() OVERRIDE {
43 return context_;
44 }
38 45
39 void OnChannelOpened(const IPC::ChannelHandle& handle) { 46 void OnChannelOpened(const IPC::ChannelHandle& handle) {
40 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 47 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
41 ASSERT_TRUE(set_plugin_info_called_); 48 ASSERT_TRUE(set_plugin_info_called_);
42 ASSERT_TRUE(!channel_); 49 ASSERT_TRUE(!channel_);
43 channel_ = new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this); 50 channel_ = new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this);
44 ASSERT_TRUE(channel_->Connect()); 51 ASSERT_TRUE(channel_->Connect());
45 } 52 }
46 53
47 void SetPluginInfo(const webkit::WebPluginInfo& info) { 54 void SetPluginInfo(const webkit::WebPluginInfo& info) {
48 ASSERT_TRUE(info.mime_types.size()); 55 ASSERT_TRUE(info.mime_types.size());
49 ASSERT_EQ(kNPAPITestPluginMimeType, info.mime_types[0].mime_type); 56 ASSERT_EQ(kNPAPITestPluginMimeType, info.mime_types[0].mime_type);
50 set_plugin_info_called_ = true; 57 set_plugin_info_called_ = true;
51 } 58 }
52 59
53 MOCK_METHOD0(OnError, void()); 60 MOCK_METHOD0(OnError, void());
54 61
55 // Listener implementation. 62 // Listener implementation.
56 MOCK_METHOD1(OnMessageReceived, bool(const IPC::Message& message)); 63 MOCK_METHOD1(OnMessageReceived, bool(const IPC::Message& message));
57 void OnChannelConnected(int32 peer_pid) OVERRIDE { 64 void OnChannelConnected(int32 peer_pid) OVERRIDE {
58 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 65 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
59 new MessageLoop::QuitTask()); 66 new MessageLoop::QuitTask());
60 } 67 }
61 MOCK_METHOD0(OnChannelError, void()); 68 MOCK_METHOD0(OnChannelError, void());
62 MOCK_METHOD0(OnChannelDenied, void()); 69 MOCK_METHOD0(OnChannelDenied, void());
63 MOCK_METHOD0(OnChannelListenError, void()); 70 MOCK_METHOD0(OnChannelListenError, void());
64 71
65 private: 72 private:
73 const content::ResourceContext& context_;
66 IPC::Channel* channel_; 74 IPC::Channel* channel_;
67 bool set_plugin_info_called_; 75 bool set_plugin_info_called_;
68 DISALLOW_COPY_AND_ASSIGN(MockPluginProcessHostClient); 76 DISALLOW_COPY_AND_ASSIGN(MockPluginProcessHostClient);
69 }; 77 };
70 78
71 } // namespace 79 } // namespace
72 80
73 class PluginServiceTest : public InProcessBrowserTest { 81 class PluginServiceTest : public InProcessBrowserTest {
74 public: 82 public:
75 PluginServiceTest() : InProcessBrowserTest() { } 83 PluginServiceTest() : InProcessBrowserTest() { }
76 84
77 virtual void SetUpCommandLine(CommandLine* command_line) { 85 virtual void SetUpCommandLine(CommandLine* command_line) {
78 #ifdef OS_MACOSX 86 #ifdef OS_MACOSX
79 FilePath browser_directory; 87 FilePath browser_directory;
80 PathService::Get(base::DIR_MODULE, &browser_directory); 88 PathService::Get(base::DIR_MODULE, &browser_directory);
81 command_line->AppendSwitchPath(switches::kExtraPluginDir, 89 command_line->AppendSwitchPath(switches::kExtraPluginDir,
82 browser_directory.AppendASCII("plugins")); 90 browser_directory.AppendASCII("plugins"));
83 #endif 91 #endif
84 } 92 }
85 }; 93 };
86 94
87 // Try to open a channel to the test plugin. Minimal plugin process spawning 95 // Try to open a channel to the test plugin. Minimal plugin process spawning
88 // test for the PluginService interface. 96 // test for the PluginService interface.
89 IN_PROC_BROWSER_TEST_F(PluginServiceTest, OpenChannelToPlugin) { 97 IN_PROC_BROWSER_TEST_F(PluginServiceTest, OpenChannelToPlugin) {
90 MockPluginProcessHostClient mock_client; 98 ::testing::StrictMock<MockPluginProcessHostClient> mock_client(
99 browser()->profile()->GetResourceContext());
91 PluginService::GetInstance()->OpenChannelToNpapiPlugin( 100 PluginService::GetInstance()->OpenChannelToNpapiPlugin(
92 0, 0, GURL(), kNPAPITestPluginMimeType, &mock_client); 101 0, 0, GURL(), GURL(), kNPAPITestPluginMimeType, &mock_client);
93 ui_test_utils::RunMessageLoop(); 102 ui_test_utils::RunMessageLoop();
94 } 103 }
OLDNEW
« no previous file with comments | « content/browser/plugin_service.cc ('k') | content/browser/plugin_service_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698