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

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

Powered by Google App Engine
This is Rietveld 408576698