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 "content/public/test/render_view_test.h" | 5 #include "content/public/test/render_view_test.h" |
6 | 6 |
| 7 #include <cctype> |
| 8 |
7 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
8 #include "components/scheduler/renderer/renderer_scheduler.h" | 10 #include "components/scheduler/renderer/renderer_scheduler.h" |
9 #include "content/common/dom_storage/dom_storage_types.h" | 11 #include "content/common/dom_storage/dom_storage_types.h" |
10 #include "content/common/frame_messages.h" | 12 #include "content/common/frame_messages.h" |
11 #include "content/common/input_messages.h" | 13 #include "content/common/input_messages.h" |
12 #include "content/common/view_messages.h" | 14 #include "content/common/view_messages.h" |
13 #include "content/public/browser/content_browser_client.h" | 15 #include "content/public/browser/content_browser_client.h" |
14 #include "content/public/browser/native_web_keyboard_event.h" | 16 #include "content/public/browser/native_web_keyboard_event.h" |
15 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
16 #include "content/public/common/renderer_preferences.h" | 18 #include "content/public/common/renderer_preferences.h" |
17 #include "content/public/renderer/content_renderer_client.h" | 19 #include "content/public/renderer/content_renderer_client.h" |
18 #include "content/public/test/frame_load_waiter.h" | 20 #include "content/public/test/frame_load_waiter.h" |
19 #include "content/renderer/history_controller.h" | 21 #include "content/renderer/history_controller.h" |
20 #include "content/renderer/history_serialization.h" | 22 #include "content/renderer/history_serialization.h" |
21 #include "content/renderer/render_thread_impl.h" | 23 #include "content/renderer/render_thread_impl.h" |
22 #include "content/renderer/render_view_impl.h" | 24 #include "content/renderer/render_view_impl.h" |
23 #include "content/renderer/renderer_blink_platform_impl.h" | 25 #include "content/renderer/renderer_blink_platform_impl.h" |
24 #include "content/renderer/renderer_main_platform_delegate.h" | 26 #include "content/renderer/renderer_main_platform_delegate.h" |
25 #include "content/test/fake_compositor_dependencies.h" | 27 #include "content/test/fake_compositor_dependencies.h" |
26 #include "content/test/mock_render_process.h" | 28 #include "content/test/mock_render_process.h" |
27 #include "content/test/test_content_client.h" | 29 #include "content/test/test_content_client.h" |
28 #include "third_party/WebKit/public/platform/WebScreenInfo.h" | 30 #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
29 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 31 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 32 #include "third_party/WebKit/public/web/WebDocument.h" |
30 #include "third_party/WebKit/public/web/WebHistoryItem.h" | 33 #include "third_party/WebKit/public/web/WebHistoryItem.h" |
| 34 #include "third_party/WebKit/public/web/WebInputElement.h" |
31 #include "third_party/WebKit/public/web/WebInputEvent.h" | 35 #include "third_party/WebKit/public/web/WebInputEvent.h" |
32 #include "third_party/WebKit/public/web/WebKit.h" | 36 #include "third_party/WebKit/public/web/WebKit.h" |
33 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 37 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
34 #include "third_party/WebKit/public/web/WebScriptSource.h" | 38 #include "third_party/WebKit/public/web/WebScriptSource.h" |
35 #include "third_party/WebKit/public/web/WebView.h" | 39 #include "third_party/WebKit/public/web/WebView.h" |
36 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
| 41 #include "ui/events/keycodes/keyboard_codes.h" |
37 #include "v8/include/v8.h" | 42 #include "v8/include/v8.h" |
38 | 43 |
39 #if defined(OS_MACOSX) | 44 #if defined(OS_MACOSX) |
40 #include "base/mac/scoped_nsautorelease_pool.h" | 45 #include "base/mac/scoped_nsautorelease_pool.h" |
41 #endif | 46 #endif |
42 | 47 |
43 using blink::WebGestureEvent; | 48 using blink::WebGestureEvent; |
44 using blink::WebInputEvent; | 49 using blink::WebInputEvent; |
45 using blink::WebLocalFrame; | 50 using blink::WebLocalFrame; |
46 using blink::WebMouseEvent; | 51 using blink::WebMouseEvent; |
47 using blink::WebScriptSource; | 52 using blink::WebScriptSource; |
48 using blink::WebString; | 53 using blink::WebString; |
49 using blink::WebURLRequest; | 54 using blink::WebURLRequest; |
50 | 55 |
51 namespace { | 56 namespace { |
| 57 |
52 const int32 kOpenerId = -2; | 58 const int32 kOpenerId = -2; |
53 const int32 kRouteId = 5; | 59 const int32 kRouteId = 5; |
54 const int32 kMainFrameRouteId = 6; | 60 const int32 kMainFrameRouteId = 6; |
55 const int32 kNewWindowRouteId = 7; | 61 const int32 kNewWindowRouteId = 7; |
56 const int32 kNewFrameRouteId = 10; | 62 const int32 kNewFrameRouteId = 10; |
57 const int32 kSurfaceId = 42; | 63 const int32 kSurfaceId = 42; |
58 | 64 |
| 65 // Converts |ascii_character| into |key_code| and returns true on success. |
| 66 // Handles only the characters needed by tests. |
| 67 bool GetWindowsKeyCode(char ascii_character, int* key_code) { |
| 68 if (isalnum(ascii_character)) { |
| 69 *key_code = base::ToUpperASCII(ascii_character); |
| 70 return true; |
| 71 } |
| 72 |
| 73 switch (ascii_character) { |
| 74 case '@': |
| 75 *key_code = '2'; |
| 76 return true; |
| 77 case '_': |
| 78 *key_code = ui::VKEY_OEM_MINUS; |
| 79 return true; |
| 80 case '.': |
| 81 *key_code = ui::VKEY_OEM_PERIOD; |
| 82 return true; |
| 83 case ui::VKEY_BACK: |
| 84 *key_code = ui::VKEY_BACK; |
| 85 return true; |
| 86 default: |
| 87 return false; |
| 88 } |
| 89 } |
| 90 |
59 } // namespace | 91 } // namespace |
60 | 92 |
61 namespace content { | 93 namespace content { |
62 | 94 |
63 class RendererBlinkPlatformImplNoSandboxImpl | 95 class RendererBlinkPlatformImplNoSandboxImpl |
64 : public RendererBlinkPlatformImpl { | 96 : public RendererBlinkPlatformImpl { |
65 public: | 97 public: |
66 RendererBlinkPlatformImplNoSandboxImpl( | 98 RendererBlinkPlatformImplNoSandboxImpl( |
67 scheduler::RendererScheduler* scheduler) | 99 scheduler::RendererScheduler* scheduler) |
68 : RendererBlinkPlatformImpl(scheduler) {} | 100 : RendererBlinkPlatformImpl(scheduler) {} |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 params.physical_backing_size = new_size; | 420 params.physical_backing_size = new_size; |
389 params.top_controls_height = 0.f; | 421 params.top_controls_height = 0.f; |
390 params.top_controls_shrink_blink_size = false; | 422 params.top_controls_shrink_blink_size = false; |
391 params.resizer_rect = resizer_rect; | 423 params.resizer_rect = resizer_rect; |
392 params.is_fullscreen_granted = is_fullscreen_granted; | 424 params.is_fullscreen_granted = is_fullscreen_granted; |
393 params.display_mode = blink::WebDisplayModeBrowser; | 425 params.display_mode = blink::WebDisplayModeBrowser; |
394 scoped_ptr<IPC::Message> resize_message(new ViewMsg_Resize(0, params)); | 426 scoped_ptr<IPC::Message> resize_message(new ViewMsg_Resize(0, params)); |
395 OnMessageReceived(*resize_message); | 427 OnMessageReceived(*resize_message); |
396 } | 428 } |
397 | 429 |
| 430 void RenderViewTest::SimulateUserTypingASCIICharacter(char ascii_character, |
| 431 bool flush_message_loop) { |
| 432 blink::WebKeyboardEvent event; |
| 433 event.text[0] = ascii_character; |
| 434 ASSERT_TRUE(GetWindowsKeyCode(ascii_character, &event.windowsKeyCode)); |
| 435 if (isupper(ascii_character) || ascii_character == '@' || |
| 436 ascii_character == '_') { |
| 437 event.modifiers = blink::WebKeyboardEvent::ShiftKey; |
| 438 } |
| 439 |
| 440 event.type = blink::WebKeyboardEvent::RawKeyDown; |
| 441 SendWebKeyboardEvent(event); |
| 442 |
| 443 event.type = blink::WebKeyboardEvent::Char; |
| 444 SendWebKeyboardEvent(event); |
| 445 |
| 446 event.type = blink::WebKeyboardEvent::KeyUp; |
| 447 SendWebKeyboardEvent(event); |
| 448 |
| 449 if (flush_message_loop) { |
| 450 // Processing is delayed because of a Blink bug: |
| 451 // https://bugs.webkit.org/show_bug.cgi?id=16976 See |
| 452 // PasswordAutofillAgent::TextDidChangeInTextField() for details. |
| 453 base::MessageLoop::current()->RunUntilIdle(); |
| 454 } |
| 455 } |
| 456 |
| 457 void RenderViewTest::SimulateUserInputChangeForElement( |
| 458 blink::WebInputElement* input, |
| 459 const std::string& new_value) { |
| 460 ASSERT_TRUE(base::IsStringASCII(new_value)); |
| 461 while (!input->focused()) |
| 462 input->document().frame()->view()->advanceFocus(false); |
| 463 |
| 464 size_t previous_length = input->value().length(); |
| 465 for (size_t i = 0; i < previous_length; ++i) |
| 466 SimulateUserTypingASCIICharacter(ui::VKEY_BACK, false); |
| 467 |
| 468 EXPECT_TRUE(input->value().utf8().empty()); |
| 469 for (size_t i = 0; i < new_value.size(); ++i) |
| 470 SimulateUserTypingASCIICharacter(new_value[i], false); |
| 471 |
| 472 // Compare only beginning, because autocomplete may have filled out the |
| 473 // form. |
| 474 EXPECT_EQ(new_value, input->value().utf8().substr(0, new_value.length())); |
| 475 |
| 476 base::MessageLoop::current()->RunUntilIdle(); |
| 477 } |
| 478 |
398 bool RenderViewTest::OnMessageReceived(const IPC::Message& msg) { | 479 bool RenderViewTest::OnMessageReceived(const IPC::Message& msg) { |
399 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 480 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
400 return impl->OnMessageReceived(msg); | 481 return impl->OnMessageReceived(msg); |
401 } | 482 } |
402 | 483 |
403 void RenderViewTest::DidNavigateWithinPage(blink::WebLocalFrame* frame, | 484 void RenderViewTest::DidNavigateWithinPage(blink::WebLocalFrame* frame, |
404 bool is_new_navigation) { | 485 bool is_new_navigation) { |
405 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 486 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
406 blink::WebHistoryItem item; | 487 blink::WebHistoryItem item; |
407 item.initialize(); | 488 item.initialize(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 | 540 |
460 impl->GetMainRenderFrame()->OnNavigate(common_params, StartNavigationParams(), | 541 impl->GetMainRenderFrame()->OnNavigate(common_params, StartNavigationParams(), |
461 request_params); | 542 request_params); |
462 | 543 |
463 // The load actually happens asynchronously, so we pump messages to process | 544 // The load actually happens asynchronously, so we pump messages to process |
464 // the pending continuation. | 545 // the pending continuation. |
465 FrameLoadWaiter(view_->GetMainRenderFrame()).Wait(); | 546 FrameLoadWaiter(view_->GetMainRenderFrame()).Wait(); |
466 } | 547 } |
467 | 548 |
468 } // namespace content | 549 } // namespace content |
OLD | NEW |