| 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 5725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5736 | 5736 |
| 5737 // This test is for selected text. | 5737 // This test is for selected text. |
| 5738 TEST_F(InputMethodStateAuraTest, GetSelectedText) { | 5738 TEST_F(InputMethodStateAuraTest, GetSelectedText) { |
| 5739 base::string16 text = base::ASCIIToUTF16("some text of length 22"); | 5739 base::string16 text = base::ASCIIToUTF16("some text of length 22"); |
| 5740 size_t offset = 0U; | 5740 size_t offset = 0U; |
| 5741 gfx::Range selection_range(20, 21); | 5741 gfx::Range selection_range(20, 21); |
| 5742 | 5742 |
| 5743 for (auto index : active_view_sequence_) { | 5743 for (auto index : active_view_sequence_) { |
| 5744 render_widget_host_delegate()->set_focused_widget( | 5744 render_widget_host_delegate()->set_focused_widget( |
| 5745 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); | 5745 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); |
| 5746 views_[index]->SelectionChanged(text, offset, selection_range); | 5746 views_[index]->SelectionChanged(text, offset, selection_range, true); |
| 5747 base::string16 expected_text = text.substr( | 5747 base::string16 expected_text = text.substr( |
| 5748 selection_range.GetMin() - offset, selection_range.length()); | 5748 selection_range.GetMin() - offset, selection_range.length()); |
| 5749 | 5749 |
| 5750 EXPECT_EQ(expected_text, views_[index]->GetSelectedText()); | 5750 EXPECT_EQ(expected_text, views_[index]->GetSelectedText()); |
| 5751 | 5751 |
| 5752 // Changing offset to make sure that the next view has a different text | 5752 // Changing offset to make sure that the next view has a different text |
| 5753 // selection. | 5753 // selection. |
| 5754 offset++; | 5754 offset++; |
| 5755 } | 5755 } |
| 5756 } | 5756 } |
| 5757 | 5757 |
| 5758 // This test is for text range. | 5758 // This test is for text range. |
| 5759 TEST_F(InputMethodStateAuraTest, GetTextRange) { | 5759 TEST_F(InputMethodStateAuraTest, GetTextRange) { |
| 5760 base::string16 text = base::ASCIIToUTF16("some text of length 22"); | 5760 base::string16 text = base::ASCIIToUTF16("some text of length 22"); |
| 5761 size_t offset = 0U; | 5761 size_t offset = 0U; |
| 5762 gfx::Range selection_range; | 5762 gfx::Range selection_range; |
| 5763 | 5763 |
| 5764 for (auto index : active_view_sequence_) { | 5764 for (auto index : active_view_sequence_) { |
| 5765 render_widget_host_delegate()->set_focused_widget( | 5765 render_widget_host_delegate()->set_focused_widget( |
| 5766 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); | 5766 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); |
| 5767 gfx::Range expected_range(offset, offset + text.length()); | 5767 gfx::Range expected_range(offset, offset + text.length()); |
| 5768 views_[index]->SelectionChanged(text, offset, selection_range); | 5768 views_[index]->SelectionChanged(text, offset, selection_range, true); |
| 5769 gfx::Range range_from_client; | 5769 gfx::Range range_from_client; |
| 5770 | 5770 |
| 5771 // For aura this always returns true. | 5771 // For aura this always returns true. |
| 5772 EXPECT_TRUE(text_input_client()->GetTextRange(&range_from_client)); | 5772 EXPECT_TRUE(text_input_client()->GetTextRange(&range_from_client)); |
| 5773 EXPECT_EQ(expected_range, range_from_client); | 5773 EXPECT_EQ(expected_range, range_from_client); |
| 5774 | 5774 |
| 5775 // Changing offset to make sure that the next view has a different text | 5775 // Changing offset to make sure that the next view has a different text |
| 5776 // selection. | 5776 // selection. |
| 5777 offset++; | 5777 offset++; |
| 5778 } | 5778 } |
| 5779 } | 5779 } |
| 5780 | 5780 |
| 5781 // This test is for selection range. | 5781 // This test is for selection range. |
| 5782 TEST_F(InputMethodStateAuraTest, GetSelectionRange) { | 5782 TEST_F(InputMethodStateAuraTest, GetSelectionRange) { |
| 5783 base::string16 text; | 5783 base::string16 text; |
| 5784 gfx::Range expected_range(0U, 1U); | 5784 gfx::Range expected_range(0U, 1U); |
| 5785 | 5785 |
| 5786 for (auto index : active_view_sequence_) { | 5786 for (auto index : active_view_sequence_) { |
| 5787 render_widget_host_delegate()->set_focused_widget( | 5787 render_widget_host_delegate()->set_focused_widget( |
| 5788 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); | 5788 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); |
| 5789 views_[index]->SelectionChanged(text, 0U, expected_range); | 5789 views_[index]->SelectionChanged(text, 0U, expected_range, true); |
| 5790 gfx::Range range_from_client; | 5790 gfx::Range range_from_client; |
| 5791 | 5791 |
| 5792 // This method always returns true. | 5792 // This method always returns true. |
| 5793 EXPECT_TRUE(text_input_client()->GetSelectionRange(&range_from_client)); | 5793 EXPECT_TRUE(text_input_client()->GetSelectionRange(&range_from_client)); |
| 5794 EXPECT_EQ(expected_range, range_from_client); | 5794 EXPECT_EQ(expected_range, range_from_client); |
| 5795 | 5795 |
| 5796 // Changing range to make sure that the next view has a different text | 5796 // Changing range to make sure that the next view has a different text |
| 5797 // selection. | 5797 // selection. |
| 5798 expected_range.set_end(expected_range.end() + 1U); | 5798 expected_range.set_end(expected_range.end() + 1U); |
| 5799 } | 5799 } |
| 5800 } | 5800 } |
| 5801 | 5801 |
| 5802 #if defined(USE_X11) && !defined(OS_CHROMEOS) | 5802 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
| 5803 // This test will verify that after selection, the selected text is written to | 5803 // This test will verify that after selection, the selected text is written to |
| 5804 // the clipboard from the focused widget. | 5804 // the clipboard from the focused widget. |
| 5805 TEST_F(InputMethodStateAuraTest, SelectedTextCopiedToClipboard) { | 5805 TEST_F(InputMethodStateAuraTest, SelectedTextCopiedToClipboard) { |
| 5806 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); | 5806 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); |
| 5807 EXPECT_TRUE(!!clipboard); | 5807 EXPECT_TRUE(!!clipboard); |
| 5808 std::vector<std::string> texts = {"text0", "text1", "text2", "text3"}; | 5808 std::vector<std::string> texts = {"text0", "text1", "text2", "text3"}; |
| 5809 for (auto index : active_view_sequence_) { | 5809 for (auto index : active_view_sequence_) { |
| 5810 clipboard->Clear(ui::CLIPBOARD_TYPE_SELECTION); | 5810 clipboard->Clear(ui::CLIPBOARD_TYPE_SELECTION); |
| 5811 | 5811 |
| 5812 // Focus the corresponding widget. | 5812 // Focus the corresponding widget. |
| 5813 render_widget_host_delegate()->set_focused_widget( | 5813 render_widget_host_delegate()->set_focused_widget( |
| 5814 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); | 5814 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); |
| 5815 | 5815 |
| 5816 // Change the selection of the currently focused widget. It suffices to just | 5816 // Change the selection of the currently focused widget. It suffices to just |
| 5817 // call the method on the view. | 5817 // call the method on the view. |
| 5818 base::string16 expected_text = base::ASCIIToUTF16(texts[index]); | 5818 base::string16 expected_text = base::ASCIIToUTF16(texts[index]); |
| 5819 views_[index]->SelectionChanged(expected_text, 0U, gfx::Range(0, 5)); | 5819 views_[index]->SelectionChanged(expected_text, 0U, gfx::Range(0, 5), true); |
| 5820 | 5820 |
| 5821 // Retrieve the selected text from clipboard and verify it is as expected. | 5821 // Retrieve the selected text from clipboard and verify it is as expected. |
| 5822 base::string16 result_text; | 5822 base::string16 result_text; |
| 5823 clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &result_text); | 5823 clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &result_text); |
| 5824 EXPECT_EQ(expected_text, result_text); | 5824 EXPECT_EQ(expected_text, result_text); |
| 5825 } | 5825 } |
| 5826 } | 5826 } |
| 5827 #endif | 5827 #endif |
| 5828 | 5828 |
| 5829 // This test verifies that when any view on the page cancels an ongoing | 5829 // This test verifies that when any view on the page cancels an ongoing |
| 5830 // composition, the RenderWidgetHostViewAura will receive the notification and | 5830 // composition, the RenderWidgetHostViewAura will receive the notification and |
| 5831 // the current composition is canceled. | 5831 // the current composition is canceled. |
| 5832 TEST_F(InputMethodStateAuraTest, ImeCancelCompositionForAllViews) { | 5832 TEST_F(InputMethodStateAuraTest, ImeCancelCompositionForAllViews) { |
| 5833 for (auto* view : views_) { | 5833 for (auto* view : views_) { |
| 5834 ActivateViewForTextInputManager(view, ui::TEXT_INPUT_TYPE_TEXT); | 5834 ActivateViewForTextInputManager(view, ui::TEXT_INPUT_TYPE_TEXT); |
| 5835 // There is no composition in the beginning. | 5835 // There is no composition in the beginning. |
| 5836 EXPECT_FALSE(has_composition_text()); | 5836 EXPECT_FALSE(has_composition_text()); |
| 5837 SetHasCompositionTextToTrue(); | 5837 SetHasCompositionTextToTrue(); |
| 5838 view->ImeCancelComposition(); | 5838 view->ImeCancelComposition(); |
| 5839 // The composition must have been canceled. | 5839 // The composition must have been canceled. |
| 5840 EXPECT_FALSE(has_composition_text()); | 5840 EXPECT_FALSE(has_composition_text()); |
| 5841 } | 5841 } |
| 5842 } | 5842 } |
| 5843 | 5843 |
| 5844 } // namespace content | 5844 } // namespace content |
| OLD | NEW |