| 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 4476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4487 } | 4487 } |
| 4488 } | 4488 } |
| 4489 | 4489 |
| 4490 // This test is for selected text. | 4490 // This test is for selected text. |
| 4491 TEST_F(InputMethodStateAuraTest, GetSelectedText) { | 4491 TEST_F(InputMethodStateAuraTest, GetSelectedText) { |
| 4492 base::string16 text = base::ASCIIToUTF16("some text of length 22"); | 4492 base::string16 text = base::ASCIIToUTF16("some text of length 22"); |
| 4493 size_t offset = 0U; | 4493 size_t offset = 0U; |
| 4494 gfx::Range selection_range(20, 21); | 4494 gfx::Range selection_range(20, 21); |
| 4495 | 4495 |
| 4496 for (auto index : active_view_sequence_) { | 4496 for (auto index : active_view_sequence_) { |
| 4497 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); | 4497 render_widget_host_delegate()->set_focused_widget( |
| 4498 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); |
| 4498 views_[index]->SelectionChanged(text, offset, selection_range); | 4499 views_[index]->SelectionChanged(text, offset, selection_range); |
| 4499 base::string16 expected_text = text.substr( | 4500 base::string16 expected_text = text.substr( |
| 4500 selection_range.GetMin() - offset, selection_range.length()); | 4501 selection_range.GetMin() - offset, selection_range.length()); |
| 4501 | 4502 |
| 4502 EXPECT_EQ(expected_text, views_[index]->GetSelectedText()); | 4503 EXPECT_EQ(expected_text, views_[index]->GetSelectedText()); |
| 4503 | 4504 |
| 4504 // Changing offset to make sure that the next view has a different text | 4505 // Changing offset to make sure that the next view has a different text |
| 4505 // selection. | 4506 // selection. |
| 4506 offset++; | 4507 offset++; |
| 4507 } | 4508 } |
| 4508 } | 4509 } |
| 4509 | 4510 |
| 4510 // This test is for text range. | 4511 // This test is for text range. |
| 4511 TEST_F(InputMethodStateAuraTest, GetTextRange) { | 4512 TEST_F(InputMethodStateAuraTest, GetTextRange) { |
| 4512 base::string16 text = base::ASCIIToUTF16("some text of length 22"); | 4513 base::string16 text = base::ASCIIToUTF16("some text of length 22"); |
| 4513 size_t offset = 0U; | 4514 size_t offset = 0U; |
| 4514 gfx::Range selection_range; | 4515 gfx::Range selection_range; |
| 4515 | 4516 |
| 4516 for (auto index : active_view_sequence_) { | 4517 for (auto index : active_view_sequence_) { |
| 4517 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); | 4518 render_widget_host_delegate()->set_focused_widget( |
| 4519 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); |
| 4518 gfx::Range expected_range(offset, offset + text.length()); | 4520 gfx::Range expected_range(offset, offset + text.length()); |
| 4519 views_[index]->SelectionChanged(text, offset, selection_range); | 4521 views_[index]->SelectionChanged(text, offset, selection_range); |
| 4520 gfx::Range range_from_client; | 4522 gfx::Range range_from_client; |
| 4521 | 4523 |
| 4522 // For aura this always returns true. | 4524 // For aura this always returns true. |
| 4523 EXPECT_TRUE(text_input_client()->GetTextRange(&range_from_client)); | 4525 EXPECT_TRUE(text_input_client()->GetTextRange(&range_from_client)); |
| 4524 EXPECT_EQ(expected_range, range_from_client); | 4526 EXPECT_EQ(expected_range, range_from_client); |
| 4525 | 4527 |
| 4526 // Changing offset to make sure that the next view has a different text | 4528 // Changing offset to make sure that the next view has a different text |
| 4527 // selection. | 4529 // selection. |
| 4528 offset++; | 4530 offset++; |
| 4529 } | 4531 } |
| 4530 } | 4532 } |
| 4531 | 4533 |
| 4532 // This test is for selection range. | 4534 // This test is for selection range. |
| 4533 TEST_F(InputMethodStateAuraTest, GetSelectionRange) { | 4535 TEST_F(InputMethodStateAuraTest, GetSelectionRange) { |
| 4534 base::string16 text; | 4536 base::string16 text; |
| 4535 gfx::Range expected_range(0U, 1U); | 4537 gfx::Range expected_range(0U, 1U); |
| 4536 | 4538 |
| 4537 for (auto index : active_view_sequence_) { | 4539 for (auto index : active_view_sequence_) { |
| 4538 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); | 4540 render_widget_host_delegate()->set_focused_widget( |
| 4541 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); |
| 4539 views_[index]->SelectionChanged(text, 0U, expected_range); | 4542 views_[index]->SelectionChanged(text, 0U, expected_range); |
| 4540 gfx::Range range_from_client; | 4543 gfx::Range range_from_client; |
| 4541 | 4544 |
| 4542 // This method always returns true. | 4545 // This method always returns true. |
| 4543 EXPECT_TRUE(text_input_client()->GetSelectionRange(&range_from_client)); | 4546 EXPECT_TRUE(text_input_client()->GetSelectionRange(&range_from_client)); |
| 4544 EXPECT_EQ(expected_range, range_from_client); | 4547 EXPECT_EQ(expected_range, range_from_client); |
| 4545 | 4548 |
| 4546 // Changing range to make sure that the next view has a different text | 4549 // Changing range to make sure that the next view has a different text |
| 4547 // selection. | 4550 // selection. |
| 4548 expected_range.set_end(expected_range.end() + 1U); | 4551 expected_range.set_end(expected_range.end() + 1U); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 4570 | 4573 |
| 4571 // Retrieve the selected text from clipboard and verify it is as expected. | 4574 // Retrieve the selected text from clipboard and verify it is as expected. |
| 4572 base::string16 result_text; | 4575 base::string16 result_text; |
| 4573 clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &result_text); | 4576 clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &result_text); |
| 4574 EXPECT_EQ(expected_text, result_text); | 4577 EXPECT_EQ(expected_text, result_text); |
| 4575 } | 4578 } |
| 4576 } | 4579 } |
| 4577 #endif | 4580 #endif |
| 4578 | 4581 |
| 4579 } // namespace content | 4582 } // namespace content |
| OLD | NEW |