summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-18 00:18:08 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-18 00:18:08 +0000
commit599490bc824bbff9968067dac44a4347122da9c2 (patch)
treef61f7a21eb4efd813329c3f10fd96d5e0618f45c
parentb090564cdd7c990aa31026f74711a526db296cf0 (diff)
downloadchromium_src-599490bc824bbff9968067dac44a4347122da9c2.zip
chromium_src-599490bc824bbff9968067dac44a4347122da9c2.tar.gz
chromium_src-599490bc824bbff9968067dac44a4347122da9c2.tar.bz2
Implemented unit tests for the public members of the PluginService class.
BUG=none TEST=browser_tests,unit_tests Review URL: http://codereview.chromium.org/5133003 Patch from Julian Pastarmov <pastarmovj@google.com>. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66555 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/plugin_service_browsertest.cc107
-rw-r--r--chrome/browser/plugin_service_unittest.cc63
-rw-r--r--chrome/chrome_tests.gypi2
3 files changed, 172 insertions, 0 deletions
diff --git a/chrome/browser/plugin_service_browsertest.cc b/chrome/browser/plugin_service_browsertest.cc
new file mode 100644
index 0000000..8d9e82e
--- /dev/null
+++ b/chrome/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 "chrome/browser/plugin_service.h"
+
+#include "base/auto_reset.h"
+#include "base/command_line.h"
+#include "chrome/browser/browser_thread.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/testing_profile.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "webkit/glue/plugins/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 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_->FindOrStartPluginProcess(
+ FilePath(kDefaultPluginLibraryName));
+
+ EXPECT_EQ(default_plugin_process_host,
+ plugin_service_->FindPluginProcess(FilePath(kDefaultPluginLibraryName)));
+}
+
+IN_PROC_BROWSER_TEST_F(PluginServiceTest, OpenChannelToPlugin) {
+ MockPluginProcessHostClient mock_client;
+ EXPECT_CALL(mock_client, SetPluginInfo(testing::_)).Times(1);
+ plugin_service_->OpenChannelToPlugin(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.
+ WebPluginInfo plugin_info;
+ std::string plugin_mime_type;
+ plugin_service_->GetFirstAllowedPluginInfo(GURL("http://google.com/"),
+ "application/pdf",
+ &plugin_info,
+ &plugin_mime_type);
+ EXPECT_EQ("application/pdf", plugin_mime_type);
+}
+
+} // namespace
diff --git a/chrome/browser/plugin_service_unittest.cc b/chrome/browser/plugin_service_unittest.cc
new file mode 100644
index 0000000..4e54526
--- /dev/null
+++ b/chrome/browser/plugin_service_unittest.cc
@@ -0,0 +1,63 @@
+// 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 "chrome/browser/plugin_service.h"
+
+#include "base/auto_reset.h"
+#include "base/command_line.h"
+#include "chrome/browser/browser_thread.h"
+#include "chrome/test/testing_profile.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/glue/plugins/plugin_list.h"
+
+namespace {
+
+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);
+};
+
+TEST_F(PluginServiceTest, SetGetChromePluginDataDir) {
+ // Check that after setting the same plugin dir we just read it is set
+ // correctly.
+ FilePath plugin_data_dir = plugin_service_->GetChromePluginDataDir();
+ FilePath new_plugin_data_dir(FILE_PATH_LITERAL("/a/bogus/dir"));
+ plugin_service_->SetChromePluginDataDir(new_plugin_data_dir);
+ EXPECT_EQ(new_plugin_data_dir, plugin_service_->GetChromePluginDataDir());
+ plugin_service_->SetChromePluginDataDir(plugin_data_dir);
+ EXPECT_EQ(plugin_data_dir, plugin_service_->GetChromePluginDataDir());
+}
+
+TEST_F(PluginServiceTest, GetUILocale) {
+ // Check for a non-empty locale string.
+ EXPECT_NE("", plugin_service_->GetUILocale());
+}
+
+} // namespace
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 2c8ea2b..67890d6 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1389,6 +1389,7 @@
'browser/password_manager/password_store_mac_unittest.cc',
'browser/password_manager/password_store_win_unittest.cc',
'browser/plugin_exceptions_table_model_unittest.cc',
+ 'browser/plugin_service_unittest.cc',
'browser/policy/config_dir_policy_provider_unittest.cc',
'browser/policy/configuration_policy_pref_store_unittest.cc',
'browser/policy/configuration_policy_provider_mac_unittest.cc',
@@ -2039,6 +2040,7 @@
'browser/in_process_webkit/indexed_db_browsertest.cc',
'browser/net/cookie_policy_browsertest.cc',
'browser/net/ftp_browsertest.cc',
+ 'browser/plugin_service_browsertest.cc',
'browser/policy/device_management_backend_impl_browsertest.cc',
'browser/policy/device_management_backend_mock.h',
'browser/popup_blocker_browsertest.cc',