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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 // Multiple terms should result in empty values. | 362 // Multiple terms should result in empty values. |
363 { L"http://blah/?q={searchTerms}&x={searchTerms}", "", "", ""}, | 363 { L"http://blah/?q={searchTerms}&x={searchTerms}", "", "", ""}, |
364 | 364 |
365 // Term in the host shouldn't match. | 365 // Term in the host shouldn't match. |
366 { L"http://{searchTerms}", "", "", ""}, | 366 { L"http://{searchTerms}", "", "", ""}, |
367 | 367 |
368 { L"http://blah/?q={searchTerms}", "blah", "/", "q"}, | 368 { L"http://blah/?q={searchTerms}", "blah", "/", "q"}, |
369 | 369 |
370 // Single term with extra chars in value should match. | 370 // Single term with extra chars in value should match. |
371 { L"http://blah/?q=stock:{searchTerms}", "blah", "/", "q"}, | 371 { L"http://blah/?q=stock:{searchTerms}", "blah", "/", "q"}, |
372 | |
373 }; | 372 }; |
374 | 373 |
375 TemplateURL t_url; | 374 TemplateURL t_url; |
376 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 375 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
377 t_url.SetURL(data[i].url, 0, 0); | 376 t_url.SetURL(data[i].url, 0, 0); |
378 EXPECT_EQ(data[i].host, t_url.url()->GetHost()); | 377 EXPECT_EQ(data[i].host, t_url.url()->GetHost()); |
379 EXPECT_EQ(data[i].path, t_url.url()->GetPath()); | 378 EXPECT_EQ(data[i].path, t_url.url()->GetPath()); |
380 EXPECT_EQ(data[i].search_term_key, t_url.url()->GetSearchTermKey()); | 379 EXPECT_EQ(data[i].search_term_key, t_url.url()->GetSearchTermKey()); |
381 } | 380 } |
382 } | 381 } |
(...skipping 21 matching lines...) Expand all Loading... |
404 EXPECT_FALSE(t_url.autogenerate_keyword()); | 403 EXPECT_FALSE(t_url.autogenerate_keyword()); |
405 t_url.set_keyword(L"foo"); | 404 t_url.set_keyword(L"foo"); |
406 EXPECT_EQ(L"foo", t_url.keyword()); | 405 EXPECT_EQ(L"foo", t_url.keyword()); |
407 t_url.set_autogenerate_keyword(true); | 406 t_url.set_autogenerate_keyword(true); |
408 EXPECT_TRUE(t_url.autogenerate_keyword()); | 407 EXPECT_TRUE(t_url.autogenerate_keyword()); |
409 EXPECT_EQ(L"google.com", t_url.keyword()); | 408 EXPECT_EQ(L"google.com", t_url.keyword()); |
410 t_url.set_keyword(L"foo"); | 409 t_url.set_keyword(L"foo"); |
411 EXPECT_FALSE(t_url.autogenerate_keyword()); | 410 EXPECT_FALSE(t_url.autogenerate_keyword()); |
412 EXPECT_EQ(L"foo", t_url.keyword()); | 411 EXPECT_EQ(L"foo", t_url.keyword()); |
413 } | 412 } |
| 413 |
| 414 TEST_F(TemplateURLTest, ParseParameterKnown) { |
| 415 std::wstring parsed_url(L"{searchTerms}"); |
| 416 TemplateURLRef url_ref(parsed_url, 0, 0); |
| 417 TemplateURLRef::Replacements replacements; |
| 418 EXPECT_TRUE(url_ref.ParseParameter(0, 12, &parsed_url, &replacements)); |
| 419 EXPECT_EQ(std::wstring(), parsed_url); |
| 420 ASSERT_EQ(1U, replacements.size()); |
| 421 EXPECT_EQ(0, replacements[0].index); |
| 422 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type); |
| 423 } |
| 424 |
| 425 TEST_F(TemplateURLTest, ParseParameterUnknown) { |
| 426 std::wstring parsed_url(L"{}"); |
| 427 TemplateURLRef url_ref(parsed_url, 0, 0); |
| 428 TemplateURLRef::Replacements replacements; |
| 429 EXPECT_FALSE(url_ref.ParseParameter(0, 1, &parsed_url, &replacements)); |
| 430 EXPECT_EQ(L"{}", parsed_url); |
| 431 EXPECT_TRUE(replacements.empty()); |
| 432 } |
| 433 |
| 434 TEST_F(TemplateURLTest, ParseURLEmpty) { |
| 435 TemplateURLRef url_ref(L"", 0, 0); |
| 436 TemplateURLRef::Replacements replacements; |
| 437 bool valid = false; |
| 438 EXPECT_EQ(std::wstring(), url_ref.ParseURL(L"", &replacements, &valid)); |
| 439 EXPECT_TRUE(replacements.empty()); |
| 440 EXPECT_TRUE(valid); |
| 441 } |
| 442 |
| 443 TEST_F(TemplateURLTest, ParseURLNoTemplateEnd) { |
| 444 TemplateURLRef url_ref(L"{", 0, 0); |
| 445 TemplateURLRef::Replacements replacements; |
| 446 bool valid = false; |
| 447 EXPECT_EQ(std::wstring(), url_ref.ParseURL(L"{", &replacements, &valid)); |
| 448 EXPECT_TRUE(replacements.empty()); |
| 449 EXPECT_FALSE(valid); |
| 450 } |
| 451 |
| 452 TEST_F(TemplateURLTest, ParseURLNoKnownParameters) { |
| 453 TemplateURLRef url_ref(L"{}", 0, 0); |
| 454 TemplateURLRef::Replacements replacements; |
| 455 bool valid = false; |
| 456 EXPECT_EQ(L"{}", url_ref.ParseURL(L"{}", &replacements, &valid)); |
| 457 EXPECT_TRUE(replacements.empty()); |
| 458 EXPECT_TRUE(valid); |
| 459 } |
| 460 |
| 461 TEST_F(TemplateURLTest, ParseURLTwoParameters) { |
| 462 TemplateURLRef url_ref(L"{}{{%s}}", 0, 0); |
| 463 TemplateURLRef::Replacements replacements; |
| 464 bool valid = false; |
| 465 EXPECT_EQ(L"{}{}", |
| 466 url_ref.ParseURL(L"{}{{searchTerms}}", &replacements, &valid)); |
| 467 ASSERT_EQ(1U, replacements.size()); |
| 468 EXPECT_EQ(3, replacements[0].index); |
| 469 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type); |
| 470 EXPECT_TRUE(valid); |
| 471 } |
| 472 |
| 473 TEST_F(TemplateURLTest, ParseURLNestedParameter) { |
| 474 TemplateURLRef url_ref(L"{%s", 0, 0); |
| 475 TemplateURLRef::Replacements replacements; |
| 476 bool valid = false; |
| 477 EXPECT_EQ(L"{", url_ref.ParseURL(L"{{searchTerms}", &replacements, &valid)); |
| 478 ASSERT_EQ(1U, replacements.size()); |
| 479 EXPECT_EQ(1, replacements[0].index); |
| 480 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type); |
| 481 EXPECT_TRUE(valid); |
| 482 } |
OLD | NEW |