Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(822)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura_unittest.cc

Issue 2130133004: Tracking text selection on the browser side in OOPIF. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added an interactive ui test Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 4230 matching lines...) Expand 10 before | Expand all | Expand 10 after
4241 for (auto index : active_view_sequence_) { 4241 for (auto index : active_view_sequence_) {
4242 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); 4242 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT);
4243 SetHasCompositionTextToTrue(); 4243 SetHasCompositionTextToTrue();
4244 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_finish_session_call, 4244 EXPECT_TRUE(!!RunAndReturnIPCSent(ime_finish_session_call,
4245 processes_[index], 4245 processes_[index],
4246 InputMsg_ImeConfirmComposition::ID)); 4246 InputMsg_ImeConfirmComposition::ID));
4247 } 4247 }
4248 } 4248 }
4249 4249
4250 // A class of tests which verify the correctness of some tracked IME related 4250 // A class of tests which verify the correctness of some tracked IME related
4251 // state at the browser side, e.g., caret bounds. 4251 // state at the browser side, e.g., caret bounds. In each test, the views are
4252 // activated according to a predefined sequence. Then the IME state for the view
4253 // is modified by invoking some method on the view. The test then verifies that
4254 // the reported state from ui::TextInputClient or the view itself matches the
4255 // expected value.
4252 class InputMethodStateAuraTest : public InputMethodAuraTestBase { 4256 class InputMethodStateAuraTest : public InputMethodAuraTestBase {
4253 public: 4257 public:
4254 InputMethodStateAuraTest() {} 4258 InputMethodStateAuraTest() {}
4255 ~InputMethodStateAuraTest() override {} 4259 ~InputMethodStateAuraTest() override {}
4256 4260
4257 protected: 4261 protected:
4258 gfx::SelectionBound GetSelectionBoundFromRect(const gfx::Rect& rect) { 4262 gfx::SelectionBound GetSelectionBoundFromRect(const gfx::Rect& rect) {
4259 gfx::SelectionBound bound; 4263 gfx::SelectionBound bound;
4260 bound.SetEdge(gfx::PointF(rect.origin()), gfx::PointF(rect.bottom_left())); 4264 bound.SetEdge(gfx::PointF(rect.origin()), gfx::PointF(rect.bottom_left()));
4261 return bound; 4265 return bound;
4262 } 4266 }
4263 4267
4264 gfx::Rect TransformRectToViewsRootCoordSpace(const gfx::Rect rect, 4268 gfx::Rect TransformRectToViewsRootCoordSpace(const gfx::Rect rect,
4265 RenderWidgetHostView* view) { 4269 RenderWidgetHostView* view) {
4266 return gfx::Rect(view->TransformPointToRootCoordSpace(rect.origin()), 4270 return gfx::Rect(view->TransformPointToRootCoordSpace(rect.origin()),
4267 rect.size()); 4271 rect.size());
4268 } 4272 }
4269 4273
4270 private: 4274 private:
4271 DISALLOW_COPY_AND_ASSIGN(InputMethodStateAuraTest); 4275 DISALLOW_COPY_AND_ASSIGN(InputMethodStateAuraTest);
4272 }; 4276 };
4273 4277
4274 // This test activates the views on the tab according to a predefined order and 4278 // This test verifies the correctness of caret bounds after a change in the
4275 // for each tab, simulates a selection bounds changed call. Then it verifies 4279 // selection bounds for the view.
4276 // that the caret bounds reported by the TextInputClient match those reported
4277 // for the active view.
4278 TEST_F(InputMethodStateAuraTest, GetCaretBounds) { 4280 TEST_F(InputMethodStateAuraTest, GetCaretBounds) {
4279 ViewHostMsg_SelectionBounds_Params params; 4281 ViewHostMsg_SelectionBounds_Params params;
4280 params.is_anchor_first = true; 4282 params.is_anchor_first = true;
4281 params.anchor_dir = blink::WebTextDirectionLeftToRight; 4283 params.anchor_dir = blink::WebTextDirectionLeftToRight;
4282 params.focus_dir = blink::WebTextDirectionLeftToRight; 4284 params.focus_dir = blink::WebTextDirectionLeftToRight;
4283 params.anchor_rect = gfx::Rect(0, 0, 10, 10); 4285 params.anchor_rect = gfx::Rect(0, 0, 10, 10);
4284 for (auto index : active_view_sequence_) { 4286 for (auto index : active_view_sequence_) {
4285 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT); 4287 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT);
4286 params.focus_rect = gfx::Rect(10 + index, 10 + index, 10, 10); 4288 params.focus_rect = gfx::Rect(10 + index, 10 + index, 10, 10);
4287 views_[index]->SelectionBoundsChanged(params); 4289 views_[index]->SelectionBoundsChanged(params);
4288 4290
4289 // Calculate the bounds. 4291 // Calculate the bounds.
4290 gfx::SelectionBound anchor_bound = GetSelectionBoundFromRect( 4292 gfx::SelectionBound anchor_bound = GetSelectionBoundFromRect(
4291 TransformRectToViewsRootCoordSpace(params.anchor_rect, views_[index])); 4293 TransformRectToViewsRootCoordSpace(params.anchor_rect, views_[index]));
4292 gfx::SelectionBound focus_bound = GetSelectionBoundFromRect( 4294 gfx::SelectionBound focus_bound = GetSelectionBoundFromRect(
4293 TransformRectToViewsRootCoordSpace(params.focus_rect, views_[index])); 4295 TransformRectToViewsRootCoordSpace(params.focus_rect, views_[index]));
4294 anchor_bound.set_type(gfx::SelectionBound::LEFT); 4296 anchor_bound.set_type(gfx::SelectionBound::LEFT);
4295 focus_bound.set_type(gfx::SelectionBound::RIGHT); 4297 focus_bound.set_type(gfx::SelectionBound::RIGHT);
4296 gfx::Rect measured_rect = 4298 gfx::Rect measured_rect =
4297 gfx::RectBetweenSelectionBounds(anchor_bound, focus_bound); 4299 gfx::RectBetweenSelectionBounds(anchor_bound, focus_bound);
4298 4300
4299 EXPECT_EQ(measured_rect, text_input_client()->GetCaretBounds()); 4301 EXPECT_EQ(measured_rect, text_input_client()->GetCaretBounds());
4300 } 4302 }
4301 } 4303 }
4302 4304
4305 // This test verifies the correctness of the selected text as reported by the
4306 // view after a text selection change on the view.
4307 TEST_F(InputMethodStateAuraTest, GetSelectedText) {
4308 // Some range in the text that follows.
4309 gfx::Range selection_range(25U, 29U);
4310
4311 // A long text containing selection.
4312 base::string16 text = base::ASCIIToUTF16("this is not a valid statement");
4313 size_t offset = 0U;
4314
4315 for (auto index : active_view_sequence_) {
4316 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT);
4317 base::string16 expected_text = text.substr(
4318 selection_range.GetMin() - offset, selection_range.length());
4319 views_[index]->SelectionChanged(text, offset, selection_range);
4320
4321 // Casting to the base class since GetSelectedText() belongs to it.
4322 RenderWidgetHostView* rwhv = views_[index];
4323 EXPECT_EQ(expected_text, rwhv->GetSelectedText());
4324
4325 // Changing offset to make sure that the next view has a different text
4326 // selection.
4327 offset++;
4328 }
4329 }
4330
4331 // This test verifies the correctness of the total text range reported by the
4332 // TextInputClient after a view is subject to a change in its text selection.
4333 TEST_F(InputMethodStateAuraTest, GetTextRange) {
4334 base::string16 text = base::ASCIIToUTF16("some text of length 22");
4335 size_t offset = 0U;
4336 gfx::Range selection_range;
4337
4338 for (auto index : active_view_sequence_) {
4339 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT);
4340 gfx::Range expected_range(offset, offset + text.length());
4341 views_[index]->SelectionChanged(text, offset, selection_range);
4342 gfx::Range range_from_client;
4343
4344 // For aura this always returns true.
4345 EXPECT_TRUE(text_input_client()->GetTextRange(&range_from_client));
4346 EXPECT_EQ(expected_range, range_from_client);
4347
4348 // Changing offset to make sure that the next view has a different text
4349 // selection.
4350 offset++;
4351 }
4352 }
4353
4354 // This test verifies the correctness of the selection range reported by the
4355 // TextInputClient after a view is subject to a change in its text selection.
4356 TEST_F(InputMethodStateAuraTest, GetSelectionRange) {
4357 base::string16 text;
4358 gfx::Range expected_range(0U, 1U);
4359
4360 for (auto index : active_view_sequence_) {
4361 ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT);
4362 views_[index]->SelectionChanged(text, 0U, expected_range);
4363 gfx::Range range_from_client;
4364
4365 // This method always returns true.
4366 EXPECT_TRUE(text_input_client()->GetSelectionRange(&range_from_client));
4367 EXPECT_EQ(expected_range, range_from_client);
4368
4369 // Changing range to make sure that the next view has a different text
4370 // selection.
4371 expected_range.set_end(expected_range.end() + 1U);
4372 }
4373 }
4374
4303 } // namespace content 4375 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698