Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: components/omnibox/browser/history_quick_provider_unittest.cc

Issue 2300323003: Adding performance tests for HQP that represent importance of optimising HistoryItemsForTerms method (Closed)
Patch Set: Review, round 3. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 { 44 struct TestURLInfo {
Peter Kasting 2016/10/27 09:00:56 Nit: Struct definition could be protected within H
dyaroshev 2016/10/27 13:04:23 Done.
54 std::string url; 45 std::string url;
55 std::string title; 46 std::string title;
56 int visit_count; 47 int visit_count;
57 int typed_count; 48 int typed_count;
58 int days_from_now; 49 int days_from_now;
59 } quick_test_db[] = { 50 };
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 51
108 // Waits for OnURLsDeletedNotification and when run quits the supplied run loop. 52 // Waits for OnURLsDeletedNotification and when run quits the supplied run loop.
109 class WaitForURLsDeletedObserver : public history::HistoryServiceObserver { 53 class WaitForURLsDeletedObserver : public history::HistoryServiceObserver {
110 public: 54 public:
111 explicit WaitForURLsDeletedObserver(base::RunLoop* runner); 55 explicit WaitForURLsDeletedObserver(base::RunLoop* runner);
112 ~WaitForURLsDeletedObserver() override; 56 ~WaitForURLsDeletedObserver() override;
113 57
114 private: 58 private:
115 // history::HistoryServiceObserver: 59 // history::HistoryServiceObserver:
116 void OnURLsDeleted(history::HistoryService* service, 60 void OnURLsDeleted(history::HistoryService* service,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 115
172 private: 116 private:
173 ~GetURLTask() override {} 117 ~GetURLTask() override {}
174 118
175 bool* result_storage_; 119 bool* result_storage_;
176 const GURL url_; 120 const GURL url_;
177 121
178 DISALLOW_COPY_AND_ASSIGN(GetURLTask); 122 DISALLOW_COPY_AND_ASSIGN(GetURLTask);
179 }; 123 };
180 124
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 125 } // namespace
233 126
234 class HistoryQuickProviderTest : public testing::Test { 127 class HistoryQuickProviderTest : public testing::Test {
235 public: 128 public:
236 HistoryQuickProviderTest() {} 129 HistoryQuickProviderTest() {}
237 130
238 protected: 131 protected:
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
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
291 base::MessageLoop message_loop_; 184 base::MessageLoop message_loop_;
Peter Kasting 2016/10/27 09:00:56 Nit: Data members should be private
dyaroshev 2016/10/27 13:04:23 Done.
292 std::unique_ptr<FakeAutocompleteProviderClient> client_; 185 std::unique_ptr<FakeAutocompleteProviderClient> client_;
293 186
294 ACMatches ac_matches_; // The resulting matches after running RunTest. 187 ACMatches ac_matches_; // The resulting matches after running RunTest.
295 188
296 scoped_refptr<HistoryQuickProvider> provider_; 189 scoped_refptr<HistoryQuickProvider> provider_;
297 }; 190 };
Peter Kasting 2016/10/27 09:00:56 Nit: DISALLOW_COPY_AND_ASSIGN
dyaroshev 2016/10/27 13:04:23 Done.
298 191
299 void HistoryQuickProviderTest::SetUp() { 192 void HistoryQuickProviderTest::SetUp() {
300 client_.reset(new FakeAutocompleteProviderClient()); 193 client_.reset(new FakeAutocompleteProviderClient());
301 ASSERT_TRUE(client_->GetHistoryService()); 194 ASSERT_TRUE(client_->GetHistoryService());
302 FillData(); 195 FillData();
303 196
304 // |FillData()| must be called before |RebuildFromHistory()|. This will 197 // FillData() must be called before RebuildFromHistory(). This will
305 // ensure that the index is properly populated with data from the database. 198 // ensure that the index is properly populated with data from the database.
306 InMemoryURLIndex* url_index = client_->GetInMemoryURLIndex(); 199 InMemoryURLIndex* url_index = client_->GetInMemoryURLIndex();
307 url_index->RebuildFromHistory( 200 url_index->RebuildFromHistory(
308 client_->GetHistoryService()->history_backend_->db()); 201 client_->GetHistoryService()->history_backend_->db());
309 BlockUntilInMemoryURLIndexIsRefreshed(url_index); 202 BlockUntilInMemoryURLIndexIsRefreshed(url_index);
310 203
311 // History index refresh creates rebuilt tasks to run on history thread. 204 // History index refresh creates rebuilt tasks to run on history thread.
312 // Block here to make sure that all of them are complete. 205 // Block here to make sure that all of them are complete.
313 history::BlockUntilHistoryProcessesPendingRequests( 206 history::BlockUntilHistoryProcessesPendingRequests(
314 client_->GetHistoryService()); 207 client_->GetHistoryService());
315 208
316 provider_ = new HistoryQuickProvider(client_.get()); 209 provider_ = new HistoryQuickProvider(client_.get());
317 } 210 }
318 211
319 void HistoryQuickProviderTest::TearDown() { 212 void HistoryQuickProviderTest::TearDown() {
320 provider_ = NULL; 213 provider_ = nullptr;
321 // The InMemoryURLIndex must be explicitly shut down or it will DCHECK() in 214 // The InMemoryURLIndex must be explicitly shut down or it will DCHECK() in
322 // its destructor. 215 // its destructor.
323 client_->GetInMemoryURLIndex()->Shutdown(); 216 client_->GetInMemoryURLIndex()->Shutdown();
324 client_->set_in_memory_url_index(nullptr); 217 client_->set_in_memory_url_index(nullptr);
325 // History index rebuild task is created from main thread during SetUp, 218 // History index rebuild task is created from main thread during SetUp,
326 // performed on DB thread and must be deleted on main thread. 219 // performed on DB thread and must be deleted on main thread.
327 // Run main loop to process delete task, to prevent leaks. 220 // Run main loop to process delete task, to prevent leaks.
328 base::RunLoop().RunUntilIdle(); 221 base::RunLoop().RunUntilIdle();
329 } 222 }
330 223
331 void HistoryQuickProviderTest::GetTestData(size_t* data_count, 224 std::vector<TestURLInfo> HistoryQuickProviderTest::GetTestData() {
332 TestURLInfo** test_data) { 225 return {
333 DCHECK(data_count); 226 {"http://www.google.com/", "Google", 3, 3, 0},
334 DCHECK(test_data); 227 {"http://slashdot.org/favorite_page.html", "Favorite page", 200, 100, 0},
335 *data_count = arraysize(quick_test_db); 228 {"http://kerneltrap.org/not_very_popular.html", "Less popular", 4, 0, 0},
336 *test_data = &quick_test_db[0]; 229 {"http://freshmeat.net/unpopular.html", "Unpopular", 1, 1, 0},
230 {"http://news.google.com/?ned=us&topic=n", "Google News - U.S.", 2, 2, 0},
231 {"http://news.google.com/", "Google News", 1, 1, 0},
232 {"http://foo.com/", "Dir", 200, 100, 0},
233 {"http://foo.com/dir/", "Dir", 2, 1, 10},
234 {"http://foo.com/dir/another/", "Dir", 10, 5, 0},
235 {"http://foo.com/dir/another/again/", "Dir", 5, 1, 0},
236 {"http://foo.com/dir/another/again/myfile.html", "File", 3, 1, 0},
237 {"http://visitedest.com/y/a", "VA", 10, 1, 20},
238 {"http://visitedest.com/y/b", "VB", 9, 1, 20},
239 {"http://visitedest.com/x/c", "VC", 8, 1, 20},
240 {"http://visitedest.com/x/d", "VD", 7, 1, 20},
241 {"http://visitedest.com/y/e", "VE", 6, 1, 20},
242 {"http://typeredest.com/y/a", "TA", 5, 5, 0},
243 {"http://typeredest.com/y/b", "TB", 5, 4, 0},
244 {"http://typeredest.com/x/c", "TC", 5, 3, 0},
245 {"http://typeredest.com/x/d", "TD", 5, 2, 0},
246 {"http://typeredest.com/y/e", "TE", 5, 1, 0},
247 {"http://daysagoest.com/y/a", "DA", 1, 1, 0},
248 {"http://daysagoest.com/y/b", "DB", 1, 1, 1},
249 {"http://daysagoest.com/x/c", "DC", 1, 1, 2},
250 {"http://daysagoest.com/x/d", "DD", 1, 1, 3},
251 {"http://daysagoest.com/y/e", "DE", 1, 1, 4},
252 {"http://abcdefghixyzjklmnopqrstuvw.com/a", "", 3, 1, 0},
253 {"http://spaces.com/path%20with%20spaces/foo.html", "Spaces", 2, 2, 0},
254 {"http://abcdefghijklxyzmnopqrstuvw.com/a", "", 3, 1, 0},
255 {"http://abcdefxyzghijklmnopqrstuvw.com/a", "", 3, 1, 0},
256 {"http://abcxyzdefghijklmnopqrstuvw.com/a", "", 3, 1, 0},
257 {"http://xyzabcdefghijklmnopqrstuvw.com/a", "", 3, 1, 0},
258 {"http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice",
259 "Dogs & Cats & Mice & Other Animals", 1, 1, 0},
260 {"https://monkeytrap.org/", "", 3, 1, 0},
261 {"http://popularsitewithpathonly.com/moo",
262 "popularsitewithpathonly.com/moo", 50, 50, 0},
263 {"http://popularsitewithroot.com/", "popularsitewithroot.com", 50, 50, 0},
264 {"http://testsearch.com/?q=thequery", "Test Search Engine", 10, 10, 0},
265 {"http://testsearch.com/", "Test Search Engine", 9, 9, 0},
266 {"http://anotherengine.com/?q=thequery", "Another Search Engine", 8, 8,
267 0},
268 // The encoded stuff between /wiki/ and the # is 第二次世界大戦
269 {"http://ja.wikipedia.org/wiki/%E7%AC%AC%E4%BA%8C%E6%AC%A1%E4%B8%96%E7%95"
270 "%8C%E5%A4%A7%E6%88%A6#.E3.83.B4.E3.82.A7.E3.83.AB.E3.82.B5.E3.82.A4.E3."
271 "83.A6.E4.BD.93.E5.88.B6",
272 "Title Unimportant", 2, 2, 0},
273 {"https://twitter.com/fungoodtimes", "relatable!", 1, 1, 0},
274 };
337 } 275 }
338 276
339 void HistoryQuickProviderTest::FillData() { 277 void HistoryQuickProviderTest::FillData() {
340 sql::Connection& db(history_backend()->db()->GetDB()); 278 for (const auto& info : GetTestData()) {
341 ASSERT_TRUE(db.is_open()); 279 history::URLRow row{GURL(info.url)};
280 ASSERT_TRUE(row.url().is_valid());
281 row.set_title(base::UTF8ToUTF16(info.title));
282 row.set_visit_count(info.visit_count);
283 row.set_typed_count(info.typed_count);
284 row.set_last_visit(base::Time::Now() -
285 base::TimeDelta::FromDays(info.days_from_now));
342 286
343 size_t data_count = 0; 287 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 } 288 }
381 } 289 }
382 290
383 HistoryQuickProviderTest::SetShouldContain::SetShouldContain( 291 HistoryQuickProviderTest::SetShouldContain::SetShouldContain(
384 const ACMatches& matched_urls) { 292 const ACMatches& matched_urls) {
385 for (ACMatches::const_iterator iter = matched_urls.begin(); 293 for (ACMatches::const_iterator iter = matched_urls.begin();
386 iter != matched_urls.end(); ++iter) 294 iter != matched_urls.end(); ++iter)
387 matches_.insert(iter->destination_url.spec()); 295 matches_.insert(iter->destination_url.spec());
388 } 296 }
389 297
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 AutocompleteInput input(ASCIIToUTF16("popularsite"), base::string16::npos, 740 AutocompleteInput input(ASCIIToUTF16("popularsite"), base::string16::npos,
833 std::string(), GURL(), 741 std::string(), GURL(),
834 metrics::OmniboxEventProto::INVALID_SPEC, false, 742 metrics::OmniboxEventProto::INVALID_SPEC, false,
835 false, true, true, true, TestSchemeClassifier()); 743 false, true, true, true, TestSchemeClassifier());
836 provider_->Start(input, false); 744 provider_->Start(input, false);
837 EXPECT_TRUE(provider_->matches().empty()); 745 EXPECT_TRUE(provider_->matches().empty());
838 } 746 }
839 747
840 // HQPOrderingTest ------------------------------------------------------------- 748 // HQPOrderingTest -------------------------------------------------------------
841 749
842 TestURLInfo ordering_test_db[] = { 750 class HQPOrderingTest : public HistoryQuickProviderTest {
843 {"http://www.teamliquid.net/tlpd/korean/games/21648_bisu_vs_iris", "", 6, 3, 751 protected:
844 256}, 752 std::vector<TestURLInfo> GetTestData() override;
845 {"http://www.amazon.com/", "amazon.com: online shopping for electronics, "
846 "apparel, computers, books, dvds & more", 20, 20, 10},
847 {"http://www.teamliquid.net/forum/viewmessage.php?topic_id=52045&"
848 "currentpage=83", "google images", 6, 6, 0},
849 {"http://www.tempurpedic.com/", "tempur-pedic", 7, 7, 0},
850 {"http://www.teamfortress.com/", "", 5, 5, 6},
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 }; 753 };
Peter Kasting 2016/10/27 09:00:56 Nit: Private DISALLOW_COPY_AND_ASSIGN
dyaroshev 2016/10/27 13:04:23 Done.
876 754
877 class HQPOrderingTest : public HistoryQuickProviderTest { 755 std::vector<TestURLInfo> HQPOrderingTest::GetTestData() {
878 protected: 756 return {
879 void GetTestData(size_t* data_count, TestURLInfo** test_data) override; 757 {"http://www.teamliquid.net/tlpd/korean/games/21648_bisu_vs_iris", "", 6,
880 }; 758 3, 256},
881 759 {"http://www.amazon.com/",
882 void HQPOrderingTest::GetTestData(size_t* data_count, TestURLInfo** test_data) { 760 "amazon.com: online shopping for electronics, "
883 DCHECK(data_count); 761 "apparel, computers, books, dvds & more",
884 DCHECK(test_data); 762 20, 20, 10},
885 *data_count = arraysize(ordering_test_db); 763 {"http://www.teamliquid.net/forum/viewmessage.php?topic_id=52045&"
886 *test_data = &ordering_test_db[0]; 764 "currentpage=83",
765 "google images", 6, 6, 0},
766 {"http://www.tempurpedic.com/", "tempur-pedic", 7, 7, 0},
767 {"http://www.teamfortress.com/", "", 5, 5, 6},
768 {"http://www.rottentomatoes.com/", "", 3, 3, 7},
769 {"http://music.google.com/music/listen?u=0#start_pl", "", 3, 3, 9},
770 {"https://www.emigrantdirect.com/",
771 "high interest savings account, high "
772 "yield savings - emigrantdirect",
773 5, 5, 3},
774 {"http://store.steampowered.com/", "", 6, 6, 1},
775 {"http://techmeme.com/", "techmeme", 111, 110, 4},
776 {"http://www.teamliquid.net/tlpd", "team liquid progaming database", 15,
777 15, 2},
778 {"http://store.steampowered.com/", "the steam summer camp sale", 6, 6, 1},
779 {"http://www.teamliquid.net/tlpd/korean/players",
780 "tlpd - bw korean - player "
Peter Kasting 2016/10/27 09:00:56 Nit: Strings like this don't need to be broken acr
dyaroshev 2016/10/27 13:04:23 Done.
781 "index",
782 25, 7, 219},
783 {"http://slashdot.org/", "slashdot: news for nerds, stuff that matters",
784 3, 3, 6},
785 {"http://translate.google.com/", "google translate", 3, 3, 0},
786 {"http://arstechnica.com/", "ars technica", 3, 3, 3},
787 {"http://www.rottentomatoes.com/",
788 "movies | movie trailers | reviews - "
789 "rotten tomatoes",
790 3, 3, 7},
791 {"http://www.teamliquid.net/",
792 "team liquid - starcraft 2 and brood war pro "
793 "gaming news",
794 26, 25, 3},
795 {"http://metaleater.com/", "metaleater", 4, 3, 8},
796 {"http://half.com/",
797 "half.com: textbooks , books , music , movies , games , "
798 "video games",
799 4, 4, 6},
800 {"http://teamliquid.net/",
801 "team liquid - starcraft 2 and brood war pro "
802 "gaming news",
803 8, 5, 9},
804 };
887 } 805 }
888 806
889 TEST_F(HQPOrderingTest, TEMatch) { 807 TEST_F(HQPOrderingTest, TEMatch) {
890 std::vector<std::string> expected_urls; 808 std::vector<std::string> expected_urls;
891 expected_urls.push_back("http://techmeme.com/"); 809 expected_urls.push_back("http://techmeme.com/");
892 expected_urls.push_back("http://www.teamliquid.net/"); 810 expected_urls.push_back("http://www.teamliquid.net/");
893 expected_urls.push_back("http://www.teamliquid.net/tlpd"); 811 expected_urls.push_back("http://www.teamliquid.net/tlpd");
894 RunTest(ASCIIToUTF16("te"), false, expected_urls, true, 812 RunTest(ASCIIToUTF16("te"), false, expected_urls, true,
895 ASCIIToUTF16("techmeme.com"), 813 ASCIIToUTF16("techmeme.com"),
896 ASCIIToUTF16("chmeme.com")); 814 ASCIIToUTF16("chmeme.com"));
897 } 815 }
898 816
899 TEST_F(HQPOrderingTest, TEAMatch) { 817 TEST_F(HQPOrderingTest, TEAMatch) {
900 std::vector<std::string> expected_urls; 818 std::vector<std::string> expected_urls;
901 expected_urls.push_back("http://www.teamliquid.net/"); 819 expected_urls.push_back("http://www.teamliquid.net/");
902 expected_urls.push_back("http://www.teamliquid.net/tlpd"); 820 expected_urls.push_back("http://www.teamliquid.net/tlpd");
903 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); 821 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players");
904 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, 822 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true,
905 ASCIIToUTF16("www.teamliquid.net"), 823 ASCIIToUTF16("www.teamliquid.net"),
906 ASCIIToUTF16("mliquid.net")); 824 ASCIIToUTF16("mliquid.net"));
907 } 825 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698