| 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 "components/omnibox/browser/history_quick_provider.h" | 5 #include "components/omnibox/browser/history_quick_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <functional> | 10 #include <functional> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/files/scoped_temp_dir.h" | |
| 17 #include "base/format_macros.h" | 16 #include "base/format_macros.h" |
| 18 #include "base/macros.h" | 17 #include "base/macros.h" |
| 19 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 20 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
| 21 #include "base/strings/stringprintf.h" | |
| 22 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/test/sequenced_worker_pool_owner.h" | |
| 24 #include "components/bookmarks/browser/bookmark_model.h" | 21 #include "components/bookmarks/browser/bookmark_model.h" |
| 25 #include "components/bookmarks/test/bookmark_test_helpers.h" | 22 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 26 #include "components/bookmarks/test/test_bookmark_client.h" | 23 #include "components/bookmarks/test/test_bookmark_client.h" |
| 27 #include "components/history/core/browser/history_backend.h" | 24 #include "components/history/core/browser/history_backend.h" |
| 28 #include "components/history/core/browser/history_database.h" | 25 #include "components/history/core/browser/history_database.h" |
| 29 #include "components/history/core/browser/history_service.h" | 26 #include "components/history/core/browser/history_service.h" |
| 30 #include "components/history/core/browser/history_service_observer.h" | 27 #include "components/history/core/browser/history_service_observer.h" |
| 31 #include "components/history/core/browser/url_database.h" | 28 #include "components/history/core/browser/url_database.h" |
| 32 #include "components/history/core/test/history_service_test_util.h" | 29 #include "components/history/core/test/history_service_test_util.h" |
| 33 #include "components/metrics/proto/omnibox_event.pb.h" | |
| 34 #include "components/omnibox/browser/autocomplete_match.h" | 30 #include "components/omnibox/browser/autocomplete_match.h" |
| 35 #include "components/omnibox/browser/autocomplete_result.h" | 31 #include "components/omnibox/browser/autocomplete_result.h" |
| 32 #include "components/omnibox/browser/fake_autocomplete_provider_client.h" |
| 33 #include "components/omnibox/browser/history_test_util.h" |
| 36 #include "components/omnibox/browser/history_url_provider.h" | 34 #include "components/omnibox/browser/history_url_provider.h" |
| 37 #include "components/omnibox/browser/in_memory_url_index.h" | |
| 38 #include "components/omnibox/browser/in_memory_url_index_test_util.h" | 35 #include "components/omnibox/browser/in_memory_url_index_test_util.h" |
| 39 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" | |
| 40 #include "components/omnibox/browser/test_scheme_classifier.h" | |
| 41 #include "components/omnibox/browser/url_index_private_data.h" | |
| 42 #include "components/prefs/pref_service.h" | 36 #include "components/prefs/pref_service.h" |
| 43 #include "components/search_engines/search_terms_data.h" | 37 #include "components/search_engines/search_terms_data.h" |
| 44 #include "sql/transaction.h" | |
| 45 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 46 | 39 |
| 47 using base::ASCIIToUTF16; | 40 using base::ASCIIToUTF16; |
| 48 using base::Time; | |
| 49 using base::TimeDelta; | |
| 50 | 41 |
| 51 namespace { | 42 namespace { |
| 52 | 43 |
| 53 struct TestURLInfo { | |
| 54 std::string url; | |
| 55 std::string title; | |
| 56 int visit_count; | |
| 57 int typed_count; | |
| 58 int days_from_now; | |
| 59 } quick_test_db[] = { | |
| 60 {"http://www.google.com/", "Google", 3, 3, 0}, | |
| 61 {"http://slashdot.org/favorite_page.html", "Favorite page", 200, 100, 0}, | |
| 62 {"http://kerneltrap.org/not_very_popular.html", "Less popular", 4, 0, 0}, | |
| 63 {"http://freshmeat.net/unpopular.html", "Unpopular", 1, 1, 0}, | |
| 64 {"http://news.google.com/?ned=us&topic=n", "Google News - U.S.", 2, 2, 0}, | |
| 65 {"http://news.google.com/", "Google News", 1, 1, 0}, | |
| 66 {"http://foo.com/", "Dir", 200, 100, 0}, | |
| 67 {"http://foo.com/dir/", "Dir", 2, 1, 10}, | |
| 68 {"http://foo.com/dir/another/", "Dir", 10, 5, 0}, | |
| 69 {"http://foo.com/dir/another/again/", "Dir", 5, 1, 0}, | |
| 70 {"http://foo.com/dir/another/again/myfile.html", "File", 3, 1, 0}, | |
| 71 {"http://visitedest.com/y/a", "VA", 10, 1, 20}, | |
| 72 {"http://visitedest.com/y/b", "VB", 9, 1, 20}, | |
| 73 {"http://visitedest.com/x/c", "VC", 8, 1, 20}, | |
| 74 {"http://visitedest.com/x/d", "VD", 7, 1, 20}, | |
| 75 {"http://visitedest.com/y/e", "VE", 6, 1, 20}, | |
| 76 {"http://typeredest.com/y/a", "TA", 5, 5, 0}, | |
| 77 {"http://typeredest.com/y/b", "TB", 5, 4, 0}, | |
| 78 {"http://typeredest.com/x/c", "TC", 5, 3, 0}, | |
| 79 {"http://typeredest.com/x/d", "TD", 5, 2, 0}, | |
| 80 {"http://typeredest.com/y/e", "TE", 5, 1, 0}, | |
| 81 {"http://daysagoest.com/y/a", "DA", 1, 1, 0}, | |
| 82 {"http://daysagoest.com/y/b", "DB", 1, 1, 1}, | |
| 83 {"http://daysagoest.com/x/c", "DC", 1, 1, 2}, | |
| 84 {"http://daysagoest.com/x/d", "DD", 1, 1, 3}, | |
| 85 {"http://daysagoest.com/y/e", "DE", 1, 1, 4}, | |
| 86 {"http://abcdefghixyzjklmnopqrstuvw.com/a", "", 3, 1, 0}, | |
| 87 {"http://spaces.com/path%20with%20spaces/foo.html", "Spaces", 2, 2, 0}, | |
| 88 {"http://abcdefghijklxyzmnopqrstuvw.com/a", "", 3, 1, 0}, | |
| 89 {"http://abcdefxyzghijklmnopqrstuvw.com/a", "", 3, 1, 0}, | |
| 90 {"http://abcxyzdefghijklmnopqrstuvw.com/a", "", 3, 1, 0}, | |
| 91 {"http://xyzabcdefghijklmnopqrstuvw.com/a", "", 3, 1, 0}, | |
| 92 {"http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice", | |
| 93 "Dogs & Cats & Mice & Other Animals", 1, 1, 0}, | |
| 94 {"https://monkeytrap.org/", "", 3, 1, 0}, | |
| 95 {"http://popularsitewithpathonly.com/moo", | |
| 96 "popularsitewithpathonly.com/moo", 50, 50, 0}, | |
| 97 {"http://popularsitewithroot.com/", "popularsitewithroot.com", 50, 50, 0}, | |
| 98 {"http://testsearch.com/?q=thequery", "Test Search Engine", 10, 10, 0}, | |
| 99 {"http://testsearch.com/", "Test Search Engine", 9, 9, 0}, | |
| 100 {"http://anotherengine.com/?q=thequery", "Another Search Engine", 8, 8, 0}, | |
| 101 // The encoded stuff between /wiki/ and the # is 第二次世界大戦 | |
| 102 {"http://ja.wikipedia.org/wiki/%E7%AC%AC%E4%BA%8C%E6%AC%A1%E4%B8%96%E7%95" | |
| 103 "%8C%E5%A4%A7%E6%88%A6#.E3.83.B4.E3.82.A7.E3.83.AB.E3.82.B5.E3.82.A4.E3." | |
| 104 "83.A6.E4.BD.93.E5.88.B6", | |
| 105 "Title Unimportant", 2, 2, 0}, | |
| 106 {"https://twitter.com/fungoodtimes", "relatable!", 1, 1, 0}}; | |
| 107 | |
| 108 // Waits for OnURLsDeletedNotification and when run quits the supplied run loop. | 44 // Waits for OnURLsDeletedNotification and when run quits the supplied run loop. |
| 109 class WaitForURLsDeletedObserver : public history::HistoryServiceObserver { | 45 class WaitForURLsDeletedObserver : public history::HistoryServiceObserver { |
| 110 public: | 46 public: |
| 111 explicit WaitForURLsDeletedObserver(base::RunLoop* runner); | 47 explicit WaitForURLsDeletedObserver(base::RunLoop* runner); |
| 112 ~WaitForURLsDeletedObserver() override; | 48 ~WaitForURLsDeletedObserver() override; |
| 113 | 49 |
| 114 private: | 50 private: |
| 115 // history::HistoryServiceObserver: | 51 // history::HistoryServiceObserver: |
| 116 void OnURLsDeleted(history::HistoryService* service, | 52 void OnURLsDeleted(history::HistoryService* service, |
| 117 bool all_history, | 53 bool all_history, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 107 |
| 172 private: | 108 private: |
| 173 ~GetURLTask() override {} | 109 ~GetURLTask() override {} |
| 174 | 110 |
| 175 bool* result_storage_; | 111 bool* result_storage_; |
| 176 const GURL url_; | 112 const GURL url_; |
| 177 | 113 |
| 178 DISALLOW_COPY_AND_ASSIGN(GetURLTask); | 114 DISALLOW_COPY_AND_ASSIGN(GetURLTask); |
| 179 }; | 115 }; |
| 180 | 116 |
| 181 class FakeAutocompleteProviderClient : public MockAutocompleteProviderClient { | |
| 182 public: | |
| 183 FakeAutocompleteProviderClient() : pool_owner_(3, "Background Pool") { | |
| 184 bookmark_model_ = bookmarks::TestBookmarkClient::CreateModel(); | |
| 185 if (history_dir_.CreateUniqueTempDir()) { | |
| 186 history_service_ = | |
| 187 history::CreateHistoryService(history_dir_.GetPath(), true); | |
| 188 } | |
| 189 | |
| 190 in_memory_url_index_.reset(new InMemoryURLIndex( | |
| 191 bookmark_model_.get(), history_service_.get(), nullptr, | |
| 192 pool_owner_.pool().get(), history_dir_.GetPath(), SchemeSet())); | |
| 193 in_memory_url_index_->Init(); | |
| 194 } | |
| 195 | |
| 196 const AutocompleteSchemeClassifier& GetSchemeClassifier() const override { | |
| 197 return scheme_classifier_; | |
| 198 } | |
| 199 | |
| 200 const SearchTermsData& GetSearchTermsData() const override { | |
| 201 return search_terms_data_; | |
| 202 } | |
| 203 | |
| 204 history::HistoryService* GetHistoryService() override { | |
| 205 return history_service_.get(); | |
| 206 } | |
| 207 | |
| 208 bookmarks::BookmarkModel* GetBookmarkModel() override { | |
| 209 return bookmark_model_.get(); | |
| 210 } | |
| 211 | |
| 212 InMemoryURLIndex* GetInMemoryURLIndex() override { | |
| 213 return in_memory_url_index_.get(); | |
| 214 } | |
| 215 | |
| 216 void set_in_memory_url_index(std::unique_ptr<InMemoryURLIndex> index) { | |
| 217 in_memory_url_index_ = std::move(index); | |
| 218 } | |
| 219 | |
| 220 private: | |
| 221 base::SequencedWorkerPoolOwner pool_owner_; | |
| 222 base::ScopedTempDir history_dir_; | |
| 223 std::unique_ptr<bookmarks::BookmarkModel> bookmark_model_; | |
| 224 TestSchemeClassifier scheme_classifier_; | |
| 225 SearchTermsData search_terms_data_; | |
| 226 std::unique_ptr<InMemoryURLIndex> in_memory_url_index_; | |
| 227 std::unique_ptr<history::HistoryService> history_service_; | |
| 228 | |
| 229 DISALLOW_COPY_AND_ASSIGN(FakeAutocompleteProviderClient); | |
| 230 }; | |
| 231 | |
| 232 } // namespace | 117 } // namespace |
| 233 | 118 |
| 234 class HistoryQuickProviderTest : public testing::Test { | 119 class HistoryQuickProviderTest : public testing::Test { |
| 235 public: | 120 public: |
| 236 HistoryQuickProviderTest() {} | 121 HistoryQuickProviderTest() = default; |
| 237 | 122 |
| 238 protected: | 123 protected: |
| 124 struct TestURLInfo { |
| 125 std::string url; |
| 126 std::string title; |
| 127 int visit_count; |
| 128 int typed_count; |
| 129 int days_from_now; |
| 130 }; |
| 131 |
| 239 class SetShouldContain { | 132 class SetShouldContain { |
| 240 public: | 133 public: |
| 241 explicit SetShouldContain(const ACMatches& matched_urls); | 134 explicit SetShouldContain(const ACMatches& matched_urls); |
| 242 | 135 |
| 243 void operator()(const std::string& expected); | 136 void operator()(const std::string& expected); |
| 244 | 137 |
| 245 std::set<std::string> LeftOvers() const { return matches_; } | 138 std::set<std::string> LeftOvers() const { return matches_; } |
| 246 | 139 |
| 247 private: | 140 private: |
| 248 std::set<std::string> matches_; | 141 std::set<std::string> matches_; |
| 249 }; | 142 }; |
| 250 | 143 |
| 251 void SetUp() override; | 144 void SetUp() override; |
| 252 void TearDown() override; | 145 void TearDown() override; |
| 253 | 146 |
| 254 virtual void GetTestData(size_t* data_count, TestURLInfo** test_data); | 147 virtual std::vector<TestURLInfo> GetTestData(); |
| 255 | 148 |
| 256 // Fills test data into the history system. | 149 // Fills test data into the history system. |
| 257 void FillData(); | 150 void FillData(); |
| 258 | 151 |
| 259 // Runs an autocomplete query on |text| and checks to see that the returned | 152 // Runs an autocomplete query on |text| and checks to see that the returned |
| 260 // results' destination URLs match those provided. |expected_urls| does not | 153 // results' destination URLs match those provided. |expected_urls| does not |
| 261 // need to be in sorted order. | 154 // need to be in sorted order. |
| 262 void RunTest(const base::string16 text, | 155 void RunTest(const base::string16 text, |
| 263 bool prevent_inline_autocomplete, | 156 bool prevent_inline_autocomplete, |
| 264 std::vector<std::string> expected_urls, | 157 std::vector<std::string> expected_urls, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 281 // > message_loop(). | 174 // > message_loop(). |
| 282 // Direct use of this object in tests is almost certainly not thread-safe. | 175 // Direct use of this object in tests is almost certainly not thread-safe. |
| 283 history::HistoryBackend* history_backend() { | 176 history::HistoryBackend* history_backend() { |
| 284 return client_->GetHistoryService()->history_backend_.get(); | 177 return client_->GetHistoryService()->history_backend_.get(); |
| 285 } | 178 } |
| 286 | 179 |
| 287 // Call history_backend()->GetURL(url, NULL) on the history thread, returning | 180 // Call history_backend()->GetURL(url, NULL) on the history thread, returning |
| 288 // the result. | 181 // the result. |
| 289 bool GetURLProxy(const GURL& url); | 182 bool GetURLProxy(const GURL& url); |
| 290 | 183 |
| 184 FakeAutocompleteProviderClient& client() { return *client_; } |
| 185 ACMatches& ac_matches() { return ac_matches_; } |
| 186 HistoryQuickProvider& provider() { return *provider_; } |
| 187 |
| 188 private: |
| 291 base::MessageLoop message_loop_; | 189 base::MessageLoop message_loop_; |
| 292 std::unique_ptr<FakeAutocompleteProviderClient> client_; | 190 std::unique_ptr<FakeAutocompleteProviderClient> client_; |
| 293 | 191 |
| 294 ACMatches ac_matches_; // The resulting matches after running RunTest. | 192 ACMatches ac_matches_; // The resulting matches after running RunTest. |
| 295 | 193 |
| 296 scoped_refptr<HistoryQuickProvider> provider_; | 194 scoped_refptr<HistoryQuickProvider> provider_; |
| 195 |
| 196 DISALLOW_COPY_AND_ASSIGN(HistoryQuickProviderTest); |
| 297 }; | 197 }; |
| 298 | 198 |
| 299 void HistoryQuickProviderTest::SetUp() { | 199 void HistoryQuickProviderTest::SetUp() { |
| 300 client_.reset(new FakeAutocompleteProviderClient()); | 200 client_.reset(new FakeAutocompleteProviderClient()); |
| 301 ASSERT_TRUE(client_->GetHistoryService()); | 201 ASSERT_TRUE(client_->GetHistoryService()); |
| 302 FillData(); | 202 ASSERT_NO_FATAL_FAILURE(FillData()); |
| 303 | 203 |
| 304 // |FillData()| must be called before |RebuildFromHistory()|. This will | 204 // FillData() must be called before RebuildFromHistory(). This will |
| 305 // ensure that the index is properly populated with data from the database. | 205 // ensure that the index is properly populated with data from the database. |
| 306 InMemoryURLIndex* url_index = client_->GetInMemoryURLIndex(); | 206 InMemoryURLIndex* url_index = client_->GetInMemoryURLIndex(); |
| 307 url_index->RebuildFromHistory( | 207 url_index->RebuildFromHistory( |
| 308 client_->GetHistoryService()->history_backend_->db()); | 208 client_->GetHistoryService()->history_backend_->db()); |
| 309 BlockUntilInMemoryURLIndexIsRefreshed(url_index); | 209 BlockUntilInMemoryURLIndexIsRefreshed(url_index); |
| 310 | 210 |
| 311 // History index refresh creates rebuilt tasks to run on history thread. | 211 // History index refresh creates rebuilt tasks to run on history thread. |
| 312 // Block here to make sure that all of them are complete. | 212 // Block here to make sure that all of them are complete. |
| 313 history::BlockUntilHistoryProcessesPendingRequests( | 213 history::BlockUntilHistoryProcessesPendingRequests( |
| 314 client_->GetHistoryService()); | 214 client_->GetHistoryService()); |
| 315 | 215 |
| 316 provider_ = new HistoryQuickProvider(client_.get()); | 216 provider_ = new HistoryQuickProvider(client_.get()); |
| 317 } | 217 } |
| 318 | 218 |
| 319 void HistoryQuickProviderTest::TearDown() { | 219 void HistoryQuickProviderTest::TearDown() { |
| 320 provider_ = NULL; | 220 provider_ = nullptr; |
| 321 // The InMemoryURLIndex must be explicitly shut down or it will DCHECK() in | 221 // The InMemoryURLIndex must be explicitly shut down or it will DCHECK() in |
| 322 // its destructor. | 222 // its destructor. |
| 323 client_->GetInMemoryURLIndex()->Shutdown(); | 223 client_->GetInMemoryURLIndex()->Shutdown(); |
| 324 client_->set_in_memory_url_index(nullptr); | 224 client_->set_in_memory_url_index(nullptr); |
| 325 // History index rebuild task is created from main thread during SetUp, | 225 // History index rebuild task is created from main thread during SetUp, |
| 326 // performed on DB thread and must be deleted on main thread. | 226 // performed on DB thread and must be deleted on main thread. |
| 327 // Run main loop to process delete task, to prevent leaks. | 227 // Run main loop to process delete task, to prevent leaks. |
| 328 base::RunLoop().RunUntilIdle(); | 228 base::RunLoop().RunUntilIdle(); |
| 329 } | 229 } |
| 330 | 230 |
| 331 void HistoryQuickProviderTest::GetTestData(size_t* data_count, | 231 std::vector<HistoryQuickProviderTest::TestURLInfo> |
| 332 TestURLInfo** test_data) { | 232 HistoryQuickProviderTest::GetTestData() { |
| 333 DCHECK(data_count); | 233 return { |
| 334 DCHECK(test_data); | 234 {"http://www.google.com/", "Google", 3, 3, 0}, |
| 335 *data_count = arraysize(quick_test_db); | 235 {"http://slashdot.org/favorite_page.html", "Favorite page", 200, 100, 0}, |
| 336 *test_data = &quick_test_db[0]; | 236 {"http://kerneltrap.org/not_very_popular.html", "Less popular", 4, 0, 0}, |
| 237 {"http://freshmeat.net/unpopular.html", "Unpopular", 1, 1, 0}, |
| 238 {"http://news.google.com/?ned=us&topic=n", "Google News - U.S.", 2, 2, 0}, |
| 239 {"http://news.google.com/", "Google News", 1, 1, 0}, |
| 240 {"http://foo.com/", "Dir", 200, 100, 0}, |
| 241 {"http://foo.com/dir/", "Dir", 2, 1, 10}, |
| 242 {"http://foo.com/dir/another/", "Dir", 10, 5, 0}, |
| 243 {"http://foo.com/dir/another/again/", "Dir", 5, 1, 0}, |
| 244 {"http://foo.com/dir/another/again/myfile.html", "File", 3, 1, 0}, |
| 245 {"http://visitedest.com/y/a", "VA", 10, 1, 20}, |
| 246 {"http://visitedest.com/y/b", "VB", 9, 1, 20}, |
| 247 {"http://visitedest.com/x/c", "VC", 8, 1, 20}, |
| 248 {"http://visitedest.com/x/d", "VD", 7, 1, 20}, |
| 249 {"http://visitedest.com/y/e", "VE", 6, 1, 20}, |
| 250 {"http://typeredest.com/y/a", "TA", 5, 5, 0}, |
| 251 {"http://typeredest.com/y/b", "TB", 5, 4, 0}, |
| 252 {"http://typeredest.com/x/c", "TC", 5, 3, 0}, |
| 253 {"http://typeredest.com/x/d", "TD", 5, 2, 0}, |
| 254 {"http://typeredest.com/y/e", "TE", 5, 1, 0}, |
| 255 {"http://daysagoest.com/y/a", "DA", 1, 1, 0}, |
| 256 {"http://daysagoest.com/y/b", "DB", 1, 1, 1}, |
| 257 {"http://daysagoest.com/x/c", "DC", 1, 1, 2}, |
| 258 {"http://daysagoest.com/x/d", "DD", 1, 1, 3}, |
| 259 {"http://daysagoest.com/y/e", "DE", 1, 1, 4}, |
| 260 {"http://abcdefghixyzjklmnopqrstuvw.com/a", "", 3, 1, 0}, |
| 261 {"http://spaces.com/path%20with%20spaces/foo.html", "Spaces", 2, 2, 0}, |
| 262 {"http://abcdefghijklxyzmnopqrstuvw.com/a", "", 3, 1, 0}, |
| 263 {"http://abcdefxyzghijklmnopqrstuvw.com/a", "", 3, 1, 0}, |
| 264 {"http://abcxyzdefghijklmnopqrstuvw.com/a", "", 3, 1, 0}, |
| 265 {"http://xyzabcdefghijklmnopqrstuvw.com/a", "", 3, 1, 0}, |
| 266 {"http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice", |
| 267 "Dogs & Cats & Mice & Other Animals", 1, 1, 0}, |
| 268 {"https://monkeytrap.org/", "", 3, 1, 0}, |
| 269 {"http://popularsitewithpathonly.com/moo", |
| 270 "popularsitewithpathonly.com/moo", 50, 50, 0}, |
| 271 {"http://popularsitewithroot.com/", "popularsitewithroot.com", 50, 50, 0}, |
| 272 {"http://testsearch.com/?q=thequery", "Test Search Engine", 10, 10, 0}, |
| 273 {"http://testsearch.com/", "Test Search Engine", 9, 9, 0}, |
| 274 {"http://anotherengine.com/?q=thequery", "Another Search Engine", 8, 8, |
| 275 0}, |
| 276 // The encoded stuff between /wiki/ and the # is 第二次世界大戦 |
| 277 {"http://ja.wikipedia.org/wiki/%E7%AC%AC%E4%BA%8C%E6%AC%A1%E4%B8%96%E7%95" |
| 278 "%8C%E5%A4%A7%E6%88%A6#.E3.83.B4.E3.82.A7.E3.83.AB.E3.82.B5.E3.82.A4.E3." |
| 279 "83.A6.E4.BD.93.E5.88.B6", |
| 280 "Title Unimportant", 2, 2, 0}, |
| 281 {"https://twitter.com/fungoodtimes", "relatable!", 1, 1, 0}, |
| 282 }; |
| 337 } | 283 } |
| 338 | 284 |
| 339 void HistoryQuickProviderTest::FillData() { | 285 void HistoryQuickProviderTest::FillData() { |
| 340 sql::Connection& db(history_backend()->db()->GetDB()); | 286 for (const auto& info : GetTestData()) { |
| 341 ASSERT_TRUE(db.is_open()); | 287 history::URLRow row{GURL(info.url)}; |
| 288 ASSERT_TRUE(row.url().is_valid()); |
| 289 row.set_title(base::UTF8ToUTF16(info.title)); |
| 290 row.set_visit_count(info.visit_count); |
| 291 row.set_typed_count(info.typed_count); |
| 292 row.set_last_visit(base::Time::Now() - |
| 293 base::TimeDelta::FromDays(info.days_from_now)); |
| 342 | 294 |
| 343 size_t data_count = 0; | 295 AddFakeURLToHistoryDB(history_backend()->db(), row); |
| 344 TestURLInfo* test_data = NULL; | |
| 345 GetTestData(&data_count, &test_data); | |
| 346 size_t visit_id = 1; | |
| 347 for (size_t i = 0; i < data_count; ++i) { | |
| 348 const TestURLInfo& cur(test_data[i]); | |
| 349 Time visit_time = Time::Now() - TimeDelta::FromDays(cur.days_from_now); | |
| 350 sql::Transaction transaction(&db); | |
| 351 | |
| 352 // Add URL. | |
| 353 transaction.Begin(); | |
| 354 std::string sql_cmd_line = base::StringPrintf( | |
| 355 "INSERT INTO \"urls\" VALUES(%" PRIuS ", \'%s\', \'%s\', %d, %d, %" | |
| 356 PRId64 ", 0, 0)", | |
| 357 i + 1, cur.url.c_str(), cur.title.c_str(), cur.visit_count, | |
| 358 cur.typed_count, visit_time.ToInternalValue()); | |
| 359 sql::Statement sql_stmt(db.GetUniqueStatement(sql_cmd_line.c_str())); | |
| 360 EXPECT_TRUE(sql_stmt.Run()); | |
| 361 transaction.Commit(); | |
| 362 | |
| 363 // Add visits. | |
| 364 for (int j = 0; j < cur.visit_count; ++j) { | |
| 365 // Assume earlier visits are at one-day intervals. | |
| 366 visit_time -= TimeDelta::FromDays(1); | |
| 367 transaction.Begin(); | |
| 368 // Mark the most recent |cur.typed_count| visits as typed. | |
| 369 std::string sql_cmd_line = base::StringPrintf( | |
| 370 "INSERT INTO \"visits\" VALUES(%" PRIuS ", %" PRIuS ", %" PRId64 | |
| 371 ", 0, %d, 0, 1)", | |
| 372 visit_id++, i + 1, visit_time.ToInternalValue(), | |
| 373 (j < cur.typed_count) ? ui::PAGE_TRANSITION_TYPED : | |
| 374 ui::PAGE_TRANSITION_LINK); | |
| 375 | |
| 376 sql::Statement sql_stmt(db.GetUniqueStatement(sql_cmd_line.c_str())); | |
| 377 EXPECT_TRUE(sql_stmt.Run()); | |
| 378 transaction.Commit(); | |
| 379 } | |
| 380 } | 296 } |
| 381 } | 297 } |
| 382 | 298 |
| 383 HistoryQuickProviderTest::SetShouldContain::SetShouldContain( | 299 HistoryQuickProviderTest::SetShouldContain::SetShouldContain( |
| 384 const ACMatches& matched_urls) { | 300 const ACMatches& matched_urls) { |
| 385 for (ACMatches::const_iterator iter = matched_urls.begin(); | 301 for (ACMatches::const_iterator iter = matched_urls.begin(); |
| 386 iter != matched_urls.end(); ++iter) | 302 iter != matched_urls.end(); ++iter) |
| 387 matches_.insert(iter->destination_url.spec()); | 303 matches_.insert(iter->destination_url.spec()); |
| 388 } | 304 } |
| 389 | 305 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 expected_urls.push_back( | 481 expected_urls.push_back( |
| 566 "http://ja.wikipedia.org/wiki/%E7%AC%AC%E4%BA%8C%E6%AC%A1%E4%B8%96%E7" | 482 "http://ja.wikipedia.org/wiki/%E7%AC%AC%E4%BA%8C%E6%AC%A1%E4%B8%96%E7" |
| 567 "%95%8C%E5%A4%A7%E6%88%A6#.E3.83.B4.E3.82.A7.E3.83.AB.E3.82.B5.E3.82." | 483 "%95%8C%E5%A4%A7%E6%88%A6#.E3.83.B4.E3.82.A7.E3.83.AB.E3.82.B5.E3.82." |
| 568 "A4.E3.83.A6.E4.BD.93.E5.88.B6"); | 484 "A4.E3.83.A6.E4.BD.93.E5.88.B6"); |
| 569 RunTest(base::UTF8ToUTF16("第二 e3"), false, expected_urls, false, | 485 RunTest(base::UTF8ToUTF16("第二 e3"), false, expected_urls, false, |
| 570 base::UTF8ToUTF16("ja.wikipedia.org/wiki/第二次世界大戦#.E3.83.B4.E3." | 486 base::UTF8ToUTF16("ja.wikipedia.org/wiki/第二次世界大戦#.E3.83.B4.E3." |
| 571 "82.A7.E3.83.AB.E3.82.B5.E3.82.A4.E3.83.A6.E4.BD." | 487 "82.A7.E3.83.AB.E3.82.B5.E3.82.A4.E3.83.A6.E4.BD." |
| 572 "93.E5.88.B6"), | 488 "93.E5.88.B6"), |
| 573 base::string16()); | 489 base::string16()); |
| 574 #ifndef NDEBUG | 490 #ifndef NDEBUG |
| 575 ac_matches_[0].Validate(); | 491 ac_matches()[0].Validate(); |
| 576 #endif | 492 #endif |
| 577 // Verify that contents_class divides the string in the right places. | 493 // Verify that contents_class divides the string in the right places. |
| 578 // [22, 24) is the "第二". All the other pairs are the "e3". | 494 // [22, 24) is the "第二". All the other pairs are the "e3". |
| 579 ACMatchClassifications contents_class(ac_matches_[0].contents_class); | 495 ACMatchClassifications contents_class(ac_matches()[0].contents_class); |
| 580 size_t expected_offsets[] = { 0, 22, 24, 31, 33, 40, 42, 49, 51, 58, 60, 67, | 496 size_t expected_offsets[] = { 0, 22, 24, 31, 33, 40, 42, 49, 51, 58, 60, 67, |
| 581 69, 76, 78 }; | 497 69, 76, 78 }; |
| 582 // ScoredHistoryMatch may not highlight all the occurrences of these terms | 498 // ScoredHistoryMatch may not highlight all the occurrences of these terms |
| 583 // because it only highlights terms at word breaks, and it only stores word | 499 // because it only highlights terms at word breaks, and it only stores word |
| 584 // breaks up to some specified number of characters (50 at the time of this | 500 // breaks up to some specified number of characters (50 at the time of this |
| 585 // comment). This test is written flexibly so it still will pass if we | 501 // comment). This test is written flexibly so it still will pass if we |
| 586 // increase that number in the future. Regardless, we require the first | 502 // increase that number in the future. Regardless, we require the first |
| 587 // five offsets to be correct--in this example these cover at least one | 503 // five offsets to be correct--in this example these cover at least one |
| 588 // occurrence of each term. | 504 // occurrence of each term. |
| 589 EXPECT_LE(contents_class.size(), arraysize(expected_offsets)); | 505 EXPECT_LE(contents_class.size(), arraysize(expected_offsets)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 RunTest(ASCIIToUTF16("ice"), false, expected_urls, false, | 546 RunTest(ASCIIToUTF16("ice"), false, expected_urls, false, |
| 631 ASCIIToUTF16("cda.com/Dogs Cats Gorillas Sea Slugs and Mice"), | 547 ASCIIToUTF16("cda.com/Dogs Cats Gorillas Sea Slugs and Mice"), |
| 632 base::string16()); | 548 base::string16()); |
| 633 // Then check that we get results when the match is at a word start | 549 // Then check that we get results when the match is at a word start |
| 634 // that is present because of an encoded separate (%20 = space). | 550 // that is present because of an encoded separate (%20 = space). |
| 635 expected_urls.push_back(url); | 551 expected_urls.push_back(url); |
| 636 RunTest(ASCIIToUTF16("Mice"), false, expected_urls, false, | 552 RunTest(ASCIIToUTF16("Mice"), false, expected_urls, false, |
| 637 ASCIIToUTF16("cda.com/Dogs Cats Gorillas Sea Slugs and Mice"), | 553 ASCIIToUTF16("cda.com/Dogs Cats Gorillas Sea Slugs and Mice"), |
| 638 base::string16()); | 554 base::string16()); |
| 639 // Verify that the matches' ACMatchClassifications offsets are in range. | 555 // Verify that the matches' ACMatchClassifications offsets are in range. |
| 640 ACMatchClassifications content(ac_matches_[0].contents_class); | 556 ACMatchClassifications content(ac_matches()[0].contents_class); |
| 641 // The max offset accounts for 6 occurrences of '%20' plus the 'http://'. | 557 // The max offset accounts for 6 occurrences of '%20' plus the 'http://'. |
| 642 const size_t max_offset = url.length() - ((6 * 2) + 7); | 558 const size_t max_offset = url.length() - ((6 * 2) + 7); |
| 643 for (ACMatchClassifications::const_iterator citer = content.begin(); | 559 for (ACMatchClassifications::const_iterator citer = content.begin(); |
| 644 citer != content.end(); ++citer) | 560 citer != content.end(); ++citer) |
| 645 EXPECT_LT(citer->offset, max_offset); | 561 EXPECT_LT(citer->offset, max_offset); |
| 646 ACMatchClassifications description(ac_matches_[0].description_class); | 562 ACMatchClassifications description(ac_matches()[0].description_class); |
| 647 std::string page_title("Dogs & Cats & Mice & Other Animals"); | 563 std::string page_title("Dogs & Cats & Mice & Other Animals"); |
| 648 for (ACMatchClassifications::const_iterator diter = description.begin(); | 564 for (ACMatchClassifications::const_iterator diter = description.begin(); |
| 649 diter != description.end(); ++diter) | 565 diter != description.end(); ++diter) |
| 650 EXPECT_LT(diter->offset, page_title.length()); | 566 EXPECT_LT(diter->offset, page_title.length()); |
| 651 } | 567 } |
| 652 | 568 |
| 653 TEST_F(HistoryQuickProviderTest, Spans) { | 569 TEST_F(HistoryQuickProviderTest, Spans) { |
| 654 // Test SpansFromTermMatch | 570 // Test SpansFromTermMatch |
| 655 TermMatches matches_a; | 571 TermMatches matches_a; |
| 656 // Simulates matches: '.xx.xxx..xx...xxxxx..' which will test no match at | 572 // Simulates matches: '.xx.xxx..xx...xxxxx..' which will test no match at |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 } | 618 } |
| 703 | 619 |
| 704 TEST_F(HistoryQuickProviderTest, DeleteMatch) { | 620 TEST_F(HistoryQuickProviderTest, DeleteMatch) { |
| 705 GURL test_url("http://slashdot.org/favorite_page.html"); | 621 GURL test_url("http://slashdot.org/favorite_page.html"); |
| 706 std::vector<std::string> expected_urls; | 622 std::vector<std::string> expected_urls; |
| 707 expected_urls.push_back(test_url.spec()); | 623 expected_urls.push_back(test_url.spec()); |
| 708 // Fill up ac_matches_; we don't really care about the test yet. | 624 // Fill up ac_matches_; we don't really care about the test yet. |
| 709 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, | 625 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, |
| 710 ASCIIToUTF16("slashdot.org/favorite_page.html"), | 626 ASCIIToUTF16("slashdot.org/favorite_page.html"), |
| 711 ASCIIToUTF16(".org/favorite_page.html")); | 627 ASCIIToUTF16(".org/favorite_page.html")); |
| 712 EXPECT_EQ(1U, ac_matches_.size()); | 628 EXPECT_EQ(1U, ac_matches().size()); |
| 713 EXPECT_TRUE(GetURLProxy(test_url)); | 629 EXPECT_TRUE(GetURLProxy(test_url)); |
| 714 provider_->DeleteMatch(ac_matches_[0]); | 630 provider().DeleteMatch(ac_matches()[0]); |
| 715 | 631 |
| 716 // Check that the underlying URL is deleted from the history DB (this implies | 632 // Check that the underlying URL is deleted from the history DB (this implies |
| 717 // that all visits are gone as well). Also verify that a deletion notification | 633 // that all visits are gone as well). Also verify that a deletion notification |
| 718 // is sent, in response to which the secondary data stores (InMemoryDatabase, | 634 // is sent, in response to which the secondary data stores (InMemoryDatabase, |
| 719 // InMemoryURLIndex) will drop any data they might have pertaining to the URL. | 635 // InMemoryURLIndex) will drop any data they might have pertaining to the URL. |
| 720 // To ensure that the deletion has been propagated everywhere before we start | 636 // To ensure that the deletion has been propagated everywhere before we start |
| 721 // verifying post-deletion states, first wait until we see the notification. | 637 // verifying post-deletion states, first wait until we see the notification. |
| 722 WaitForURLsDeletedNotification(client_->GetHistoryService()); | 638 WaitForURLsDeletedNotification(client().GetHistoryService()); |
| 723 EXPECT_FALSE(GetURLProxy(test_url)); | 639 EXPECT_FALSE(GetURLProxy(test_url)); |
| 724 | 640 |
| 725 // Just to be on the safe side, explicitly verify that we have deleted enough | 641 // Just to be on the safe side, explicitly verify that we have deleted enough |
| 726 // data so that we will not be serving the same result again. | 642 // data so that we will not be serving the same result again. |
| 727 expected_urls.clear(); | 643 expected_urls.clear(); |
| 728 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, | 644 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, |
| 729 ASCIIToUTF16("NONE EXPECTED"), base::string16()); | 645 ASCIIToUTF16("NONE EXPECTED"), base::string16()); |
| 730 } | 646 } |
| 731 | 647 |
| 732 TEST_F(HistoryQuickProviderTest, PreventBeatingURLWhatYouTypedMatch) { | 648 TEST_F(HistoryQuickProviderTest, PreventBeatingURLWhatYouTypedMatch) { |
| 733 std::vector<std::string> expected_urls; | 649 std::vector<std::string> expected_urls; |
| 734 | 650 |
| 735 expected_urls.clear(); | 651 expected_urls.clear(); |
| 736 expected_urls.push_back("http://popularsitewithroot.com/"); | 652 expected_urls.push_back("http://popularsitewithroot.com/"); |
| 737 // If the user enters a hostname (no path) that they have visited | 653 // If the user enters a hostname (no path) that they have visited |
| 738 // before, we should make sure that all HistoryQuickProvider results | 654 // before, we should make sure that all HistoryQuickProvider results |
| 739 // have scores less than what HistoryURLProvider will assign the | 655 // have scores less than what HistoryURLProvider will assign the |
| 740 // URL-what-you-typed match. | 656 // URL-what-you-typed match. |
| 741 RunTest(ASCIIToUTF16("popularsitewithroot.com"), false, expected_urls, true, | 657 RunTest(ASCIIToUTF16("popularsitewithroot.com"), false, expected_urls, true, |
| 742 ASCIIToUTF16("popularsitewithroot.com"), base::string16()); | 658 ASCIIToUTF16("popularsitewithroot.com"), base::string16()); |
| 743 EXPECT_LT(ac_matches_[0].relevance, | 659 EXPECT_LT(ac_matches()[0].relevance, |
| 744 HistoryURLProvider::kScoreForBestInlineableResult); | 660 HistoryURLProvider::kScoreForBestInlineableResult); |
| 745 | 661 |
| 746 // Check that if the user didn't quite enter the full hostname, this | 662 // Check that if the user didn't quite enter the full hostname, this |
| 747 // hostname would've normally scored above the URL-what-you-typed match. | 663 // hostname would've normally scored above the URL-what-you-typed match. |
| 748 RunTest(ASCIIToUTF16("popularsitewithroot.c"), false, expected_urls, true, | 664 RunTest(ASCIIToUTF16("popularsitewithroot.c"), false, expected_urls, true, |
| 749 ASCIIToUTF16("popularsitewithroot.com"), | 665 ASCIIToUTF16("popularsitewithroot.com"), |
| 750 ASCIIToUTF16("om")); | 666 ASCIIToUTF16("om")); |
| 751 EXPECT_GE(ac_matches_[0].relevance, | 667 EXPECT_GE(ac_matches()[0].relevance, |
| 752 HistoryURLProvider::kScoreForWhatYouTypedResult); | 668 HistoryURLProvider::kScoreForWhatYouTypedResult); |
| 753 | 669 |
| 754 expected_urls.clear(); | 670 expected_urls.clear(); |
| 755 expected_urls.push_back("http://popularsitewithpathonly.com/moo"); | 671 expected_urls.push_back("http://popularsitewithpathonly.com/moo"); |
| 756 // If the user enters a hostname of a host that they have visited | 672 // If the user enters a hostname of a host that they have visited |
| 757 // but never visited the root page of, we should make sure that all | 673 // but never visited the root page of, we should make sure that all |
| 758 // HistoryQuickProvider results have scores less than what the | 674 // HistoryQuickProvider results have scores less than what the |
| 759 // HistoryURLProvider will assign the URL-what-you-typed match. | 675 // HistoryURLProvider will assign the URL-what-you-typed match. |
| 760 RunTest(ASCIIToUTF16("popularsitewithpathonly.com"), false, expected_urls, | 676 RunTest(ASCIIToUTF16("popularsitewithpathonly.com"), false, expected_urls, |
| 761 true, | 677 true, |
| 762 ASCIIToUTF16("popularsitewithpathonly.com/moo"), | 678 ASCIIToUTF16("popularsitewithpathonly.com/moo"), |
| 763 ASCIIToUTF16("/moo")); | 679 ASCIIToUTF16("/moo")); |
| 764 EXPECT_LT(ac_matches_[0].relevance, | 680 EXPECT_LT(ac_matches()[0].relevance, |
| 765 HistoryURLProvider::kScoreForUnvisitedIntranetResult); | 681 HistoryURLProvider::kScoreForUnvisitedIntranetResult); |
| 766 | 682 |
| 767 // Verify the same thing happens if the user adds a / to end of the | 683 // Verify the same thing happens if the user adds a / to end of the |
| 768 // hostname. | 684 // hostname. |
| 769 RunTest(ASCIIToUTF16("popularsitewithpathonly.com/"), false, expected_urls, | 685 RunTest(ASCIIToUTF16("popularsitewithpathonly.com/"), false, expected_urls, |
| 770 true, ASCIIToUTF16("popularsitewithpathonly.com/moo"), | 686 true, ASCIIToUTF16("popularsitewithpathonly.com/moo"), |
| 771 ASCIIToUTF16("moo")); | 687 ASCIIToUTF16("moo")); |
| 772 EXPECT_LT(ac_matches_[0].relevance, | 688 EXPECT_LT(ac_matches()[0].relevance, |
| 773 HistoryURLProvider::kScoreForUnvisitedIntranetResult); | 689 HistoryURLProvider::kScoreForUnvisitedIntranetResult); |
| 774 | 690 |
| 775 // Check that if the user didn't quite enter the full hostname, this | 691 // Check that if the user didn't quite enter the full hostname, this |
| 776 // page would've normally scored above the URL-what-you-typed match. | 692 // page would've normally scored above the URL-what-you-typed match. |
| 777 RunTest(ASCIIToUTF16("popularsitewithpathonly.co"), false, expected_urls, | 693 RunTest(ASCIIToUTF16("popularsitewithpathonly.co"), false, expected_urls, |
| 778 true, ASCIIToUTF16("popularsitewithpathonly.com/moo"), | 694 true, ASCIIToUTF16("popularsitewithpathonly.com/moo"), |
| 779 ASCIIToUTF16("m/moo")); | 695 ASCIIToUTF16("m/moo")); |
| 780 EXPECT_GE(ac_matches_[0].relevance, | 696 EXPECT_GE(ac_matches()[0].relevance, |
| 781 HistoryURLProvider::kScoreForWhatYouTypedResult); | 697 HistoryURLProvider::kScoreForWhatYouTypedResult); |
| 782 | 698 |
| 783 // If the user enters a hostname + path that they have not visited | 699 // If the user enters a hostname + path that they have not visited |
| 784 // before (but visited other things on the host), we can allow | 700 // before (but visited other things on the host), we can allow |
| 785 // inline autocompletions. | 701 // inline autocompletions. |
| 786 RunTest(ASCIIToUTF16("popularsitewithpathonly.com/mo"), false, expected_urls, | 702 RunTest(ASCIIToUTF16("popularsitewithpathonly.com/mo"), false, expected_urls, |
| 787 true, | 703 true, |
| 788 ASCIIToUTF16("popularsitewithpathonly.com/moo"), | 704 ASCIIToUTF16("popularsitewithpathonly.com/moo"), |
| 789 ASCIIToUTF16("o")); | 705 ASCIIToUTF16("o")); |
| 790 EXPECT_GE(ac_matches_[0].relevance, | 706 EXPECT_GE(ac_matches()[0].relevance, |
| 791 HistoryURLProvider::kScoreForWhatYouTypedResult); | 707 HistoryURLProvider::kScoreForWhatYouTypedResult); |
| 792 | 708 |
| 793 // If the user enters a hostname + path that they have visited | 709 // If the user enters a hostname + path that they have visited |
| 794 // before, we should make sure that all HistoryQuickProvider results | 710 // before, we should make sure that all HistoryQuickProvider results |
| 795 // have scores less than what the HistoryURLProvider will assign | 711 // have scores less than what the HistoryURLProvider will assign |
| 796 // the URL-what-you-typed match. | 712 // the URL-what-you-typed match. |
| 797 RunTest(ASCIIToUTF16("popularsitewithpathonly.com/moo"), false, | 713 RunTest(ASCIIToUTF16("popularsitewithpathonly.com/moo"), false, |
| 798 expected_urls, true, | 714 expected_urls, true, |
| 799 ASCIIToUTF16("popularsitewithpathonly.com/moo"), base::string16()); | 715 ASCIIToUTF16("popularsitewithpathonly.com/moo"), base::string16()); |
| 800 EXPECT_LT(ac_matches_[0].relevance, | 716 EXPECT_LT(ac_matches()[0].relevance, |
| 801 HistoryURLProvider::kScoreForBestInlineableResult); | 717 HistoryURLProvider::kScoreForBestInlineableResult); |
| 802 } | 718 } |
| 803 | 719 |
| 804 TEST_F(HistoryQuickProviderTest, PreventInlineAutocomplete) { | 720 TEST_F(HistoryQuickProviderTest, PreventInlineAutocomplete) { |
| 805 std::vector<std::string> expected_urls; | 721 std::vector<std::string> expected_urls; |
| 806 expected_urls.push_back("http://popularsitewithroot.com/"); | 722 expected_urls.push_back("http://popularsitewithroot.com/"); |
| 807 | 723 |
| 808 // Check that the desired URL is normally allowed to be the default match | 724 // Check that the desired URL is normally allowed to be the default match |
| 809 // against input that is a prefex of the URL. | 725 // against input that is a prefex of the URL. |
| 810 RunTest(ASCIIToUTF16("popularsitewithr"), false, expected_urls, true, | 726 RunTest(ASCIIToUTF16("popularsitewithr"), false, expected_urls, true, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 826 // The above still holds even with an extra trailing slash. | 742 // The above still holds even with an extra trailing slash. |
| 827 RunTest(ASCIIToUTF16("popularsitewithroot.com/"), true, expected_urls, true, | 743 RunTest(ASCIIToUTF16("popularsitewithroot.com/"), true, expected_urls, true, |
| 828 ASCIIToUTF16("popularsitewithroot.com"), base::string16()); | 744 ASCIIToUTF16("popularsitewithroot.com"), base::string16()); |
| 829 } | 745 } |
| 830 | 746 |
| 831 TEST_F(HistoryQuickProviderTest, DoesNotProvideMatchesOnFocus) { | 747 TEST_F(HistoryQuickProviderTest, DoesNotProvideMatchesOnFocus) { |
| 832 AutocompleteInput input(ASCIIToUTF16("popularsite"), base::string16::npos, | 748 AutocompleteInput input(ASCIIToUTF16("popularsite"), base::string16::npos, |
| 833 std::string(), GURL(), | 749 std::string(), GURL(), |
| 834 metrics::OmniboxEventProto::INVALID_SPEC, false, | 750 metrics::OmniboxEventProto::INVALID_SPEC, false, |
| 835 false, true, true, true, TestSchemeClassifier()); | 751 false, true, true, true, TestSchemeClassifier()); |
| 836 provider_->Start(input, false); | 752 provider().Start(input, false); |
| 837 EXPECT_TRUE(provider_->matches().empty()); | 753 EXPECT_TRUE(provider().matches().empty()); |
| 838 } | 754 } |
| 839 | 755 |
| 840 // HQPOrderingTest ------------------------------------------------------------- | 756 // HQPOrderingTest ------------------------------------------------------------- |
| 841 | 757 |
| 842 TestURLInfo ordering_test_db[] = { | 758 class HQPOrderingTest : public HistoryQuickProviderTest { |
| 843 {"http://www.teamliquid.net/tlpd/korean/games/21648_bisu_vs_iris", "", 6, 3, | 759 public: |
| 844 256}, | 760 HQPOrderingTest() = default; |
| 845 {"http://www.amazon.com/", "amazon.com: online shopping for electronics, " | 761 |
| 846 "apparel, computers, books, dvds & more", 20, 20, 10}, | 762 protected: |
| 847 {"http://www.teamliquid.net/forum/viewmessage.php?topic_id=52045&" | 763 std::vector<TestURLInfo> GetTestData() override; |
| 848 "currentpage=83", "google images", 6, 6, 0}, | 764 |
| 849 {"http://www.tempurpedic.com/", "tempur-pedic", 7, 7, 0}, | 765 private: |
| 850 {"http://www.teamfortress.com/", "", 5, 5, 6}, | 766 DISALLOW_COPY_AND_ASSIGN(HQPOrderingTest); |
| 851 {"http://www.rottentomatoes.com/", "", 3, 3, 7}, | |
| 852 {"http://music.google.com/music/listen?u=0#start_pl", "", 3, 3, 9}, | |
| 853 {"https://www.emigrantdirect.com/", "high interest savings account, high " | |
| 854 "yield savings - emigrantdirect", 5, 5, 3}, | |
| 855 {"http://store.steampowered.com/", "", 6, 6, 1}, | |
| 856 {"http://techmeme.com/", "techmeme", 111, 110, 4}, | |
| 857 {"http://www.teamliquid.net/tlpd", "team liquid progaming database", 15, 15, | |
| 858 2}, | |
| 859 {"http://store.steampowered.com/", "the steam summer camp sale", 6, 6, 1}, | |
| 860 {"http://www.teamliquid.net/tlpd/korean/players", "tlpd - bw korean - player " | |
| 861 "index", 25, 7, 219}, | |
| 862 {"http://slashdot.org/", "slashdot: news for nerds, stuff that matters", 3, 3, | |
| 863 6}, | |
| 864 {"http://translate.google.com/", "google translate", 3, 3, 0}, | |
| 865 {"http://arstechnica.com/", "ars technica", 3, 3, 3}, | |
| 866 {"http://www.rottentomatoes.com/", "movies | movie trailers | reviews - " | |
| 867 "rotten tomatoes", 3, 3, 7}, | |
| 868 {"http://www.teamliquid.net/", "team liquid - starcraft 2 and brood war pro " | |
| 869 "gaming news", 26, 25, 3}, | |
| 870 {"http://metaleater.com/", "metaleater", 4, 3, 8}, | |
| 871 {"http://half.com/", "half.com: textbooks , books , music , movies , games , " | |
| 872 "video games", 4, 4, 6}, | |
| 873 {"http://teamliquid.net/", "team liquid - starcraft 2 and brood war pro " | |
| 874 "gaming news", 8, 5, 9}, | |
| 875 }; | 767 }; |
| 876 | 768 |
| 877 class HQPOrderingTest : public HistoryQuickProviderTest { | 769 std::vector<HistoryQuickProviderTest::TestURLInfo> |
| 878 protected: | 770 HQPOrderingTest::GetTestData() { |
| 879 void GetTestData(size_t* data_count, TestURLInfo** test_data) override; | 771 return { |
| 880 }; | 772 {"http://www.teamliquid.net/tlpd/korean/games/21648_bisu_vs_iris", "", 6, |
| 881 | 773 3, 256}, |
| 882 void HQPOrderingTest::GetTestData(size_t* data_count, TestURLInfo** test_data) { | 774 {"http://www.amazon.com/", |
| 883 DCHECK(data_count); | 775 "amazon.com: online shopping for electronics, apparel, computers, " |
| 884 DCHECK(test_data); | 776 "books, dvds & more", |
| 885 *data_count = arraysize(ordering_test_db); | 777 20, 20, 10}, |
| 886 *test_data = &ordering_test_db[0]; | 778 {"http://www.teamliquid.net/forum/viewmessage.php?topic_id=52045&" |
| 779 "currentpage=83", |
| 780 "google images", 6, 6, 0}, |
| 781 {"http://www.tempurpedic.com/", "tempur-pedic", 7, 7, 0}, |
| 782 {"http://www.teamfortress.com/", "", 5, 5, 6}, |
| 783 {"http://www.rottentomatoes.com/", "", 3, 3, 7}, |
| 784 {"http://music.google.com/music/listen?u=0#start_pl", "", 3, 3, 9}, |
| 785 {"https://www.emigrantdirect.com/", |
| 786 "high interest savings account, high yield savings - emigrantdirect", 5, |
| 787 5, 3}, |
| 788 {"http://store.steampowered.com/", "", 6, 6, 1}, |
| 789 {"http://techmeme.com/", "techmeme", 111, 110, 4}, |
| 790 {"http://www.teamliquid.net/tlpd", "team liquid progaming database", 15, |
| 791 15, 2}, |
| 792 {"http://store.steampowered.com/", "the steam summer camp sale", 6, 6, 1}, |
| 793 {"http://www.teamliquid.net/tlpd/korean/players", |
| 794 "tlpd - bw korean - player index", 25, 7, 219}, |
| 795 {"http://slashdot.org/", "slashdot: news for nerds, stuff that matters", |
| 796 3, 3, 6}, |
| 797 {"http://translate.google.com/", "google translate", 3, 3, 0}, |
| 798 {"http://arstechnica.com/", "ars technica", 3, 3, 3}, |
| 799 {"http://www.rottentomatoes.com/", |
| 800 "movies | movie trailers | reviews - rotten tomatoes", 3, 3, 7}, |
| 801 {"http://www.teamliquid.net/", |
| 802 "team liquid - starcraft 2 and brood war pro gaming news", 26, 25, 3}, |
| 803 {"http://metaleater.com/", "metaleater", 4, 3, 8}, |
| 804 {"http://half.com/", |
| 805 "half.com: textbooks , books , music , movies , games , video games", 4, |
| 806 4, 6}, |
| 807 {"http://teamliquid.net/", |
| 808 "team liquid - starcraft 2 and brood war pro gaming news", 8, 5, 9}, |
| 809 }; |
| 887 } | 810 } |
| 888 | 811 |
| 889 TEST_F(HQPOrderingTest, TEMatch) { | 812 TEST_F(HQPOrderingTest, TEMatch) { |
| 890 std::vector<std::string> expected_urls; | 813 std::vector<std::string> expected_urls; |
| 891 expected_urls.push_back("http://techmeme.com/"); | 814 expected_urls.push_back("http://techmeme.com/"); |
| 892 expected_urls.push_back("http://www.teamliquid.net/"); | 815 expected_urls.push_back("http://www.teamliquid.net/"); |
| 893 expected_urls.push_back("http://www.teamliquid.net/tlpd"); | 816 expected_urls.push_back("http://www.teamliquid.net/tlpd"); |
| 894 RunTest(ASCIIToUTF16("te"), false, expected_urls, true, | 817 RunTest(ASCIIToUTF16("te"), false, expected_urls, true, |
| 895 ASCIIToUTF16("techmeme.com"), | 818 ASCIIToUTF16("techmeme.com"), |
| 896 ASCIIToUTF16("chmeme.com")); | 819 ASCIIToUTF16("chmeme.com")); |
| 897 } | 820 } |
| 898 | 821 |
| 899 TEST_F(HQPOrderingTest, TEAMatch) { | 822 TEST_F(HQPOrderingTest, TEAMatch) { |
| 900 std::vector<std::string> expected_urls; | 823 std::vector<std::string> expected_urls; |
| 901 expected_urls.push_back("http://www.teamliquid.net/"); | 824 expected_urls.push_back("http://www.teamliquid.net/"); |
| 902 expected_urls.push_back("http://www.teamliquid.net/tlpd"); | 825 expected_urls.push_back("http://www.teamliquid.net/tlpd"); |
| 903 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); | 826 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); |
| 904 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, | 827 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, |
| 905 ASCIIToUTF16("www.teamliquid.net"), | 828 ASCIIToUTF16("www.teamliquid.net"), |
| 906 ASCIIToUTF16("mliquid.net")); | 829 ASCIIToUTF16("mliquid.net")); |
| 907 } | 830 } |
| OLD | NEW |