| 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 "chrome/browser/autocomplete/history_quick_provider.h" | 5 #include "chrome/browser/autocomplete/history_quick_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/format_macros.h" | 13 #include "base/format_macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "chrome/browser/autocomplete/autocomplete_match.h" | 19 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 20 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" | |
| 21 #include "chrome/browser/autocomplete/autocomplete_result.h" | 20 #include "chrome/browser/autocomplete/autocomplete_result.h" |
| 22 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 21 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
| 23 #include "chrome/browser/autocomplete/history_url_provider.h" | 22 #include "chrome/browser/autocomplete/history_url_provider.h" |
| 24 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 25 #include "chrome/browser/chrome_notification_types.h" | 24 #include "chrome/browser/chrome_notification_types.h" |
| 26 #include "chrome/browser/history/history_backend.h" | 25 #include "chrome/browser/history/history_backend.h" |
| 27 #include "chrome/browser/history/history_database.h" | 26 #include "chrome/browser/history/history_database.h" |
| 28 #include "chrome/browser/history/history_service.h" | 27 #include "chrome/browser/history/history_service.h" |
| 29 #include "chrome/browser/history/history_service_factory.h" | 28 #include "chrome/browser/history/history_service_factory.h" |
| 30 #include "chrome/browser/history/in_memory_url_index.h" | 29 #include "chrome/browser/history/in_memory_url_index.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 {"http://popularsitewithroot.com/", "popularsitewithroot.com", 50, 50, 0}, | 98 {"http://popularsitewithroot.com/", "popularsitewithroot.com", 50, 50, 0}, |
| 100 {"http://testsearch.com/?q=thequery", "Test Search Engine", 10, 10, 0}, | 99 {"http://testsearch.com/?q=thequery", "Test Search Engine", 10, 10, 0}, |
| 101 {"http://testsearch.com/", "Test Search Engine", 9, 9, 0}, | 100 {"http://testsearch.com/", "Test Search Engine", 9, 9, 0}, |
| 102 {"http://anotherengine.com/?q=thequery", "Another Search Engine", 8, 8, 0}, | 101 {"http://anotherengine.com/?q=thequery", "Another Search Engine", 8, 8, 0}, |
| 103 // The encoded stuff between /wiki/ and the # is 第二次世界大戦 | 102 // The encoded stuff between /wiki/ and the # is 第二次世界大戦 |
| 104 {"http://ja.wikipedia.org/wiki/%E7%AC%AC%E4%BA%8C%E6%AC%A1%E4%B8%96%E7%95" | 103 {"http://ja.wikipedia.org/wiki/%E7%AC%AC%E4%BA%8C%E6%AC%A1%E4%B8%96%E7%95" |
| 105 "%8C%E5%A4%A7%E6%88%A6#.E3.83.B4.E3.82.A7.E3.83.AB.E3.82.B5.E3.82.A4.E3." | 104 "%8C%E5%A4%A7%E6%88%A6#.E3.83.B4.E3.82.A7.E3.83.AB.E3.82.B5.E3.82.A4.E3." |
| 106 "83.A6.E4.BD.93.E5.88.B6", "Title Unimportant", 2, 2, 0} | 105 "83.A6.E4.BD.93.E5.88.B6", "Title Unimportant", 2, 2, 0} |
| 107 }; | 106 }; |
| 108 | 107 |
| 109 class HistoryQuickProviderTest : public testing::Test, | 108 class HistoryQuickProviderTest : public testing::Test { |
| 110 public AutocompleteProviderListener { | |
| 111 public: | 109 public: |
| 112 HistoryQuickProviderTest() | 110 HistoryQuickProviderTest() |
| 113 : ui_thread_(BrowserThread::UI, &message_loop_), | 111 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 114 file_thread_(BrowserThread::FILE, &message_loop_) {} | 112 file_thread_(BrowserThread::FILE, &message_loop_) {} |
| 115 | 113 |
| 116 // AutocompleteProviderListener: | |
| 117 virtual void OnProviderUpdate(bool updated_matches) OVERRIDE {} | |
| 118 | |
| 119 protected: | 114 protected: |
| 120 class SetShouldContain : public std::unary_function<const std::string&, | 115 class SetShouldContain : public std::unary_function<const std::string&, |
| 121 std::set<std::string> > { | 116 std::set<std::string> > { |
| 122 public: | 117 public: |
| 123 explicit SetShouldContain(const ACMatches& matched_urls); | 118 explicit SetShouldContain(const ACMatches& matched_urls); |
| 124 | 119 |
| 125 void operator()(const std::string& expected); | 120 void operator()(const std::string& expected); |
| 126 | 121 |
| 127 std::set<std::string> LeftOvers() const { return matches_; } | 122 std::set<std::string> LeftOvers() const { return matches_; } |
| 128 | 123 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 profile_.reset(new TestingProfile()); | 182 profile_.reset(new TestingProfile()); |
| 188 ASSERT_TRUE(profile_->CreateHistoryService(true, false)); | 183 ASSERT_TRUE(profile_->CreateHistoryService(true, false)); |
| 189 profile_->CreateBookmarkModel(true); | 184 profile_->CreateBookmarkModel(true); |
| 190 test::WaitForBookmarkModelToLoad( | 185 test::WaitForBookmarkModelToLoad( |
| 191 BookmarkModelFactory::GetForProfile(profile_.get())); | 186 BookmarkModelFactory::GetForProfile(profile_.get())); |
| 192 profile_->BlockUntilHistoryIndexIsRefreshed(); | 187 profile_->BlockUntilHistoryIndexIsRefreshed(); |
| 193 history_service_ = | 188 history_service_ = |
| 194 HistoryServiceFactory::GetForProfile(profile_.get(), | 189 HistoryServiceFactory::GetForProfile(profile_.get(), |
| 195 Profile::EXPLICIT_ACCESS); | 190 Profile::EXPLICIT_ACCESS); |
| 196 EXPECT_TRUE(history_service_); | 191 EXPECT_TRUE(history_service_); |
| 197 provider_ = new HistoryQuickProvider(this, profile_.get()); | 192 provider_ = new HistoryQuickProvider(profile_.get()); |
| 198 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 193 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 199 profile_.get(), &HistoryQuickProviderTest::CreateTemplateURLService); | 194 profile_.get(), &HistoryQuickProviderTest::CreateTemplateURLService); |
| 200 FillData(); | 195 FillData(); |
| 201 provider_->GetIndex()->RebuildFromHistory(history_backend()->db()); | 196 provider_->GetIndex()->RebuildFromHistory(history_backend()->db()); |
| 202 } | 197 } |
| 203 | 198 |
| 204 void HistoryQuickProviderTest::TearDown() { | 199 void HistoryQuickProviderTest::TearDown() { |
| 205 provider_ = NULL; | 200 provider_ = NULL; |
| 206 } | 201 } |
| 207 | 202 |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 | 775 |
| 781 TEST_F(HQPOrderingTest, TEAMatch) { | 776 TEST_F(HQPOrderingTest, TEAMatch) { |
| 782 std::vector<std::string> expected_urls; | 777 std::vector<std::string> expected_urls; |
| 783 expected_urls.push_back("http://www.teamliquid.net/"); | 778 expected_urls.push_back("http://www.teamliquid.net/"); |
| 784 expected_urls.push_back("http://www.teamliquid.net/tlpd"); | 779 expected_urls.push_back("http://www.teamliquid.net/tlpd"); |
| 785 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); | 780 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); |
| 786 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, | 781 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, |
| 787 ASCIIToUTF16("www.teamliquid.net"), | 782 ASCIIToUTF16("www.teamliquid.net"), |
| 788 ASCIIToUTF16("mliquid.net")); | 783 ASCIIToUTF16("mliquid.net")); |
| 789 } | 784 } |
| OLD | NEW |