Commit faabdffd authored by amanda@chromium.org's avatar amanda@chromium.org

Rewrite plugin_tests.cc to use FilePath and file_utils.h instead

of Windows file & string manipulation, enable plugin tests on the Mac.
Review URL: http://codereview.chromium.org/102014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14968 0039d316-1c4b-4281-b951-d872f2087c98
parent 767543df
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <string> #include <string>
#include "base/file_path.h"
#include "base/file_util.h" #include "base/file_util.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/string_util.h" #include "base/string_util.h"
...@@ -19,31 +20,39 @@ ...@@ -19,31 +20,39 @@
using WebKit::WebScriptSource; using WebKit::WebScriptSource;
using WebKit::WebString; using WebKit::WebString;
#if defined(OS_WIN)
#define TEST_PLUGIN_NAME "npapi_test_plugin.dll"
#elif defined(OS_MACOSX)
#define TEST_PLUGIN_NAME "npapi_test_plugin.bundle"
#elif defined(OS_LINUX)
#define TEST_PLUGIN_NAME "npapi_test_plugin.so"
#endif
// Provides functionality for creating plugin tests. // Provides functionality for creating plugin tests.
class PluginTest : public TestShellTest { class PluginTest : public TestShellTest {
public: public:
PluginTest() { PluginTest() {
std::wstring current_directory; FilePath executable_directory;
PathService::Get(base::DIR_EXE, &current_directory); PathService::Get(base::DIR_EXE, &executable_directory);
plugin_src_ = current_directory + L"\\npapi_test_plugin.dll"; plugin_src_ = executable_directory.AppendASCII(TEST_PLUGIN_NAME);
CHECK(file_util::PathExists(plugin_src_)); CHECK(file_util::PathExists(plugin_src_));
plugin_file_path_ = current_directory + L"\\plugins"; plugin_file_path_ = executable_directory.AppendASCII("plugins");
::CreateDirectory(plugin_file_path_.c_str(), NULL); file_util::CreateDirectory(plugin_file_path_);
plugin_file_path_ += L"\\npapi_test_plugin.dll"; plugin_file_path_ = plugin_file_path_.AppendASCII(TEST_PLUGIN_NAME);
} }
void CopyTestPlugin() { void CopyTestPlugin() {
ASSERT_TRUE(CopyFile(plugin_src_.c_str(), plugin_file_path_.c_str(), FALSE)); ASSERT_TRUE(file_util::CopyDirectory(plugin_src_, plugin_file_path_, true));
} }
void DeleteTestPlugin() { void DeleteTestPlugin() {
::DeleteFile(plugin_file_path_.c_str()); file_util::Delete(plugin_file_path_, true);
} }
std::wstring plugin_src_; FilePath plugin_src_;
std::wstring plugin_file_path_; FilePath plugin_file_path_;
}; };
// Tests navigator.plugins.refresh() works. // Tests navigator.plugins.refresh() works.
...@@ -55,7 +64,7 @@ TEST_F(PluginTest, Refresh) { ...@@ -55,7 +64,7 @@ TEST_F(PluginTest, Refresh) {
var l = navigator.plugins.length;\ var l = navigator.plugins.length;\
var result = document.getElementById('result');\ var result = document.getElementById('result');\
for(var i = 0; i < l; i++) {\ for(var i = 0; i < l; i++) {\
if (navigator.plugins[i].filename == 'npapi_test_plugin.dll') {\ if (navigator.plugins[i].filename == '" TEST_PLUGIN_NAME "') {\
result.innerHTML = 'DONE';\ result.innerHTML = 'DONE';\
break;\ break;\
}\ }\
...@@ -98,6 +107,8 @@ TEST_F(PluginTest, Refresh) { ...@@ -98,6 +107,8 @@ TEST_F(PluginTest, Refresh) {
DeleteTestPlugin(); DeleteTestPlugin();
} }
#if defined(OS_WIN)
// TODO(port): Reenable on mac and linux once they have working default plugins.
TEST_F(PluginTest, DefaultPluginLoadTest) { TEST_F(PluginTest, DefaultPluginLoadTest) {
std::string html = "\ std::string html = "\
<div id='result'>Test running....</div>\ <div id='result'>Test running....</div>\
...@@ -125,6 +136,7 @@ TEST_F(PluginTest, DefaultPluginLoadTest) { ...@@ -125,6 +136,7 @@ TEST_F(PluginTest, DefaultPluginLoadTest) {
ASSERT_EQ(true, StartsWith(text, L"DONE", true)); ASSERT_EQ(true, StartsWith(text, L"DONE", true));
} }
#endif
// Tests that if a frame is deleted as a result of calling NPP_HandleEvent, we // Tests that if a frame is deleted as a result of calling NPP_HandleEvent, we
// don't crash. // don't crash.
......
...@@ -431,6 +431,7 @@ ...@@ -431,6 +431,7 @@
# TODO(port) # TODO(port)
'../../../skia/ext/platform_canvas_unittest.cc', '../../../skia/ext/platform_canvas_unittest.cc',
'../../glue/webplugin_impl_unittest.cc', '../../glue/webplugin_impl_unittest.cc',
'plugin_tests.cc'
], ],
}], }],
['OS=="mac"', { ['OS=="mac"', {
...@@ -446,7 +447,6 @@ ...@@ -446,7 +447,6 @@
'../../../skia/ext/vector_canvas_unittest.cc', '../../../skia/ext/vector_canvas_unittest.cc',
'../webcore_unit_tests/UniscribeHelper_unittest.cpp', '../webcore_unit_tests/UniscribeHelper_unittest.cpp',
'../webcore_unit_tests/TransparencyWin_unittest.cpp', '../webcore_unit_tests/TransparencyWin_unittest.cpp',
'plugin_tests.cc'
], ],
}], }],
], ],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment