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

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: 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 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 30defc8652ebd6e26f713df9a26c93555bf04233..2d95eee1931675c3705cc4d043a6a5b092ffdf12 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
@@ -4248,7 +4248,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() {}
@@ -4271,10 +4275,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;
@@ -4300,4 +4302,74 @@ TEST_F(InputMethodStateAuraTest, GetCaretBounds) {
}
}
+// This test verifies the correctness of the selected text as reported by the
+// view after a text selection change on the view.
+TEST_F(InputMethodStateAuraTest, GetSelectedText) {
+ // Some range in the text that follows.
+ gfx::Range selection_range(25U, 29U);
+
+ // A long text containing selection.
+ base::string16 text = base::ASCIIToUTF16("this is not a valid statement");
+ size_t offset = 0U;
+
+ for (auto index : active_view_sequence_) {
+ ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT);
+ base::string16 expected_text = text.substr(
+ selection_range.GetMin() - offset, selection_range.length());
+ views_[index]->SelectionChanged(text, offset, selection_range);
+
+ // Casting to the base class since GetSelectedText() belongs to it.
+ RenderWidgetHostView* rwhv = views_[index];
+ EXPECT_EQ(expected_text, rwhv->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