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

Unified 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: Rebased 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/render_widget_host_view_aura_unittest.cc
diff --git a/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc b/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc
index 2c164fbe461c2c257bb6dfabfebfec45d1398d82..5791f7a2d81cba7e1b914889f516d1118bd4de76 100644
--- a/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc
+++ b/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc
@@ -4398,7 +4398,11 @@ TEST_F(InputMethodResultAuraTest, FinishImeCompositionSession) {
}
// A class of tests which verify the correctness of some tracked IME related
-// state at the browser side, e.g., caret bounds.
+// state at the browser side, e.g., caret bounds. In each test, the views are
+// activated according to a predefined sequence. Then the IME state for the view
+// is modified by invoking some method on the view. The test then verifies that
+// the reported state from ui::TextInputClient or the view itself matches the
+// expected value.
class InputMethodStateAuraTest : public InputMethodAuraTestBase {
public:
InputMethodStateAuraTest() {}
@@ -4421,10 +4425,8 @@ class InputMethodStateAuraTest : public InputMethodAuraTestBase {
DISALLOW_COPY_AND_ASSIGN(InputMethodStateAuraTest);
};
-// This test activates the views on the tab according to a predefined order and
-// for each tab, simulates a selection bounds changed call. Then it verifies
-// that the caret bounds reported by the TextInputClient match those reported
-// for the active view.
+// This test verifies the correctness of caret bounds after a change in the
+// selection bounds for the view.
TEST_F(InputMethodStateAuraTest, GetCaretBounds) {
ViewHostMsg_SelectionBounds_Params params;
params.is_anchor_first = true;
@@ -4472,4 +4474,70 @@ TEST_F(InputMethodStateAuraTest, GetCompositionCharacterBounds) {
}
}
+// This test verifies the correctness of the selected text reported by the
+// RenderWidgetHostView after the view is subject to a change in its text
+// selection.
+TEST_F(InputMethodStateAuraTest, GetSelectedText) {
+ base::string16 text = base::ASCIIToUTF16("some text of length 22");
+ size_t offset = 0U;
+ gfx::Range selection_range(20, 21);
+
+ for (auto index : active_view_sequence_) {
+ ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT);
+ views_[index]->SelectionChanged(text, offset, selection_range);
+ base::string16 expected_text = text.substr(
+ selection_range.GetMin() - offset, selection_range.length());
+
+ EXPECT_EQ(expected_text, views_[index]->GetSelectedText());
+
+ // Changing offset to make sure that the next view has a different text
+ // selection.
+ offset++;
+ }
+}
+
+// This test verifies the correctness of the total text range reported by the
+// TextInputClient after a view is subject to a change in its text selection.
+TEST_F(InputMethodStateAuraTest, GetTextRange) {
+ base::string16 text = base::ASCIIToUTF16("some text of length 22");
+ size_t offset = 0U;
+ gfx::Range selection_range;
+
+ for (auto index : active_view_sequence_) {
+ ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT);
+ gfx::Range expected_range(offset, offset + text.length());
+ views_[index]->SelectionChanged(text, offset, selection_range);
+ gfx::Range range_from_client;
+
+ // For aura this always returns true.
+ EXPECT_TRUE(text_input_client()->GetTextRange(&range_from_client));
+ EXPECT_EQ(expected_range, range_from_client);
+
+ // Changing offset to make sure that the next view has a different text
+ // selection.
+ offset++;
+ }
+}
+
+// This test verifies the correctness of the selection range reported by the
+// TextInputClient after a view is subject to a change in its text selection.
+TEST_F(InputMethodStateAuraTest, GetSelectionRange) {
+ base::string16 text;
+ gfx::Range expected_range(0U, 1U);
+
+ for (auto index : active_view_sequence_) {
+ ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT);
+ views_[index]->SelectionChanged(text, 0U, expected_range);
+ gfx::Range range_from_client;
+
+ // This method always returns true.
+ EXPECT_TRUE(text_input_client()->GetSelectionRange(&range_from_client));
+ EXPECT_EQ(expected_range, range_from_client);
+
+ // Changing range to make sure that the next view has a different text
+ // selection.
+ expected_range.set_end(expected_range.end() + 1U);
+ }
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698