#include "components/omnibox/autocomplete_provider_listener.h"
#include "components/omnibox/omnibox_field_trial.h"
#include "components/omnibox/omnibox_switches.h"
+#include "components/omnibox/suggestion_answer.h"
#include "components/search_engines/search_engine_type.h"
#include "components/search_engines/search_engines_switches.h"
#include "components/search_engines/search_terms_data.h"
bool is_success() { return is_success_; };
protected:
- virtual ~SearchProviderForTest();
+ ~SearchProviderForTest() override;
private:
- virtual void RecordDeletionResult(bool success) OVERRIDE;
+ void RecordDeletionResult(bool success) override;
bool is_success_;
DISALLOW_COPY_AND_ASSIGN(SearchProviderForTest);
};
}
// See description above class for what this registers.
- virtual void SetUp() OVERRIDE;
- virtual void TearDown() OVERRIDE;
+ void SetUp() override;
+ void TearDown() override;
void RunTest(TestData* cases, int num_cases, bool prefer_keyword);
// AutocompleteProviderListener:
// If we're waiting for the provider to finish, this exits the message loop.
- virtual void OnProviderUpdate(bool updated_matches) OVERRIDE;
+ void OnProviderUpdate(bool updated_matches) override;
// Runs a nested message loop until provider_ is done. The message loop is
// exited by way of OnProviderUpdate.
&profile_, &AutocompleteClassifierFactory::BuildInstanceFor);
provider_ = new SearchProviderForTest(this, turl_model, &profile_);
- provider_->kMinimumTimeBetweenSuggestQueriesMs = 0;
+ OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs = 0;
}
void SearchProviderTest::TearDown() {
ACMatches matches;
for (int i = 0; i < num_cases; ++i) {
AutocompleteInput input(cases[i].input, base::string16::npos,
- base::string16(), GURL(),
+ std::string(), GURL(),
metrics::OmniboxEventProto::INVALID_SPEC, false,
prefer_keyword, true, true,
ChromeAutocompleteSchemeClassifier(&profile_));
bool prevent_inline_autocomplete,
bool prefer_keyword) {
// Start a query.
- AutocompleteInput input(text, base::string16::npos, base::string16(), GURL(),
+ AutocompleteInput input(text, base::string16::npos, std::string(), GURL(),
metrics::OmniboxEventProto::INVALID_SPEC,
prevent_inline_autocomplete, prefer_keyword, true,
true, ChromeAutocompleteSchemeClassifier(&profile_));
{ "a2", "a", kEmptyMatch } },
};
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ for (size_t i = 0; i < arraysize(cases); ++i) {
ForcedQueryTestHelper("a", cases[i].json, cases[i].matches_in_default_mode,
"regular input with json=" + cases[i].json);
ForcedQueryTestHelper("?a", cases[i].json,
TemplateURLServiceFactory::GetForProfile(&profile_),
NULL, AutocompleteProvider::TYPE_SEARCH);
controller.Start(AutocompleteInput(
- ASCIIToUTF16("k t"), base::string16::npos, base::string16(), GURL(),
+ ASCIIToUTF16("k t"), base::string16::npos, std::string(), GURL(),
metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true,
ChromeAutocompleteSchemeClassifier(&profile_)));
const AutocompleteResult& result = controller.result();
{ "akeyword-query", "a", "k a", "adefault.com", "k adefault-query" } }
};
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ for (size_t i = 0; i < arraysize(cases); ++i) {
// Send the query twice in order to have a synchronous pass after the first
// response is received. This is necessary because SearchProvider doesn't
// allow an asynchronous response to change the default match.
cases[i].default_provider_json + " and keyword_provider_json=" +
cases[i].keyword_provider_json);
const ACMatches& matches = provider_->matches();
- ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
+ ASSERT_LE(matches.size(), arraysize(cases[i].matches));
size_t j = 0;
// Ensure that the returned matches equal the expectations.
for (; j < matches.size(); ++j)
EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]), matches[j].contents);
// Ensure that no expected matches are missing.
- for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
+ for (; j < arraysize(cases[i].matches); ++j)
EXPECT_EQ(std::string(), cases[i].matches[j]);
}
}
std::string() },
};
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ for (size_t i = 0; i < arraysize(cases); ++i) {
// Send the query twice in order to have a synchronous pass after the first
// response is received. This is necessary because SearchProvider doesn't
// allow an asynchronous response to change the default match.
}
const std::string description = "for input with json=" + cases[i].json;
- CheckMatches(description, ARRAYSIZE_UNSAFE(cases[i].matches),
- cases[i].matches, provider_->matches());
+ CheckMatches(description, arraysize(cases[i].matches), cases[i].matches,
+ provider_->matches());
}
}
"3" },
};
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ for (size_t i = 0; i < arraysize(cases); ++i) {
// Send the query twice in order to have a synchronous pass after the first
// response is received. This is necessary because SearchProvider doesn't
// allow an asynchronous response to change the default match.
EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion),
it->inline_autocompletion);
- ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
+ ASSERT_LE(matches.size(), arraysize(cases[i].matches));
size_t j = 0;
// Ensure that the returned matches equal the expectations.
for (; j < matches.size(); ++j) {
matches[j].allowed_to_be_default_match);
}
// Ensure that no expected matches are missing.
- for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) {
+ for (; j < arraysize(cases[i].matches); ++j) {
SCOPED_TRACE(" Case # " + base::IntToString(i));
EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents);
}
kEmptyExpectedMatch } },
};
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ for (size_t i = 0; i < arraysize(cases); ++i) {
// First, send the query "a" and receive the JSON response |first_json|.
ClearAllResults();
QueryForInputAndWaitForFetcherResponses(
// Verify that the matches after the asynchronous results are as expected.
std::string description = "first asynchronous response for input with "
"first_json=" + cases[i].first_json;
- CheckMatches(description, ARRAYSIZE_UNSAFE(cases[i].first_async_matches),
+ CheckMatches(description, arraysize(cases[i].first_async_matches),
cases[i].first_async_matches, provider_->matches());
// Then, send the query "ab" and check the synchronous matches.
description = "synchronous response after the first keystroke after input "
"with first_json=" + cases[i].first_json;
QueryForInput(ASCIIToUTF16("ab"), false, false);
- CheckMatches(description, ARRAYSIZE_UNSAFE(cases[i].sync_matches),
+ CheckMatches(description, arraysize(cases[i].sync_matches),
cases[i].sync_matches, provider_->matches());
// Finally, get the provided JSON response, |second_json|, and verify the
second_fetcher->SetResponseString(cases[i].second_json);
second_fetcher->delegate()->OnURLFetchComplete(second_fetcher);
RunTillProviderDone();
- CheckMatches(description, ARRAYSIZE_UNSAFE(cases[i].second_async_matches),
+ CheckMatches(description, arraysize(cases[i].second_async_matches),
cases[i].second_async_matches, provider_->matches());
}
}
{ "term", "a1", "a2", "term2", "a3", "a4" } }
};
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ for (size_t i = 0; i < arraysize(cases); ++i) {
QueryForInputAndWaitForFetcherResponses(
cases[i].input, false, cases[i].json, std::string());
const ACMatches& matches = provider_->matches();
// Ensure no extra matches are present.
- ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
+ ASSERT_LE(matches.size(), arraysize(cases[i].matches));
size_t j = 0;
// Ensure that the returned matches equal the expectations.
EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]),
matches[j].contents) << description;
// Ensure that no expected matches are missing.
- for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
+ for (; j < arraysize(cases[i].matches); ++j)
EXPECT_EQ(kNotApplicable, cases[i].matches[j]) <<
"Case # " << i << " " << description;
}
kEmptyMatch, kEmptyMatch } },
};
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ for (size_t i = 0; i < arraysize(cases); ++i) {
// Send the query twice in order to have a synchronous pass after the first
// response is received. This is necessary because SearchProvider doesn't
// allow an asynchronous response to change the default match.
SCOPED_TRACE("input=" + cases[i].input + " json=" + cases[i].json);
size_t j = 0;
const ACMatches& matches = provider_->matches();
- ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].output));
+ ASSERT_LE(matches.size(), arraysize(cases[i].output));
// Ensure that the returned matches equal the expectations.
for (; j < matches.size(); ++j) {
EXPECT_EQ(ASCIIToUTF16(cases[i].output[j].match_contents),
matches[j].allowed_to_be_default_match);
}
// Ensure that no expected matches are missing.
- for (; j < ARRAYSIZE_UNSAFE(cases[i].output); ++j) {
+ for (; j < arraysize(cases[i].output); ++j) {
EXPECT_EQ(kNotApplicable, cases[i].output[j].match_contents);
EXPECT_EQ(AutocompleteMatchType::NUM_TYPES,
cases[i].output[j].match_type);
"?www.abc.com", std::string(), true, true },
};
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ for (size_t i = 0; i < arraysize(cases); ++i) {
// First test regular mode.
QueryForInput(ASCIIToUTF16(cases[i].input), false, false);
SearchSuggestionParser::NavigationResult result(
},
},
};
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ for (size_t i = 0; i < arraysize(cases); ++i) {
QueryForInputAndWaitForFetcherResponses(
ASCIIToUTF16(cases[i].input_text), false, cases[i].response_json,
std::string());
SCOPED_TRACE("for input with json = " + cases[i].response_json);
- ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
+ ASSERT_LE(matches.size(), arraysize(cases[i].matches));
size_t j = 0;
// Ensure that the returned matches equal the expectations.
for (; j < matches.size(); ++j) {
EXPECT_EQ(match.type, matches[j].type);
}
// Ensure that no expected matches are missing.
- for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) {
+ for (; j < arraysize(cases[i].matches); ++j) {
SCOPED_TRACE(" and match index: " + base::IntToString(j));
EXPECT_EQ(cases[i].matches[j].contents, kNotApplicable);
EXPECT_EQ(cases[i].matches[j].description, kNotApplicable);
}
};
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ for (size_t i = 0; i < arraysize(cases); ++i) {
QueryForInputAndWaitForFetcherResponses(
ASCIIToUTF16(cases[i].input_text),
cases[i].prefer_keyword_provider_results,
ASSERT_FALSE(matches.empty());
EXPECT_GE(matches[0].relevance, 1300);
- ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
+ ASSERT_LE(matches.size(), arraysize(cases[i].matches));
// Ensure that the returned matches equal the expectations.
for (size_t j = 0; j < matches.size(); ++j) {
SCOPED_TRACE(description);
},
};
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ for (size_t i = 0; i < arraysize(cases); ++i) {
ClearAllResults();
QueryForInputAndWaitForFetcherResponses(
ASCIIToUTF16(cases[i].input_text), false,
EXPECT_GE(matches[0].relevance, 1300);
SCOPED_TRACE("for case: " + base::IntToString(i));
- ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
+ ASSERT_LE(matches.size(), arraysize(cases[i].matches));
size_t j = 0;
// Ensure that the returned matches equal the expectations.
for (; j < matches.size(); ++j) {
base::UTF16ToUTF8(matches[j].contents));
EXPECT_EQ(cases[i].matches[j].type, matches[j].type);
}
- for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) {
+ for (; j < arraysize(cases[i].matches); ++j) {
SCOPED_TRACE("and match: " + base::IntToString(j));
EXPECT_EQ(cases[i].matches[j].contents, kNotApplicable);
EXPECT_EQ(cases[i].matches[j].type, AutocompleteMatchType::NUM_TYPES);
},
};
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ for (size_t i = 0; i < arraysize(cases); ++i) {
QueryForInputAndWaitForFetcherResponses(
ASCIIToUTF16(cases[i].input_text), false, cases[i].response_json,
std::string());
base::string16 query = base::ASCIIToUTF16("weather los angeles");
SearchSuggestionParser::SuggestResult suggest_result(
query, AutocompleteMatchType::SEARCH_HISTORY, query, base::string16(),
- base::string16(), base::string16(), base::string16(), std::string(),
- std::string(), false, 1200, false, false, query);
+ base::string16(), base::string16(), base::string16(), nullptr,
+ std::string(), std::string(), false, 1200, false, false, query);
QueryForInput(ASCIIToUTF16("weather l"), false, false);
provider_->transformed_default_history_results_.push_back(suggest_result);
answer = provider_->FindAnswersPrefetchData();
}
TEST_F(SearchProviderTest, RemoveExtraAnswers) {
+ SuggestionAnswer answer1;
+ answer1.set_type(42);
+ SuggestionAnswer answer2;
+ answer2.set_type(1983);
+ SuggestionAnswer answer3;
+ answer3.set_type(423);
+
ACMatches matches;
AutocompleteMatch match1, match2, match3, match4, match5;
+ match1.answer = SuggestionAnswer::copy(&answer1);
match1.answer_contents = base::ASCIIToUTF16("the answer");
match1.answer_type = base::ASCIIToUTF16("42");
+ match3.answer = SuggestionAnswer::copy(&answer2);
match3.answer_contents = base::ASCIIToUTF16("not to play");
match3.answer_type = base::ASCIIToUTF16("1983");
+ match5.answer = SuggestionAnswer::copy(&answer3);
match5.answer_contents = base::ASCIIToUTF16("a man");
match5.answer_type = base::ASCIIToUTF16("423");
SearchProvider::RemoveExtraAnswers(&matches);
EXPECT_EQ(base::ASCIIToUTF16("the answer"), matches[0].answer_contents);
EXPECT_EQ(base::ASCIIToUTF16("42"), matches[0].answer_type);
+ EXPECT_TRUE(answer1.Equals(*matches[0].answer));
EXPECT_TRUE(matches[1].answer_contents.empty());
EXPECT_TRUE(matches[1].answer_type.empty());
+ EXPECT_FALSE(matches[1].answer);
EXPECT_TRUE(matches[2].answer_contents.empty());
EXPECT_TRUE(matches[2].answer_type.empty());
+ EXPECT_FALSE(matches[2].answer);
EXPECT_TRUE(matches[3].answer_contents.empty());
EXPECT_TRUE(matches[3].answer_type.empty());
+ EXPECT_FALSE(matches[3].answer);
EXPECT_TRUE(matches[4].answer_contents.empty());
EXPECT_TRUE(matches[4].answer_type.empty());
+ EXPECT_FALSE(matches[4].answer);
}