Commit 9eedf23e authored by Tommy Li's avatar Tommy Li Committed by Commit Bot

[omnibox] Steady State Elisions: Fix bug with End Key and intranet URLs

Currently, if the user presses an End Key on an intranet URL with no
path, i.e. "https://foobar" elided to "foobar/", the cursor position
will not end up in the right place.

This is because the elided form is not a strict substring of the full
formatted URL.

This CL fixes this corner case and adds a test.

Bug: 883310
Change-Id: Id3bb4c24da05dc8de3b2703edc5b12c1f2e3cab4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1759230
Commit-Queue: Tommy Li <tommycli@chromium.org>
Reviewed-by: default avatarmanuk hovanesian <manukh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688156}
parent 067cbde1
...@@ -864,6 +864,18 @@ bool OmniboxViewViews::UnapplySteadyStateElisions(UnelisionGesture gesture) { ...@@ -864,6 +864,18 @@ bool OmniboxViewViews::UnapplySteadyStateElisions(UnelisionGesture gesture) {
// This simple logic only works because we elide only prefixes from the full // This simple logic only works because we elide only prefixes from the full
// URL. Otherwise, we would have to use the FormatURL offset adjustments. // URL. Otherwise, we would have to use the FormatURL offset adjustments.
size_t offset = GetText().find(original_text); size_t offset = GetText().find(original_text);
// Some intranet URLs have an elided form that's not a substring of the full
// URL string. e.g. "https://foobar" has the elided form "foobar/". This is
// to prevent elided URLs from looking like search terms. See
// AutocompleteInput::FormattedStringWithEquivalentMeaning for details.
//
// In this special case, chop off the trailing slash and search again.
if (offset == base::string16::npos && !original_text.empty() &&
original_text.back() == base::char16('/')) {
offset = GetText().find(original_text.substr(0, original_text.size() - 1));
}
if (offset != base::string16::npos) { if (offset != base::string16::npos) {
AutocompleteMatch match; AutocompleteMatch match;
model()->ClassifyString(original_selected_text, &match, nullptr); model()->ClassifyString(original_selected_text, &match, nullptr);
......
...@@ -901,6 +901,31 @@ TEST_F(OmniboxViewViewsSteadyStateElisionsTest, UnelideOnHomeKey) { ...@@ -901,6 +901,31 @@ TEST_F(OmniboxViewViewsSteadyStateElisionsTest, UnelideOnHomeKey) {
EXPECT_EQ(0U, end); EXPECT_EQ(0U, end);
} }
TEST_F(OmniboxViewViewsSteadyStateElisionsTest,
UnelideViaEndKeyWorksWithIntranetUrls) {
location_bar_model()->set_url(GURL("https://foobar/"));
location_bar_model()->set_formatted_full_url(
base::ASCIIToUTF16("https://foobar"));
location_bar_model()->set_url_for_display(base::ASCIIToUTF16("foobar/"));
omnibox_view()->model()->ResetDisplayTexts();
omnibox_view()->RevertAll();
SendMouseClick(0);
// End key should unelide and move the cursor to the end of the full URL.
omnibox_textfield_view()->OnKeyPressed(
ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_END, 0));
EXPECT_EQ(base::ASCIIToUTF16("https://foobar"), omnibox_view()->GetText());
EXPECT_FALSE(omnibox_view()->model()->user_input_in_progress());
size_t start, end;
omnibox_view()->GetSelectionBounds(&start, &end);
EXPECT_EQ(14U, start);
EXPECT_EQ(14U, end);
}
TEST_F(OmniboxViewViewsSteadyStateElisionsTest, GestureTaps) { TEST_F(OmniboxViewViewsSteadyStateElisionsTest, GestureTaps) {
ui::GestureEvent tap_down(0, 0, 0, ui::EventTimeForNow(), ui::GestureEvent tap_down(0, 0, 0, ui::EventTimeForNow(),
ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN));
......
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