diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-23 03:55:40 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-23 03:55:40 +0000 |
commit | a0421736a8a437ff97eb7deb6050f08b75810343 (patch) | |
tree | 0df2ac04070f1fa41b1a3dfbd5582f0f9bb9817e /content/browser/plugin_service_browsertest.cc | |
parent | a6d8357a9702c6ce48e15914760708c1970a03e2 (diff) | |
download | chromium_src-a0421736a8a437ff97eb7deb6050f08b75810343.zip chromium_src-a0421736a8a437ff97eb7deb6050f08b75810343.tar.gz chromium_src-a0421736a8a437ff97eb7deb6050f08b75810343.tar.bz2 |
Move the rest of the core files in chrome\browser to content\browser.
TBR=avi
Review URL: http://codereview.chromium.org/6538111
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75711 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/plugin_service_browsertest.cc')
-rw-r--r-- | content/browser/plugin_service_browsertest.cc | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/content/browser/plugin_service_browsertest.cc b/content/browser/plugin_service_browsertest.cc new file mode 100644 index 0000000..2a0edb5 --- /dev/null +++ b/content/browser/plugin_service_browsertest.cc @@ -0,0 +1,107 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/plugin_service.h" + +#include "base/auto_reset.h" +#include "base/command_line.h" +#include "chrome/test/in_process_browser_test.h" +#include "chrome/test/testing_profile.h" +#include "content/browser/browser_thread.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "webkit/plugins/npapi/plugin_list.h" + +namespace { + +// We have to mock the Client class up in order to be able to test the +// OpenChannelToPlugin function. The only really needed function of this mockup +// is SetPluginInfo, which gets called in +// PluginService::FinishOpenChannelToPlugin. +class MockPluginProcessHostClient : public PluginProcessHost::Client { + public: + MockPluginProcessHostClient() {} + virtual ~MockPluginProcessHostClient() {} + + MOCK_METHOD0(ID, int()); + MOCK_METHOD0(OffTheRecord, bool()); + MOCK_METHOD1(SetPluginInfo, void(const webkit::npapi::WebPluginInfo& info)); + MOCK_METHOD1(OnChannelOpened, void(const IPC::ChannelHandle& handle)); + MOCK_METHOD0(OnError, void()); + + private: + DISALLOW_COPY_AND_ASSIGN(MockPluginProcessHostClient); +}; + +class PluginServiceTest : public testing::Test { + public: + PluginServiceTest() + : message_loop_(MessageLoop::TYPE_IO), + ui_thread_(BrowserThread::UI, &message_loop_), + file_thread_(BrowserThread::FILE, &message_loop_), + io_thread_(BrowserThread::IO, &message_loop_) {} + + virtual ~PluginServiceTest() {} + + virtual void SetUp() { + profile_.reset(new TestingProfile()); + + PluginService::InitGlobalInstance(profile_.get()); + plugin_service_ = PluginService::GetInstance(); + ASSERT_TRUE(plugin_service_); + } + + protected: + MessageLoop message_loop_; + PluginService* plugin_service_; + + private: + BrowserThread ui_thread_; + BrowserThread file_thread_; + BrowserThread io_thread_; + scoped_ptr<TestingProfile> profile_; + + DISALLOW_COPY_AND_ASSIGN(PluginServiceTest); +}; + +// These tests need to be implemented as in process tests because on mac os the +// plugin loading mechanism checks whether plugin paths are in the bundle path +// and the test fails this check when run outside of the browser process. +IN_PROC_BROWSER_TEST_F(PluginServiceTest, StartAndFindPluginProcess) { + // Try to load the default plugin and if this is successful consecutive + // calls to FindPluginProcess should return non-zero values. + PluginProcessHost* default_plugin_process_host = + plugin_service_->FindOrStartNpapiPluginProcess( + FilePath(webkit::npapi::kDefaultPluginLibraryName)); + + EXPECT_EQ(default_plugin_process_host, + plugin_service_->FindNpapiPluginProcess( + FilePath(webkit::npapi::kDefaultPluginLibraryName))); +} + +IN_PROC_BROWSER_TEST_F(PluginServiceTest, OpenChannelToPlugin) { + MockPluginProcessHostClient mock_client; + EXPECT_CALL(mock_client, SetPluginInfo(testing::_)).Times(1); + plugin_service_->OpenChannelToNpapiPlugin(0, 0, GURL("http://google.com/"), + "audio/mp3", &mock_client); + message_loop_.RunAllPending(); +} + +IN_PROC_BROWSER_TEST_F(PluginServiceTest, GetFirstAllowedPluginInfo) { + // on ChromeOS the plugin policy gets loaded on the FILE thread and the + // GetFirstAllowedPluginInfo will fail if we don't allow it to finish. + message_loop_.RunAllPending(); + // We should always get a positive response no matter whether we really have + // a plugin to support that particular mime type because the Default plugin + // supports all mime types. + webkit::npapi::WebPluginInfo plugin_info; + std::string plugin_mime_type; + plugin_service_->GetFirstAllowedPluginInfo(0, 0, GURL("http://google.com/"), + "application/pdf", + &plugin_info, + &plugin_mime_type); + EXPECT_EQ("application/pdf", plugin_mime_type); +} + +} // namespace |