Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #define STRSAFE_NO_DEPRECATE | 5 #define STRSAFE_NO_DEPRECATE |
| 6 #include "webkit/glue/plugins/test/plugin_windowless_test.h" | 6 #include "webkit/glue/plugins/test/plugin_windowless_test.h" |
| 7 #include "webkit/glue/plugins/test/plugin_client.h" | 7 #include "webkit/glue/plugins/test/plugin_client.h" |
| 8 | 8 |
| 9 namespace NPAPIClient { | 9 namespace NPAPIClient { |
| 10 | 10 |
| 11 // Remember the first plugin instance for tests involving multiple instances | |
| 12 WindowlessPluginTest* g_other_instance = NULL; | |
| 13 | |
| 11 WindowlessPluginTest::WindowlessPluginTest( | 14 WindowlessPluginTest::WindowlessPluginTest( |
| 12 NPP id, NPNetscapeFuncs *host_functions, const std::string& test_name) | 15 NPP id, NPNetscapeFuncs *host_functions, const std::string& test_name) |
| 13 : PluginTest(id, host_functions), | 16 : PluginTest(id, host_functions), |
| 14 test_name_(test_name) { | 17 test_name_(test_name) { |
| 18 if (!g_other_instance) | |
| 19 g_other_instance = this; | |
| 15 } | 20 } |
| 16 | 21 |
| 17 int16 WindowlessPluginTest::HandleEvent(void* event) { | 22 int16 WindowlessPluginTest::HandleEvent(void* event) { |
| 18 | 23 |
| 19 NPNetscapeFuncs* browser = NPAPIClient::PluginClient::HostFunctions(); | 24 NPNetscapeFuncs* browser = NPAPIClient::PluginClient::HostFunctions(); |
| 20 | 25 |
| 21 NPBool supports_windowless = 0; | 26 NPBool supports_windowless = 0; |
| 22 NPError result = browser->getvalue(id(), NPNVSupportsWindowless, | 27 NPError result = browser->getvalue(id(), NPNVSupportsWindowless, |
| 23 &supports_windowless); | 28 &supports_windowless); |
| 24 if ((result != NPERR_NO_ERROR) || (supports_windowless != TRUE)) { | 29 if ((result != NPERR_NO_ERROR) || (supports_windowless != TRUE)) { |
| 25 SetError("Failed to read NPNVSupportsWindowless value"); | 30 SetError("Failed to read NPNVSupportsWindowless value"); |
| 26 SignalTestCompleted(); | 31 SignalTestCompleted(); |
| 27 return PluginTest::HandleEvent(event); | 32 return PluginTest::HandleEvent(event); |
| 28 } | 33 } |
| 29 | 34 |
| 30 NPEvent* np_event = reinterpret_cast<NPEvent*>(event); | 35 NPEvent* np_event = reinterpret_cast<NPEvent*>(event); |
| 31 if (WM_PAINT == np_event->event && | 36 if (WM_PAINT == np_event->event) { |
| 32 test_name_ == "execute_script_delete_in_paint") { | |
| 33 HDC paint_dc = reinterpret_cast<HDC>(np_event->wParam); | 37 HDC paint_dc = reinterpret_cast<HDC>(np_event->wParam); |
| 34 if (paint_dc == NULL) { | 38 if (paint_dc == NULL) { |
| 35 SetError("Invalid Window DC passed to HandleEvent for WM_PAINT"); | 39 SetError("Invalid Window DC passed to HandleEvent for WM_PAINT"); |
| 36 SignalTestCompleted(); | 40 SignalTestCompleted(); |
| 37 return NPERR_GENERIC_ERROR; | 41 return NPERR_GENERIC_ERROR; |
| 38 } | 42 } |
| 39 | 43 |
| 40 HRGN clipping_region = CreateRectRgn(0, 0, 0, 0); | 44 HRGN clipping_region = CreateRectRgn(0, 0, 0, 0); |
| 41 if (!GetClipRgn(paint_dc, clipping_region)) { | 45 if (!GetClipRgn(paint_dc, clipping_region)) { |
| 42 SetError("No clipping region set in window DC"); | 46 SetError("No clipping region set in window DC"); |
| 43 DeleteObject(clipping_region); | 47 DeleteObject(clipping_region); |
| 44 SignalTestCompleted(); | 48 SignalTestCompleted(); |
| 45 return NPERR_GENERIC_ERROR; | 49 return NPERR_GENERIC_ERROR; |
| 46 } | 50 } |
| 47 | 51 |
| 48 DeleteObject(clipping_region); | 52 DeleteObject(clipping_region); |
| 49 | 53 |
| 50 NPUTF8* urlString = "javascript:DeletePluginWithinScript()"; | 54 if (test_name_ == "execute_script_delete_in_paint") { |
| 51 NPUTF8* targetString = NULL; | 55 ExecuteScriptDeleteInPaint(browser); |
| 52 browser->geturl(id(), urlString, targetString); | 56 } else if (test_name_ == "multiple_instances_sync_calls") { |
| 53 SignalTestCompleted(); | 57 MultipleInstanceSyncCalls(browser); |
| 58 } | |
| 59 | |
| 54 } else if (WM_MOUSEMOVE == np_event->event && | 60 } else if (WM_MOUSEMOVE == np_event->event && |
| 55 test_name_ == "execute_script_delete_in_mouse_move") { | 61 test_name_ == "execute_script_delete_in_mouse_move") { |
| 56 std::string script = "javascript:DeletePluginWithinScript()"; | 62 ExecuteScript(browser, id(), "DeletePluginWithinScript();", NULL); |
| 57 NPString script_string; | |
| 58 script_string.UTF8Characters = script.c_str(); | |
| 59 script_string.UTF8Length = static_cast<unsigned int>(script.length()); | |
| 60 | |
| 61 NPObject *window_obj = NULL; | |
| 62 browser->getvalue(id(), NPNVWindowNPObject, &window_obj); | |
| 63 NPVariant result_var; | |
| 64 NPError result = browser->evaluate(id(), window_obj, | |
| 65 &script_string, &result_var); | |
| 66 SignalTestCompleted(); | 63 SignalTestCompleted(); |
| 67 } else if (WM_LBUTTONUP == np_event->event && | 64 } else if (WM_LBUTTONUP == np_event->event && |
| 68 test_name_ == "delete_frame_test") { | 65 test_name_ == "delete_frame_test") { |
| 69 std::string script = | 66 ExecuteScript(browser, id(), |
| 70 "javascript:parent.document.getElementById('frame').outerHTML = ''"; | 67 "parent.document.getElementById('frame').outerHTML = ''", NULL); |
|
ananta
2009/06/03 17:08:36
You may want to move the parameters to the next li
| |
| 71 NPString script_string; | |
| 72 script_string.UTF8Characters = script.c_str(); | |
| 73 script_string.UTF8Length = static_cast<unsigned int>(script.length()); | |
| 74 | |
| 75 NPObject *window_obj = NULL; | |
| 76 browser->getvalue(id(), NPNVWindowNPObject, &window_obj); | |
| 77 NPVariant result_var; | |
| 78 NPError result = browser->evaluate(id(), window_obj, | |
| 79 &script_string, &result_var); | |
| 80 } | 68 } |
| 81 // If this test failed, then we'd have crashed by now. | 69 // If this test failed, then we'd have crashed by now. |
| 82 return PluginTest::HandleEvent(event); | 70 return PluginTest::HandleEvent(event); |
| 83 } | 71 } |
| 84 | 72 |
| 73 NPError WindowlessPluginTest::ExecuteScript(NPNetscapeFuncs* browser, NPP id, | |
| 74 const std::string& script, NPVariant* result) { | |
| 75 std::string script_url = "javascript:"; | |
| 76 script_url += script; | |
| 77 | |
| 78 NPString script_string = { script_url.c_str(), script_url.length() }; | |
| 79 NPObject *window_obj = NULL; | |
| 80 browser->getvalue(id, NPNVWindowNPObject, &window_obj); | |
| 81 | |
| 82 NPVariant unused_result; | |
| 83 if (!result) | |
| 84 result = &unused_result; | |
| 85 | |
| 86 return browser->evaluate(id, window_obj, &script_string, result); | |
| 87 } | |
| 88 | |
| 89 void WindowlessPluginTest::ExecuteScriptDeleteInPaint( | |
| 90 NPNetscapeFuncs* browser) { | |
| 91 NPUTF8* urlString = "javascript:DeletePluginWithinScript()"; | |
| 92 NPUTF8* targetString = NULL; | |
| 93 browser->geturl(id(), urlString, targetString); | |
| 94 SignalTestCompleted(); | |
| 95 } | |
| 96 | |
| 97 void WindowlessPluginTest::MultipleInstanceSyncCalls(NPNetscapeFuncs* browser) { | |
| 98 if (this == g_other_instance) | |
| 99 return; | |
| 100 | |
| 101 DCHECK(g_other_instance); | |
| 102 ExecuteScript(browser, g_other_instance->id(), "TestCallback();", NULL); | |
| 103 SignalTestCompleted(); | |
| 104 } | |
| 105 | |
| 85 } // namespace NPAPIClient | 106 } // namespace NPAPIClient |
| OLD | NEW |