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

Side by Side Diff: webkit/glue/plugins/test/plugin_windowless_test.cc

Issue 6012002: Move the NPAPI files from webkit/glue/plugins to webkit/plugins/npapi and put... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years 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/glue/plugins/test/plugin_windowless_test.h ('k') | webkit/glue/plugins/test/resource.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 #define STRSAFE_NO_DEPRECATE
6 #include "base/string_number_conversions.h"
7 #include "base/string_util.h"
8 #include "webkit/glue/plugins/test/plugin_windowless_test.h"
9 #include "webkit/glue/plugins/test/plugin_client.h"
10
11 #if defined(OS_MACOSX)
12 #include <ApplicationServices/ApplicationServices.h>
13 #include <Carbon/Carbon.h>
14 #endif
15
16 namespace NPAPIClient {
17
18 // Remember the first plugin instance for tests involving multiple instances
19 WindowlessPluginTest* g_other_instance = NULL;
20
21 WindowlessPluginTest::WindowlessPluginTest(NPP id,
22 NPNetscapeFuncs *host_functions)
23 : PluginTest(id, host_functions) {
24 if (!g_other_instance)
25 g_other_instance = this;
26 }
27
28 static bool IsPaintEvent(NPEvent* np_event) {
29 #if defined(OS_WIN)
30 return WM_PAINT == np_event->event;
31 #elif defined(OS_MACOSX)
32 return np_event->what == updateEvt;
33 #endif
34 }
35
36 static bool IsMouseMoveEvent(NPEvent* np_event) {
37 #if defined(OS_WIN)
38 return WM_MOUSEMOVE == np_event->event;
39 #elif defined(OS_MACOSX)
40 return np_event->what == nullEvent;
41 #endif
42 }
43
44 static bool IsMouseUpEvent(NPEvent* np_event) {
45 #if defined(OS_WIN)
46 return WM_LBUTTONUP == np_event->event;
47 #elif defined(OS_MACOSX)
48 return np_event->what == mouseUp;
49 #endif
50 }
51
52 static bool IsWindowActivationEvent(NPEvent* np_event) {
53 #if defined(OS_WIN)
54 NOTIMPLEMENTED();
55 return false;
56 #elif defined(OS_MACOSX)
57 return np_event->what == activateEvt;
58 #endif
59 }
60
61 int16 WindowlessPluginTest::HandleEvent(void* event) {
62
63 NPNetscapeFuncs* browser = NPAPIClient::PluginClient::HostFunctions();
64
65 NPBool supports_windowless = 0;
66 NPError result = browser->getvalue(id(), NPNVSupportsWindowless,
67 &supports_windowless);
68 if ((result != NPERR_NO_ERROR) || (supports_windowless != TRUE)) {
69 SetError("Failed to read NPNVSupportsWindowless value");
70 SignalTestCompleted();
71 return PluginTest::HandleEvent(event);
72 }
73
74 NPEvent* np_event = reinterpret_cast<NPEvent*>(event);
75 if (IsPaintEvent(np_event)) {
76 #if defined(OS_WIN)
77 HDC paint_dc = reinterpret_cast<HDC>(np_event->wParam);
78 if (paint_dc == NULL) {
79 SetError("Invalid Window DC passed to HandleEvent for WM_PAINT");
80 SignalTestCompleted();
81 return NPERR_GENERIC_ERROR;
82 }
83
84 HRGN clipping_region = CreateRectRgn(0, 0, 0, 0);
85 if (!GetClipRgn(paint_dc, clipping_region)) {
86 SetError("No clipping region set in window DC");
87 DeleteObject(clipping_region);
88 SignalTestCompleted();
89 return NPERR_GENERIC_ERROR;
90 }
91
92 DeleteObject(clipping_region);
93 #endif
94
95 if (test_name() == "execute_script_delete_in_paint") {
96 ExecuteScriptDeleteInPaint(browser);
97 } else if (test_name() == "multiple_instances_sync_calls") {
98 MultipleInstanceSyncCalls(browser);
99 }
100 #if OS_MACOSX
101 } else if (IsWindowActivationEvent(np_event) &&
102 test_name() == "convert_point") {
103 ConvertPoint(browser);
104 #endif
105 } else if (IsMouseMoveEvent(np_event) &&
106 test_name() == "execute_script_delete_in_mouse_move") {
107 ExecuteScript(browser, id(), "DeletePluginWithinScript();", NULL);
108 SignalTestCompleted();
109 } else if (IsMouseUpEvent(np_event) &&
110 test_name() == "delete_frame_test") {
111 ExecuteScript(
112 browser, id(),
113 "parent.document.getElementById('frame').outerHTML = ''", NULL);
114 }
115 // If this test failed, then we'd have crashed by now.
116 return PluginTest::HandleEvent(event);
117 }
118
119 NPError WindowlessPluginTest::ExecuteScript(NPNetscapeFuncs* browser, NPP id,
120 const std::string& script, NPVariant* result) {
121 std::string script_url = "javascript:";
122 script_url += script;
123
124 NPString script_string = { script_url.c_str(), script_url.length() };
125 NPObject *window_obj = NULL;
126 browser->getvalue(id, NPNVWindowNPObject, &window_obj);
127
128 NPVariant unused_result;
129 if (!result)
130 result = &unused_result;
131
132 return browser->evaluate(id, window_obj, &script_string, result);
133 }
134
135 void WindowlessPluginTest::ExecuteScriptDeleteInPaint(
136 NPNetscapeFuncs* browser) {
137 const NPUTF8* urlString = "javascript:DeletePluginWithinScript()";
138 const NPUTF8* targetString = NULL;
139 browser->geturl(id(), urlString, targetString);
140 SignalTestCompleted();
141 }
142
143 void WindowlessPluginTest::MultipleInstanceSyncCalls(NPNetscapeFuncs* browser) {
144 if (this == g_other_instance)
145 return;
146
147 DCHECK(g_other_instance);
148 ExecuteScript(browser, g_other_instance->id(), "TestCallback();", NULL);
149 SignalTestCompleted();
150 }
151
152 #if defined(OS_MACOSX)
153 std::string StringForPoint(int x, int y) {
154 std::string point_string("(");
155 point_string.append(base::IntToString(x));
156 point_string.append(", ");
157 point_string.append(base::IntToString(y));
158 point_string.append(")");
159 return point_string;
160 }
161 #endif
162
163 void WindowlessPluginTest::ConvertPoint(NPNetscapeFuncs* browser) {
164 #if defined(OS_MACOSX)
165 // First, just sanity-test that round trips work.
166 NPCoordinateSpace spaces[] = { NPCoordinateSpacePlugin,
167 NPCoordinateSpaceWindow,
168 NPCoordinateSpaceFlippedWindow,
169 NPCoordinateSpaceScreen,
170 NPCoordinateSpaceFlippedScreen };
171 for (unsigned int i = 0; i < arraysize(spaces); ++i) {
172 for (unsigned int j = 0; j < arraysize(spaces); ++j) {
173 double x, y, round_trip_x, round_trip_y;
174 if (!(browser->convertpoint(id(), 0, 0, spaces[i], &x, &y, spaces[j])) ||
175 !(browser->convertpoint(id(), x, y, spaces[j], &round_trip_x,
176 &round_trip_y, spaces[i]))) {
177 SetError("Conversion failed");
178 SignalTestCompleted();
179 return;
180 }
181 if (i != j && x == 0 && y == 0) {
182 SetError("Converting a coordinate should change it");
183 SignalTestCompleted();
184 return;
185 }
186 if (round_trip_x != 0 || round_trip_y != 0) {
187 SetError("Round-trip conversion should return the original point");
188 SignalTestCompleted();
189 return;
190 }
191 }
192 }
193
194 // Now, more extensive testing on a single point.
195 double screen_x, screen_y;
196 browser->convertpoint(id(), 0, 0, NPCoordinateSpacePlugin,
197 &screen_x, &screen_y, NPCoordinateSpaceScreen);
198 double flipped_screen_x, flipped_screen_y;
199 browser->convertpoint(id(), 0, 0, NPCoordinateSpacePlugin,
200 &flipped_screen_x, &flipped_screen_y,
201 NPCoordinateSpaceFlippedScreen);
202 double window_x, window_y;
203 browser->convertpoint(id(), 0, 0, NPCoordinateSpacePlugin,
204 &window_x, &window_y, NPCoordinateSpaceWindow);
205 double flipped_window_x, flipped_window_y;
206 browser->convertpoint(id(), 0, 0, NPCoordinateSpacePlugin,
207 &flipped_window_x, &flipped_window_y,
208 NPCoordinateSpaceFlippedWindow);
209
210 CGRect main_display_bounds = CGDisplayBounds(CGMainDisplayID());
211
212 // Check that all the coordinates are right. The constants below are based on
213 // the window frame set in the UI test and the content offset in the test
214 // html. Y-coordinates are not checked exactly so that the test is robust
215 // against toolbar changes, info and bookmark bar visibility, etc.
216 const int kWindowHeight = 400;
217 const int kWindowXOrigin = 50;
218 const int kWindowYOrigin = 50;
219 const int kPluginXContentOffset = 50;
220 const int kPluginYContentOffset = 50;
221 const int kChromeYTolerance = 200;
222
223 std::string error_string;
224 if (screen_x != flipped_screen_x)
225 error_string = "Flipping screen coordinates shouldn't change x";
226 else if (flipped_screen_y != main_display_bounds.size.height - screen_y)
227 error_string = "Flipped screen coordinates should be flipped vertically";
228 else if (screen_x != kWindowXOrigin + kPluginXContentOffset)
229 error_string = "Screen x location is wrong";
230 else if (flipped_screen_y < kWindowYOrigin + kPluginYContentOffset ||
231 flipped_screen_y > kWindowYOrigin + kPluginYContentOffset +
232 kChromeYTolerance)
233 error_string = "Screen y location is wrong";
234 else if (window_x != flipped_window_x)
235 error_string = "Flipping window coordinates shouldn't change x";
236 else if (flipped_window_y != kWindowHeight - window_y)
237 error_string = "Flipped window coordinates should be flipped vertically";
238 else if (window_x != kPluginXContentOffset)
239 error_string = "Window x location is wrong";
240 else if (flipped_window_y < kPluginYContentOffset ||
241 flipped_window_y > kPluginYContentOffset + kChromeYTolerance)
242 error_string = "Window y location is wrong";
243
244 if (!error_string.empty()) {
245 error_string.append(" - ");
246 error_string.append(StringForPoint(screen_x, screen_y));
247 error_string.append(" - ");
248 error_string.append(StringForPoint(flipped_screen_x, flipped_screen_y));
249 error_string.append(" - ");
250 error_string.append(StringForPoint(window_x, window_y));
251 error_string.append(" - ");
252 error_string.append(StringForPoint(flipped_window_x, flipped_window_y));
253 SetError(error_string);
254 }
255 #else
256 SetError("Unimplemented");
257 #endif
258 SignalTestCompleted();
259 }
260
261 } // namespace NPAPIClient
OLDNEW
« no previous file with comments | « webkit/glue/plugins/test/plugin_windowless_test.h ('k') | webkit/glue/plugins/test/resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698