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 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 54 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
55 #include "third_party/WebKit/public/web/WebPerformance.h" | 55 #include "third_party/WebKit/public/web/WebPerformance.h" |
56 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 56 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
57 #include "third_party/WebKit/public/web/WebView.h" | 57 #include "third_party/WebKit/public/web/WebView.h" |
58 #include "third_party/WebKit/public/web/WebWindowFeatures.h" | 58 #include "third_party/WebKit/public/web/WebWindowFeatures.h" |
59 #include "ui/events/event.h" | 59 #include "ui/events/event.h" |
60 #include "ui/events/keycodes/keyboard_codes.h" | 60 #include "ui/events/keycodes/keyboard_codes.h" |
61 #include "ui/gfx/codec/jpeg_codec.h" | 61 #include "ui/gfx/codec/jpeg_codec.h" |
62 #include "ui/gfx/range/range.h" | 62 #include "ui/gfx/range/range.h" |
63 | 63 |
64 #if defined(USE_AURA) && defined(USE_X11) | |
65 #include <X11/Xlib.h> | |
66 #include "ui/events/event_constants.h" | |
67 #include "ui/events/keycodes/keyboard_code_conversion.h" | |
68 #include "ui/events/test/events_test_utils.h" | |
69 #include "ui/events/test/events_test_utils_x11.h" | |
70 #endif | |
71 | |
72 #if defined(USE_OZONE) | |
73 #include "ui/events/keycodes/keyboard_code_conversion.h" | |
74 #endif | |
75 | |
76 using blink::WebFrame; | 64 using blink::WebFrame; |
77 using blink::WebInputEvent; | 65 using blink::WebInputEvent; |
78 using blink::WebLocalFrame; | 66 using blink::WebLocalFrame; |
79 using blink::WebMouseEvent; | 67 using blink::WebMouseEvent; |
80 using blink::WebRuntimeFeatures; | 68 using blink::WebRuntimeFeatures; |
81 using blink::WebString; | 69 using blink::WebString; |
82 using blink::WebTextDirection; | 70 using blink::WebTextDirection; |
83 using blink::WebURLError; | 71 using blink::WebURLError; |
84 | 72 |
85 namespace content { | 73 namespace content { |
86 | 74 |
87 namespace { | 75 namespace { |
88 | 76 |
89 static const int kProxyRoutingId = 13; | 77 static const int kProxyRoutingId = 13; |
90 | 78 |
91 #if (defined(USE_AURA) && defined(USE_X11)) || defined(USE_OZONE) | |
92 // Converts MockKeyboard::Modifiers to ui::EventFlags. | |
93 int ConvertMockKeyboardModifier(MockKeyboard::Modifiers modifiers) { | |
94 static struct ModifierMap { | |
95 MockKeyboard::Modifiers src; | |
96 int dst; | |
97 } kModifierMap[] = { | |
98 { MockKeyboard::LEFT_SHIFT, ui::EF_SHIFT_DOWN }, | |
99 { MockKeyboard::RIGHT_SHIFT, ui::EF_SHIFT_DOWN }, | |
100 { MockKeyboard::LEFT_CONTROL, ui::EF_CONTROL_DOWN }, | |
101 { MockKeyboard::RIGHT_CONTROL, ui::EF_CONTROL_DOWN }, | |
102 { MockKeyboard::LEFT_ALT, ui::EF_ALT_DOWN }, | |
103 { MockKeyboard::RIGHT_ALT, ui::EF_ALT_DOWN }, | |
104 }; | |
105 int flags = 0; | |
106 for (size_t i = 0; i < arraysize(kModifierMap); ++i) { | |
107 if (kModifierMap[i].src & modifiers) { | |
108 flags |= kModifierMap[i].dst; | |
109 } | |
110 } | |
111 return flags; | |
112 } | |
113 #endif | |
114 | |
115 class WebUITestWebUIControllerFactory : public WebUIControllerFactory { | 79 class WebUITestWebUIControllerFactory : public WebUIControllerFactory { |
116 public: | 80 public: |
117 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui, | 81 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui, |
118 const GURL& url) const override { | 82 const GURL& url) const override { |
119 return NULL; | 83 return NULL; |
120 } | 84 } |
121 WebUI::TypeID GetWebUIType(BrowserContext* browser_context, | 85 WebUI::TypeID GetWebUIType(BrowserContext* browser_context, |
122 const GURL& url) const override { | 86 const GURL& url) const override { |
123 return WebUI::kNoWebUI; | 87 return WebUI::kNoWebUI; |
124 } | 88 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 120 } |
157 | 121 |
158 int view_page_id() { | 122 int view_page_id() { |
159 return view()->page_id_; | 123 return view()->page_id_; |
160 } | 124 } |
161 | 125 |
162 RenderFrameImpl* frame() { | 126 RenderFrameImpl* frame() { |
163 return static_cast<RenderFrameImpl*>(view()->GetMainRenderFrame()); | 127 return static_cast<RenderFrameImpl*>(view()->GetMainRenderFrame()); |
164 } | 128 } |
165 | 129 |
166 // Sends IPC messages that emulates a key-press event. | |
167 int SendKeyEvent(MockKeyboard::Layout layout, | |
168 int key_code, | |
169 MockKeyboard::Modifiers modifiers, | |
170 base::string16* output) { | |
171 #if defined(OS_WIN) | |
172 // Retrieve the Unicode character for the given tuple (keyboard-layout, | |
173 // key-code, and modifiers). | |
174 // Exit when a keyboard-layout driver cannot assign a Unicode character to | |
175 // the tuple to prevent sending an invalid key code to the RenderView | |
176 // object. | |
177 CHECK(mock_keyboard_.get()); | |
178 CHECK(output); | |
179 int length = mock_keyboard_->GetCharacters(layout, key_code, modifiers, | |
180 output); | |
181 if (length != 1) | |
182 return -1; | |
183 | |
184 // Create IPC messages from Windows messages and send them to our | |
185 // back-end. | |
186 // A keyboard event of Windows consists of three Windows messages: | |
187 // WM_KEYDOWN, WM_CHAR, and WM_KEYUP. | |
188 // WM_KEYDOWN and WM_KEYUP sends virtual-key codes. On the other hand, | |
189 // WM_CHAR sends a composed Unicode character. | |
190 MSG msg1 = { NULL, WM_KEYDOWN, key_code, 0 }; | |
191 ui::KeyEvent evt1(msg1); | |
192 NativeWebKeyboardEvent keydown_event(evt1); | |
193 SendNativeKeyEvent(keydown_event); | |
194 | |
195 MSG msg2 = { NULL, WM_CHAR, (*output)[0], 0 }; | |
196 ui::KeyEvent evt2(msg2); | |
197 NativeWebKeyboardEvent char_event(evt2); | |
198 SendNativeKeyEvent(char_event); | |
199 | |
200 MSG msg3 = { NULL, WM_KEYUP, key_code, 0 }; | |
201 ui::KeyEvent evt3(msg3); | |
202 NativeWebKeyboardEvent keyup_event(evt3); | |
203 SendNativeKeyEvent(keyup_event); | |
204 | |
205 return length; | |
206 #elif defined(USE_AURA) && defined(USE_X11) | |
207 // We ignore |layout|, which means we are only testing the layout of the | |
208 // current locale. TODO(mazda): fix this to respect |layout|. | |
209 CHECK(output); | |
210 const int flags = ConvertMockKeyboardModifier(modifiers); | |
211 | |
212 ui::ScopedXI2Event xevent; | |
213 xevent.InitKeyEvent(ui::ET_KEY_PRESSED, | |
214 static_cast<ui::KeyboardCode>(key_code), | |
215 flags); | |
216 ui::KeyEvent event1(xevent); | |
217 NativeWebKeyboardEvent keydown_event(event1); | |
218 SendNativeKeyEvent(keydown_event); | |
219 | |
220 // X11 doesn't actually have native character events, but give the test | |
221 // what it wants. | |
222 xevent.InitKeyEvent(ui::ET_KEY_PRESSED, | |
223 static_cast<ui::KeyboardCode>(key_code), | |
224 flags); | |
225 ui::KeyEvent event2(xevent); | |
226 event2.set_character(GetCharacterFromKeyCode(event2.key_code(), | |
227 event2.flags())); | |
228 ui::KeyEventTestApi test_event2(&event2); | |
229 test_event2.set_is_char(true); | |
230 NativeWebKeyboardEvent char_event(event2); | |
231 SendNativeKeyEvent(char_event); | |
232 | |
233 xevent.InitKeyEvent(ui::ET_KEY_RELEASED, | |
234 static_cast<ui::KeyboardCode>(key_code), | |
235 flags); | |
236 ui::KeyEvent event3(xevent); | |
237 NativeWebKeyboardEvent keyup_event(event3); | |
238 SendNativeKeyEvent(keyup_event); | |
239 | |
240 long c = GetCharacterFromKeyCode(static_cast<ui::KeyboardCode>(key_code), | |
241 flags); | |
242 output->assign(1, static_cast<base::char16>(c)); | |
243 return 1; | |
244 #elif defined(USE_OZONE) | |
245 const int flags = ConvertMockKeyboardModifier(modifiers); | |
246 | |
247 ui::KeyEvent keydown_event(ui::ET_KEY_PRESSED, | |
248 static_cast<ui::KeyboardCode>(key_code), | |
249 flags); | |
250 NativeWebKeyboardEvent keydown_web_event(keydown_event); | |
251 SendNativeKeyEvent(keydown_web_event); | |
252 | |
253 ui::KeyEvent char_event(keydown_event.GetCharacter(), | |
254 static_cast<ui::KeyboardCode>(key_code), | |
255 flags); | |
256 NativeWebKeyboardEvent char_web_event(char_event); | |
257 SendNativeKeyEvent(char_web_event); | |
258 | |
259 ui::KeyEvent keyup_event(ui::ET_KEY_RELEASED, | |
260 static_cast<ui::KeyboardCode>(key_code), | |
261 flags); | |
262 NativeWebKeyboardEvent keyup_web_event(keyup_event); | |
263 SendNativeKeyEvent(keyup_web_event); | |
264 | |
265 long c = GetCharacterFromKeyCode(static_cast<ui::KeyboardCode>(key_code), | |
266 flags); | |
267 output->assign(1, static_cast<base::char16>(c)); | |
268 return 1; | |
269 #else | |
270 NOTIMPLEMENTED(); | |
271 return L'\0'; | |
272 #endif | |
273 } | |
274 | |
275 void EnablePreferredSizeMode() { | 130 void EnablePreferredSizeMode() { |
276 view()->OnEnablePreferredSizeChangedMode(); | 131 view()->OnEnablePreferredSizeChangedMode(); |
277 } | 132 } |
278 | 133 |
279 const gfx::Size& GetPreferredSize() { | 134 const gfx::Size& GetPreferredSize() { |
280 view()->CheckPreferredSize(); | 135 view()->CheckPreferredSize(); |
281 return view()->preferred_size_; | 136 return view()->preferred_size_; |
282 } | 137 } |
283 | 138 |
284 void SetZoomLevel(double level) { | 139 void SetZoomLevel(double level) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 frame()->OnSetAccessibilityMode(new_mode); | 174 frame()->OnSetAccessibilityMode(new_mode); |
320 } | 175 } |
321 | 176 |
322 void SetCompositionFromExistingText( | 177 void SetCompositionFromExistingText( |
323 int start, | 178 int start, |
324 int end, | 179 int end, |
325 const std::vector<blink::WebCompositionUnderline>& underlines) { | 180 const std::vector<blink::WebCompositionUnderline>& underlines) { |
326 frame()->OnSetCompositionFromExistingText(start, end, underlines); | 181 frame()->OnSetCompositionFromExistingText(start, end, underlines); |
327 } | 182 } |
328 | 183 |
329 private: | 184 protected: |
330 scoped_ptr<MockKeyboard> mock_keyboard_; | 185 scoped_ptr<MockKeyboard> mock_keyboard_; |
331 }; | 186 }; |
332 | 187 |
333 class DevToolsAgentTest : public RenderViewImplTest { | 188 class DevToolsAgentTest : public RenderViewImplTest { |
334 public: | 189 public: |
335 void Attach() { | 190 void Attach() { |
336 std::string host_id = "host_id"; | 191 std::string host_id = "host_id"; |
337 agent()->OnAttach(host_id); | 192 agent()->OnAttach(host_id); |
338 } | 193 } |
339 | 194 |
(...skipping 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 ui::VKEY_OEM_8, | 1242 ui::VKEY_OEM_8, |
1388 #endif | 1243 #endif |
1389 }; | 1244 }; |
1390 | 1245 |
1391 MockKeyboard::Modifiers modifiers = kModifierData[j].modifiers; | 1246 MockKeyboard::Modifiers modifiers = kModifierData[j].modifiers; |
1392 for (size_t k = 0; k < arraysize(kKeyCodes); ++k) { | 1247 for (size_t k = 0; k < arraysize(kKeyCodes); ++k) { |
1393 // Send a keyboard event to the RenderView object. | 1248 // Send a keyboard event to the RenderView object. |
1394 // We should test a keyboard event only when the given keyboard-layout | 1249 // We should test a keyboard event only when the given keyboard-layout |
1395 // driver is installed in a PC and the driver can assign a Unicode | 1250 // driver is installed in a PC and the driver can assign a Unicode |
1396 // charcter for the given tuple (key-code and modifiers). | 1251 // charcter for the given tuple (key-code and modifiers). |
| 1252 if (!mock_keyboard_->Update(layout, modifiers)) |
| 1253 continue; |
| 1254 |
1397 int key_code = kKeyCodes[k]; | 1255 int key_code = kKeyCodes[k]; |
1398 base::string16 char_code; | 1256 base::string16 char_code; |
1399 if (SendKeyEvent(layout, key_code, modifiers, &char_code) < 0) | 1257 if (SendKeyEvent(*mock_keyboard_, key_code, &char_code) < 0) |
1400 continue; | 1258 continue; |
1401 | 1259 |
1402 // Create an expected result from the virtual-key code, the character | 1260 // Create an expected result from the virtual-key code, the character |
1403 // code, and the modifier-key status. | 1261 // code, and the modifier-key status. |
1404 // We format a string that emulates a DOM-event string produced hy | 1262 // We format a string that emulates a DOM-event string produced hy |
1405 // our JavaScript function. (See the above comment for the format.) | 1263 // our JavaScript function. (See the above comment for the format.) |
1406 static char expected_result[1024]; | 1264 static char expected_result[1024]; |
1407 expected_result[0] = 0; | 1265 expected_result[0] = 0; |
1408 base::snprintf(&expected_result[0], | 1266 base::snprintf(&expected_result[0], |
1409 sizeof(expected_result), | 1267 sizeof(expected_result), |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 ui::VKEY_OEM_8, | 1492 ui::VKEY_OEM_8, |
1635 #endif | 1493 #endif |
1636 }; | 1494 }; |
1637 | 1495 |
1638 MockKeyboard::Modifiers modifiers = kModifiers[j]; | 1496 MockKeyboard::Modifiers modifiers = kModifiers[j]; |
1639 for (size_t k = 0; k < arraysize(kKeyCodes); ++k) { | 1497 for (size_t k = 0; k < arraysize(kKeyCodes); ++k) { |
1640 // Send a keyboard event to the RenderView object. | 1498 // Send a keyboard event to the RenderView object. |
1641 // We should test a keyboard event only when the given keyboard-layout | 1499 // We should test a keyboard event only when the given keyboard-layout |
1642 // driver is installed in a PC and the driver can assign a Unicode | 1500 // driver is installed in a PC and the driver can assign a Unicode |
1643 // charcter for the given tuple (layout, key-code, and modifiers). | 1501 // charcter for the given tuple (layout, key-code, and modifiers). |
| 1502 if (!mock_keyboard_->Update(layout, modifiers)) |
| 1503 continue; |
| 1504 |
1644 int key_code = kKeyCodes[k]; | 1505 int key_code = kKeyCodes[k]; |
1645 base::string16 char_code; | 1506 base::string16 char_code; |
1646 if (SendKeyEvent(layout, key_code, modifiers, &char_code) < 0) | 1507 if (SendKeyEvent(*mock_keyboard_, key_code, &char_code) < 0) |
1647 continue; | 1508 continue; |
1648 } | 1509 } |
1649 } | 1510 } |
1650 | 1511 |
1651 // Retrieve the text in the test page and compare it with the expected | 1512 // Retrieve the text in the test page and compare it with the expected |
1652 // text created from a virtual-key code, a character code, and the | 1513 // text created from a virtual-key code, a character code, and the |
1653 // modifier-key status. | 1514 // modifier-key status. |
1654 const int kMaxOutputCharacters = 4096; | 1515 const int kMaxOutputCharacters = 4096; |
1655 base::string16 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); | 1516 base::string16 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); |
1656 EXPECT_EQ(base::WideToUTF16(kLayouts[i].expected_result), output); | 1517 EXPECT_EQ(base::WideToUTF16(kLayouts[i].expected_result), output); |
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2412 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 2273 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
2413 &DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); | 2274 &DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); |
2414 ExecuteJavaScript("debugger;"); | 2275 ExecuteJavaScript("debugger;"); |
2415 | 2276 |
2416 // CloseWhilePaused should resume execution and continue here. | 2277 // CloseWhilePaused should resume execution and continue here. |
2417 EXPECT_FALSE(IsPaused()); | 2278 EXPECT_FALSE(IsPaused()); |
2418 Detach(); | 2279 Detach(); |
2419 } | 2280 } |
2420 | 2281 |
2421 } // namespace content | 2282 } // namespace content |
OLD | NEW |