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

Unified Diff: chrome/browser/ui/omnibox/omnibox_view_browsertest.cc

Issue 2891653003: [omnibox] Break out SetCaretPos() method and enhance browser test (Closed)
Patch Set: Fixed range on Cocoa Created 3 years, 7 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: chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
diff --git a/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc b/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
index f50e5aa2b21729397151b593e7bb21a91071dcc9..9fc16a9ece2990adbd9bde85e306b3fb3a12215f 100644
--- a/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
+++ b/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
@@ -861,13 +861,35 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest, BasicTextOperations) {
EXPECT_EQ(0U, end);
EXPECT_TRUE(omnibox_view->GetText().empty());
- // Check if RevertAll() can set text and cursor correctly.
+ // Add a small amount of text to move the cursor past offset 0.
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, 0));
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_B, 0));
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_C, 0));
+
+ // Check if RevertAll() resets the text and preserves the cursor position.
omnibox_view->RevertAll();
EXPECT_FALSE(omnibox_view->IsSelectAll());
EXPECT_EQ(old_text, omnibox_view->GetText());
omnibox_view->GetSelectionBounds(&start, &end);
- EXPECT_EQ(0U, start);
- EXPECT_EQ(0U, end);
+ EXPECT_EQ(3U, start);
+ EXPECT_EQ(3U, end);
+
+ // Check that reverting clamps the cursor to the bounds of the new text.
+ // Move the cursor to the end.
+#if defined(OS_MACOSX)
+ // End doesn't work on Mac trybot.
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_E, ui::EF_CONTROL_DOWN));
+#else
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, 0));
+#endif
+ // Add a small amount of text to push the cursor past where the text end
+ // will be once we revert.
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, 0));
+ omnibox_view->RevertAll();
+ // Cursor should be no further than original text.
+ omnibox_view->GetSelectionBounds(&start, &end);
+ EXPECT_EQ(11U, start);
+ EXPECT_EQ(11U, end);
}
// Make sure the cursor position doesn't get set past the last character of
« no previous file with comments | « chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm ('k') | chrome/browser/ui/views/omnibox/omnibox_view_views.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698