| 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 "content/common/dom_storage/dom_storage_types.h" | 10 #include "content/common/dom_storage/dom_storage_types.h" |
| 9 #include "content/common/frame_messages.h" | 11 #include "content/common/frame_messages.h" |
| 10 #include "content/common/input_messages.h" | 12 #include "content/common/input_messages.h" |
| 11 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
| 12 #include "content/public/browser/content_browser_client.h" | 14 #include "content/public/browser/content_browser_client.h" |
| 13 #include "content/public/browser/native_web_keyboard_event.h" | 15 #include "content/public/browser/native_web_keyboard_event.h" |
| 14 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
| 15 #include "content/public/common/renderer_preferences.h" | 17 #include "content/public/common/renderer_preferences.h" |
| 16 #include "content/public/renderer/content_renderer_client.h" | 18 #include "content/public/renderer/content_renderer_client.h" |
| 17 #include "content/public/test/frame_load_waiter.h" | 19 #include "content/public/test/frame_load_waiter.h" |
| 18 #include "content/renderer/history_controller.h" | 20 #include "content/renderer/history_controller.h" |
| 19 #include "content/renderer/history_serialization.h" | 21 #include "content/renderer/history_serialization.h" |
| 20 #include "content/renderer/render_thread_impl.h" | 22 #include "content/renderer/render_thread_impl.h" |
| 21 #include "content/renderer/render_view_impl.h" | 23 #include "content/renderer/render_view_impl.h" |
| 22 #include "content/renderer/renderer_blink_platform_impl.h" | 24 #include "content/renderer/renderer_blink_platform_impl.h" |
| 23 #include "content/renderer/renderer_main_platform_delegate.h" | 25 #include "content/renderer/renderer_main_platform_delegate.h" |
| 24 #include "content/renderer/scheduler/renderer_scheduler.h" | 26 #include "content/renderer/scheduler/renderer_scheduler.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(RendererScheduler* scheduler) | 98 RendererBlinkPlatformImplNoSandboxImpl(RendererScheduler* scheduler) |
| 67 : RendererBlinkPlatformImpl(scheduler) {} | 99 : RendererBlinkPlatformImpl(scheduler) {} |
| 68 | 100 |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 params.physical_backing_size = new_size; | 419 params.physical_backing_size = new_size; |
| 388 params.top_controls_height = 0.f; | 420 params.top_controls_height = 0.f; |
| 389 params.top_controls_shrink_blink_size = false; | 421 params.top_controls_shrink_blink_size = false; |
| 390 params.resizer_rect = resizer_rect; | 422 params.resizer_rect = resizer_rect; |
| 391 params.is_fullscreen_granted = is_fullscreen_granted; | 423 params.is_fullscreen_granted = is_fullscreen_granted; |
| 392 params.display_mode = blink::WebDisplayModeBrowser; | 424 params.display_mode = blink::WebDisplayModeBrowser; |
| 393 scoped_ptr<IPC::Message> resize_message(new ViewMsg_Resize(0, params)); | 425 scoped_ptr<IPC::Message> resize_message(new ViewMsg_Resize(0, params)); |
| 394 OnMessageReceived(*resize_message); | 426 OnMessageReceived(*resize_message); |
| 395 } | 427 } |
| 396 | 428 |
| 429 void RenderViewTest::SimulateUserTypingASCIICharacter(char ascii_character) { |
| 430 blink::WebKeyboardEvent event; |
| 431 event.text[0] = ascii_character; |
| 432 ASSERT_TRUE(GetWindowsKeyCode(ascii_character, &event.windowsKeyCode)); |
| 433 if (isupper(ascii_character) || ascii_character == '@' || |
| 434 ascii_character == '_') { |
| 435 event.modifiers = blink::WebKeyboardEvent::ShiftKey; |
| 436 } |
| 437 |
| 438 event.type = blink::WebKeyboardEvent::RawKeyDown; |
| 439 SendWebKeyboardEvent(event); |
| 440 |
| 441 event.type = blink::WebKeyboardEvent::Char; |
| 442 SendWebKeyboardEvent(event); |
| 443 |
| 444 event.type = blink::WebKeyboardEvent::KeyUp; |
| 445 SendWebKeyboardEvent(event); |
| 446 } |
| 447 |
| 448 void RenderViewTest::ProcessInputForAutofill() { |
| 449 // Processing is delayed because of a Blink bug: |
| 450 // https://bugs.webkit.org/show_bug.cgi?id=16976 See |
| 451 // PasswordAutofillAgent::TextDidChangeInTextField() for details. |
| 452 |
| 453 // Autocomplete will trigger a style recalculation when we put up the next |
| 454 // frame, but we don't want to wait that long. Instead, trigger a style |
| 455 // recalcuation manually after TextFieldDidChangeImpl runs. |
| 456 base::MessageLoop::current()->PostTask( |
| 457 FROM_HERE, |
| 458 base::Bind(&RenderViewTest::LayoutMainFrame, base::Unretained(this))); |
| 459 |
| 460 base::MessageLoop::current()->RunUntilIdle(); |
| 461 } |
| 462 |
| 463 void RenderViewTest::SimulateUserInputChangeForElement( |
| 464 blink::WebInputElement* input, |
| 465 const std::string& new_value) { |
| 466 while (!input->focused()) |
| 467 input->document().frame()->view()->advanceFocus(false); |
| 468 |
| 469 size_t previous_length = input->value().length(); |
| 470 for (size_t i = 0; i < previous_length; ++i) |
| 471 SimulateUserTypingASCIICharacter(ui::VKEY_BACK); |
| 472 |
| 473 EXPECT_TRUE(input->value().utf8().empty()); |
| 474 ASSERT_TRUE(base::IsStringASCII(new_value)); |
| 475 for (size_t i = 0; i < new_value.size(); ++i) |
| 476 SimulateUserTypingASCIICharacter(new_value[i]); |
| 477 |
| 478 // Compare only beginning, because autocomplete may have filled out the |
| 479 // form. |
| 480 EXPECT_EQ(new_value, input->value().utf8().substr(0, new_value.length())); |
| 481 |
| 482 ProcessInputForAutofill(); |
| 483 } |
| 484 |
| 397 bool RenderViewTest::OnMessageReceived(const IPC::Message& msg) { | 485 bool RenderViewTest::OnMessageReceived(const IPC::Message& msg) { |
| 398 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 486 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
| 399 return impl->OnMessageReceived(msg); | 487 return impl->OnMessageReceived(msg); |
| 400 } | 488 } |
| 401 | 489 |
| 402 void RenderViewTest::DidNavigateWithinPage(blink::WebLocalFrame* frame, | 490 void RenderViewTest::DidNavigateWithinPage(blink::WebLocalFrame* frame, |
| 403 bool is_new_navigation) { | 491 bool is_new_navigation) { |
| 404 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 492 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
| 405 blink::WebHistoryItem item; | 493 blink::WebHistoryItem item; |
| 406 item.initialize(); | 494 item.initialize(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 request_params.current_history_list_length = history_list_length; | 545 request_params.current_history_list_length = history_list_length; |
| 458 | 546 |
| 459 impl->GetMainRenderFrame()->OnNavigate(common_params, StartNavigationParams(), | 547 impl->GetMainRenderFrame()->OnNavigate(common_params, StartNavigationParams(), |
| 460 request_params); | 548 request_params); |
| 461 | 549 |
| 462 // The load actually happens asynchronously, so we pump messages to process | 550 // The load actually happens asynchronously, so we pump messages to process |
| 463 // the pending continuation. | 551 // the pending continuation. |
| 464 FrameLoadWaiter(view_->GetMainRenderFrame()).Wait(); | 552 FrameLoadWaiter(view_->GetMainRenderFrame()).Wait(); |
| 465 } | 553 } |
| 466 | 554 |
| 555 void RenderViewTest::LayoutMainFrame() { |
| 556 GetMainFrame()->view()->layout(); |
| 557 } |
| 558 |
| 467 } // namespace content | 559 } // namespace content |
| OLD | NEW |