Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: chrome/browser/search_engines/template_url_unittest.cc

Issue 11448005: Add Android-specific parameters to search_engines/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing nits Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/search_engines/template_url.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/string_util.h" 6 #include "base/string_util.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/rlz/rlz.h" 9 #include "chrome/browser/rlz/rlz.h"
10 #include "chrome/browser/search_engines/search_terms_data.h" 10 #include "chrome/browser/search_engines/search_terms_data.h"
11 #include "chrome/browser/search_engines/template_url.h" 11 #include "chrome/browser/search_engines/template_url.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 #if defined(ENABLE_RLZ) 14 #if defined(ENABLE_RLZ)
15 #include "chrome/browser/google/google_util.h" 15 #include "chrome/browser/google/google_util.h"
16 #endif 16 #endif
17 17
18 #if defined(OS_ANDROID)
19 #include "chrome/browser/search_engines/search_terms_data_android.h"
20 #endif
21
18 // TestSearchTermsData -------------------------------------------------------- 22 // TestSearchTermsData --------------------------------------------------------
19 23
20 // Simple implementation of SearchTermsData. 24 // Simple implementation of SearchTermsData.
21 class TestSearchTermsData : public SearchTermsData { 25 class TestSearchTermsData : public SearchTermsData {
22 public: 26 public:
23 explicit TestSearchTermsData(const std::string& google_base_url); 27 explicit TestSearchTermsData(const std::string& google_base_url);
24 28
25 virtual std::string GoogleBaseURLValue() const OVERRIDE; 29 virtual std::string GoogleBaseURLValue() const OVERRIDE;
26 30
27 private: 31 private:
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 } 472 }
469 473
470 TEST_F(TemplateURLTest, RLZ) { 474 TEST_F(TemplateURLTest, RLZ) {
471 string16 rlz_string; 475 string16 rlz_string;
472 #if defined(ENABLE_RLZ) 476 #if defined(ENABLE_RLZ)
473 std::string brand; 477 std::string brand;
474 if (google_util::GetBrand(&brand) && !brand.empty() && 478 if (google_util::GetBrand(&brand) && !brand.empty() &&
475 !google_util::IsOrganic(brand)) { 479 !google_util::IsOrganic(brand)) {
476 RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX, &rlz_string); 480 RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX, &rlz_string);
477 } 481 }
482 #elif defined(OS_ANDROID)
483 SearchTermsDataAndroid::rlz_parameter_value_.Get() =
484 ASCIIToUTF16("android_test");
485 rlz_string = SearchTermsDataAndroid::rlz_parameter_value_.Get();
478 #endif 486 #endif
479 487
480 TemplateURLData data; 488 TemplateURLData data;
481 data.SetURL("http://bar/?{google:RLZ}{searchTerms}"); 489 data.SetURL("http://bar/?{google:RLZ}{searchTerms}");
482 TemplateURL url(NULL, data); 490 TemplateURL url(NULL, data);
483 EXPECT_TRUE(url.url_ref().IsValid()); 491 EXPECT_TRUE(url.url_ref().IsValid());
484 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 492 ASSERT_TRUE(url.url_ref().SupportsReplacement());
485 GURL result(url.url_ref().ReplaceSearchTerms( 493 GURL result(url.url_ref().ReplaceSearchTerms(
486 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("x")))); 494 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("x"))));
487 ASSERT_TRUE(result.is_valid()); 495 ASSERT_TRUE(result.is_valid());
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 TemplateURLRef::Replacements replacements; 641 TemplateURLRef::Replacements replacements;
634 bool valid = false; 642 bool valid = false;
635 EXPECT_EQ("{", 643 EXPECT_EQ("{",
636 url.url_ref().ParseURL("{{searchTerms}", &replacements, &valid)); 644 url.url_ref().ParseURL("{{searchTerms}", &replacements, &valid));
637 ASSERT_EQ(1U, replacements.size()); 645 ASSERT_EQ(1U, replacements.size());
638 EXPECT_EQ(1U, replacements[0].index); 646 EXPECT_EQ(1U, replacements[0].index);
639 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type); 647 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
640 EXPECT_TRUE(valid); 648 EXPECT_TRUE(valid);
641 } 649 }
642 650
651 #if defined(OS_ANDROID)
652 TEST_F(TemplateURLTest, SearchClient) {
653 const std::string base_url_str("http://google.com/?");
654 const std::string terms_str("{searchTerms}&{google:searchClient}");
655 const std::string full_url_str = base_url_str + terms_str;
656 const string16 terms(ASCIIToUTF16(terms_str));
657 UIThreadSearchTermsData::SetGoogleBaseURL(base_url_str);
658
659 TemplateURLData data;
660 data.SetURL(full_url_str);
661 TemplateURL url(NULL, data);
662 EXPECT_TRUE(url.url_ref().IsValid());
663 ASSERT_TRUE(url.url_ref().SupportsReplacement());
664 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foobar"));
665
666 // Check that the URL is correct when a client is not present.
667 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args));
668 ASSERT_TRUE(result.is_valid());
669 EXPECT_EQ("http://google.com/?foobar&", result.spec());
670
671 // Check that the URL is correct when a client is present.
672 SearchTermsDataAndroid::search_client_.Get() = "android_test";
673 GURL result_2(url.url_ref().ReplaceSearchTerms(search_terms_args));
674 ASSERT_TRUE(result_2.is_valid());
675 EXPECT_EQ("http://google.com/?foobar&client=android_test&", result_2.spec());
676 }
677 #endif
678
643 TEST_F(TemplateURLTest, GetURLNoInstantURL) { 679 TEST_F(TemplateURLTest, GetURLNoInstantURL) {
644 TemplateURLData data; 680 TemplateURLData data;
645 data.SetURL("http://google.com/?q={searchTerms}"); 681 data.SetURL("http://google.com/?q={searchTerms}");
646 data.suggestions_url = "http://google.com/suggest?q={searchTerms}"; 682 data.suggestions_url = "http://google.com/suggest?q={searchTerms}";
647 data.alternate_urls.push_back("http://google.com/alt?q={searchTerms}"); 683 data.alternate_urls.push_back("http://google.com/alt?q={searchTerms}");
648 data.alternate_urls.push_back("{google:baseURL}/alt/#q={searchTerms}"); 684 data.alternate_urls.push_back("{google:baseURL}/alt/#q={searchTerms}");
649 TemplateURL url(NULL, data); 685 TemplateURL url(NULL, data);
650 ASSERT_EQ(3U, url.URLCount()); 686 ASSERT_EQ(3U, url.URLCount());
651 EXPECT_EQ("http://google.com/alt?q={searchTerms}", url.GetURL(0)); 687 EXPECT_EQ("http://google.com/alt?q={searchTerms}", url.GetURL(0));
652 EXPECT_EQ("{google:baseURL}/alt/#q={searchTerms}", url.GetURL(1)); 688 EXPECT_EQ("{google:baseURL}/alt/#q={searchTerms}", url.GetURL(1));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 EXPECT_EQ(string16(), result); 769 EXPECT_EQ(string16(), result);
734 770
735 EXPECT_FALSE(url.ExtractSearchTermsFromURL( 771 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
736 GURL("http://google.com/alt/?q=123#q="), &result)); 772 GURL("http://google.com/alt/?q=123#q="), &result));
737 EXPECT_EQ(string16(), result); 773 EXPECT_EQ(string16(), result);
738 774
739 EXPECT_TRUE(url.ExtractSearchTermsFromURL( 775 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
740 GURL("http://google.com/alt/?q=#q=123"), &result)); 776 GURL("http://google.com/alt/?q=#q=123"), &result));
741 EXPECT_EQ(ASCIIToUTF16("123"), result); 777 EXPECT_EQ(ASCIIToUTF16("123"), result);
742 } 778 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698