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 4380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4391 for (auto index : active_view_sequence_) { | 4391 for (auto index : active_view_sequence_) { |
4392 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); | 4392 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); |
4393 SetHasCompositionTextToTrue(); | 4393 SetHasCompositionTextToTrue(); |
4394 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_finish_session_call, | 4394 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_finish_session_call, |
4395 processes_[index], | 4395 processes_[index], |
4396 InputMsg_ImeConfirmComposition::ID)); | 4396 InputMsg_ImeConfirmComposition::ID)); |
4397 } | 4397 } |
4398 } | 4398 } |
4399 | 4399 |
4400 // A class of tests which verify the correctness of some tracked IME related | 4400 // A class of tests which verify the correctness of some tracked IME related |
4401 // state at the browser side, e.g., caret bounds. | 4401 // state at the browser side, e.g., caret bounds. In each test, the views are |
4402 // activated according to a predefined sequence. Then the IME state for the view | |
4403 // is modified by invoking some method on the view. The test then verifies that | |
4404 // the reported state from ui::TextInputClient or the view itself matches the | |
4405 // expected value. | |
4402 class InputMethodStateAuraTest : public InputMethodAuraTestBase { | 4406 class InputMethodStateAuraTest : public InputMethodAuraTestBase { |
4403 public: | 4407 public: |
4404 InputMethodStateAuraTest() {} | 4408 InputMethodStateAuraTest() {} |
4405 ~InputMethodStateAuraTest() override {} | 4409 ~InputMethodStateAuraTest() override {} |
4406 | 4410 |
4407 protected: | 4411 protected: |
4408 gfx::SelectionBound GetSelectionBoundFromRect(const gfx::Rect& rect) { | 4412 gfx::SelectionBound GetSelectionBoundFromRect(const gfx::Rect& rect) { |
4409 gfx::SelectionBound bound; | 4413 gfx::SelectionBound bound; |
4410 bound.SetEdge(gfx::PointF(rect.origin()), gfx::PointF(rect.bottom_left())); | 4414 bound.SetEdge(gfx::PointF(rect.origin()), gfx::PointF(rect.bottom_left())); |
4411 return bound; | 4415 return bound; |
4412 } | 4416 } |
4413 | 4417 |
4414 gfx::Rect TransformRectToViewsRootCoordSpace(const gfx::Rect rect, | 4418 gfx::Rect TransformRectToViewsRootCoordSpace(const gfx::Rect rect, |
4415 RenderWidgetHostView* view) { | 4419 RenderWidgetHostView* view) { |
4416 return gfx::Rect(view->TransformPointToRootCoordSpace(rect.origin()), | 4420 return gfx::Rect(view->TransformPointToRootCoordSpace(rect.origin()), |
4417 rect.size()); | 4421 rect.size()); |
4418 } | 4422 } |
4419 | 4423 |
4420 private: | 4424 private: |
4421 DISALLOW_COPY_AND_ASSIGN(InputMethodStateAuraTest); | 4425 DISALLOW_COPY_AND_ASSIGN(InputMethodStateAuraTest); |
4422 }; | 4426 }; |
4423 | 4427 |
4424 // This test activates the views on the tab according to a predefined order and | 4428 // This test verifies the correctness of caret bounds after a change in the |
4425 // for each tab, simulates a selection bounds changed call. Then it verifies | 4429 // selection bounds for the view. |
4426 // that the caret bounds reported by the TextInputClient match those reported | |
4427 // for the active view. | |
4428 TEST_F(InputMethodStateAuraTest, GetCaretBounds) { | 4430 TEST_F(InputMethodStateAuraTest, GetCaretBounds) { |
4429 ViewHostMsg_SelectionBounds_Params params; | 4431 ViewHostMsg_SelectionBounds_Params params; |
4430 params.is_anchor_first = true; | 4432 params.is_anchor_first = true; |
4431 params.anchor_dir = blink::WebTextDirectionLeftToRight; | 4433 params.anchor_dir = blink::WebTextDirectionLeftToRight; |
4432 params.focus_dir = blink::WebTextDirectionLeftToRight; | 4434 params.focus_dir = blink::WebTextDirectionLeftToRight; |
4433 params.anchor_rect = gfx::Rect(0, 0, 10, 10); | 4435 params.anchor_rect = gfx::Rect(0, 0, 10, 10); |
4434 for (auto index : active_view_sequence_) { | 4436 for (auto index : active_view_sequence_) { |
4435 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); | 4437 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); |
4436 params.focus_rect = gfx::Rect(10 + index, 10 + index, 10, 10); | 4438 params.focus_rect = gfx::Rect(10 + index, 10 + index, 10, 10); |
4437 views_[index]->SelectionBoundsChanged(params); | 4439 views_[index]->SelectionBoundsChanged(params); |
(...skipping 27 matching lines...) Expand all Loading... | |
4465 | 4467 |
4466 // No bounds at index 1. | 4468 // No bounds at index 1. |
4467 EXPECT_FALSE(text_input_client()->GetCompositionCharacterBounds(1, &bound)); | 4469 EXPECT_FALSE(text_input_client()->GetCompositionCharacterBounds(1, &bound)); |
4468 | 4470 |
4469 // Valid bound at index 0. | 4471 // Valid bound at index 0. |
4470 EXPECT_TRUE(text_input_client()->GetCompositionCharacterBounds(0, &bound)); | 4472 EXPECT_TRUE(text_input_client()->GetCompositionCharacterBounds(0, &bound)); |
4471 EXPECT_EQ(4 + (int)index, bound.height()); | 4473 EXPECT_EQ(4 + (int)index, bound.height()); |
4472 } | 4474 } |
4473 } | 4475 } |
4474 | 4476 |
4477 // This test verifies the correctness of the selected text reported by the | |
4478 // RenderWidgetHostView after the view is subject to a change in its text | |
4479 // selection. | |
4480 TEST_F(InputMethodStateAuraTest, GetSelectedText) { | |
EhsanK
2016/07/18 15:21:29
I added this again since we still have a (now doci
| |
4481 base::string16 text = base::ASCIIToUTF16("some text of length 22"); | |
4482 size_t offset = 0U; | |
4483 gfx::Range selection_range(20, 21); | |
4484 | |
4485 for (auto index : active_view_sequence_) { | |
4486 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); | |
4487 views_[index]->SelectionChanged(text, offset, selection_range); | |
4488 base::string16 expected_text = text.substr( | |
4489 selection_range.GetMin() - offset, selection_range.length()); | |
4490 | |
4491 EXPECT_EQ(expected_text, views_[index]->GetSelectedText()); | |
4492 | |
4493 // Changing offset to make sure that the next view has a different text | |
4494 // selection. | |
4495 offset++; | |
4496 } | |
4497 } | |
4498 | |
4499 // This test verifies the correctness of the total text range reported by the | |
4500 // TextInputClient after a view is subject to a change in its text selection. | |
4501 TEST_F(InputMethodStateAuraTest, GetTextRange) { | |
4502 base::string16 text = base::ASCIIToUTF16("some text of length 22"); | |
4503 size_t offset = 0U; | |
4504 gfx::Range selection_range; | |
4505 | |
4506 for (auto index : active_view_sequence_) { | |
4507 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); | |
4508 gfx::Range expected_range(offset, offset + text.length()); | |
4509 views_[index]->SelectionChanged(text, offset, selection_range); | |
4510 gfx::Range range_from_client; | |
4511 | |
4512 // For aura this always returns true. | |
4513 EXPECT_TRUE(text_input_client()->GetTextRange(&range_from_client)); | |
4514 EXPECT_EQ(expected_range, range_from_client); | |
4515 | |
4516 // Changing offset to make sure that the next view has a different text | |
4517 // selection. | |
4518 offset++; | |
4519 } | |
4520 } | |
4521 | |
4522 // This test verifies the correctness of the selection range reported by the | |
4523 // TextInputClient after a view is subject to a change in its text selection. | |
4524 TEST_F(InputMethodStateAuraTest, GetSelectionRange) { | |
4525 base::string16 text; | |
4526 gfx::Range expected_range(0U, 1U); | |
4527 | |
4528 for (auto index : active_view_sequence_) { | |
4529 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); | |
4530 views_[index]->SelectionChanged(text, 0U, expected_range); | |
4531 gfx::Range range_from_client; | |
4532 | |
4533 // This method always returns true. | |
4534 EXPECT_TRUE(text_input_client()->GetSelectionRange(&range_from_client)); | |
4535 EXPECT_EQ(expected_range, range_from_client); | |
4536 | |
4537 // Changing range to make sure that the next view has a different text | |
4538 // selection. | |
4539 expected_range.set_end(expected_range.end() + 1U); | |
4540 } | |
4541 } | |
4542 | |
4475 } // namespace content | 4543 } // namespace content |
OLD | NEW |