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

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

Issue 14304004: Convert a bunch of test_shell_tests to content_browsertests. These are tests that depend on loading… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 7 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "base/file_util.h"
8 #include "base/files/file_path.h"
9 #include "base/path_service.h"
10 #include "base/string_util.h"
11 #include "net/base/escape.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
18 #include "webkit/tools/test_shell/test_shell.h"
19 #include "webkit/tools/test_shell/test_shell_test.h"
20
21 using WebKit::WebFrame;
22 using WebKit::WebScriptSource;
23 using WebKit::WebString;
24
25 #if defined(OS_WIN)
26 #define TEST_PLUGIN_NAME "npapi_test_plugin.dll"
27 #elif defined(OS_MACOSX)
28 #define TEST_PLUGIN_NAME "npapi_test_plugin.plugin"
29 #elif defined(OS_POSIX)
30 #define TEST_PLUGIN_NAME "libnpapi_test_plugin.so"
31 #endif
32
33 namespace {
34
35 const char kPluginsDir[] = "plugins";
36
37 }
38
39 // Ignore these until 64-bit plugin build is fixed. http://crbug.com/18337
40 #if !defined(ARCH_CPU_64_BITS)
41 // Provides functionality for creating plugin tests.
42 class PluginTest : public TestShellTest {
43 public:
44 PluginTest() {
45 base::FilePath executable_directory;
46 PathService::Get(base::DIR_EXE, &executable_directory);
47 plugin_src_ = executable_directory.AppendASCII(TEST_PLUGIN_NAME);
48 CHECK(file_util::PathExists(plugin_src_));
49
50 plugin_file_path_ = executable_directory.AppendASCII(kPluginsDir);
51 file_util::CreateDirectory(plugin_file_path_);
52
53 plugin_file_path_ = plugin_file_path_.AppendASCII(TEST_PLUGIN_NAME);
54 }
55
56 void CopyTestPlugin() {
57 // On Linux, we need to delete before copying because if the plugin is a
58 // hard link, the copy will fail.
59 DeleteTestPlugin();
60 ASSERT_TRUE(file_util::CopyDirectory(plugin_src_, plugin_file_path_, true));
61 }
62
63 void DeleteTestPlugin() {
64 file_util::Delete(plugin_file_path_, true);
65 }
66
67 virtual void SetUp() {
68 CopyTestPlugin();
69 TestShellTest::SetUp();
70 }
71
72 base::FilePath plugin_src_;
73 base::FilePath plugin_file_path_;
74 };
75
76 // Tests navigator.plugins.refresh() works.
77 TEST_F(PluginTest, Refresh) {
78 std::string html = "\
79 <div id='result'>Test running....</div>\
80 <script>\
81 function check() {\
82 var l = navigator.plugins.length;\
83 var result = document.getElementById('result');\
84 for(var i = 0; i < l; i++) {\
85 if (navigator.plugins[i].filename == '" TEST_PLUGIN_NAME "') {\
86 result.innerHTML = 'DONE';\
87 break;\
88 }\
89 }\
90 \
91 if (result.innerHTML != 'DONE')\
92 result.innerHTML = 'FAIL';\
93 }\
94 </script>\
95 ";
96
97 WebScriptSource call_check(
98 WebString::fromUTF8("check();"));
99 WebScriptSource refresh(
100 WebString::fromUTF8("navigator.plugins.refresh(false)"));
101
102 // Remove any leftover from previous tests if they exist. We must also
103 // refresh WebKit's plugin cache since it might have had an entry for the
104 // test plugin from a previous test.
105 DeleteTestPlugin();
106 ASSERT_FALSE(file_util::PathExists(plugin_file_path_));
107 test_shell_->webView()->mainFrame()->executeScript(refresh);
108
109 test_shell_->webView()->mainFrame()->loadHTMLString(
110 html, GURL("about:blank"));
111 test_shell_->WaitTestFinished();
112
113 std::string text;
114 test_shell_->webView()->mainFrame()->executeScript(call_check);
115 text = test_shell_->webView()->mainFrame()->contentAsText(10000).utf8();
116 ASSERT_EQ(text, "FAIL");
117
118 CopyTestPlugin();
119
120 test_shell_->webView()->mainFrame()->executeScript(refresh);
121 test_shell_->webView()->mainFrame()->executeScript(call_check);
122 text = test_shell_->webView()->mainFrame()->contentAsText(10000).utf8();
123 ASSERT_EQ(text, "DONE");
124 }
125
126 // Tests that if a frame is deleted as a result of calling NPP_HandleEvent, we
127 // don't crash.
128 TEST_F(PluginTest, DeleteFrameDuringEvent) {
129 base::FilePath test_html = data_dir_;
130 test_html = test_html.AppendASCII(kPluginsDir);
131 test_html = test_html.AppendASCII("delete_frame.html");
132 test_shell_->LoadFile(test_html);
133 test_shell_->WaitTestFinished();
134
135 WebKit::WebMouseEvent input;
136 input.button = WebKit::WebMouseEvent::ButtonLeft;
137 input.x = 50;
138 input.y = 50;
139 input.type = WebKit::WebInputEvent::MouseUp;
140 test_shell_->webView()->handleInputEvent(input);
141
142 // No crash means we passed.
143 }
144
145 // Tests that a forced reload of the plugin will not crash.
146 TEST_F(PluginTest, ForceReload) {
147 base::FilePath test_html = data_dir_;
148 test_html = test_html.AppendASCII(kPluginsDir);
149 test_html = test_html.AppendASCII("force_reload.html");
150 test_shell_->LoadFile(test_html);
151 test_shell_->WaitTestFinished();
152
153 // No crash means we passed.
154 }
155
156 #if defined(OS_WIN)
157 BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam) {
158 HWND* plugin_hwnd = reinterpret_cast<HWND*>(lparam);
159 if (*plugin_hwnd) {
160 // More than one child window found, unexpected.
161 plugin_hwnd = NULL;
162 return FALSE;
163 }
164 *plugin_hwnd = hwnd;
165 return TRUE;
166 }
167
168 // Tests that hiding/showing the parent frame hides/shows the plugin.
169 // Fails for WIN. http://crbug.com/111601
170 #if defined(OS_WIN)
171 #define MAYBE_PluginVisibilty DISABLED_PluginVisibilty
172 #else
173 #define MAYBE_PluginVisibilty PluginVisibilty
174 #endif
175
176 TEST_F(PluginTest, MAYBE_PluginVisibilty) {
177 base::FilePath test_html = data_dir_;
178 test_html = test_html.AppendASCII(kPluginsDir);
179 test_html = test_html.AppendASCII("plugin_visibility.html");
180 test_shell_->LoadFile(test_html);
181 test_shell_->WaitTestFinished();
182
183 WebFrame* main_frame = test_shell_->webView()->mainFrame();
184 HWND frame_hwnd = test_shell_->webViewWnd();
185 HWND plugin_hwnd = NULL;
186 EnumChildWindows(frame_hwnd, EnumChildProc,
187 reinterpret_cast<LPARAM>(&plugin_hwnd));
188 ASSERT_TRUE(plugin_hwnd != NULL);
189 ASSERT_FALSE(IsWindowVisible(plugin_hwnd));
190
191 main_frame->executeScript(WebString::fromUTF8("showPlugin(true)"));
192 ASSERT_TRUE(IsWindowVisible(plugin_hwnd));
193
194 main_frame->executeScript(WebString::fromUTF8("showFrame(false)"));
195 ASSERT_FALSE(IsWindowVisible(plugin_hwnd));
196
197 main_frame->executeScript(WebString::fromUTF8("showFrame(true)"));
198 ASSERT_TRUE(IsWindowVisible(plugin_hwnd));
199 }
200 #endif
201 #endif //!ARCH_CPU_64_BITS
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/mock_spellcheck_unittest.cc ('k') | webkit/tools/test_shell/run_all_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698