| Index: chrome/browser/search/search_unittest.cc
|
| ===================================================================
|
| --- chrome/browser/search/search_unittest.cc (revision 208572)
|
| +++ chrome/browser/search/search_unittest.cc (working copy)
|
| @@ -9,6 +9,7 @@
|
| #include "base/metrics/statistics_recorder.h"
|
| #include "base/prefs/pref_service.h"
|
| #include "chrome/browser/search/search.h"
|
| +#include "chrome/browser/search_engines/search_terms_data.h"
|
| #include "chrome/browser/search_engines/template_url_service.h"
|
| #include "chrome/browser/search_engines/template_url_service_factory.h"
|
| #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| @@ -395,17 +396,6 @@
|
| }
|
| }
|
|
|
| -TEST_F(SearchTest, CoerceCommandLineURLToTemplateURL) {
|
| - TemplateURL* template_url =
|
| - TemplateURLServiceFactory::GetForProfile(profile())->
|
| - GetDefaultSearchProvider();
|
| - EXPECT_EQ(
|
| - GURL("https://foo.com/dev?bar=bar#bar=bar"),
|
| - CoerceCommandLineURLToTemplateURL(
|
| - GURL("http://myserver.com:9000/dev?bar=bar#bar=bar"),
|
| - template_url->instant_url_ref(), kDisableStartMargin));
|
| -}
|
| -
|
| const SearchTestCase kInstantNTPTestCases[] = {
|
| {"https://foo.com/instant?strk", true, "Valid Instant URL"},
|
| {"https://foo.com/instant#strk", true, "Valid Instant URL"},
|
| @@ -504,19 +494,6 @@
|
| EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"),
|
| GetInstantURL(profile(), kDisableStartMargin));
|
|
|
| - // Override the Instant URL on the commandline. Oops, forgot "strk".
|
| - CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| - switches::kInstantURL,
|
| - "http://myserver.com:9000/dev?bar=bar#bar=bar");
|
| - EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin));
|
| -
|
| - // Override with "strk". For fun, put it in the query, instead of the ref.
|
| - CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| - switches::kInstantURL,
|
| - "http://myserver.com:9000/dev?bar=bar&strk#bar=bar");
|
| - EXPECT_EQ(GURL("http://myserver.com:9000/dev?bar=bar&strk#bar=bar"),
|
| - GetInstantURL(profile(), kDisableStartMargin));
|
| -
|
| // Disable suggest. No Instant URL.
|
| profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false);
|
| EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin));
|
| @@ -560,15 +537,6 @@
|
| profile()->GetPrefs()->SetBoolean(prefs::kSearchInstantEnabled, false);
|
| EXPECT_TRUE(DefaultSearchProviderSupportsInstant(profile()));
|
|
|
| - // Override the Instant URL on the commandline. Oops, forgot "strk".
|
| - CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| - switches::kInstantURL,
|
| - "http://myserver.com:9000/dev?bar=bar#bar=bar");
|
| - EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin));
|
| -
|
| - // Check that command line overrides don't affect the default search provider.
|
| - EXPECT_TRUE(DefaultSearchProviderSupportsInstant(profile()));
|
| -
|
| // Disable suggest. No Instant URL.
|
| profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false);
|
| EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin));
|
| @@ -678,5 +646,55 @@
|
| EXPECT_FALSE(IsInstantCheckboxChecked(profile()));
|
| }
|
|
|
| +TEST_F(SearchTest, CommandLineOverrides) {
|
| + EnableInstantExtendedAPIForTesting();
|
| + profile()->GetPrefs()->SetBoolean(prefs::kSearchInstantEnabled, true);
|
|
|
| + // GetLocalInstantURL() should default to the non-Google local NTP.
|
| + SetSearchProvider(false);
|
| + GURL local_instant_url(GetLocalInstantURL(profile()));
|
| + EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url);
|
| +
|
| + TemplateURLService* template_url_service =
|
| + TemplateURLServiceFactory::GetForProfile(profile());
|
| + TemplateURLData data;
|
| + data.SetURL("{google:baseURL}search?q={searchTerms}");
|
| + data.instant_url = "{google:baseURL}webhp?strk";
|
| + data.search_terms_replacement_key = "strk";
|
| + TemplateURL* template_url = new TemplateURL(profile(), data);
|
| + // Takes ownership of |template_url|.
|
| + template_url_service->Add(template_url);
|
| + template_url_service->SetDefaultSearchProvider(template_url);
|
| +
|
| + // By default, Instant Extended forces the instant URL to be HTTPS, so even if
|
| + // we set a Google base URL that is HTTP, we should get an HTTPS URL.
|
| + UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/");
|
| + GURL instant_url(GetInstantURL(profile(), kDisableStartMargin));
|
| + ASSERT_TRUE(instant_url.is_valid());
|
| + EXPECT_EQ("https://www.foo.com/webhp?strk", instant_url.spec());
|
| +
|
| + // However, if the Google base URL is specified on the command line, the
|
| + // instant URL should just use it, even if it's HTTP.
|
| + UIThreadSearchTermsData::SetGoogleBaseURL(std::string());
|
| + CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL,
|
| + "http://www.bar.com/");
|
| + instant_url = GetInstantURL(profile(), kDisableStartMargin);
|
| + ASSERT_TRUE(instant_url.is_valid());
|
| + EXPECT_EQ("http://www.bar.com/webhp?strk", instant_url.spec());
|
| +
|
| + // Similarly, setting a Google base URL on the command line should allow you
|
| + // to get the Google version of the local NTP, even though search provider's
|
| + // URL doesn't contain "google".
|
| + local_instant_url = GetLocalInstantURL(profile());
|
| + EXPECT_EQ(GURL(chrome::kChromeSearchLocalGoogleNtpUrl), local_instant_url);
|
| +
|
| + // If we specify extra search query params, they should be inserted into the
|
| + // query portion of the instant URL.
|
| + CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| + switches::kExtraSearchQueryParams, "a=b");
|
| + instant_url = GetInstantURL(profile(), kDisableStartMargin);
|
| + ASSERT_TRUE(instant_url.is_valid());
|
| + EXPECT_EQ("http://www.bar.com/webhp?a=b&strk", instant_url.spec());
|
| +}
|
| +
|
| } // namespace chrome
|
|
|