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

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

Issue 10855141: Fix race condition with windowless plugin buffers. The problem, which is already fixed for Mac, is … (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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/plugins/npapi/test/plugin_windowless_test.h ('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) 2012 The Chromium Authors. All rights reserved. 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 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 #define STRSAFE_NO_DEPRECATE 5 #define STRSAFE_NO_DEPRECATE
6 #include "base/string_number_conversions.h" 6 #include "base/string_number_conversions.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "webkit/plugins/npapi/test/plugin_windowless_test.h" 8 #include "webkit/plugins/npapi/test/plugin_windowless_test.h"
9 #include "webkit/plugins/npapi/test/plugin_client.h" 9 #include "webkit/plugins/npapi/test/plugin_client.h"
10 10
11 #if defined(OS_MACOSX) 11 #if defined(OS_MACOSX)
12 #include <ApplicationServices/ApplicationServices.h> 12 #include <ApplicationServices/ApplicationServices.h>
13 #include <Carbon/Carbon.h> 13 #include <Carbon/Carbon.h>
14 #elif defined(TOOLKIT_GTK)
15 #include <gdk/gdkx.h>
14 #endif 16 #endif
15 17
16 namespace NPAPIClient { 18 namespace NPAPIClient {
17 19
18 // Remember the first plugin instance for tests involving multiple instances 20 // Remember the first plugin instance for tests involving multiple instances
19 WindowlessPluginTest* g_other_instance = NULL; 21 WindowlessPluginTest* g_other_instance = NULL;
20 22
23 void OnFinishTest(void* data) {
24 static_cast<WindowlessPluginTest*>(data)->SignalTestCompleted();
25 }
26
21 WindowlessPluginTest::WindowlessPluginTest(NPP id, 27 WindowlessPluginTest::WindowlessPluginTest(NPP id,
22 NPNetscapeFuncs *host_functions) 28 NPNetscapeFuncs *host_functions)
23 : PluginTest(id, host_functions) { 29 : PluginTest(id, host_functions),
30 paint_counter_(0) {
24 if (!g_other_instance) 31 if (!g_other_instance)
25 g_other_instance = this; 32 g_other_instance = this;
26 } 33 }
27 34
28 static bool IsPaintEvent(NPEvent* np_event) { 35 static bool IsPaintEvent(NPEvent* np_event) {
29 #if defined(OS_WIN) 36 #if defined(OS_WIN)
30 return WM_PAINT == np_event->event; 37 return WM_PAINT == np_event->event;
31 #elif defined(OS_MACOSX) 38 #elif defined(OS_MACOSX)
32 return np_event->what == updateEvt; 39 return np_event->what == updateEvt;
40 #elif defined(TOOLKIT_GTK)
41 return np_event->type == GraphicsExpose;
33 #else 42 #else
34 NOTIMPLEMENTED(); 43 NOTIMPLEMENTED();
35 return false; 44 return false;
36 #endif 45 #endif
37 } 46 }
38 47
39 static bool IsMouseUpEvent(NPEvent* np_event) { 48 static bool IsMouseUpEvent(NPEvent* np_event) {
40 #if defined(OS_WIN) 49 #if defined(OS_WIN)
41 return WM_LBUTTONUP == np_event->event; 50 return WM_LBUTTONUP == np_event->event;
42 #elif defined(OS_MACOSX) 51 #elif defined(OS_MACOSX)
(...skipping 22 matching lines...) Expand all
65 if (test_name() == "invoke_js_function_on_create") { 74 if (test_name() == "invoke_js_function_on_create") {
66 ExecuteScript( 75 ExecuteScript(
67 NPAPIClient::PluginClient::HostFunctions(), g_other_instance->id(), 76 NPAPIClient::PluginClient::HostFunctions(), g_other_instance->id(),
68 "PluginCreated();", NULL); 77 "PluginCreated();", NULL);
69 } 78 }
70 79
71 return error; 80 return error;
72 } 81 }
73 82
74 int16 WindowlessPluginTest::HandleEvent(void* event) { 83 int16 WindowlessPluginTest::HandleEvent(void* event) {
75
76 NPNetscapeFuncs* browser = NPAPIClient::PluginClient::HostFunctions(); 84 NPNetscapeFuncs* browser = NPAPIClient::PluginClient::HostFunctions();
77 85
78 NPBool supports_windowless = 0; 86 NPBool supports_windowless = 0;
79 NPError result = browser->getvalue(id(), NPNVSupportsWindowless, 87 NPError result = browser->getvalue(id(), NPNVSupportsWindowless,
80 &supports_windowless); 88 &supports_windowless);
81 if ((result != NPERR_NO_ERROR) || (!supports_windowless)) { 89 if ((result != NPERR_NO_ERROR) || (!supports_windowless)) {
82 SetError("Failed to read NPNVSupportsWindowless value"); 90 SetError("Failed to read NPNVSupportsWindowless value");
83 SignalTestCompleted(); 91 SignalTestCompleted();
84 return PluginTest::HandleEvent(event); 92 return PluginTest::HandleEvent(event);
85 } 93 }
86 94
87 NPEvent* np_event = reinterpret_cast<NPEvent*>(event); 95 NPEvent* np_event = reinterpret_cast<NPEvent*>(event);
88 if (IsPaintEvent(np_event)) { 96 if (IsPaintEvent(np_event)) {
97 paint_counter_++;
89 #if defined(OS_WIN) 98 #if defined(OS_WIN)
90 HDC paint_dc = reinterpret_cast<HDC>(np_event->wParam); 99 HDC paint_dc = reinterpret_cast<HDC>(np_event->wParam);
91 if (paint_dc == NULL) { 100 if (paint_dc == NULL) {
92 SetError("Invalid Window DC passed to HandleEvent for WM_PAINT"); 101 SetError("Invalid Window DC passed to HandleEvent for WM_PAINT");
93 SignalTestCompleted(); 102 SignalTestCompleted();
94 return NPERR_GENERIC_ERROR; 103 return NPERR_GENERIC_ERROR;
95 } 104 }
96 105
97 HRGN clipping_region = CreateRectRgn(0, 0, 0, 0); 106 HRGN clipping_region = CreateRectRgn(0, 0, 0, 0);
98 if (!GetClipRgn(paint_dc, clipping_region)) { 107 if (!GetClipRgn(paint_dc, clipping_region)) {
99 SetError("No clipping region set in window DC"); 108 SetError("No clipping region set in window DC");
100 DeleteObject(clipping_region); 109 DeleteObject(clipping_region);
101 SignalTestCompleted(); 110 SignalTestCompleted();
102 return NPERR_GENERIC_ERROR; 111 return NPERR_GENERIC_ERROR;
103 } 112 }
104 113
105 DeleteObject(clipping_region); 114 DeleteObject(clipping_region);
106 #endif 115 #endif
107 116
108 if (test_name() == "execute_script_delete_in_paint") { 117 if (test_name() == "execute_script_delete_in_paint") {
109 ExecuteScriptDeleteInPaint(browser); 118 ExecuteScriptDeleteInPaint(browser);
110 } else if (test_name() == "multiple_instances_sync_calls") { 119 } else if (test_name() == "multiple_instances_sync_calls") {
111 MultipleInstanceSyncCalls(browser); 120 MultipleInstanceSyncCalls(browser);
121 } else if (test_name() == "resize_during_paint") {
122 if (paint_counter_ == 1) {
123 // So that we get another paint later.
124 browser->invalidaterect(id(), NULL);
125 } else if (paint_counter_ == 2) {
126 // Do this in the second paint since that's asynchronous. The first will
127 // be async and WebKit will assert that style recalc doesn't occur while
128 // _it's_ painting (as opposed to the plugin).
Tom Hudson 2012/08/15 17:04:00 Nit: I'd like to understand this, but I don't foll
jam 2012/08/15 17:28:11 my bad, I was lazy and wrote a comment that I myse
Tom Hudson 2012/08/15 17:59:04 So there are two paints, and both are asynchronous
jam 2012/08/15 18:22:22 that was a typo, check out the update
129 ExecuteScriptResizeInPaint(browser);
130
131 // So that we can exit later.
132 browser->pluginthreadasynccall(id(), OnFinishTest, this);
133 }
112 } 134 }
113 #if defined(OS_MACOSX) 135 #if defined(OS_MACOSX)
114 } else if (IsWindowActivationEvent(np_event) && 136 } else if (IsWindowActivationEvent(np_event) &&
115 test_name() == "convert_point") { 137 test_name() == "convert_point") {
116 ConvertPoint(browser); 138 ConvertPoint(browser);
117 #endif 139 #endif
118 } else if (IsMouseUpEvent(np_event) && 140 } else if (IsMouseUpEvent(np_event) &&
119 test_name() == "execute_script_delete_in_mouse_up") { 141 test_name() == "execute_script_delete_in_mouse_up") {
120 ExecuteScript(browser, id(), "DeletePluginWithinScript();", NULL); 142 ExecuteScript(browser, id(), "DeletePluginWithinScript();", NULL);
121 SignalTestCompleted(); 143 SignalTestCompleted();
(...skipping 30 matching lines...) Expand all
152 } 174 }
153 175
154 void WindowlessPluginTest::ExecuteScriptDeleteInPaint( 176 void WindowlessPluginTest::ExecuteScriptDeleteInPaint(
155 NPNetscapeFuncs* browser) { 177 NPNetscapeFuncs* browser) {
156 const NPUTF8* urlString = "javascript:DeletePluginWithinScript()"; 178 const NPUTF8* urlString = "javascript:DeletePluginWithinScript()";
157 const NPUTF8* targetString = NULL; 179 const NPUTF8* targetString = NULL;
158 browser->geturl(id(), urlString, targetString); 180 browser->geturl(id(), urlString, targetString);
159 SignalTestCompleted(); 181 SignalTestCompleted();
160 } 182 }
161 183
184 void WindowlessPluginTest::ExecuteScriptResizeInPaint(
185 NPNetscapeFuncs* browser) {
186 ExecuteScript(browser, id(), "ResizePluginWithinScript();", NULL);
187 }
188
162 void WindowlessPluginTest::MultipleInstanceSyncCalls(NPNetscapeFuncs* browser) { 189 void WindowlessPluginTest::MultipleInstanceSyncCalls(NPNetscapeFuncs* browser) {
163 if (this == g_other_instance) 190 if (this == g_other_instance)
164 return; 191 return;
165 192
166 DCHECK(g_other_instance); 193 DCHECK(g_other_instance);
167 ExecuteScript(browser, g_other_instance->id(), "TestCallback();", NULL); 194 ExecuteScript(browser, g_other_instance->id(), "TestCallback();", NULL);
168 SignalTestCompleted(); 195 SignalTestCompleted();
169 } 196 }
170 197
171 #if defined(OS_MACOSX) 198 #if defined(OS_MACOSX)
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 error_string.append(StringForPoint(flipped_window_x, flipped_window_y)); 298 error_string.append(StringForPoint(flipped_window_x, flipped_window_y));
272 SetError(error_string); 299 SetError(error_string);
273 } 300 }
274 #else 301 #else
275 SetError("Unimplemented"); 302 SetError("Unimplemented");
276 #endif 303 #endif
277 SignalTestCompleted(); 304 SignalTestCompleted();
278 } 305 }
279 306
280 } // namespace NPAPIClient 307 } // namespace NPAPIClient
OLDNEW
« no previous file with comments | « webkit/plugins/npapi/test/plugin_windowless_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698