| Index: chrome/browser/autocomplete/search_provider_unittest.cc
|
| ===================================================================
|
| --- chrome/browser/autocomplete/search_provider_unittest.cc (revision 208590)
|
| +++ chrome/browser/autocomplete/search_provider_unittest.cc (working copy)
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "chrome/browser/autocomplete/search_provider.h"
|
|
|
| +#include "base/command_line.h"
|
| #include "base/metrics/field_trial.h"
|
| #include "base/prefs/pref_service.h"
|
| #include "base/run_loop.h"
|
| @@ -25,6 +26,7 @@
|
| #include "chrome/browser/search_engines/template_url.h"
|
| #include "chrome/browser/search_engines/template_url_service.h"
|
| #include "chrome/browser/search_engines/template_url_service_factory.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| #include "chrome/common/instant_types.h"
|
| #include "chrome/common/metrics/entropy_provider.h"
|
| #include "chrome/common/pref_names.h"
|
| @@ -35,8 +37,9 @@
|
| #include "net/url_request/url_request_status.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| -using content::BrowserThread;
|
|
|
| +// SearchProviderTest ---------------------------------------------------------
|
| +
|
| // The following environment is configured for these tests:
|
| // . The TemplateURL default_t_url_ is set as the default provider.
|
| // . The TemplateURL keyword_t_url_ is added to the TemplateURLService. This
|
| @@ -49,26 +52,6 @@
|
| class SearchProviderTest : public testing::Test,
|
| public AutocompleteProviderListener {
|
| public:
|
| - SearchProviderTest()
|
| - : default_t_url_(NULL),
|
| - term1_(ASCIIToUTF16("term1")),
|
| - keyword_t_url_(NULL),
|
| - keyword_term_(ASCIIToUTF16("keyword")),
|
| - ui_thread_(BrowserThread::UI, &message_loop_),
|
| - io_thread_(BrowserThread::IO),
|
| - quit_when_done_(false) {
|
| - io_thread_.Start();
|
| - }
|
| -
|
| - static void SetUpTestCase();
|
| -
|
| - static void TearDownTestCase();
|
| -
|
| - // See description above class for what this registers.
|
| - virtual void SetUp();
|
| -
|
| - virtual void TearDown();
|
| -
|
| struct ResultInfo {
|
| ResultInfo() : result_type(AutocompleteMatchType::NUM_TYPES) {
|
| }
|
| @@ -79,16 +62,36 @@
|
| result_type(result_type),
|
| fill_into_edit(fill_into_edit) {
|
| }
|
| +
|
| const GURL gurl;
|
| const AutocompleteMatch::Type result_type;
|
| const string16 fill_into_edit;
|
| };
|
| +
|
| struct TestData {
|
| const string16 input;
|
| const size_t num_results;
|
| const ResultInfo output[3];
|
| };
|
|
|
| + SearchProviderTest()
|
| + : default_t_url_(NULL),
|
| + term1_(ASCIIToUTF16("term1")),
|
| + keyword_t_url_(NULL),
|
| + keyword_term_(ASCIIToUTF16("keyword")),
|
| + ui_thread_(content::BrowserThread::UI, &message_loop_),
|
| + io_thread_(content::BrowserThread::IO),
|
| + quit_when_done_(false) {
|
| + io_thread_.Start();
|
| + }
|
| +
|
| + static void SetUpTestCase();
|
| + static void TearDownTestCase();
|
| +
|
| + // See description above class for what this registers.
|
| + virtual void SetUp() OVERRIDE;
|
| + virtual void TearDown() OVERRIDE;
|
| +
|
| void RunTest(TestData* cases, int num_cases, bool prefer_keyword);
|
|
|
| protected:
|
| @@ -166,8 +169,6 @@
|
|
|
| // static
|
| base::FieldTrialList* SearchProviderTest::field_trial_list_ = NULL;
|
| -
|
| -// static
|
| const std::string SearchProviderTest::kNotApplicable = "Not Applicable";
|
|
|
| // static
|
| @@ -237,6 +238,41 @@
|
| provider_->kMinimumTimeBetweenSuggestQueriesMs = 0;
|
| }
|
|
|
| +void SearchProviderTest::TearDown() {
|
| + message_loop_.RunUntilIdle();
|
| +
|
| + // Shutdown the provider before the profile.
|
| + provider_ = NULL;
|
| +}
|
| +
|
| +void SearchProviderTest::RunTest(TestData* cases,
|
| + int num_cases,
|
| + bool prefer_keyword) {
|
| + ACMatches matches;
|
| + for (int i = 0; i < num_cases; ++i) {
|
| + AutocompleteInput input(cases[i].input, string16::npos, string16(), GURL(),
|
| + false, prefer_keyword, true,
|
| + AutocompleteInput::ALL_MATCHES);
|
| + provider_->Start(input, false);
|
| + matches = provider_->matches();
|
| + string16 diagnostic_details = ASCIIToUTF16("Input was: ") + cases[i].input +
|
| + ASCIIToUTF16("; prefer_keyword was: ") +
|
| + (prefer_keyword ? ASCIIToUTF16("true") : ASCIIToUTF16("false"));
|
| + EXPECT_EQ(cases[i].num_results, matches.size()) << diagnostic_details;
|
| + if (matches.size() == cases[i].num_results) {
|
| + for (size_t j = 0; j < cases[i].num_results; ++j) {
|
| + EXPECT_EQ(cases[i].output[j].gurl, matches[j].destination_url) <<
|
| + diagnostic_details;
|
| + EXPECT_EQ(cases[i].output[j].result_type, matches[j].type) <<
|
| + diagnostic_details;
|
| + EXPECT_EQ(cases[i].output[j].fill_into_edit,
|
| + matches[j].fill_into_edit) <<
|
| + diagnostic_details;
|
| + }
|
| + }
|
| + }
|
| +}
|
| +
|
| void SearchProviderTest::OnProviderUpdate(bool updated_matches) {
|
| if (quit_when_done_ && provider_->done()) {
|
| quit_when_done_ = false;
|
| @@ -296,41 +332,6 @@
|
| wyt_match));
|
| }
|
|
|
| -void SearchProviderTest::TearDown() {
|
| - message_loop_.RunUntilIdle();
|
| -
|
| - // Shutdown the provider before the profile.
|
| - provider_ = NULL;
|
| -}
|
| -
|
| -void SearchProviderTest::RunTest(TestData* cases,
|
| - int num_cases,
|
| - bool prefer_keyword) {
|
| - ACMatches matches;
|
| - for (int i = 0; i < num_cases; ++i) {
|
| - AutocompleteInput input(cases[i].input, string16::npos, string16(), GURL(),
|
| - false, prefer_keyword, true,
|
| - AutocompleteInput::ALL_MATCHES);
|
| - provider_->Start(input, false);
|
| - matches = provider_->matches();
|
| - string16 diagnostic_details = ASCIIToUTF16("Input was: ") + cases[i].input +
|
| - ASCIIToUTF16("; prefer_keyword was: ") +
|
| - (prefer_keyword ? ASCIIToUTF16("true") : ASCIIToUTF16("false"));
|
| - EXPECT_EQ(cases[i].num_results, matches.size()) << diagnostic_details;
|
| - if (matches.size() == cases[i].num_results) {
|
| - for (size_t j = 0; j < cases[i].num_results; ++j) {
|
| - EXPECT_EQ(cases[i].output[j].gurl, matches[j].destination_url) <<
|
| - diagnostic_details;
|
| - EXPECT_EQ(cases[i].output[j].result_type, matches[j].type) <<
|
| - diagnostic_details;
|
| - EXPECT_EQ(cases[i].output[j].fill_into_edit,
|
| - matches[j].fill_into_edit) <<
|
| - diagnostic_details;
|
| - }
|
| - }
|
| - }
|
| -}
|
| -
|
| GURL SearchProviderTest::AddSearchToHistory(TemplateURL* t_url,
|
| string16 term,
|
| int visit_count) {
|
| @@ -382,8 +383,9 @@
|
| default_fetcher->delegate()->OnURLFetchComplete(default_fetcher);
|
| }
|
|
|
| -// Tests -----------------------------------------------------------------------
|
|
|
| +// Actual Tests ---------------------------------------------------------------
|
| +
|
| // Make sure we query history for the default provider and a URLFetcher is
|
| // created for the default provider suggest results.
|
| TEST_F(SearchProviderTest, QueryDefaultProvider) {
|
| @@ -980,6 +982,38 @@
|
| RunTest(cases, arraysize(cases), true);
|
| }
|
|
|
| +// Ensures command-line flags are reflected in the URLs the search provider
|
| +// generates.
|
| +TEST_F(SearchProviderTest, CommandLineOverrides) {
|
| + TemplateURLService* turl_model =
|
| + TemplateURLServiceFactory::GetForProfile(&profile_);
|
| +
|
| + TemplateURLData data;
|
| + data.short_name = ASCIIToUTF16("default");
|
| + data.SetKeyword(data.short_name);
|
| + data.SetURL("{google:baseURL}{searchTerms}");
|
| + default_t_url_ = new TemplateURL(&profile_, data);
|
| + turl_model->Add(default_t_url_);
|
| + turl_model->SetDefaultSearchProvider(default_t_url_);
|
| +
|
| + CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL,
|
| + "http://www.bar.com/");
|
| + CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| + switches::kExtraSearchQueryParams, "a=b");
|
| +
|
| + TestData cases[] = {
|
| + { ASCIIToUTF16("k a"), 2,
|
| + { ResultInfo(GURL("http://keyword/a"),
|
| + AutocompleteMatchType::SEARCH_OTHER_ENGINE,
|
| + ASCIIToUTF16("k a")),
|
| + ResultInfo(GURL("http://www.bar.com/k%20a?a=b"),
|
| + AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
|
| + ASCIIToUTF16("k a")) } },
|
| + };
|
| +
|
| + RunTest(cases, arraysize(cases), false);
|
| +}
|
| +
|
| // Verifies Navsuggest results don't set a TemplateURL, which Instant relies on.
|
| // Also verifies that just the *first* navigational result is listed as a match
|
| // if suggested relevance scores were not sent.
|
|
|