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 4305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4316 int32_t message_id) { | 4316 int32_t message_id) { |
4317 process->sink().ClearMessages(); | 4317 process->sink().ClearMessages(); |
4318 closure.Run(); | 4318 closure.Run(); |
4319 return process->sink().GetFirstMessageMatching(message_id); | 4319 return process->sink().GetFirstMessageMatching(message_id); |
4320 } | 4320 } |
4321 | 4321 |
4322 private: | 4322 private: |
4323 DISALLOW_COPY_AND_ASSIGN(InputMethodResultAuraTest); | 4323 DISALLOW_COPY_AND_ASSIGN(InputMethodResultAuraTest); |
4324 }; | 4324 }; |
4325 | 4325 |
4326 // This test verifies that ui::TextInputClient::SetCompositionText call leads to | 4326 // This test verifies ui::TextInputClient::SetCompositionText. |
4327 // IPC message InputMsg_ImeSetComposition being sent to the right renderer | |
4328 // process. | |
4329 TEST_F(InputMethodResultAuraTest, SetCompositionText) { | 4327 TEST_F(InputMethodResultAuraTest, SetCompositionText) { |
4330 base::Closure ime_call = | 4328 base::Closure ime_call = |
4331 base::Bind(&ui::TextInputClient::SetCompositionText, | 4329 base::Bind(&ui::TextInputClient::SetCompositionText, |
4332 base::Unretained(text_input_client()), ui::CompositionText()); | 4330 base::Unretained(text_input_client()), ui::CompositionText()); |
4333 for (auto index : active_view_sequence_) { | 4331 for (auto index : active_view_sequence_) { |
4334 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); | 4332 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); |
4335 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_call, processes_[index], | 4333 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_call, processes_[index], |
4336 InputMsg_ImeSetComposition::ID)); | 4334 InputMsg_ImeSetComposition::ID)); |
4337 } | 4335 } |
4338 } | 4336 } |
4339 | 4337 |
4340 // This test verifies that ui::TextInputClient::ConfirmCompositionText call | 4338 // This test is for ui::TextInputClient::ConfirmCompositionText. |
4341 // leads to IPC message InputMsg_ImeConfirmComposition being sent to the right | |
4342 // renderer process. | |
4343 TEST_F(InputMethodResultAuraTest, ConfirmCompositionText) { | 4339 TEST_F(InputMethodResultAuraTest, ConfirmCompositionText) { |
4344 base::Closure ime_call = | 4340 base::Closure ime_call = |
4345 base::Bind(&ui::TextInputClient::ConfirmCompositionText, | 4341 base::Bind(&ui::TextInputClient::ConfirmCompositionText, |
4346 base::Unretained(text_input_client())); | 4342 base::Unretained(text_input_client())); |
4347 for (auto index : active_view_sequence_) { | 4343 for (auto index : active_view_sequence_) { |
4348 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); | 4344 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); |
4349 SetHasCompositionTextToTrue(); | 4345 SetHasCompositionTextToTrue(); |
4350 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_call, processes_[index], | 4346 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_call, processes_[index], |
4351 InputMsg_ImeConfirmComposition::ID)); | 4347 InputMsg_ImeConfirmComposition::ID)); |
4352 } | 4348 } |
4353 } | 4349 } |
4354 | 4350 |
4355 // This test verifies that ui::TextInputClient::ConfirmCompositionText call | 4351 // This test is for ui::TextInputClient::ConfirmCompositionText. |
4356 // leads to IPC message InputMsg_ImeSetComposition being sent to the right | |
4357 // renderer process. | |
4358 TEST_F(InputMethodResultAuraTest, ClearCompositionText) { | 4352 TEST_F(InputMethodResultAuraTest, ClearCompositionText) { |
4359 base::Closure ime_call = | 4353 base::Closure ime_call = |
4360 base::Bind(&ui::TextInputClient::ClearCompositionText, | 4354 base::Bind(&ui::TextInputClient::ClearCompositionText, |
4361 base::Unretained(text_input_client())); | 4355 base::Unretained(text_input_client())); |
4362 for (auto index : active_view_sequence_) { | 4356 for (auto index : active_view_sequence_) { |
4363 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); | 4357 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); |
4364 SetHasCompositionTextToTrue(); | 4358 SetHasCompositionTextToTrue(); |
4365 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_call, processes_[index], | 4359 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_call, processes_[index], |
4366 InputMsg_ImeSetComposition::ID)); | 4360 InputMsg_ImeSetComposition::ID)); |
4367 } | 4361 } |
4368 } | 4362 } |
4369 | 4363 |
4370 // This test verifies that ui::TextInputClient::InsertText call leads to IPC | 4364 // This test is for that ui::TextInputClient::InsertText. |
4371 // message InputMsg_ImeSetComposition being sent to the right renderer process. | |
4372 TEST_F(InputMethodResultAuraTest, InsertText) { | 4365 TEST_F(InputMethodResultAuraTest, InsertText) { |
4373 base::Closure ime_call = | 4366 base::Closure ime_call = |
4374 base::Bind(&ui::TextInputClient::InsertText, | 4367 base::Bind(&ui::TextInputClient::InsertText, |
4375 base::Unretained(text_input_client()), base::string16()); | 4368 base::Unretained(text_input_client()), base::string16()); |
4376 for (auto index : active_view_sequence_) { | 4369 for (auto index : active_view_sequence_) { |
4377 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); | 4370 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); |
4378 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_call, processes_[index], | 4371 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_call, processes_[index], |
4379 InputMsg_ImeConfirmComposition::ID)); | 4372 InputMsg_ImeConfirmComposition::ID)); |
4380 } | 4373 } |
4381 } | 4374 } |
4382 | 4375 |
4383 // This test makes a specific view active and then forces the tab's view end the | 4376 // This test is for RenderWidgetHostViewAura::FinishImeCompositionSession which |
4384 // current IME composition session by sending out an IME IPC to confirm | 4377 // is in response to a mouse click during an ongoing composition. |
4385 // composition. The test then verifies that the message is sent | |
4386 // to the active widget's process. | |
4387 TEST_F(InputMethodResultAuraTest, FinishImeCompositionSession) { | 4378 TEST_F(InputMethodResultAuraTest, FinishImeCompositionSession) { |
4388 base::Closure ime_finish_session_call = | 4379 base::Closure ime_finish_session_call = |
4389 base::Bind(&RenderWidgetHostViewAura::FinishImeCompositionSession, | 4380 base::Bind(&RenderWidgetHostViewAura::FinishImeCompositionSession, |
4390 base::Unretained(tab_view())); | 4381 base::Unretained(tab_view())); |
4391 for (auto index : active_view_sequence_) { | 4382 for (auto index : active_view_sequence_) { |
4392 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); | 4383 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); |
4393 SetHasCompositionTextToTrue(); | 4384 SetHasCompositionTextToTrue(); |
4394 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_finish_session_call, | 4385 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_finish_session_call, |
4395 processes_[index], | 4386 processes_[index], |
4396 InputMsg_ImeConfirmComposition::ID)); | 4387 InputMsg_ImeConfirmComposition::ID)); |
4397 } | 4388 } |
4398 } | 4389 } |
4399 | 4390 |
| 4391 // This test is for ui::TextInputClient::ChangeTextDirectionAndLayoutAlignment. |
| 4392 TEST_F(InputMethodResultAuraTest, ChangeTextDirectionAndLayoutAlignment) { |
| 4393 base::Closure ime_finish_session_call = base::Bind( |
| 4394 base::IgnoreResult( |
| 4395 &RenderWidgetHostViewAura::ChangeTextDirectionAndLayoutAlignment), |
| 4396 base::Unretained(tab_view()), base::i18n::LEFT_TO_RIGHT); |
| 4397 for (auto index : active_view_sequence_) { |
| 4398 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); |
| 4399 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_finish_session_call, |
| 4400 processes_[index], |
| 4401 ViewMsg_SetTextDirection::ID)); |
| 4402 } |
| 4403 } |
| 4404 |
4400 // A class of tests which verify the correctness of some tracked IME related | 4405 // A class of tests which verify the correctness of some tracked IME related |
4401 // state at the browser side, e.g., caret bounds. | 4406 // state at the browser side. Each test verifies the correctness tracking for |
| 4407 // one specific state. To do so, the views are activated in a predetermined |
| 4408 // sequence and each time, the IPC call for the corresponding state is simulated |
| 4409 // through calling the method on the view. Then the test verifies that the value |
| 4410 // returned by the view or ui::TextInputClient is the expected value from IPC. |
4402 class InputMethodStateAuraTest : public InputMethodAuraTestBase { | 4411 class InputMethodStateAuraTest : public InputMethodAuraTestBase { |
4403 public: | 4412 public: |
4404 InputMethodStateAuraTest() {} | 4413 InputMethodStateAuraTest() {} |
4405 ~InputMethodStateAuraTest() override {} | 4414 ~InputMethodStateAuraTest() override {} |
4406 | 4415 |
4407 protected: | 4416 protected: |
4408 gfx::SelectionBound GetSelectionBoundFromRect(const gfx::Rect& rect) { | 4417 gfx::SelectionBound GetSelectionBoundFromRect(const gfx::Rect& rect) { |
4409 gfx::SelectionBound bound; | 4418 gfx::SelectionBound bound; |
4410 bound.SetEdge(gfx::PointF(rect.origin()), gfx::PointF(rect.bottom_left())); | 4419 bound.SetEdge(gfx::PointF(rect.origin()), gfx::PointF(rect.bottom_left())); |
4411 return bound; | 4420 return bound; |
4412 } | 4421 } |
4413 | 4422 |
4414 gfx::Rect TransformRectToViewsRootCoordSpace(const gfx::Rect rect, | 4423 gfx::Rect TransformRectToViewsRootCoordSpace(const gfx::Rect rect, |
4415 RenderWidgetHostView* view) { | 4424 RenderWidgetHostView* view) { |
4416 return gfx::Rect(view->TransformPointToRootCoordSpace(rect.origin()), | 4425 return gfx::Rect(view->TransformPointToRootCoordSpace(rect.origin()), |
4417 rect.size()); | 4426 rect.size()); |
4418 } | 4427 } |
4419 | 4428 |
4420 private: | 4429 private: |
4421 DISALLOW_COPY_AND_ASSIGN(InputMethodStateAuraTest); | 4430 DISALLOW_COPY_AND_ASSIGN(InputMethodStateAuraTest); |
4422 }; | 4431 }; |
4423 | 4432 |
4424 // This test activates the views on the tab according to a predefined order and | 4433 // This test is for caret bounds which are calculated based on the tracked value |
4425 // for each tab, simulates a selection bounds changed call. Then it verifies | 4434 // for selection bounds. |
4426 // that the caret bounds reported by the TextInputClient match those reported | |
4427 // for the active view. | |
4428 TEST_F(InputMethodStateAuraTest, GetCaretBounds) { | 4435 TEST_F(InputMethodStateAuraTest, GetCaretBounds) { |
4429 ViewHostMsg_SelectionBounds_Params params; | 4436 ViewHostMsg_SelectionBounds_Params params; |
4430 params.is_anchor_first = true; | 4437 params.is_anchor_first = true; |
4431 params.anchor_dir = blink::WebTextDirectionLeftToRight; | 4438 params.anchor_dir = blink::WebTextDirectionLeftToRight; |
4432 params.focus_dir = blink::WebTextDirectionLeftToRight; | 4439 params.focus_dir = blink::WebTextDirectionLeftToRight; |
4433 params.anchor_rect = gfx::Rect(0, 0, 10, 10); | 4440 params.anchor_rect = gfx::Rect(0, 0, 10, 10); |
4434 for (auto index : active_view_sequence_) { | 4441 for (auto index : active_view_sequence_) { |
4435 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); | 4442 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); |
4436 params.focus_rect = gfx::Rect(10 + index, 10 + index, 10, 10); | 4443 params.focus_rect = gfx::Rect(10 + index, 10 + index, 10, 10); |
4437 views_[index]->SelectionBoundsChanged(params); | 4444 views_[index]->SelectionBoundsChanged(params); |
4438 | 4445 |
4439 // Calculate the bounds. | 4446 // Calculate the bounds. |
4440 gfx::SelectionBound anchor_bound = GetSelectionBoundFromRect( | 4447 gfx::SelectionBound anchor_bound = GetSelectionBoundFromRect( |
4441 TransformRectToViewsRootCoordSpace(params.anchor_rect, views_[index])); | 4448 TransformRectToViewsRootCoordSpace(params.anchor_rect, views_[index])); |
4442 gfx::SelectionBound focus_bound = GetSelectionBoundFromRect( | 4449 gfx::SelectionBound focus_bound = GetSelectionBoundFromRect( |
4443 TransformRectToViewsRootCoordSpace(params.focus_rect, views_[index])); | 4450 TransformRectToViewsRootCoordSpace(params.focus_rect, views_[index])); |
4444 anchor_bound.set_type(gfx::SelectionBound::LEFT); | 4451 anchor_bound.set_type(gfx::SelectionBound::LEFT); |
4445 focus_bound.set_type(gfx::SelectionBound::RIGHT); | 4452 focus_bound.set_type(gfx::SelectionBound::RIGHT); |
4446 gfx::Rect measured_rect = | 4453 gfx::Rect measured_rect = |
4447 gfx::RectBetweenSelectionBounds(anchor_bound, focus_bound); | 4454 gfx::RectBetweenSelectionBounds(anchor_bound, focus_bound); |
4448 | 4455 |
4449 EXPECT_EQ(measured_rect, text_input_client()->GetCaretBounds()); | 4456 EXPECT_EQ(measured_rect, text_input_client()->GetCaretBounds()); |
4450 } | 4457 } |
4451 } | 4458 } |
4452 | 4459 |
4453 // This test activates child frames in a specific sequence and changes their | 4460 // This test is for composition character bounds. |
4454 // composition range. Then it verifies that the ui::TextInputClient returns the | |
4455 // correct character bound at the given indices. | |
4456 TEST_F(InputMethodStateAuraTest, GetCompositionCharacterBounds) { | 4461 TEST_F(InputMethodStateAuraTest, GetCompositionCharacterBounds) { |
4457 gfx::Rect bound; | 4462 gfx::Rect bound; |
4458 // Initially, there should be no bounds. | 4463 // Initially, there should be no bounds. |
4459 EXPECT_FALSE(text_input_client()->GetCompositionCharacterBounds(0, &bound)); | 4464 EXPECT_FALSE(text_input_client()->GetCompositionCharacterBounds(0, &bound)); |
4460 for (auto index : active_view_sequence_) { | 4465 for (auto index : active_view_sequence_) { |
4461 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); | 4466 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); |
4462 // Simulate an IPC to set character bounds for the view. | 4467 // Simulate an IPC to set character bounds for the view. |
4463 views_[index]->ImeCompositionRangeChanged(gfx::Range(), | 4468 views_[index]->ImeCompositionRangeChanged(gfx::Range(), |
4464 {gfx::Rect(1, 2, 3, 4 + index)}); | 4469 {gfx::Rect(1, 2, 3, 4 + index)}); |
4465 | 4470 |
4466 // No bounds at index 1. | 4471 // No bounds at index 1. |
4467 EXPECT_FALSE(text_input_client()->GetCompositionCharacterBounds(1, &bound)); | 4472 EXPECT_FALSE(text_input_client()->GetCompositionCharacterBounds(1, &bound)); |
4468 | 4473 |
4469 // Valid bound at index 0. | 4474 // Valid bound at index 0. |
4470 EXPECT_TRUE(text_input_client()->GetCompositionCharacterBounds(0, &bound)); | 4475 EXPECT_TRUE(text_input_client()->GetCompositionCharacterBounds(0, &bound)); |
4471 EXPECT_EQ(4 + (int)index, bound.height()); | 4476 EXPECT_EQ(4 + (int)index, bound.height()); |
4472 } | 4477 } |
4473 } | 4478 } |
4474 | 4479 |
4475 } // namespace content | 4480 } // namespace content |
OLD | NEW |