diff options
author | alokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 19:52:11 +0000 |
---|---|---|
committer | alokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 19:52:11 +0000 |
commit | 22b5f52c422118fd6f090e9f6784ae9aede919f7 (patch) | |
tree | 764b3975594d488fcff18e1d99100092fdb92060 | |
parent | b7b9e034719610e59a4577043f326dd5b6a27640 (diff) | |
download | chromium_src-22b5f52c422118fd6f090e9f6784ae9aede919f7.zip chromium_src-22b5f52c422118fd6f090e9f6784ae9aede919f7.tar.gz chromium_src-22b5f52c422118fd6f090e9f6784ae9aede919f7.tar.bz2 |
Refactored NPAPITester to accomodate PepperTester. The functionality to load/unload npapi plugins has been moved to a base class NPAPITesterBase which does not have a hard-coded plugin name.
Review URL: http://codereview.chromium.org/1052001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41863 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/test/ui/npapi_test_helper.cc | 76 | ||||
-rw-r--r-- | chrome/test/ui/npapi_test_helper.h | 30 |
2 files changed, 81 insertions, 25 deletions
diff --git a/chrome/test/ui/npapi_test_helper.cc b/chrome/test/ui/npapi_test_helper.cc index 04c109f..1c8e7f1 100644 --- a/chrome/test/ui/npapi_test_helper.cc +++ b/chrome/test/ui/npapi_test_helper.cc @@ -16,20 +16,45 @@ #include "chrome/common/chrome_switches.h" #if defined(OS_WIN) -#define TEST_PLUGIN_NAME "npapi_test_plugin.dll" +static const char kNpapiTestPluginName[] = "npapi_test_plugin.dll"; +static const char kPepperTestPluginName[] = "pepper_test_plugin.dll"; #elif defined(OS_MACOSX) -#define TEST_PLUGIN_NAME "npapi_test_plugin.plugin" -#define LAYOUT_PLUGIN_NAME "TestNetscapePlugIn.plugin" +static const char kNpapiTestPluginName[] = "npapi_test_plugin.plugin"; +static const char kPepperTestPluginName[] = "PepperTestPlugin.plugin"; +static const char kLayoutPluginName[] = "TestNetscapePlugIn.plugin"; #elif defined(OS_LINUX) -#define TEST_PLUGIN_NAME "libnpapi_test_plugin.so" +static const char kNpapiTestPluginName[] = "libnpapi_test_plugin.so"; +static const char kPepperTestPluginName[] = "libpepper_test_plugin.so"; #endif -NPAPITester::NPAPITester() { +NPAPITesterBase::NPAPITesterBase(const std::string& test_plugin_name) + : test_plugin_name_(test_plugin_name) { } -void NPAPITester::SetUp() { +void NPAPITesterBase::SetUp() { // We need to copy our test-plugin into the plugins directory so that // the browser can load it. + FilePath plugins_directory = GetPluginsDirectory(); + FilePath plugin_src = browser_directory_.AppendASCII(test_plugin_name_); + ASSERT_TRUE(file_util::PathExists(plugin_src)); + test_plugin_path_ = plugins_directory.AppendASCII(test_plugin_name_); + + file_util::CreateDirectory(plugins_directory); + ASSERT_TRUE(file_util::CopyDirectory(plugin_src, test_plugin_path_, true)) + << "Copy failed from " << plugin_src.value() + << " to " << test_plugin_path_.value(); + + UITest::SetUp(); +} + +void NPAPITesterBase::TearDown() { + // Tear down the UI test first so that the browser stops using the plugin + // files. + UITest::TearDown(); + EXPECT_TRUE(file_util::DieFileDie(test_plugin_path_, true)); +} + +FilePath NPAPITesterBase::GetPluginsDirectory() { #if defined(OS_MACOSX) std::wstring plugin_subpath(chrome::kBrowserProcessExecutableName); plugin_subpath.append(L".app/Contents/PlugIns"); @@ -38,41 +63,37 @@ void NPAPITester::SetUp() { #else FilePath plugins_directory = browser_directory_.AppendASCII("plugins"); #endif + return plugins_directory; +} - FilePath plugin_src = browser_directory_.AppendASCII(TEST_PLUGIN_NAME); - ASSERT_TRUE(file_util::PathExists(plugin_src)); - test_plugin_path_ = plugins_directory.AppendASCII(TEST_PLUGIN_NAME); - - file_util::CreateDirectory(plugins_directory); - ASSERT_TRUE(file_util::CopyDirectory(plugin_src, test_plugin_path_, true)) - << "Copy failed from " << plugin_src.value() - << " to " << test_plugin_path_.value(); +NPAPITester::NPAPITester() : NPAPITesterBase(kNpapiTestPluginName) { +} +void NPAPITester::SetUp() { #if defined(OS_MACOSX) // On Windows and Linux, the layout plugin is copied into plugins/ as part of // its build process; we can't do the equivalent on the Mac since Chromium // doesn't exist during the Test Shell build. - FilePath layout_src = browser_directory_.AppendASCII(LAYOUT_PLUGIN_NAME); + FilePath layout_src = browser_directory_.AppendASCII(kLayoutPluginName); ASSERT_TRUE(file_util::PathExists(layout_src)); - layout_plugin_path_ = plugins_directory.AppendASCII(LAYOUT_PLUGIN_NAME); + FilePath plugins_directory = GetPluginsDirectory(); + layout_plugin_path_ = plugins_directory.AppendASCII(kLayoutPluginName); + file_util::CreateDirectory(plugins_directory); ASSERT_TRUE(file_util::CopyDirectory(layout_src, layout_plugin_path_, true)); #endif - UITest::SetUp(); + NPAPITesterBase::SetUp(); } void NPAPITester::TearDown() { - // Tear down the UI test first so that the browser stops using the plugin + // Tear down the base class first so that the browser stops using the plugin // files. - UITest::TearDown(); - - EXPECT_TRUE(file_util::DieFileDie(test_plugin_path_, true)); + NPAPITesterBase::TearDown(); #if defined(OS_MACOSX) EXPECT_TRUE(file_util::DieFileDie(layout_plugin_path_, true)); -#endif +#endif // OS_MACOSX } - // NPAPIVisiblePluginTester members. void NPAPIVisiblePluginTester::SetUp() { show_window_ = true; @@ -84,3 +105,12 @@ void NPAPIIncognitoTester::SetUp() { launch_arguments_.AppendSwitch(switches::kIncognito); NPAPITester::SetUp(); } + +PepperTester::PepperTester() : NPAPITesterBase(kPepperTestPluginName) { +} + +void PepperTester::SetUp() { + // TODO(alokp): Add command-line arguments + // --no-sandbox --internal-pepper --enable-gpu-plugin + NPAPITesterBase::SetUp(); +} diff --git a/chrome/test/ui/npapi_test_helper.h b/chrome/test/ui/npapi_test_helper.h index c64382a..a0c2f3b 100644 --- a/chrome/test/ui/npapi_test_helper.h +++ b/chrome/test/ui/npapi_test_helper.h @@ -7,16 +7,35 @@ #include "chrome/test/ui/ui_test.h" +// Base class for NPAPI tests. It provides common functionality between +// regular NPAPI plugins and pepper NPAPI plugins. The base classes provide the +// name of the plugin they need test in the constructor. This base class will +// copy the plugin (assuming it has been built) to the plugins directory +// so it is loaded when chromium is launched. +class NPAPITesterBase : public UITest { + protected: + explicit NPAPITesterBase(const std::string& test_plugin_name); + virtual void SetUp(); + virtual void TearDown(); + + FilePath GetPluginsDirectory(); + + private: + std::string test_plugin_name_; + FilePath test_plugin_path_; +}; + // Helper class for NPAPI plugin UI tests. -class NPAPITester : public UITest { +class NPAPITester : public NPAPITesterBase { protected: NPAPITester(); virtual void SetUp(); virtual void TearDown(); private: - FilePath test_plugin_path_; +#if defined(OS_MACOSX) FilePath layout_plugin_path_; +#endif // OS_MACOSX }; // Helper class for NPAPI plugin UI tests, which need the browser window @@ -32,4 +51,11 @@ class NPAPIIncognitoTester : public NPAPITester { virtual void SetUp(); }; +// Helper class pepper NPAPI tests. +class PepperTester : public NPAPITesterBase { + protected: + PepperTester(); + virtual void SetUp(); +}; + #endif // CHROME_TEST_UI_NPAPI_TEST_HELPER_H_ |