| 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/browser/renderer_host/render_widget_host_view_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 #include "ui/compositor/compositor.h" | 79 #include "ui/compositor/compositor.h" |
| 80 #include "ui/compositor/layer_tree_owner.h" | 80 #include "ui/compositor/layer_tree_owner.h" |
| 81 #include "ui/compositor/test/draw_waiter_for_test.h" | 81 #include "ui/compositor/test/draw_waiter_for_test.h" |
| 82 #include "ui/events/blink/blink_event_util.h" | 82 #include "ui/events/blink/blink_event_util.h" |
| 83 #include "ui/events/event.h" | 83 #include "ui/events/event.h" |
| 84 #include "ui/events/event_utils.h" | 84 #include "ui/events/event_utils.h" |
| 85 #include "ui/events/gesture_detection/gesture_configuration.h" | 85 #include "ui/events/gesture_detection/gesture_configuration.h" |
| 86 #include "ui/events/keycodes/dom/dom_code.h" | 86 #include "ui/events/keycodes/dom/dom_code.h" |
| 87 #include "ui/events/keycodes/dom/keycode_converter.h" | 87 #include "ui/events/keycodes/dom/keycode_converter.h" |
| 88 #include "ui/events/test/event_generator.h" | 88 #include "ui/events/test/event_generator.h" |
| 89 #include "ui/gfx/geometry/rect.h" |
| 90 #include "ui/gfx/selection_bound.h" |
| 89 #include "ui/wm/core/default_activation_client.h" | 91 #include "ui/wm/core/default_activation_client.h" |
| 90 #include "ui/wm/core/default_screen_position_client.h" | 92 #include "ui/wm/core/default_screen_position_client.h" |
| 91 #include "ui/wm/core/window_util.h" | 93 #include "ui/wm/core/window_util.h" |
| 92 | 94 |
| 93 using testing::_; | 95 using testing::_; |
| 94 | 96 |
| 95 using blink::WebGestureEvent; | 97 using blink::WebGestureEvent; |
| 96 using blink::WebInputEvent; | 98 using blink::WebInputEvent; |
| 97 using blink::WebMouseEvent; | 99 using blink::WebMouseEvent; |
| 98 using blink::WebMouseWheelEvent; | 100 using blink::WebMouseWheelEvent; |
| (...skipping 3924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4023 EXPECT_TRUE(delegate->context_menu_request_received()); | 4025 EXPECT_TRUE(delegate->context_menu_request_received()); |
| 4024 EXPECT_EQ(delegate->context_menu_source_type(), ui::MENU_SOURCE_TOUCH); | 4026 EXPECT_EQ(delegate->context_menu_source_type(), ui::MENU_SOURCE_TOUCH); |
| 4025 #endif | 4027 #endif |
| 4026 | 4028 |
| 4027 RenderViewHostFactory::set_is_real_render_view_host(false); | 4029 RenderViewHostFactory::set_is_real_render_view_host(false); |
| 4028 } | 4030 } |
| 4029 | 4031 |
| 4030 // ---------------------------------------------------------------------------- | 4032 // ---------------------------------------------------------------------------- |
| 4031 // TextInputManager and IME-Related Tests | 4033 // TextInputManager and IME-Related Tests |
| 4032 | 4034 |
| 4033 // A group of tests which verify that the IME method results are routed to the | 4035 // The test class for OOPIF IME related unit tests in RenderWidgetHostViewAura. |
| 4034 // right RenderWidget in the OOPIF structure. | |
| 4035 // In each test, 3 views are created where one is in process with main frame and | 4036 // In each test, 3 views are created where one is in process with main frame and |
| 4036 // the other two are in distinct processes (this makes a total of 4 RWHVs). Then | 4037 // the other two are in distinct processes (this makes a total of 4 RWHVs). |
| 4037 // each test will verify the correctness of routing for one of the IME result | 4038 class InputMethodAuraTestBase : public RenderWidgetHostViewAuraTest { |
| 4038 // methods. The method is called on ui::TextInputClient (i.e., RWHV for the tab | |
| 4039 // in aura) and then the test verifies that the IPC is routed to the | |
| 4040 // RenderWidget corresponding to the active view (i.e., the RenderWidget | |
| 4041 // with focused <input>). | |
| 4042 class InputMethodResultAuraTest : public RenderWidgetHostViewAuraTest { | |
| 4043 public: | 4039 public: |
| 4044 InputMethodResultAuraTest() {} | 4040 InputMethodAuraTestBase() {} |
| 4045 ~InputMethodResultAuraTest() override {} | 4041 ~InputMethodAuraTestBase() override {} |
| 4046 | 4042 |
| 4047 void SetUp() override { | 4043 void SetUp() override { |
| 4048 RenderWidgetHostViewAuraTest::SetUp(); | 4044 RenderWidgetHostViewAuraTest::SetUp(); |
| 4049 InitializeAura(); | 4045 InitializeAura(); |
| 4050 | 4046 |
| 4051 view_for_first_process_ = CreateViewForProcess(tab_process()); | 4047 view_for_first_process_ = CreateViewForProcess(tab_process()); |
| 4052 | 4048 |
| 4053 second_process_host_ = CreateNewProcessHost(); | 4049 second_process_host_ = CreateNewProcessHost(); |
| 4054 view_for_second_process_ = CreateViewForProcess(second_process_host_); | 4050 view_for_second_process_ = CreateViewForProcess(second_process_host_); |
| 4055 | 4051 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 4079 | 4075 |
| 4080 RenderWidgetHost* widget_for_third_process = | 4076 RenderWidgetHost* widget_for_third_process = |
| 4081 view_for_third_process_->GetRenderWidgetHost(); | 4077 view_for_third_process_->GetRenderWidgetHost(); |
| 4082 view_for_third_process_->Destroy(); | 4078 view_for_third_process_->Destroy(); |
| 4083 delete widget_for_third_process; | 4079 delete widget_for_third_process; |
| 4084 | 4080 |
| 4085 RenderWidgetHostViewAuraTest::TearDown(); | 4081 RenderWidgetHostViewAuraTest::TearDown(); |
| 4086 } | 4082 } |
| 4087 | 4083 |
| 4088 protected: | 4084 protected: |
| 4089 const IPC::Message* RunAndReturnIPCSent(const base::Closure closure, | |
| 4090 MockRenderProcessHost* process, | |
| 4091 int32_t message_id) { | |
| 4092 process->sink().ClearMessages(); | |
| 4093 closure.Run(); | |
| 4094 return process->sink().GetFirstMessageMatching(message_id); | |
| 4095 } | |
| 4096 | |
| 4097 MockRenderWidgetHostDelegate* render_widget_host_delegate() const { | 4085 MockRenderWidgetHostDelegate* render_widget_host_delegate() const { |
| 4098 return delegates_.back().get(); | 4086 return delegates_.back().get(); |
| 4099 } | 4087 } |
| 4100 | 4088 |
| 4101 ui::TextInputClient* text_input_client() const { return view_; } | 4089 ui::TextInputClient* text_input_client() const { return view_; } |
| 4102 | 4090 |
| 4103 bool has_composition_text() const { | 4091 bool has_composition_text() const { |
| 4104 return tab_view()->has_composition_text_; | 4092 return tab_view()->has_composition_text_; |
| 4105 } | 4093 } |
| 4106 | 4094 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4149 view_->InitAsChild(nullptr); | 4137 view_->InitAsChild(nullptr); |
| 4150 view_->Show(); | 4138 view_->Show(); |
| 4151 } | 4139 } |
| 4152 | 4140 |
| 4153 TestRenderWidgetHostView* view_for_first_process_; | 4141 TestRenderWidgetHostView* view_for_first_process_; |
| 4154 MockRenderProcessHost* second_process_host_; | 4142 MockRenderProcessHost* second_process_host_; |
| 4155 TestRenderWidgetHostView* view_for_second_process_; | 4143 TestRenderWidgetHostView* view_for_second_process_; |
| 4156 MockRenderProcessHost* third_process_host_; | 4144 MockRenderProcessHost* third_process_host_; |
| 4157 TestRenderWidgetHostView* view_for_third_process_; | 4145 TestRenderWidgetHostView* view_for_third_process_; |
| 4158 | 4146 |
| 4147 DISALLOW_COPY_AND_ASSIGN(InputMethodAuraTestBase); |
| 4148 }; |
| 4149 |
| 4150 // A group of tests which verify that the IME method results are routed to the |
| 4151 // right RenderWidget when there are multiple RenderWidgetHostViews on tab. Each |
| 4152 // test will verify the correctness of routing for one of the IME result |
| 4153 // methods. The method is called on ui::TextInputClient (i.e., RWHV for the tab |
| 4154 // in aura) and then the test verifies that the IPC is routed to the |
| 4155 // RenderWidget corresponding to the active view (i.e., the RenderWidget |
| 4156 // with focused <input>). |
| 4157 class InputMethodResultAuraTest : public InputMethodAuraTestBase { |
| 4158 public: |
| 4159 InputMethodResultAuraTest() {} |
| 4160 ~InputMethodResultAuraTest() override {} |
| 4161 |
| 4162 protected: |
| 4163 const IPC::Message* RunAndReturnIPCSent(const base::Closure closure, |
| 4164 MockRenderProcessHost* process, |
| 4165 int32_t message_id) { |
| 4166 process->sink().ClearMessages(); |
| 4167 closure.Run(); |
| 4168 return process->sink().GetFirstMessageMatching(message_id); |
| 4169 } |
| 4170 |
| 4171 private: |
| 4159 DISALLOW_COPY_AND_ASSIGN(InputMethodResultAuraTest); | 4172 DISALLOW_COPY_AND_ASSIGN(InputMethodResultAuraTest); |
| 4160 }; | 4173 }; |
| 4161 | 4174 |
| 4162 // This test verifies that ui::TextInputClient::SetCompositionText call leads to | 4175 // This test verifies that ui::TextInputClient::SetCompositionText call leads to |
| 4163 // IPC message InputMsg_ImeSetComposition being sent to the right renderer | 4176 // IPC message InputMsg_ImeSetComposition being sent to the right renderer |
| 4164 // process. | 4177 // process. |
| 4165 TEST_F(InputMethodResultAuraTest, SetCompositionText) { | 4178 TEST_F(InputMethodResultAuraTest, SetCompositionText) { |
| 4166 base::Closure ime_call = | 4179 base::Closure ime_call = |
| 4167 base::Bind(&ui::TextInputClient::SetCompositionText, | 4180 base::Bind(&ui::TextInputClient::SetCompositionText, |
| 4168 base::Unretained(text_input_client()), ui::CompositionText()); | 4181 base::Unretained(text_input_client()), ui::CompositionText()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4209 base::Closure ime_call = | 4222 base::Closure ime_call = |
| 4210 base::Bind(&ui::TextInputClient::InsertText, | 4223 base::Bind(&ui::TextInputClient::InsertText, |
| 4211 base::Unretained(text_input_client()), base::string16()); | 4224 base::Unretained(text_input_client()), base::string16()); |
| 4212 for (auto index : active_view_sequence_) { | 4225 for (auto index : active_view_sequence_) { |
| 4213 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); | 4226 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); |
| 4214 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_call, processes_[index], | 4227 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_call, processes_[index], |
| 4215 InputMsg_ImeConfirmComposition::ID)); | 4228 InputMsg_ImeConfirmComposition::ID)); |
| 4216 } | 4229 } |
| 4217 } | 4230 } |
| 4218 | 4231 |
| 4219 // This test makes a specific child frame's view active and then forces the | 4232 // This test makes a specific view active and then forces the tab's view end the |
| 4220 // tab's view end the current IME composition session by sending out an IME | 4233 // current IME composition session by sending out an IME IPC to confirm |
| 4221 // IPC to confirm composition. The test then verifies that the message is sent | 4234 // composition. The test then verifies that the message is sent |
| 4222 // to the active widget's process. | 4235 // to the active widget's process. |
| 4223 TEST_F(InputMethodResultAuraTest, FinishImeCompositionSession) { | 4236 TEST_F(InputMethodResultAuraTest, FinishImeCompositionSession) { |
| 4224 base::Closure ime_finish_session_call = | 4237 base::Closure ime_finish_session_call = |
| 4225 base::Bind(&RenderWidgetHostViewAura::FinishImeCompositionSession, | 4238 base::Bind(&RenderWidgetHostViewAura::FinishImeCompositionSession, |
| 4226 base::Unretained(tab_view())); | 4239 base::Unretained(tab_view())); |
| 4227 for (auto index : active_view_sequence_) { | 4240 for (auto index : active_view_sequence_) { |
| 4228 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); | 4241 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); |
| 4229 SetHasCompositionTextToTrue(); | 4242 SetHasCompositionTextToTrue(); |
| 4230 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_finish_session_call, | 4243 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_finish_session_call, |
| 4231 processes_[index], | 4244 processes_[index], |
| 4232 InputMsg_ImeConfirmComposition::ID)); | 4245 InputMsg_ImeConfirmComposition::ID)); |
| 4233 } | 4246 } |
| 4234 } | 4247 } |
| 4235 | 4248 |
| 4249 // A class of tests which verify the correctness of some tracked IME related |
| 4250 // state at the browser side, e.g., caret bounds. |
| 4251 class InputMethodStateAuraTest : public InputMethodAuraTestBase { |
| 4252 public: |
| 4253 InputMethodStateAuraTest() {} |
| 4254 ~InputMethodStateAuraTest() override {} |
| 4255 |
| 4256 protected: |
| 4257 gfx::SelectionBound GetSelectionBoundFromRect(const gfx::Rect& rect) { |
| 4258 gfx::SelectionBound bound; |
| 4259 bound.SetEdge(gfx::PointF(rect.origin()), gfx::PointF(rect.bottom_left())); |
| 4260 return bound; |
| 4261 } |
| 4262 |
| 4263 gfx::Rect TransformRectToViewsRootCoordSpace(const gfx::Rect rect, |
| 4264 RenderWidgetHostView* view) { |
| 4265 return gfx::Rect(view->TransformPointToRootCoordSpace(rect.origin()), |
| 4266 rect.size()); |
| 4267 } |
| 4268 |
| 4269 private: |
| 4270 DISALLOW_COPY_AND_ASSIGN(InputMethodStateAuraTest); |
| 4271 }; |
| 4272 |
| 4273 // This test activates the views on the tab according to a predefined order and |
| 4274 // for each tab, simulates a selection bounds changed call. Then it verifies |
| 4275 // that the caret bounds reported by the TextInputClient match those reported |
| 4276 // for the active view. |
| 4277 TEST_F(InputMethodStateAuraTest, GetCaretBounds) { |
| 4278 ViewHostMsg_SelectionBounds_Params params; |
| 4279 params.is_anchor_first = true; |
| 4280 params.anchor_dir = blink::WebTextDirectionLeftToRight; |
| 4281 params.focus_dir = blink::WebTextDirectionLeftToRight; |
| 4282 params.anchor_rect = gfx::Rect(0, 0, 10, 10); |
| 4283 for (auto index : active_view_sequence_) { |
| 4284 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); |
| 4285 params.focus_rect = gfx::Rect(10 + index, 10 + index, 10, 10); |
| 4286 views_[index]->SelectionBoundsChanged(params); |
| 4287 |
| 4288 // Calculate the bounds. |
| 4289 gfx::SelectionBound anchor_bound = GetSelectionBoundFromRect( |
| 4290 TransformRectToViewsRootCoordSpace(params.anchor_rect, views_[index])); |
| 4291 gfx::SelectionBound focus_bound = GetSelectionBoundFromRect( |
| 4292 TransformRectToViewsRootCoordSpace(params.focus_rect, views_[index])); |
| 4293 anchor_bound.set_type(gfx::SelectionBound::LEFT); |
| 4294 focus_bound.set_type(gfx::SelectionBound::RIGHT); |
| 4295 gfx::Rect measured_rect = |
| 4296 gfx::RectBetweenSelectionBounds(anchor_bound, focus_bound); |
| 4297 |
| 4298 EXPECT_EQ(measured_rect, text_input_client()->GetCaretBounds()); |
| 4299 } |
| 4300 } |
| 4301 |
| 4236 } // namespace content | 4302 } // namespace content |
| OLD | NEW |