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 6124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6135 | 6135 |
6136 // This test is for selected text. | 6136 // This test is for selected text. |
6137 TEST_F(InputMethodStateAuraTest, GetSelectedText) { | 6137 TEST_F(InputMethodStateAuraTest, GetSelectedText) { |
6138 base::string16 text = base::ASCIIToUTF16("some text of length 22"); | 6138 base::string16 text = base::ASCIIToUTF16("some text of length 22"); |
6139 size_t offset = 0U; | 6139 size_t offset = 0U; |
6140 gfx::Range selection_range(20, 21); | 6140 gfx::Range selection_range(20, 21); |
6141 | 6141 |
6142 for (auto index : active_view_sequence_) { | 6142 for (auto index : active_view_sequence_) { |
6143 render_widget_host_delegate()->set_focused_widget( | 6143 render_widget_host_delegate()->set_focused_widget( |
6144 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); | 6144 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); |
6145 views_[index]->SelectionChanged(text, offset, selection_range); | 6145 views_[index]->SelectionChanged(text, offset, selection_range, true); |
6146 base::string16 expected_text = text.substr( | 6146 base::string16 expected_text = text.substr( |
6147 selection_range.GetMin() - offset, selection_range.length()); | 6147 selection_range.GetMin() - offset, selection_range.length()); |
6148 | 6148 |
6149 EXPECT_EQ(expected_text, views_[index]->GetSelectedText()); | 6149 EXPECT_EQ(expected_text, views_[index]->GetSelectedText()); |
6150 | 6150 |
6151 // Changing offset to make sure that the next view has a different text | 6151 // Changing offset to make sure that the next view has a different text |
6152 // selection. | 6152 // selection. |
6153 offset++; | 6153 offset++; |
6154 } | 6154 } |
6155 } | 6155 } |
6156 | 6156 |
6157 // This test is for text range. | 6157 // This test is for text range. |
6158 TEST_F(InputMethodStateAuraTest, GetTextRange) { | 6158 TEST_F(InputMethodStateAuraTest, GetTextRange) { |
6159 base::string16 text = base::ASCIIToUTF16("some text of length 22"); | 6159 base::string16 text = base::ASCIIToUTF16("some text of length 22"); |
6160 size_t offset = 0U; | 6160 size_t offset = 0U; |
6161 gfx::Range selection_range; | 6161 gfx::Range selection_range; |
6162 | 6162 |
6163 for (auto index : active_view_sequence_) { | 6163 for (auto index : active_view_sequence_) { |
6164 render_widget_host_delegate()->set_focused_widget( | 6164 render_widget_host_delegate()->set_focused_widget( |
6165 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); | 6165 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); |
6166 gfx::Range expected_range(offset, offset + text.length()); | 6166 gfx::Range expected_range(offset, offset + text.length()); |
6167 views_[index]->SelectionChanged(text, offset, selection_range); | 6167 views_[index]->SelectionChanged(text, offset, selection_range, true); |
6168 gfx::Range range_from_client; | 6168 gfx::Range range_from_client; |
6169 | 6169 |
6170 // For aura this always returns true. | 6170 // For aura this always returns true. |
6171 EXPECT_TRUE(text_input_client()->GetTextRange(&range_from_client)); | 6171 EXPECT_TRUE(text_input_client()->GetTextRange(&range_from_client)); |
6172 EXPECT_EQ(expected_range, range_from_client); | 6172 EXPECT_EQ(expected_range, range_from_client); |
6173 | 6173 |
6174 // Changing offset to make sure that the next view has a different text | 6174 // Changing offset to make sure that the next view has a different text |
6175 // selection. | 6175 // selection. |
6176 offset++; | 6176 offset++; |
6177 } | 6177 } |
6178 } | 6178 } |
6179 | 6179 |
6180 // This test is for selection range. | 6180 // This test is for selection range. |
6181 TEST_F(InputMethodStateAuraTest, GetSelectionRange) { | 6181 TEST_F(InputMethodStateAuraTest, GetSelectionRange) { |
6182 base::string16 text; | 6182 base::string16 text; |
6183 gfx::Range expected_range(0U, 1U); | 6183 gfx::Range expected_range(0U, 1U); |
6184 | 6184 |
6185 for (auto index : active_view_sequence_) { | 6185 for (auto index : active_view_sequence_) { |
6186 render_widget_host_delegate()->set_focused_widget( | 6186 render_widget_host_delegate()->set_focused_widget( |
6187 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); | 6187 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); |
6188 views_[index]->SelectionChanged(text, 0U, expected_range); | 6188 views_[index]->SelectionChanged(text, 0U, expected_range, true); |
6189 gfx::Range range_from_client; | 6189 gfx::Range range_from_client; |
6190 | 6190 |
6191 // This method always returns true. | 6191 // This method always returns true. |
6192 EXPECT_TRUE(text_input_client()->GetSelectionRange(&range_from_client)); | 6192 EXPECT_TRUE(text_input_client()->GetSelectionRange(&range_from_client)); |
6193 EXPECT_EQ(expected_range, range_from_client); | 6193 EXPECT_EQ(expected_range, range_from_client); |
6194 | 6194 |
6195 // Changing range to make sure that the next view has a different text | 6195 // Changing range to make sure that the next view has a different text |
6196 // selection. | 6196 // selection. |
6197 expected_range.set_end(expected_range.end() + 1U); | 6197 expected_range.set_end(expected_range.end() + 1U); |
6198 } | 6198 } |
6199 } | 6199 } |
6200 | 6200 |
6201 #if defined(USE_X11) && !defined(OS_CHROMEOS) | 6201 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
6202 // This test will verify that after selection, the selected text is written to | 6202 // This test will verify that after selection, the selected text is written to |
6203 // the clipboard from the focused widget. | 6203 // the clipboard from the focused widget. |
6204 TEST_F(InputMethodStateAuraTest, SelectedTextCopiedToClipboard) { | 6204 TEST_F(InputMethodStateAuraTest, SelectedTextCopiedToClipboard) { |
6205 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); | 6205 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); |
6206 EXPECT_TRUE(!!clipboard); | 6206 EXPECT_TRUE(!!clipboard); |
6207 std::vector<std::string> texts = {"text0", "text1", "text2", "text3"}; | 6207 std::vector<std::string> texts = {"text0", "text1", "text2", "text3"}; |
6208 for (auto index : active_view_sequence_) { | 6208 for (auto index : active_view_sequence_) { |
6209 clipboard->Clear(ui::CLIPBOARD_TYPE_SELECTION); | 6209 clipboard->Clear(ui::CLIPBOARD_TYPE_SELECTION); |
6210 | 6210 |
6211 // Focus the corresponding widget. | 6211 // Focus the corresponding widget. |
6212 render_widget_host_delegate()->set_focused_widget( | 6212 render_widget_host_delegate()->set_focused_widget( |
6213 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); | 6213 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); |
6214 | 6214 |
6215 // Change the selection of the currently focused widget. It suffices to just | 6215 // Change the selection of the currently focused widget. It suffices to just |
6216 // call the method on the view. | 6216 // call the method on the view. |
6217 base::string16 expected_text = base::ASCIIToUTF16(texts[index]); | 6217 base::string16 expected_text = base::ASCIIToUTF16(texts[index]); |
6218 views_[index]->SelectionChanged(expected_text, 0U, gfx::Range(0, 5)); | 6218 views_[index]->SelectionChanged(expected_text, 0U, gfx::Range(0, 5), true); |
6219 | 6219 |
6220 // Retrieve the selected text from clipboard and verify it is as expected. | 6220 // Retrieve the selected text from clipboard and verify it is as expected. |
6221 base::string16 result_text; | 6221 base::string16 result_text; |
6222 clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &result_text); | 6222 clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &result_text); |
6223 EXPECT_EQ(expected_text, result_text); | 6223 EXPECT_EQ(expected_text, result_text); |
6224 } | 6224 } |
6225 } | 6225 } |
6226 #endif | 6226 #endif |
6227 | 6227 |
6228 // This test verifies that when any view on the page cancels an ongoing | 6228 // This test verifies that when any view on the page cancels an ongoing |
6229 // composition, the RenderWidgetHostViewAura will receive the notification and | 6229 // composition, the RenderWidgetHostViewAura will receive the notification and |
6230 // the current composition is canceled. | 6230 // the current composition is canceled. |
6231 TEST_F(InputMethodStateAuraTest, ImeCancelCompositionForAllViews) { | 6231 TEST_F(InputMethodStateAuraTest, ImeCancelCompositionForAllViews) { |
6232 for (auto* view : views_) { | 6232 for (auto* view : views_) { |
6233 ActivateViewForTextInputManager(view, ui::TEXT_INPUT_TYPE_TEXT); | 6233 ActivateViewForTextInputManager(view, ui::TEXT_INPUT_TYPE_TEXT); |
6234 // There is no composition in the beginning. | 6234 // There is no composition in the beginning. |
6235 EXPECT_FALSE(has_composition_text()); | 6235 EXPECT_FALSE(has_composition_text()); |
6236 SetHasCompositionTextToTrue(); | 6236 SetHasCompositionTextToTrue(); |
6237 view->ImeCancelComposition(); | 6237 view->ImeCancelComposition(); |
6238 // The composition must have been canceled. | 6238 // The composition must have been canceled. |
6239 EXPECT_FALSE(has_composition_text()); | 6239 EXPECT_FALSE(has_composition_text()); |
6240 } | 6240 } |
6241 } | 6241 } |
6242 | 6242 |
6243 } // namespace content | 6243 } // namespace content |
OLD | NEW |