Skip to content

Commit

Permalink
Include a URL what-you-typed option when the default search provider …
Browse files Browse the repository at this point in the history
…is not available and the input type is unknown.

Previously, when the default search provider was disabled via an enterprise policy, backspacing through the URL in the omnibar would get stuck as soon as the input got short enough to be classified as unknown. Normally, this is when the top autocomplete option would become a search for what you typed. But with search disabled, the top autocomplete option became the full previously visited URL. This change makes a URL what-you-typed autocomplete option to be provided instead under these circumstances.

BUG=363656

R=mpearson@chromium.org

Review URL: https://codereview.chromium.org/672773003

Cr-Commit-Position: refs/heads/master@{#301295}
  • Loading branch information
chrisvasselli authored and Commit bot committed Oct 25, 2014
1 parent 5cf0f5d commit 7d6b4f8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Chansik Yun <chansik.yun@gmail.com>
Chaobin Zhang <zhchbin@gmail.com>
Chris Harrelson <chrishtr@gmail.com>
Chris Nardi <hichris123@gmail.com>
Chris Vasselli <clindsay@gmail.com>
Christophe Dumez <ch.dumez@samsung.com>
Christopher Dale <chrelad@gmail.com>
Clemens Fruhwirth <clemens@endorphin.org>
Expand Down
16 changes: 8 additions & 8 deletions chrome/browser/autocomplete/history_url_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -756,20 +756,20 @@ void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend,
SortAndDedupMatches(&params->matches);

// Try to create a shorter suggestion from the best match.
// We consider the what you typed match eligible for display when there's a
// reasonable chance the user actually cares:
// * Their input can be opened as a URL, and
// * We parsed the input as a URL, or it starts with an explicit "http:" or
// "https:".
// Otherwise, this is just low-quality noise. In the cases where we've parsed
// as UNKNOWN, we'll still show an accidental search infobar if need be.
// We consider the what you typed match eligible for display when it's
// navigable and there's a reasonable chance the user intended to do
// something other than search. We use a variety of heuristics to determine
// this, e.g. whether the user explicitly typed a scheme, or if omnibox
// searching has been disabled by policy. In the cases where we've parsed as
// UNKNOWN, we'll still show an accidental search infobar if need be.
VisitClassifier classifier(this, params->input, db);
params->have_what_you_typed_match =
(params->input.type() != metrics::OmniboxInputType::QUERY) &&
((params->input.type() != metrics::OmniboxInputType::UNKNOWN) ||
(classifier.type() == VisitClassifier::UNVISITED_INTRANET) ||
!params->trim_http ||
(AutocompleteInput::NumNonHostComponents(params->input.parts()) > 0));
(AutocompleteInput::NumNonHostComponents(params->input.parts()) > 0) ||
!params->default_search_provider);
const bool have_shorter_suggestion_suitable_for_inline_autocomplete =
PromoteOrCreateShorterSuggestion(
db, params->have_what_you_typed_match, params);
Expand Down
40 changes: 37 additions & 3 deletions chrome/browser/autocomplete/history_url_provider_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "components/omnibox/autocomplete_provider.h"
#include "components/omnibox/autocomplete_provider_listener.h"
#include "components/omnibox/autocomplete_result.h"
#include "components/search_engines/default_search_manager.h"
#include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
Expand Down Expand Up @@ -183,10 +184,10 @@ class HistoryURLProviderTest : public testing::Test,
}

// testing::Test
virtual void SetUp() {
void SetUp() override {
ASSERT_TRUE(SetUpImpl(false));
}
virtual void TearDown();
void TearDown() override;

// Does the real setup.
bool SetUpImpl(bool no_db) WARN_UNUSED_RESULT;
Expand Down Expand Up @@ -226,11 +227,24 @@ class HistoryURLProviderTest : public testing::Test,

class HistoryURLProviderTestNoDB : public HistoryURLProviderTest {
protected:
virtual void SetUp() {
void SetUp() override {
ASSERT_TRUE(SetUpImpl(true));
}
};

class HistoryURLProviderTestNoSearchProvider : public HistoryURLProviderTest {
protected:
void SetUp() override {
DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(true);
HistoryURLProviderTest::SetUp();
}

void TearDown() override {
HistoryURLProviderTest::TearDown();
DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false);
}
};

void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) {
if (autocomplete_->done())
base::MessageLoop::current()->Quit();
Expand Down Expand Up @@ -480,6 +494,26 @@ TEST_F(HistoryURLProviderTest, CullRedirects) {
arraysize(expected_results));
}

TEST_F(HistoryURLProviderTestNoSearchProvider, WhatYouTypedNoSearchProvider) {
// When no search provider is available, make sure we provide WYT matches
// for text that could be a URL.

const UrlAndLegalDefault results_1[] = {
{ "http://wytmatch/", true }
};
RunTest(ASCIIToUTF16("wytmatch"), std::string(), false, results_1,
arraysize(results_1));

RunTest(ASCIIToUTF16("wytmatch foo bar"), std::string(), false, NULL, 0);
RunTest(ASCIIToUTF16("wytmatch+foo+bar"), std::string(), false, NULL, 0);

const UrlAndLegalDefault results_2[] = {
{ "http://wytmatch+foo+bar.com/", true }
};
RunTest(ASCIIToUTF16("wytmatch+foo+bar.com"), std::string(), false,
results_2, arraysize(results_2));
}

TEST_F(HistoryURLProviderTest, WhatYouTyped) {
// Make sure we suggest a What You Typed match at the right times.
RunTest(ASCIIToUTF16("wytmatch"), std::string(), false, NULL, 0);
Expand Down

0 comments on commit 7d6b4f8

Please sign in to comment.