Commit 182a0a91 authored by Tommy Li's avatar Tommy Li Committed by Commit Bot

[omnibox] Port RendererInitiatedFocusPreservesUserText to unit test

This CL is a followup to:
https://chromium-review.googlesource.com/c/chromium/src/+/2485561

It ports one more browser test to a unit test.

Bug: 751031
Change-Id: I56928ef473e3a14982c2fec0d900176c3175de9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485562
Commit-Queue: Tommy Li <tommycli@chromium.org>
Reviewed-by: default avatarmanuk hovanesian <manukh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818958}
parent 05c6e46a
...@@ -737,25 +737,6 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest, ...@@ -737,25 +737,6 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
EXPECT_EQ(old_selected_line, popup_model->selected_line()); EXPECT_EQ(old_selected_line, popup_model->selected_line());
} }
// Verifies that https://crbug.com/924935 doesn't regress.
IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
RendererInitiatedFocusPreservesUserText) {
OmniboxView* omnibox_view = nullptr;
ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
// Type a single character.
ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, 0));
EXPECT_EQ(base::ASCIIToUTF16("a"), omnibox_view->GetText());
// Simulate a renderer-initated focus event.
browser()->SetFocusToLocationBar();
// Type an additional character and verify that we didn't clobber the
// character we already typed.
ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_B, 0));
EXPECT_EQ(base::ASCIIToUTF16("ab"), omnibox_view->GetText());
}
IN_PROC_BROWSER_TEST_F(OmniboxViewTest, BasicTextOperations) { IN_PROC_BROWSER_TEST_F(OmniboxViewTest, BasicTextOperations) {
ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
chrome::FocusLocationBar(browser()); chrome::FocusLocationBar(browser());
......
...@@ -280,6 +280,9 @@ class OmniboxViewViews : public OmniboxView, ...@@ -280,6 +280,9 @@ class OmniboxViewViews : public OmniboxView,
virtual void ApplyColor(SkColor color, const gfx::Range& range); virtual void ApplyColor(SkColor color, const gfx::Range& range);
private: private:
FRIEND_TEST_ALL_PREFIXES(
OmniboxViewViewsTest,
RendererInitiatedFocusPreservesCursorWhenStartingFocused);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest, HoverAndExit); FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest, HoverAndExit);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest, HoverAndExitIDN); FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest, HoverAndExitIDN);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest, PrivateRegistry); FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest, PrivateRegistry);
......
...@@ -790,6 +790,24 @@ TEST_F(OmniboxViewViewsTest, ...@@ -790,6 +790,24 @@ TEST_F(OmniboxViewViewsTest,
EXPECT_TRUE(omnibox_view()->IsSelectAll()); EXPECT_TRUE(omnibox_view()->IsSelectAll());
} }
// Verifies that https://crbug.com/924935 doesn't regress.
TEST_F(OmniboxViewViewsTest,
RendererInitiatedFocusPreservesCursorWhenStartingFocused) {
// Simulate the user focusing the omnibox and typing something. This is just
// the test setup, not the actual focus event we are testing.
omnibox_view()->SetFocus(/*is_user_initiated*/ true);
omnibox_view()->SetTextAndSelectedRanges(base::ASCIIToUTF16("user text"),
{gfx::Range(9, 9)});
ASSERT_FALSE(omnibox_view()->IsSelectAll());
ASSERT_TRUE(omnibox_view()->SelectionAtEnd());
// Simulate a renderer-initated focus event. Expect the cursor position to be
// preserved, and that the omnibox did not select-all the text.
omnibox_view()->SetFocus(/*is_user_initiated=*/false);
EXPECT_FALSE(omnibox_view()->IsSelectAll());
EXPECT_TRUE(omnibox_view()->SelectionAtEnd());
}
TEST_F(OmniboxViewViewsTest, Emphasis) { TEST_F(OmniboxViewViewsTest, Emphasis) {
constexpr struct { constexpr struct {
const char* input; const char* input;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment