| Index: webkit/tools/test_shell/plugin_tests.cc
|
| ===================================================================
|
| --- webkit/tools/test_shell/plugin_tests.cc (revision 12587)
|
| +++ webkit/tools/test_shell/plugin_tests.cc (working copy)
|
| @@ -5,116 +5,83 @@
|
| #include <string>
|
|
|
| #include "base/file_util.h"
|
| -#include "base/message_loop.h"
|
| +#include "base/path_service.h"
|
| #include "base/string_util.h"
|
| -#include "net/base/cookie_monster.h"
|
| -#include "net/base/net_util.h"
|
| -#include "net/http/http_cache.h"
|
| -#include "net/url_request/url_request_context.h"
|
| -#include "net/url_request/url_request_unittest.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| -#include "webkit/glue/plugins/plugin_list.h"
|
| -#include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
|
| +#include "webkit/glue/webframe.h"
|
| +#include "webkit/glue/webscriptsource.h"
|
| +#include "webkit/glue/webview.h"
|
| #include "webkit/tools/test_shell/test_shell.h"
|
| #include "webkit/tools/test_shell/test_shell_test.h"
|
|
|
| -static const char kTestCompleteCookie[] = "status";
|
| -static const char kTestCompleteSuccess[] = "OK";
|
|
|
| // Provides functionality for creating plugin tests.
|
| class PluginTest : public TestShellTest {
|
| - // A basic URLRequestContext that only provides an in-memory cookie store.
|
| - class RequestContext : public TestURLRequestContext {
|
| - public:
|
| - RequestContext() {
|
| - cookie_store_ = new net::CookieMonster();
|
| - }
|
| -
|
| - virtual ~RequestContext() {
|
| - delete cookie_store_;
|
| - }
|
| - };
|
| -
|
| public:
|
| - PluginTest() {}
|
| - ~PluginTest() {}
|
| -
|
| - void NavigateToURL(const std::wstring& test_url) {
|
| - ASSERT_TRUE(file_util::PathExists(test_url));
|
| - test_url_ = net::FilePathToFileURL(test_url);
|
| - test_shell_->LoadURL(test_url.c_str());
|
| - }
|
| -
|
| - // Waits for the test case to finish.
|
| - // ASSERTS if there are test failures.
|
| - void WaitForFinish(const std::string &name, const std::string &id) {
|
| - test_shell_->WaitTestFinished();
|
| -
|
| - std::string cookies =
|
| - request_context_->cookie_store()->GetCookies(test_url_);
|
| - EXPECT_FALSE(cookies.empty());
|
| -
|
| - std::string cookieName = name;
|
| - cookieName.append(".");
|
| - cookieName.append(id);
|
| - cookieName.append(".");
|
| - cookieName.append(kTestCompleteCookie);
|
| - cookieName.append("=");
|
| - std::string::size_type idx = cookies.find(cookieName);
|
| - std::string cookie;
|
| - if (idx != std::string::npos) {
|
| - cookies.erase(0, idx + cookieName.length());
|
| - cookie = cookies.substr(0, cookies.find(";"));
|
| - }
|
| -
|
| - EXPECT_EQ(kTestCompleteSuccess, cookie);
|
| - }
|
| -
|
| - protected:
|
| - virtual void SetUp() {
|
| - // We need to copy our test-plugin into the plugins directory so that
|
| - // the test can load it.
|
| + PluginTest() {
|
| std::wstring current_directory;
|
| PathService::Get(base::DIR_EXE, ¤t_directory);
|
| - std::wstring plugin_src = current_directory + L"\\npapi_test_plugin.dll";
|
| - ASSERT_TRUE(file_util::PathExists(plugin_src));
|
| + plugin_src_ = current_directory + L"\\npapi_test_plugin.dll";
|
| + CHECK(file_util::PathExists(plugin_src_));
|
|
|
| plugin_file_path_ = current_directory + L"\\plugins";
|
| ::CreateDirectory(plugin_file_path_.c_str(), NULL);
|
|
|
| plugin_file_path_ += L"\\npapi_test_plugin.dll";
|
| - ASSERT_TRUE(CopyFile(plugin_src.c_str(), plugin_file_path_.c_str(), FALSE));
|
| + }
|
|
|
| - // The plugin list has to be refreshed to ensure that the npapi_test_plugin
|
| - // is loaded by webkit.
|
| - std::vector<WebPluginInfo> plugin_list;
|
| - bool refresh = true;
|
| - NPAPI::PluginList::Singleton()->GetPlugins(refresh, &plugin_list);
|
| -
|
| - TestShellTest::SetUp();
|
| -
|
| - plugin_data_dir_ = data_dir_;
|
| - file_util::AppendToPath(&plugin_data_dir_, L"plugin_tests");
|
| - ASSERT_TRUE(file_util::PathExists(plugin_data_dir_));
|
| + void CopyTestPlugin() {
|
| + ASSERT_TRUE(CopyFile(plugin_src_.c_str(), plugin_file_path_.c_str(), FALSE));
|
| }
|
|
|
| - virtual void TearDown() {
|
| - TestShellTest::TearDown();
|
| -
|
| - // TODO(iyengar) The DeleteFile call fails in some cases as the plugin is
|
| - // still in use. Needs more investigation.
|
| + void DeleteTestPlugin() {
|
| ::DeleteFile(plugin_file_path_.c_str());
|
| }
|
|
|
| - std::wstring plugin_data_dir_;
|
| + std::wstring plugin_src_;
|
| std::wstring plugin_file_path_;
|
| - RequestContext* request_context_;
|
| - GURL test_url_;
|
| };
|
|
|
| -TEST_F(PluginTest, DISABLED_VerifyPluginWindowRect) {
|
| - std::wstring test_url = GetTestURL(plugin_data_dir_,
|
| - L"verify_plugin_window_rect.html");
|
| - NavigateToURL(test_url);
|
| - WaitForFinish("checkwindowrect", "1");
|
| +// Tests navigator.plugins.refresh() works.
|
| +TEST_F(PluginTest, Refresh) {
|
| + std::string html = "\
|
| + <div id='result'>Test running....</div>\
|
| + <script>\
|
| + function check() {\
|
| + var l = navigator.plugins.length;\
|
| + var result = document.getElementById('result');\
|
| + for(var i = 0; i < l; i++) {\
|
| + if (navigator.plugins[i].filename == 'npapi_test_plugin.dll') {\
|
| + result.innerHTML = 'DONE';\
|
| + break;\
|
| + }\
|
| + }\
|
| + \
|
| + if (result.innerHTML != 'DONE')\
|
| + result.innerHTML = 'FAIL';\
|
| + }\
|
| + </script>\
|
| + ";
|
| +
|
| + DeleteTestPlugin(); // Remove any leftover from previous tests if they exist.
|
| + test_shell_->webView()->GetMainFrame()->LoadHTMLString(
|
| + html, GURL("about:blank"));
|
| + test_shell_->WaitTestFinished();
|
| +
|
| + std::wstring text;
|
| + webkit_glue::WebScriptSource call_check("check();");
|
| + webkit_glue::WebScriptSource refresh("navigator.plugins.refresh(false)");
|
| +
|
| + test_shell_->webView()->GetMainFrame()->ExecuteScript(call_check);
|
| + test_shell_->webView()->GetMainFrame()->GetContentAsPlainText(10000, &text);
|
| + ASSERT_EQ(text, L"FAIL");
|
| +
|
| + CopyTestPlugin();
|
| +
|
| + test_shell_->webView()->GetMainFrame()->ExecuteScript(refresh);
|
| + test_shell_->webView()->GetMainFrame()->ExecuteScript(call_check);
|
| + test_shell_->webView()->GetMainFrame()->GetContentAsPlainText(10000, &text);
|
| + ASSERT_EQ(text, L"DONE");
|
| +
|
| + DeleteTestPlugin();
|
| }
|
|
|