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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "chrome/browser/search_engines/template_url.h" | 8 #include "chrome/browser/search_engines/template_url.h" |
9 #include "chrome/browser/search_engines/template_url_model.h" | 9 #include "chrome/browser/search_engines/template_url_model.h" |
10 #include "chrome/common/pref_service.h" | 10 #include "chrome/common/pref_service.h" |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 // changing. | 625 // changing. |
626 SetGoogleBaseURL(L"http://foo.com/"); | 626 SetGoogleBaseURL(L"http://foo.com/"); |
627 model_->GoogleBaseURLChanged(); | 627 model_->GoogleBaseURLChanged(); |
628 VerifyObserverCount(1); | 628 VerifyObserverCount(1); |
629 | 629 |
630 // Make sure the host->TemplateURL map was updated appropriately. | 630 // Make sure the host->TemplateURL map was updated appropriately. |
631 ASSERT_EQ(t_url, model_->GetTemplateURLForHost("foo.com")); | 631 ASSERT_EQ(t_url, model_->GetTemplateURLForHost("foo.com")); |
632 EXPECT_TRUE(model_->GetTemplateURLForHost("google.com") == NULL); | 632 EXPECT_TRUE(model_->GetTemplateURLForHost("google.com") == NULL); |
633 EXPECT_EQ("foo.com", t_url->url()->GetHost()); | 633 EXPECT_EQ("foo.com", t_url->url()->GetHost()); |
634 EXPECT_EQ(L"foo.com", t_url->keyword()); | 634 EXPECT_EQ(L"foo.com", t_url->keyword()); |
635 EXPECT_EQ("http://foo.com/?q=x", t_url->url()->ReplaceSearchTerms(*t_url, | 635 EXPECT_EQ(L"http://foo.com/?q=x", t_url->url()->ReplaceSearchTerms(*t_url, |
636 L"x", TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()).spec()); | 636 L"x", TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); |
637 } | 637 } |
638 | 638 |
639 struct QueryHistoryCallbackImpl { | 639 struct QueryHistoryCallbackImpl { |
640 QueryHistoryCallbackImpl() : success(false) {} | 640 QueryHistoryCallbackImpl() : success(false) {} |
641 | 641 |
642 void Callback(HistoryService::Handle handle, | 642 void Callback(HistoryService::Handle handle, |
643 bool success, const history::URLRow* row, | 643 bool success, const history::URLRow* row, |
644 history::VisitVector* visits) { | 644 history::VisitVector* visits) { |
645 this->success = success; | 645 this->success = success; |
646 if (row) | 646 if (row) |
(...skipping 15 matching lines...) Expand all Loading... |
662 | 662 |
663 // Create a keyword. | 663 // Create a keyword. |
664 TemplateURL* t_url = AddKeywordWithDate( | 664 TemplateURL* t_url = AddKeywordWithDate( |
665 L"keyword", false, L"http://foo.com/foo?query={searchTerms}", | 665 L"keyword", false, L"http://foo.com/foo?query={searchTerms}", |
666 L"keyword", true, base::Time::Now()); | 666 L"keyword", true, base::Time::Now()); |
667 | 667 |
668 // Add a visit that matches the url of the keyword. | 668 // Add a visit that matches the url of the keyword. |
669 HistoryService* history = | 669 HistoryService* history = |
670 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 670 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
671 history->AddPage( | 671 history->AddPage( |
672 t_url->url()->ReplaceSearchTerms(*t_url, L"blah", 0, std::wstring()), | 672 GURL(WideToUTF8(t_url->url()->ReplaceSearchTerms(*t_url, L"blah", 0, |
| 673 std::wstring()))), |
673 NULL, 0, GURL(), PageTransition::KEYWORD, HistoryService::RedirectList()); | 674 NULL, 0, GURL(), PageTransition::KEYWORD, HistoryService::RedirectList()); |
674 | 675 |
675 // Wait for history to finish processing the request. | 676 // Wait for history to finish processing the request. |
676 profile_->BlockUntilHistoryProcessesPendingRequests(); | 677 profile_->BlockUntilHistoryProcessesPendingRequests(); |
677 | 678 |
678 // Query history for the generated url. | 679 // Query history for the generated url. |
679 CancelableRequestConsumer consumer; | 680 CancelableRequestConsumer consumer; |
680 QueryHistoryCallbackImpl callback; | 681 QueryHistoryCallbackImpl callback; |
681 history->QueryURL(GURL("http://keyword"), true, &consumer, | 682 history->QueryURL(GURL("http://keyword"), true, &consumer, |
682 NewCallback(&callback, &QueryHistoryCallbackImpl::Callback)); | 683 NewCallback(&callback, &QueryHistoryCallbackImpl::Callback)); |
683 | 684 |
684 // Wait for the request to be processed. | 685 // Wait for the request to be processed. |
685 profile_->BlockUntilHistoryProcessesPendingRequests(); | 686 profile_->BlockUntilHistoryProcessesPendingRequests(); |
686 | 687 |
687 // And make sure the url and visit were added. | 688 // And make sure the url and visit were added. |
688 EXPECT_TRUE(callback.success); | 689 EXPECT_TRUE(callback.success); |
689 EXPECT_NE(0, callback.row.id()); | 690 EXPECT_NE(0, callback.row.id()); |
690 ASSERT_EQ(1U, callback.visits.size()); | 691 ASSERT_EQ(1U, callback.visits.size()); |
691 EXPECT_EQ(PageTransition::KEYWORD_GENERATED, | 692 EXPECT_EQ(PageTransition::KEYWORD_GENERATED, |
692 PageTransition::StripQualifier(callback.visits[0].transition)); | 693 PageTransition::StripQualifier(callback.visits[0].transition)); |
693 } | 694 } |
OLD | NEW |