| OLD | NEW |
| 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 Loading... |
| 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 |
| 127 // paint will always be synchronous (since the renderer process doesn't |
| 128 // have a cache of the plugin yet). If we try calling NPN_Evaluate while |
| 129 // WebKit is painting, it will assert since style recalc is happening |
| 130 // during painting. |
| 131 ExecuteScriptResizeInPaint(browser); |
| 132 |
| 133 // So that we can exit the test after the message loop is unrolled. |
| 134 browser->pluginthreadasynccall(id(), OnFinishTest, this); |
| 135 } |
| 112 } | 136 } |
| 113 #if defined(OS_MACOSX) | 137 #if defined(OS_MACOSX) |
| 114 } else if (IsWindowActivationEvent(np_event) && | 138 } else if (IsWindowActivationEvent(np_event) && |
| 115 test_name() == "convert_point") { | 139 test_name() == "convert_point") { |
| 116 ConvertPoint(browser); | 140 ConvertPoint(browser); |
| 117 #endif | 141 #endif |
| 118 } else if (IsMouseUpEvent(np_event) && | 142 } else if (IsMouseUpEvent(np_event) && |
| 119 test_name() == "execute_script_delete_in_mouse_up") { | 143 test_name() == "execute_script_delete_in_mouse_up") { |
| 120 ExecuteScript(browser, id(), "DeletePluginWithinScript();", NULL); | 144 ExecuteScript(browser, id(), "DeletePluginWithinScript();", NULL); |
| 121 SignalTestCompleted(); | 145 SignalTestCompleted(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 152 } | 176 } |
| 153 | 177 |
| 154 void WindowlessPluginTest::ExecuteScriptDeleteInPaint( | 178 void WindowlessPluginTest::ExecuteScriptDeleteInPaint( |
| 155 NPNetscapeFuncs* browser) { | 179 NPNetscapeFuncs* browser) { |
| 156 const NPUTF8* urlString = "javascript:DeletePluginWithinScript()"; | 180 const NPUTF8* urlString = "javascript:DeletePluginWithinScript()"; |
| 157 const NPUTF8* targetString = NULL; | 181 const NPUTF8* targetString = NULL; |
| 158 browser->geturl(id(), urlString, targetString); | 182 browser->geturl(id(), urlString, targetString); |
| 159 SignalTestCompleted(); | 183 SignalTestCompleted(); |
| 160 } | 184 } |
| 161 | 185 |
| 186 void WindowlessPluginTest::ExecuteScriptResizeInPaint( |
| 187 NPNetscapeFuncs* browser) { |
| 188 ExecuteScript(browser, id(), "ResizePluginWithinScript();", NULL); |
| 189 } |
| 190 |
| 162 void WindowlessPluginTest::MultipleInstanceSyncCalls(NPNetscapeFuncs* browser) { | 191 void WindowlessPluginTest::MultipleInstanceSyncCalls(NPNetscapeFuncs* browser) { |
| 163 if (this == g_other_instance) | 192 if (this == g_other_instance) |
| 164 return; | 193 return; |
| 165 | 194 |
| 166 DCHECK(g_other_instance); | 195 DCHECK(g_other_instance); |
| 167 ExecuteScript(browser, g_other_instance->id(), "TestCallback();", NULL); | 196 ExecuteScript(browser, g_other_instance->id(), "TestCallback();", NULL); |
| 168 SignalTestCompleted(); | 197 SignalTestCompleted(); |
| 169 } | 198 } |
| 170 | 199 |
| 171 #if defined(OS_MACOSX) | 200 #if defined(OS_MACOSX) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 error_string.append(StringForPoint(flipped_window_x, flipped_window_y)); | 300 error_string.append(StringForPoint(flipped_window_x, flipped_window_y)); |
| 272 SetError(error_string); | 301 SetError(error_string); |
| 273 } | 302 } |
| 274 #else | 303 #else |
| 275 SetError("Unimplemented"); | 304 SetError("Unimplemented"); |
| 276 #endif | 305 #endif |
| 277 SignalTestCompleted(); | 306 SignalTestCompleted(); |
| 278 } | 307 } |
| 279 | 308 |
| 280 } // namespace NPAPIClient | 309 } // namespace NPAPIClient |
| OLD | NEW |