Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: webkit/tools/test_shell/plugin_tests.cc

Issue 42687: Add a test to test_shell_tests to verify that navigator.plugins.refresh() wor... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/data/plugin_tests/verify_plugin_window_rect.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/message_loop.h" 8 #include "base/path_service.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "net/base/cookie_monster.h"
11 #include "net/base/net_util.h"
12 #include "net/http/http_cache.h"
13 #include "net/url_request/url_request_context.h"
14 #include "net/url_request/url_request_unittest.h"
15 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webkit/glue/plugins/plugin_list.h" 11 #include "webkit/glue/webframe.h"
17 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" 12 #include "webkit/glue/webscriptsource.h"
13 #include "webkit/glue/webview.h"
18 #include "webkit/tools/test_shell/test_shell.h" 14 #include "webkit/tools/test_shell/test_shell.h"
19 #include "webkit/tools/test_shell/test_shell_test.h" 15 #include "webkit/tools/test_shell/test_shell_test.h"
20 16
21 static const char kTestCompleteCookie[] = "status";
22 static const char kTestCompleteSuccess[] = "OK";
23 17
24 // Provides functionality for creating plugin tests. 18 // Provides functionality for creating plugin tests.
25 class PluginTest : public TestShellTest { 19 class PluginTest : public TestShellTest {
26 // A basic URLRequestContext that only provides an in-memory cookie store.
27 class RequestContext : public TestURLRequestContext {
28 public:
29 RequestContext() {
30 cookie_store_ = new net::CookieMonster();
31 }
32
33 virtual ~RequestContext() {
34 delete cookie_store_;
35 }
36 };
37
38 public: 20 public:
39 PluginTest() {} 21 PluginTest() {
40 ~PluginTest() {}
41
42 void NavigateToURL(const std::wstring& test_url) {
43 ASSERT_TRUE(file_util::PathExists(test_url));
44 test_url_ = net::FilePathToFileURL(test_url);
45 test_shell_->LoadURL(test_url.c_str());
46 }
47
48 // Waits for the test case to finish.
49 // ASSERTS if there are test failures.
50 void WaitForFinish(const std::string &name, const std::string &id) {
51 test_shell_->WaitTestFinished();
52
53 std::string cookies =
54 request_context_->cookie_store()->GetCookies(test_url_);
55 EXPECT_FALSE(cookies.empty());
56
57 std::string cookieName = name;
58 cookieName.append(".");
59 cookieName.append(id);
60 cookieName.append(".");
61 cookieName.append(kTestCompleteCookie);
62 cookieName.append("=");
63 std::string::size_type idx = cookies.find(cookieName);
64 std::string cookie;
65 if (idx != std::string::npos) {
66 cookies.erase(0, idx + cookieName.length());
67 cookie = cookies.substr(0, cookies.find(";"));
68 }
69
70 EXPECT_EQ(kTestCompleteSuccess, cookie);
71 }
72
73 protected:
74 virtual void SetUp() {
75 // We need to copy our test-plugin into the plugins directory so that
76 // the test can load it.
77 std::wstring current_directory; 22 std::wstring current_directory;
78 PathService::Get(base::DIR_EXE, &current_directory); 23 PathService::Get(base::DIR_EXE, &current_directory);
79 std::wstring plugin_src = current_directory + L"\\npapi_test_plugin.dll"; 24 plugin_src_ = current_directory + L"\\npapi_test_plugin.dll";
80 ASSERT_TRUE(file_util::PathExists(plugin_src)); 25 CHECK(file_util::PathExists(plugin_src_));
81 26
82 plugin_file_path_ = current_directory + L"\\plugins"; 27 plugin_file_path_ = current_directory + L"\\plugins";
83 ::CreateDirectory(plugin_file_path_.c_str(), NULL); 28 ::CreateDirectory(plugin_file_path_.c_str(), NULL);
84 29
85 plugin_file_path_ += L"\\npapi_test_plugin.dll"; 30 plugin_file_path_ += L"\\npapi_test_plugin.dll";
86 ASSERT_TRUE(CopyFile(plugin_src.c_str(), plugin_file_path_.c_str(), FALSE));
87
88 // The plugin list has to be refreshed to ensure that the npapi_test_plugin
89 // is loaded by webkit.
90 std::vector<WebPluginInfo> plugin_list;
91 bool refresh = true;
92 NPAPI::PluginList::Singleton()->GetPlugins(refresh, &plugin_list);
93
94 TestShellTest::SetUp();
95
96 plugin_data_dir_ = data_dir_;
97 file_util::AppendToPath(&plugin_data_dir_, L"plugin_tests");
98 ASSERT_TRUE(file_util::PathExists(plugin_data_dir_));
99 } 31 }
100 32
101 virtual void TearDown() { 33 void CopyTestPlugin() {
102 TestShellTest::TearDown(); 34 ASSERT_TRUE(CopyFile(plugin_src_.c_str(), plugin_file_path_.c_str(), FALSE)) ;
35 }
103 36
104 // TODO(iyengar) The DeleteFile call fails in some cases as the plugin is 37 void DeleteTestPlugin() {
105 // still in use. Needs more investigation.
106 ::DeleteFile(plugin_file_path_.c_str()); 38 ::DeleteFile(plugin_file_path_.c_str());
107 } 39 }
108 40
109 std::wstring plugin_data_dir_; 41 std::wstring plugin_src_;
110 std::wstring plugin_file_path_; 42 std::wstring plugin_file_path_;
111 RequestContext* request_context_;
112 GURL test_url_;
113 }; 43 };
114 44
115 TEST_F(PluginTest, DISABLED_VerifyPluginWindowRect) { 45 // Tests navigator.plugins.refresh() works.
116 std::wstring test_url = GetTestURL(plugin_data_dir_, 46 TEST_F(PluginTest, Refresh) {
117 L"verify_plugin_window_rect.html"); 47 std::string html = "\
118 NavigateToURL(test_url); 48 <div id='result'>Test running....</div>\
119 WaitForFinish("checkwindowrect", "1"); 49 <script>\
50 function check() {\
51 var l = navigator.plugins.length;\
52 var result = document.getElementById('result');\
53 for(var i = 0; i < l; i++) {\
54 if (navigator.plugins[i].filename == 'npapi_test_plugin.dll') {\
55 result.innerHTML = 'DONE';\
56 break;\
57 }\
58 }\
59 \
60 if (result.innerHTML != 'DONE')\
61 result.innerHTML = 'FAIL';\
62 }\
63 </script>\
64 ";
65
66 DeleteTestPlugin(); // Remove any leftover from previous tests if they exist.
67 test_shell_->webView()->GetMainFrame()->LoadHTMLString(
68 html, GURL("about:blank"));
69 test_shell_->WaitTestFinished();
70
71 std::wstring text;
72 webkit_glue::WebScriptSource call_check("check();");
73 webkit_glue::WebScriptSource refresh("navigator.plugins.refresh(false)");
74
75 test_shell_->webView()->GetMainFrame()->ExecuteScript(call_check);
76 test_shell_->webView()->GetMainFrame()->GetContentAsPlainText(10000, &text);
77 ASSERT_EQ(text, L"FAIL");
78
79 CopyTestPlugin();
80
81 test_shell_->webView()->GetMainFrame()->ExecuteScript(refresh);
82 test_shell_->webView()->GetMainFrame()->ExecuteScript(call_check);
83 test_shell_->webView()->GetMainFrame()->GetContentAsPlainText(10000, &text);
84 ASSERT_EQ(text, L"DONE");
85
86 DeleteTestPlugin();
120 } 87 }
OLDNEW
« no previous file with comments | « webkit/data/plugin_tests/verify_plugin_window_rect.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698