OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 #include "content/test/plugin/plugin_windowed_test.h" | 5 #include "content/test/plugin/plugin_windowed_test.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/test/plugin/plugin_client.h" | 8 #include "content/test/plugin/plugin_client.h" |
9 | 9 |
10 namespace NPAPIClient { | 10 namespace NPAPIClient { |
(...skipping 21 matching lines...) Expand all Loading... |
32 return NPERR_NO_ERROR; | 32 return NPERR_NO_ERROR; |
33 | 33 |
34 HWND parent = reinterpret_cast<HWND>(pNPWindow->window); | 34 HWND parent = reinterpret_cast<HWND>(pNPWindow->window); |
35 if (!::IsWindow(parent)) { | 35 if (!::IsWindow(parent)) { |
36 SetError("Invalid arguments passed in"); | 36 SetError("Invalid arguments passed in"); |
37 return NPERR_INVALID_PARAM; | 37 return NPERR_INVALID_PARAM; |
38 } | 38 } |
39 | 39 |
40 if ((test_name() == "create_instance_in_paint" && test_id() == "1") || | 40 if ((test_name() == "create_instance_in_paint" && test_id() == "1") || |
41 test_name() == "alert_in_window_message" || | 41 test_name() == "alert_in_window_message" || |
42 test_name() == "set_title_in_paint") { | 42 test_name() == "set_title_in_paint" || |
| 43 test_name() == "set_title_in_set_window_and_paint") { |
43 static ATOM window_class = 0; | 44 static ATOM window_class = 0; |
44 if (!window_class) { | 45 if (!window_class) { |
45 WNDCLASSEX wcex; | 46 WNDCLASSEX wcex; |
46 wcex.cbSize = sizeof(WNDCLASSEX); | 47 wcex.cbSize = sizeof(WNDCLASSEX); |
47 wcex.style = CS_DBLCLKS; | 48 wcex.style = CS_DBLCLKS; |
48 wcex.lpfnWndProc = &NPAPIClient::WindowedPluginTest::WindowProc; | 49 wcex.lpfnWndProc = &NPAPIClient::WindowedPluginTest::WindowProc; |
49 wcex.cbClsExtra = 0; | 50 wcex.cbClsExtra = 0; |
50 wcex.cbWndExtra = 0; | 51 wcex.cbWndExtra = 0; |
51 wcex.hInstance = GetModuleHandle(NULL); | 52 wcex.hInstance = GetModuleHandle(NULL); |
52 wcex.hIcon = 0; | 53 wcex.hIcon = 0; |
53 wcex.hCursor = 0; | 54 wcex.hCursor = 0; |
54 wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW+1); | 55 wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW+1); |
55 wcex.lpszMenuName = 0; | 56 wcex.lpszMenuName = 0; |
56 wcex.lpszClassName = L"CreateInstanceInPaintTestWindowClass"; | 57 wcex.lpszClassName = L"CreateInstanceInPaintTestWindowClass"; |
57 wcex.hIconSm = 0; | 58 wcex.hIconSm = 0; |
58 window_class = RegisterClassEx(&wcex); | 59 window_class = RegisterClassEx(&wcex); |
59 } | 60 } |
60 | 61 |
61 window_ = CreateWindowEx( | 62 window_ = CreateWindowEx( |
62 WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR, | 63 WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR, |
63 MAKEINTATOM(window_class), 0, | 64 MAKEINTATOM(window_class), 0, |
64 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE , | 65 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE , |
65 0, 0, 100, 100, parent, 0, GetModuleHandle(NULL), 0); | 66 0, 0, 100, 100, parent, 0, GetModuleHandle(NULL), 0); |
66 DCHECK(window_); | 67 DCHECK(window_); |
67 // TODO: this propery leaks. | 68 // TODO: this propery leaks. |
68 ::SetProp(window_, L"Plugin_Instance", this); | 69 ::SetProp(window_, L"Plugin_Instance", this); |
69 } | 70 } |
70 | 71 |
| 72 if (test_name() == "set_title_in_set_window_and_paint") |
| 73 CallJSFunction(this, "PluginCreated"); |
| 74 |
71 return NPERR_NO_ERROR; | 75 return NPERR_NO_ERROR; |
72 } | 76 } |
73 | 77 |
74 NPError WindowedPluginTest::Destroy() { | 78 NPError WindowedPluginTest::Destroy() { |
75 if (test_name() != "ensure_scripting_works_in_destroy") | 79 if (test_name() != "ensure_scripting_works_in_destroy") |
76 return NPERR_NO_ERROR; | 80 return NPERR_NO_ERROR; |
77 | 81 |
78 // Bug 23706: ensure that scripting works with no asserts. | 82 // Bug 23706: ensure that scripting works with no asserts. |
79 NPObject *window_obj = NULL; | 83 NPObject *window_obj = NULL; |
80 HostFunctions()->getvalue(id(), NPNVWindowNPObject,&window_obj); | 84 HostFunctions()->getvalue(id(), NPNVWindowNPObject,&window_obj); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 this_ptr->HostFunctions()->invoke( | 119 this_ptr->HostFunctions()->invoke( |
116 this_ptr->id(), window_obj, function_id, NULL, 0, &rv); | 120 this_ptr->id(), window_obj, function_id, NULL, 0, &rv); |
117 } | 121 } |
118 | 122 |
119 LRESULT CALLBACK WindowedPluginTest::WindowProc( | 123 LRESULT CALLBACK WindowedPluginTest::WindowProc( |
120 HWND window, UINT message, WPARAM wparam, LPARAM lparam) { | 124 HWND window, UINT message, WPARAM wparam, LPARAM lparam) { |
121 WindowedPluginTest* this_ptr = | 125 WindowedPluginTest* this_ptr = |
122 reinterpret_cast<WindowedPluginTest*> | 126 reinterpret_cast<WindowedPluginTest*> |
123 (::GetProp(window, L"Plugin_Instance")); | 127 (::GetProp(window, L"Plugin_Instance")); |
124 | 128 |
| 129 if (message == WM_PAINT) { |
| 130 PAINTSTRUCT ps; |
| 131 HDC hdc = BeginPaint(window, &ps); |
| 132 HBRUSH brush = CreateSolidBrush(RGB(255, 0, 0)); |
| 133 SelectObject(hdc, brush); |
| 134 RECT r; |
| 135 GetClientRect(window, &r); |
| 136 Rectangle(hdc, 0, 0, r.right, r.bottom); |
| 137 DeleteObject(brush); |
| 138 EndPaint(window, &ps); |
| 139 } |
| 140 |
125 if (this_ptr && !this_ptr->done_) { | 141 if (this_ptr && !this_ptr->done_) { |
126 if (this_ptr->test_name() == "create_instance_in_paint" && | 142 if (this_ptr->test_name() == "create_instance_in_paint" && |
127 message == WM_PAINT) { | 143 message == WM_PAINT) { |
128 this_ptr->done_ = true; | 144 this_ptr->done_ = true; |
129 CallJSFunction(this_ptr, "CreateNewInstance"); | 145 CallJSFunction(this_ptr, "CreateNewInstance"); |
130 } else if (this_ptr->test_name() == "alert_in_window_message" && | 146 } else if (this_ptr->test_name() == "alert_in_window_message" && |
131 message == WM_PAINT) { | 147 message == WM_PAINT) { |
132 this_ptr->done_ = true; | 148 this_ptr->done_ = true; |
133 // We call this function twice as we want to display two alerts | 149 // We call this function twice as we want to display two alerts |
134 // and verify that we don't hang the browser. | 150 // and verify that we don't hang the browser. |
135 CallJSFunction(this_ptr, "CallAlert"); | 151 CallJSFunction(this_ptr, "CallAlert"); |
136 CallJSFunction(this_ptr, "CallAlert"); | 152 CallJSFunction(this_ptr, "CallAlert"); |
137 } else if (this_ptr->test_name() == "set_title_in_paint" && | 153 } else if (this_ptr->test_name() == "set_title_in_paint" && |
138 message == WM_PAINT) { | 154 message == WM_PAINT) { |
139 this_ptr->done_ = true; | 155 this_ptr->done_ = true; |
140 CallJSFunction(this_ptr, "SetTitle"); | 156 CallJSFunction(this_ptr, "SetTitle"); |
| 157 } else if (this_ptr->test_name() == "set_title_in_set_window_and_paint" && |
| 158 message == WM_PAINT) { |
| 159 this_ptr->done_ = true; |
| 160 CallJSFunction(this_ptr, "PluginShown"); |
141 } | 161 } |
142 | 162 |
143 if (this_ptr->done_) { | 163 if (this_ptr->done_) { |
144 ::RemoveProp(window, L"Plugin_Instance"); | 164 ::RemoveProp(window, L"Plugin_Instance"); |
145 } | 165 } |
146 } | 166 } |
147 | 167 |
148 return DefWindowProc(window, message, wparam, lparam); | 168 return DefWindowProc(window, message, wparam, lparam); |
149 } | 169 } |
150 | 170 |
151 } // namespace NPAPIClient | 171 } // namespace NPAPIClient |
OLD | NEW |