summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-27 23:26:18 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-27 23:26:18 +0000
commitb5f4e2c82f8443d62eaa21714822634de5cfbc46 (patch)
tree6f7f1ddf7c42f6b95ea804b1fe9c2095bbc0a725 /webkit
parentbb063b71478fe0dad927d7bd1f2496b8e4f1713d (diff)
downloadchromium_src-b5f4e2c82f8443d62eaa21714822634de5cfbc46.zip
chromium_src-b5f4e2c82f8443d62eaa21714822634de5cfbc46.tar.gz
chromium_src-b5f4e2c82f8443d62eaa21714822634de5cfbc46.tar.bz2
Add a test to test_shell_tests to verify that navigator.plugins.refresh() works.
Also get rid of the duplicate disabled verify_plugin_window_rect test. Review URL: http://codereview.chromium.org/42687 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12725 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/data/plugin_tests/npapi.js28
-rw-r--r--webkit/data/plugin_tests/verify_plugin_window_rect.html30
-rw-r--r--webkit/tools/test_shell/plugin_tests.cc141
3 files changed, 54 insertions, 145 deletions
diff --git a/webkit/data/plugin_tests/npapi.js b/webkit/data/plugin_tests/npapi.js
deleted file mode 100644
index 207d188..0000000
--- a/webkit/data/plugin_tests/npapi.js
+++ /dev/null
@@ -1,28 +0,0 @@
-//
-// This script provides some mechanics for testing NPAPI
-//
-
-/* public */ function onSuccess(name, id)
-{
- setTimeout(onFinished, 0, name, id, "OK");
-}
-
-/* public */ function onFailure(name, id, status)
-{
- setTimeout(onFinished, 0, name, id, status);
-}
-
-
-
-// Finish running a test by setting the status
-// and the cookie.
-/* private */ function onFinished(name, id, result)
-{
- var statusPanel = document.getElementById("statusPanel");
- if (statusPanel) {
- statusPanel.innerHTML = result;
- }
-
- var cookie = name + "." + id + ".status=" + result + "; path=/";
- document.cookie = cookie;
-}
diff --git a/webkit/data/plugin_tests/verify_plugin_window_rect.html b/webkit/data/plugin_tests/verify_plugin_window_rect.html
deleted file mode 100644
index 7dca47a..0000000
--- a/webkit/data/plugin_tests/verify_plugin_window_rect.html
+++ /dev/null
@@ -1,30 +0,0 @@
-<html>
-
-<head>
-<script src="npapi.js"></script>
-</head>
-
-<body>
-<div id="statusPanel" style="border: 1px solid red; width: 100%">
-Test running....
-</div>
-
-
-Plugin Window Rect Test<p>
-
-Tests whether the plugin window has a non zero client rect.
-
-<DIV ID=PluginDiv>
-<embed type="application/vnd.npapi-test"
- src="foo"
- name="checkwindowrect"
- id="1"
- mode="np_embed"
->
-</DIV>
-<script>
- var height = document.body.offsetHeight;
-</script>
-
-</body>
-</html>
diff --git a/webkit/tools/test_shell/plugin_tests.cc b/webkit/tools/test_shell/plugin_tests.cc
index ad06166..859b52a 100644
--- a/webkit/tools/test_shell/plugin_tests.cc
+++ b/webkit/tools/test_shell/plugin_tests.cc
@@ -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, &current_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_));
}
- virtual void TearDown() {
- TestShellTest::TearDown();
+ void CopyTestPlugin() {
+ ASSERT_TRUE(CopyFile(plugin_src_.c_str(), plugin_file_path_.c_str(), FALSE));
+ }
- // 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();
}