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

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

Issue 501074: Enable windowless-based npapi_test_plugin tests on the Mac. (Closed)
Patch Set: Created 11 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
« no previous file with comments | « webkit/glue/plugins/test/plugin_client.cc ('k') | webkit/tools/test_shell/test_shell.gyp » ('j') | 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) 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 #if defined(OS_MACOSX)
10 #include <Carbon/Carbon.h>
11 #endif
12
9 namespace NPAPIClient { 13 namespace NPAPIClient {
10 14
11 // Remember the first plugin instance for tests involving multiple instances 15 // Remember the first plugin instance for tests involving multiple instances
12 WindowlessPluginTest* g_other_instance = NULL; 16 WindowlessPluginTest* g_other_instance = NULL;
13 17
14 WindowlessPluginTest::WindowlessPluginTest( 18 WindowlessPluginTest::WindowlessPluginTest(
15 NPP id, NPNetscapeFuncs *host_functions, const std::string& test_name) 19 NPP id, NPNetscapeFuncs *host_functions, const std::string& test_name)
16 : PluginTest(id, host_functions), 20 : PluginTest(id, host_functions),
17 test_name_(test_name) { 21 test_name_(test_name) {
18 if (!g_other_instance) 22 if (!g_other_instance)
19 g_other_instance = this; 23 g_other_instance = this;
20 } 24 }
21 25
26 static bool IsPaintEvent(NPEvent* np_event) {
27 #if defined(OS_WIN)
28 return WM_PAINT == np_event->event;
29 #elif defined(OS_MACOSX)
30 return np_event->what == updateEvt;
31 #endif
32 }
33
34 static bool IsMouseMoveEvent(NPEvent* np_event) {
35 #if defined(OS_WIN)
36 return WM_MOUSEMOVE == np_event->event;
37 #elif defined(OS_MACOSX)
38 return np_event->what == nullEvent;
39 #endif
40 }
41
42 static bool IsMouseUpEvent(NPEvent* np_event) {
43 #if defined(OS_WIN)
44 return WM_LBUTTONUP == np_event->event;
45 #elif defined(OS_MACOSX)
46 return np_event->what == mouseUp;
47 #endif
48 }
49
22 int16 WindowlessPluginTest::HandleEvent(void* event) { 50 int16 WindowlessPluginTest::HandleEvent(void* event) {
23 51
24 NPNetscapeFuncs* browser = NPAPIClient::PluginClient::HostFunctions(); 52 NPNetscapeFuncs* browser = NPAPIClient::PluginClient::HostFunctions();
25 53
26 NPBool supports_windowless = 0; 54 NPBool supports_windowless = 0;
27 NPError result = browser->getvalue(id(), NPNVSupportsWindowless, 55 NPError result = browser->getvalue(id(), NPNVSupportsWindowless,
28 &supports_windowless); 56 &supports_windowless);
29 if ((result != NPERR_NO_ERROR) || (supports_windowless != TRUE)) { 57 if ((result != NPERR_NO_ERROR) || (supports_windowless != TRUE)) {
30 SetError("Failed to read NPNVSupportsWindowless value"); 58 SetError("Failed to read NPNVSupportsWindowless value");
31 SignalTestCompleted(); 59 SignalTestCompleted();
32 return PluginTest::HandleEvent(event); 60 return PluginTest::HandleEvent(event);
33 } 61 }
34 62
35 NPEvent* np_event = reinterpret_cast<NPEvent*>(event); 63 NPEvent* np_event = reinterpret_cast<NPEvent*>(event);
36 if (WM_PAINT == np_event->event) { 64 if (IsPaintEvent(np_event)) {
65 #if defined(OS_WIN)
37 HDC paint_dc = reinterpret_cast<HDC>(np_event->wParam); 66 HDC paint_dc = reinterpret_cast<HDC>(np_event->wParam);
38 if (paint_dc == NULL) { 67 if (paint_dc == NULL) {
39 SetError("Invalid Window DC passed to HandleEvent for WM_PAINT"); 68 SetError("Invalid Window DC passed to HandleEvent for WM_PAINT");
40 SignalTestCompleted(); 69 SignalTestCompleted();
41 return NPERR_GENERIC_ERROR; 70 return NPERR_GENERIC_ERROR;
42 } 71 }
43 72
44 HRGN clipping_region = CreateRectRgn(0, 0, 0, 0); 73 HRGN clipping_region = CreateRectRgn(0, 0, 0, 0);
45 if (!GetClipRgn(paint_dc, clipping_region)) { 74 if (!GetClipRgn(paint_dc, clipping_region)) {
46 SetError("No clipping region set in window DC"); 75 SetError("No clipping region set in window DC");
47 DeleteObject(clipping_region); 76 DeleteObject(clipping_region);
48 SignalTestCompleted(); 77 SignalTestCompleted();
49 return NPERR_GENERIC_ERROR; 78 return NPERR_GENERIC_ERROR;
50 } 79 }
51 80
52 DeleteObject(clipping_region); 81 DeleteObject(clipping_region);
82 #endif
53 83
54 if (test_name_ == "execute_script_delete_in_paint") { 84 if (test_name_ == "execute_script_delete_in_paint") {
55 ExecuteScriptDeleteInPaint(browser); 85 ExecuteScriptDeleteInPaint(browser);
56 } else if (test_name_ == "multiple_instances_sync_calls") { 86 } else if (test_name_ == "multiple_instances_sync_calls") {
57 MultipleInstanceSyncCalls(browser); 87 MultipleInstanceSyncCalls(browser);
58 } 88 }
59 89
60 } else if (WM_MOUSEMOVE == np_event->event && 90 } else if (IsMouseMoveEvent(np_event) &&
61 test_name_ == "execute_script_delete_in_mouse_move") { 91 test_name_ == "execute_script_delete_in_mouse_move") {
62 ExecuteScript(browser, id(), "DeletePluginWithinScript();", NULL); 92 ExecuteScript(browser, id(), "DeletePluginWithinScript();", NULL);
63 SignalTestCompleted(); 93 SignalTestCompleted();
64 } else if (WM_LBUTTONUP == np_event->event && 94 } else if (IsMouseUpEvent(np_event) &&
65 test_name_ == "delete_frame_test") { 95 test_name_ == "delete_frame_test") {
66 ExecuteScript( 96 ExecuteScript(
67 browser, id(), 97 browser, id(),
68 "parent.document.getElementById('frame').outerHTML = ''", NULL); 98 "parent.document.getElementById('frame').outerHTML = ''", NULL);
69 } 99 }
70 // If this test failed, then we'd have crashed by now. 100 // If this test failed, then we'd have crashed by now.
71 return PluginTest::HandleEvent(event); 101 return PluginTest::HandleEvent(event);
72 } 102 }
73 103
74 NPError WindowlessPluginTest::ExecuteScript(NPNetscapeFuncs* browser, NPP id, 104 NPError WindowlessPluginTest::ExecuteScript(NPNetscapeFuncs* browser, NPP id,
75 const std::string& script, NPVariant* result) { 105 const std::string& script, NPVariant* result) {
76 std::string script_url = "javascript:"; 106 std::string script_url = "javascript:";
77 script_url += script; 107 script_url += script;
78 108
79 NPString script_string = { script_url.c_str(), script_url.length() }; 109 NPString script_string = { script_url.c_str(), script_url.length() };
80 NPObject *window_obj = NULL; 110 NPObject *window_obj = NULL;
81 browser->getvalue(id, NPNVWindowNPObject, &window_obj); 111 browser->getvalue(id, NPNVWindowNPObject, &window_obj);
82 112
83 NPVariant unused_result; 113 NPVariant unused_result;
84 if (!result) 114 if (!result)
85 result = &unused_result; 115 result = &unused_result;
86 116
87 return browser->evaluate(id, window_obj, &script_string, result); 117 return browser->evaluate(id, window_obj, &script_string, result);
88 } 118 }
89 119
90 void WindowlessPluginTest::ExecuteScriptDeleteInPaint( 120 void WindowlessPluginTest::ExecuteScriptDeleteInPaint(
91 NPNetscapeFuncs* browser) { 121 NPNetscapeFuncs* browser) {
92 NPUTF8* urlString = "javascript:DeletePluginWithinScript()"; 122 const NPUTF8* urlString = "javascript:DeletePluginWithinScript()";
93 NPUTF8* targetString = NULL; 123 const NPUTF8* targetString = NULL;
94 browser->geturl(id(), urlString, targetString); 124 browser->geturl(id(), urlString, targetString);
95 SignalTestCompleted(); 125 SignalTestCompleted();
96 } 126 }
97 127
98 void WindowlessPluginTest::MultipleInstanceSyncCalls(NPNetscapeFuncs* browser) { 128 void WindowlessPluginTest::MultipleInstanceSyncCalls(NPNetscapeFuncs* browser) {
99 if (this == g_other_instance) 129 if (this == g_other_instance)
100 return; 130 return;
101 131
102 DCHECK(g_other_instance); 132 DCHECK(g_other_instance);
103 ExecuteScript(browser, g_other_instance->id(), "TestCallback();", NULL); 133 ExecuteScript(browser, g_other_instance->id(), "TestCallback();", NULL);
104 SignalTestCompleted(); 134 SignalTestCompleted();
105 } 135 }
106 136
107 } // namespace NPAPIClient 137 } // namespace NPAPIClient
OLDNEW
« no previous file with comments | « webkit/glue/plugins/test/plugin_client.cc ('k') | webkit/tools/test_shell/test_shell.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698