OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/plugin_service.h" | |
6 | |
7 #include "base/auto_reset.h" | |
8 #include "base/command_line.h" | |
9 #include "chrome/browser/browser_thread.h" | |
10 #include "chrome/test/in_process_browser_test.h" | |
11 #include "chrome/test/testing_profile.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 #include "testing/gmock/include/gmock/gmock.h" | |
14 #include "webkit/plugins/npapi/plugin_list.h" | |
15 | |
16 namespace { | |
17 | |
18 // We have to mock the Client class up in order to be able to test the | |
19 // OpenChannelToPlugin function. The only really needed function of this mockup | |
20 // is SetPluginInfo, which gets called in | |
21 // PluginService::FinishOpenChannelToPlugin. | |
22 class MockPluginProcessHostClient : public PluginProcessHost::Client { | |
23 public: | |
24 MockPluginProcessHostClient() {} | |
25 virtual ~MockPluginProcessHostClient() {} | |
26 | |
27 MOCK_METHOD0(ID, int()); | |
28 MOCK_METHOD0(OffTheRecord, bool()); | |
29 MOCK_METHOD1(SetPluginInfo, void(const webkit::npapi::WebPluginInfo& info)); | |
30 MOCK_METHOD1(OnChannelOpened, void(const IPC::ChannelHandle& handle)); | |
31 MOCK_METHOD0(OnError, void()); | |
32 | |
33 private: | |
34 DISALLOW_COPY_AND_ASSIGN(MockPluginProcessHostClient); | |
35 }; | |
36 | |
37 class PluginServiceTest : public testing::Test { | |
38 public: | |
39 PluginServiceTest() | |
40 : message_loop_(MessageLoop::TYPE_IO), | |
41 ui_thread_(BrowserThread::UI, &message_loop_), | |
42 file_thread_(BrowserThread::FILE, &message_loop_), | |
43 io_thread_(BrowserThread::IO, &message_loop_) {} | |
44 | |
45 virtual ~PluginServiceTest() {} | |
46 | |
47 virtual void SetUp() { | |
48 profile_.reset(new TestingProfile()); | |
49 | |
50 PluginService::InitGlobalInstance(profile_.get()); | |
51 plugin_service_ = PluginService::GetInstance(); | |
52 ASSERT_TRUE(plugin_service_); | |
53 } | |
54 | |
55 protected: | |
56 MessageLoop message_loop_; | |
57 PluginService* plugin_service_; | |
58 | |
59 private: | |
60 BrowserThread ui_thread_; | |
61 BrowserThread file_thread_; | |
62 BrowserThread io_thread_; | |
63 scoped_ptr<TestingProfile> profile_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(PluginServiceTest); | |
66 }; | |
67 | |
68 // These tests need to be implemented as in process tests because on mac os the | |
69 // plugin loading mechanism checks whether plugin paths are in the bundle path | |
70 // and the test fails this check when run outside of the browser process. | |
71 IN_PROC_BROWSER_TEST_F(PluginServiceTest, StartAndFindPluginProcess) { | |
72 // Try to load the default plugin and if this is successful consecutive | |
73 // calls to FindPluginProcess should return non-zero values. | |
74 PluginProcessHost* default_plugin_process_host = | |
75 plugin_service_->FindOrStartNpapiPluginProcess( | |
76 FilePath(webkit::npapi::kDefaultPluginLibraryName)); | |
77 | |
78 EXPECT_EQ(default_plugin_process_host, | |
79 plugin_service_->FindNpapiPluginProcess( | |
80 FilePath(webkit::npapi::kDefaultPluginLibraryName))); | |
81 } | |
82 | |
83 IN_PROC_BROWSER_TEST_F(PluginServiceTest, OpenChannelToPlugin) { | |
84 MockPluginProcessHostClient mock_client; | |
85 EXPECT_CALL(mock_client, SetPluginInfo(testing::_)).Times(1); | |
86 plugin_service_->OpenChannelToNpapiPlugin(0, 0, GURL("http://google.com/"), | |
87 "audio/mp3", &mock_client); | |
88 message_loop_.RunAllPending(); | |
89 } | |
90 | |
91 IN_PROC_BROWSER_TEST_F(PluginServiceTest, GetFirstAllowedPluginInfo) { | |
92 // on ChromeOS the plugin policy gets loaded on the FILE thread and the | |
93 // GetFirstAllowedPluginInfo will fail if we don't allow it to finish. | |
94 message_loop_.RunAllPending(); | |
95 // We should always get a positive response no matter whether we really have | |
96 // a plugin to support that particular mime type because the Default plugin | |
97 // supports all mime types. | |
98 webkit::npapi::WebPluginInfo plugin_info; | |
99 std::string plugin_mime_type; | |
100 plugin_service_->GetFirstAllowedPluginInfo(0, 0, GURL("http://google.com/"), | |
101 "application/pdf", | |
102 &plugin_info, | |
103 &plugin_mime_type); | |
104 EXPECT_EQ("application/pdf", plugin_mime_type); | |
105 } | |
106 | |
107 } // namespace | |
OLD | NEW |