OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/base_paths.h" | 5 #include "base/base_paths.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/autocomplete/autocomplete_input.h" | |
11 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/rlz/rlz.h" | 11 #include "chrome/browser/rlz/rlz.h" |
13 #include "chrome/browser/search_engines/template_url.h" | 12 #include "chrome/browser/search_engines/template_url.h" |
14 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 13 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
15 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "components/metrics/proto/omnibox_event.pb.h" |
16 #include "components/metrics/proto/omnibox_input_type.pb.h" | 16 #include "components/metrics/proto/omnibox_input_type.pb.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 #if defined(ENABLE_RLZ) | 19 #if defined(ENABLE_RLZ) |
20 #include "chrome/browser/google/google_brand.h" | 20 #include "chrome/browser/google/google_brand.h" |
21 #endif | 21 #endif |
22 | 22 |
23 #if defined(OS_ANDROID) | 23 #if defined(OS_ANDROID) |
24 #include "chrome/browser/search_engines/ui_thread_search_terms_data_android.h" | 24 #include "chrome/browser/search_engines/ui_thread_search_terms_data_android.h" |
25 #endif | 25 #endif |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 search_terms_data_)); | 589 search_terms_data_)); |
590 ASSERT_TRUE(result.is_valid()); | 590 ASSERT_TRUE(result.is_valid()); |
591 EXPECT_EQ(test_data[i].expected_result, result.spec()); | 591 EXPECT_EQ(test_data[i].expected_result, result.spec()); |
592 } | 592 } |
593 } | 593 } |
594 | 594 |
595 // Tests replacing input type (&oit=). | 595 // Tests replacing input type (&oit=). |
596 TEST_F(TemplateURLTest, ReplaceInputType) { | 596 TEST_F(TemplateURLTest, ReplaceInputType) { |
597 struct TestData { | 597 struct TestData { |
598 const base::string16 search_term; | 598 const base::string16 search_term; |
599 AutocompleteInput::Type input_type; | 599 metrics::OmniboxInputType::Type input_type; |
600 const std::string url; | 600 const std::string url; |
601 const std::string expected_result; | 601 const std::string expected_result; |
602 } test_data[] = { | 602 } test_data[] = { |
603 { ASCIIToUTF16("foo"), | 603 { ASCIIToUTF16("foo"), |
604 metrics::OmniboxInputType::UNKNOWN, | 604 metrics::OmniboxInputType::UNKNOWN, |
605 "{google:baseURL}?{searchTerms}&{google:inputType}", | 605 "{google:baseURL}?{searchTerms}&{google:inputType}", |
606 "http://www.google.com/?foo&oit=1&" }, | 606 "http://www.google.com/?foo&oit=1&" }, |
607 { ASCIIToUTF16("foo"), | 607 { ASCIIToUTF16("foo"), |
608 metrics::OmniboxInputType::URL, | 608 metrics::OmniboxInputType::URL, |
609 "{google:baseURL}?{searchTerms}&{google:inputType}", | 609 "{google:baseURL}?{searchTerms}&{google:inputType}", |
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1325 data.SetURL("{google:baseURL}?{google:pageClassification}q={searchTerms}"); | 1325 data.SetURL("{google:baseURL}?{google:pageClassification}q={searchTerms}"); |
1326 TemplateURL url(data); | 1326 TemplateURL url(data); |
1327 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_)); | 1327 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_)); |
1328 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_)); | 1328 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_)); |
1329 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo")); | 1329 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo")); |
1330 | 1330 |
1331 std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args, | 1331 std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args, |
1332 search_terms_data_); | 1332 search_terms_data_); |
1333 EXPECT_EQ("http://www.google.com/?q=foo", result); | 1333 EXPECT_EQ("http://www.google.com/?q=foo", result); |
1334 | 1334 |
1335 search_terms_args.page_classification = AutocompleteInput::NTP; | 1335 search_terms_args.page_classification = metrics::OmniboxEventProto::NTP; |
1336 result = url.url_ref().ReplaceSearchTerms(search_terms_args, | 1336 result = url.url_ref().ReplaceSearchTerms(search_terms_args, |
1337 search_terms_data_); | 1337 search_terms_data_); |
1338 EXPECT_EQ("http://www.google.com/?pgcl=1&q=foo", result); | 1338 EXPECT_EQ("http://www.google.com/?pgcl=1&q=foo", result); |
1339 | 1339 |
1340 search_terms_args.page_classification = | 1340 search_terms_args.page_classification = |
1341 AutocompleteInput::HOME_PAGE; | 1341 metrics::OmniboxEventProto::HOME_PAGE; |
1342 result = url.url_ref().ReplaceSearchTerms(search_terms_args, | 1342 result = url.url_ref().ReplaceSearchTerms(search_terms_args, |
1343 search_terms_data_); | 1343 search_terms_data_); |
1344 EXPECT_EQ("http://www.google.com/?pgcl=3&q=foo", result); | 1344 EXPECT_EQ("http://www.google.com/?pgcl=3&q=foo", result); |
1345 } | 1345 } |
1346 | 1346 |
1347 // Test the IsSearchResults function. | 1347 // Test the IsSearchResults function. |
1348 TEST_F(TemplateURLTest, IsSearchResults) { | 1348 TEST_F(TemplateURLTest, IsSearchResults) { |
1349 TemplateURLData data; | 1349 TemplateURLData data; |
1350 data.SetURL("http://bar/search?q={searchTerms}"); | 1350 data.SetURL("http://bar/search?q={searchTerms}"); |
1351 data.instant_url = "http://bar/instant#q={searchTerms}"; | 1351 data.instant_url = "http://bar/instant#q={searchTerms}"; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 search_terms_data_); | 1468 search_terms_data_); |
1469 EXPECT_EQ("http://bar/_/contextualsearch?" | 1469 EXPECT_EQ("http://bar/_/contextualsearch?" |
1470 "ctxs=1&" | 1470 "ctxs=1&" |
1471 "ctxs_start=6&" | 1471 "ctxs_start=6&" |
1472 "ctxs_end=11&" | 1472 "ctxs_end=11&" |
1473 "q=allen&" | 1473 "q=allen&" |
1474 "ctxs_content=woody+allen+movies&" | 1474 "ctxs_content=woody+allen+movies&" |
1475 "ctxs_url=www.wikipedia.org&" | 1475 "ctxs_url=www.wikipedia.org&" |
1476 "ctxs_encoding=utf-8&", result); | 1476 "ctxs_encoding=utf-8&", result); |
1477 } | 1477 } |
OLD | NEW |