| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/rlz/rlz.h" | 8 #include "chrome/browser/rlz/rlz.h" |
| 9 #include "chrome/browser/search_engines/template_url.h" | 9 #include "chrome/browser/search_engines/template_url.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 ASSERT_FALSE(url.safe_for_autoreplace()); | 31 ASSERT_FALSE(url.safe_for_autoreplace()); |
| 32 ASSERT_EQ(0, url.prepopulate_id()); | 32 ASSERT_EQ(0, url.prepopulate_id()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 TEST_F(TemplateURLTest, TestValidWithComplete) { | 35 TEST_F(TemplateURLTest, TestValidWithComplete) { |
| 36 TemplateURLRef ref(L"{searchTerms}", 0, 0); | 36 TemplateURLRef ref(L"{searchTerms}", 0, 0); |
| 37 ASSERT_TRUE(ref.IsValid()); | 37 ASSERT_TRUE(ref.IsValid()); |
| 38 } | 38 } |
| 39 | 39 |
| 40 TEST_F(TemplateURLTest, URLRefTestSearchTerms) { | 40 TEST_F(TemplateURLTest, URLRefTestSearchTerms) { |
| 41 TemplateURL t_url; | 41 struct SearchTermsCase { |
| 42 TemplateURLRef ref(L"http://foo{searchTerms}", 0, 0); | 42 const wchar_t* url; |
| 43 ASSERT_TRUE(ref.IsValid()); | 43 const wchar_t* terms; |
| 44 const char* output; |
| 45 } search_term_cases[] = { |
| 46 { L"http://foo{searchTerms}", L"sea rch", "http://foosea%20rch/" }, |
| 47 { L"http://foo{searchTerms}?boo=abc", L"sea rch", |
| 48 "http://foosea%20rch/?boo=abc" }, |
| 49 { L"http://foo/?boo={searchTerms}", L"sea rch", |
| 50 "http://foo/?boo=sea+rch" } |
| 51 }; |
| 52 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) { |
| 53 const SearchTermsCase& value = search_term_cases[i]; |
| 54 TemplateURL t_url; |
| 55 TemplateURLRef ref(value.url, 0, 0); |
| 56 ASSERT_TRUE(ref.IsValid()); |
| 44 | 57 |
| 45 ASSERT_TRUE(ref.SupportsReplacement()); | 58 ASSERT_TRUE(ref.SupportsReplacement()); |
| 46 GURL result = GURL(WideToUTF8(ref.ReplaceSearchTerms(t_url, L"search", | 59 GURL result = GURL(WideToUTF8(ref.ReplaceSearchTerms(t_url, value.terms, |
| 47 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))); | 60 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))); |
| 48 ASSERT_TRUE(result.is_valid()); | 61 ASSERT_TRUE(result.is_valid()); |
| 49 ASSERT_EQ("http://foosearch/", result.spec()); | 62 ASSERT_EQ(value.output, result.spec()); |
| 63 } |
| 50 } | 64 } |
| 51 | 65 |
| 52 TEST_F(TemplateURLTest, URLRefTestCount) { | 66 TEST_F(TemplateURLTest, URLRefTestCount) { |
| 53 TemplateURL t_url; | 67 TemplateURL t_url; |
| 54 TemplateURLRef ref(L"http://foo{searchTerms}{count?}", 0, 0); | 68 TemplateURLRef ref(L"http://foo{searchTerms}{count?}", 0, 0); |
| 55 ASSERT_TRUE(ref.IsValid()); | 69 ASSERT_TRUE(ref.IsValid()); |
| 56 ASSERT_TRUE(ref.SupportsReplacement()); | 70 ASSERT_TRUE(ref.SupportsReplacement()); |
| 57 GURL result = GURL(WideToUTF8(ref.ReplaceSearchTerms(t_url, L"X", | 71 GURL result = GURL(WideToUTF8(ref.ReplaceSearchTerms(t_url, L"X", |
| 58 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))); | 72 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))); |
| 59 ASSERT_TRUE(result.is_valid()); | 73 ASSERT_TRUE(result.is_valid()); |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 EXPECT_FALSE(t_url.autogenerate_keyword()); | 404 EXPECT_FALSE(t_url.autogenerate_keyword()); |
| 391 t_url.set_keyword(L"foo"); | 405 t_url.set_keyword(L"foo"); |
| 392 EXPECT_EQ(L"foo", t_url.keyword()); | 406 EXPECT_EQ(L"foo", t_url.keyword()); |
| 393 t_url.set_autogenerate_keyword(true); | 407 t_url.set_autogenerate_keyword(true); |
| 394 EXPECT_TRUE(t_url.autogenerate_keyword()); | 408 EXPECT_TRUE(t_url.autogenerate_keyword()); |
| 395 EXPECT_EQ(L"google.com", t_url.keyword()); | 409 EXPECT_EQ(L"google.com", t_url.keyword()); |
| 396 t_url.set_keyword(L"foo"); | 410 t_url.set_keyword(L"foo"); |
| 397 EXPECT_FALSE(t_url.autogenerate_keyword()); | 411 EXPECT_FALSE(t_url.autogenerate_keyword()); |
| 398 EXPECT_EQ(L"foo", t_url.keyword()); | 412 EXPECT_EQ(L"foo", t_url.keyword()); |
| 399 } | 413 } |
| OLD | NEW |