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

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

Issue 1635653002: Componentizes history_quick_provider_unittest.cc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move
Patch Set: Review. Created 4 years, 10 months 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
« no previous file with comments | « components/omnibox/browser/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/files/scoped_temp_dir.h"
15 #include "base/format_macros.h" 16 #include "base/format_macros.h"
16 #include "base/macros.h" 17 #include "base/macros.h"
17 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
18 #include "base/message_loop/message_loop.h" 19 #include "base/message_loop/message_loop.h"
19 #include "base/prefs/pref_service.h" 20 #include "base/prefs/pref_service.h"
20 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
21 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
22 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" 23 #include "base/test/sequenced_worker_pool_owner.h"
23 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" 24 #include "components/bookmarks/browser/bookmark_model.h"
24 #include "chrome/browser/autocomplete/in_memory_url_index_factory.h"
25 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
26 #include "chrome/browser/history/history_service_factory.h"
27 #include "chrome/browser/search_engines/chrome_template_url_service_client.h"
28 #include "chrome/browser/search_engines/template_url_service_factory.h"
29 #include "chrome/test/base/testing_browser_process.h"
30 #include "chrome/test/base/testing_profile.h"
31 #include "components/bookmarks/test/bookmark_test_helpers.h" 25 #include "components/bookmarks/test/bookmark_test_helpers.h"
26 #include "components/bookmarks/test/test_bookmark_client.h"
32 #include "components/history/core/browser/history_backend.h" 27 #include "components/history/core/browser/history_backend.h"
33 #include "components/history/core/browser/history_database.h" 28 #include "components/history/core/browser/history_database.h"
29 #include "components/history/core/browser/history_database_params.h"
34 #include "components/history/core/browser/history_service.h" 30 #include "components/history/core/browser/history_service.h"
35 #include "components/history/core/browser/history_service_observer.h" 31 #include "components/history/core/browser/history_service_observer.h"
36 #include "components/history/core/browser/url_database.h" 32 #include "components/history/core/browser/url_database.h"
33 #include "components/history/core/test/test_history_database.h"
37 #include "components/metrics/proto/omnibox_event.pb.h" 34 #include "components/metrics/proto/omnibox_event.pb.h"
38 #include "components/omnibox/browser/autocomplete_match.h" 35 #include "components/omnibox/browser/autocomplete_match.h"
39 #include "components/omnibox/browser/autocomplete_result.h" 36 #include "components/omnibox/browser/autocomplete_result.h"
37 #include "components/omnibox/browser/history_index_restore_observer.h"
40 #include "components/omnibox/browser/history_url_provider.h" 38 #include "components/omnibox/browser/history_url_provider.h"
41 #include "components/omnibox/browser/in_memory_url_index.h" 39 #include "components/omnibox/browser/in_memory_url_index.h"
40 #include "components/omnibox/browser/mock_autocomplete_provider_client.h"
41 #include "components/omnibox/browser/test_scheme_classifier.h"
42 #include "components/omnibox/browser/url_index_private_data.h" 42 #include "components/omnibox/browser/url_index_private_data.h"
43 #include "components/search_engines/search_terms_data.h" 43 #include "components/search_engines/search_terms_data.h"
44 #include "components/search_engines/template_url.h" 44 #include "components/search_engines/template_url.h"
45 #include "components/search_engines/template_url_service.h" 45 #include "components/search_engines/template_url_service.h"
46 #include "content/public/test/test_browser_thread.h"
47 #include "content/public/test/test_utils.h"
48 #include "sql/transaction.h" 46 #include "sql/transaction.h"
49 #include "testing/gtest/include/gtest/gtest.h" 47 #include "testing/gtest/include/gtest/gtest.h"
50 48
51 using base::ASCIIToUTF16; 49 using base::ASCIIToUTF16;
52 using base::Time; 50 using base::Time;
53 using base::TimeDelta; 51 using base::TimeDelta;
54 52
55 using content::BrowserThread;
56
57 namespace { 53 namespace {
58 54
59 struct TestURLInfo { 55 struct TestURLInfo {
60 std::string url; 56 std::string url;
61 std::string title; 57 std::string title;
62 int visit_count; 58 int visit_count;
63 int typed_count; 59 int typed_count;
64 int days_from_now; 60 int days_from_now;
65 } quick_test_db[] = { 61 } quick_test_db[] = {
66 {"http://www.google.com/", "Google", 3, 3, 0}, 62 {"http://www.google.com/", "Google", 3, 3, 0},
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 172
177 private: 173 private:
178 ~GetURLTask() override {} 174 ~GetURLTask() override {}
179 175
180 bool* result_storage_; 176 bool* result_storage_;
181 const GURL url_; 177 const GURL url_;
182 178
183 DISALLOW_COPY_AND_ASSIGN(GetURLTask); 179 DISALLOW_COPY_AND_ASSIGN(GetURLTask);
184 }; 180 };
185 181
182 class QuitTask : public history::HistoryDBTask {
183 public:
184 QuitTask() {}
185
186 bool RunOnDBThread(history::HistoryBackend* backend,
187 history::HistoryDatabase* db) override {
188 return true;
189 }
190
191 void DoneRunOnMainThread() override {
192 base::MessageLoop::current()->QuitWhenIdle();
193 }
194
195 private:
196 ~QuitTask() override {}
197
198 DISALLOW_COPY_AND_ASSIGN(QuitTask);
199 };
200
201 class FakeAutocompleteProviderClient : public MockAutocompleteProviderClient {
202 public:
203 FakeAutocompleteProviderClient() {
204 bookmark_model_ = bookmark_client_.CreateModel();
205 set_template_url_service(
206 make_scoped_ptr(new TemplateURLService(nullptr, 0)));
207 }
208
209 const AutocompleteSchemeClassifier& GetSchemeClassifier() const override {
210 return scheme_classifier_;
211 }
212
213 const SearchTermsData& GetSearchTermsData() const override {
214 return search_terms_data_;
215 }
216
217 history::HistoryService* GetHistoryService() override {
218 return &history_service_;
219 }
220
221 bookmarks::BookmarkModel* GetBookmarkModel() override {
222 return bookmark_model_.get();
223 }
224
225 InMemoryURLIndex* GetInMemoryURLIndex() override {
226 return in_memory_url_index_.get();
227 }
228
229 std::string GetAcceptLanguages() const override { return "en,en-US,ko"; }
230
231 void set_in_memory_url_index(scoped_ptr<InMemoryURLIndex> index) {
232 in_memory_url_index_ = std::move(index);
233 }
234
235 private:
236 bookmarks::TestBookmarkClient bookmark_client_;
237 scoped_ptr<bookmarks::BookmarkModel> bookmark_model_;
238
Peter Kasting 2016/01/26 16:21:45 Nit: Why this blank line?
rohitrao (ping after 24h) 2016/01/27 13:55:43 Done.
239 TestSchemeClassifier scheme_classifier_;
240 SearchTermsData search_terms_data_;
241 scoped_ptr<InMemoryURLIndex> in_memory_url_index_;
242 history::HistoryService history_service_;
243
244 DISALLOW_COPY_AND_ASSIGN(FakeAutocompleteProviderClient);
245 };
246
186 } // namespace 247 } // namespace
187 248
188 class HistoryQuickProviderTest : public testing::Test { 249 class HistoryQuickProviderTest : public testing::Test {
189 public: 250 public:
190 HistoryQuickProviderTest() 251 HistoryQuickProviderTest() : pool_owner_(3, "Background Pool") {}
191 : ui_thread_(BrowserThread::UI, &message_loop_),
192 file_thread_(BrowserThread::FILE, &message_loop_) {}
193 252
194 protected: 253 protected:
195 class SetShouldContain : public std::unary_function<const std::string&, 254 class SetShouldContain : public std::unary_function<const std::string&,
196 std::set<std::string> > { 255 std::set<std::string> > {
197 public: 256 public:
198 explicit SetShouldContain(const ACMatches& matched_urls); 257 explicit SetShouldContain(const ACMatches& matched_urls);
199 258
200 void operator()(const std::string& expected); 259 void operator()(const std::string& expected);
201 260
202 std::set<std::string> LeftOvers() const { return matches_; } 261 std::set<std::string> LeftOvers() const { return matches_; }
203 262
204 private: 263 private:
205 std::set<std::string> matches_; 264 std::set<std::string> matches_;
206 }; 265 };
207 266
208 static scoped_ptr<KeyedService> CreateTemplateURLService(
209 content::BrowserContext* context) {
210 Profile* profile = static_cast<Profile*>(context);
211 return make_scoped_ptr(new TemplateURLService(
212 profile->GetPrefs(), make_scoped_ptr(new SearchTermsData), NULL,
213 scoped_ptr<TemplateURLServiceClient>(new ChromeTemplateURLServiceClient(
214 HistoryServiceFactory::GetForProfile(
215 profile, ServiceAccessType::EXPLICIT_ACCESS))),
216 NULL, NULL, base::Closure()));
217 }
218
219 void SetUp() override; 267 void SetUp() override;
220 void TearDown() override; 268 void TearDown() override;
221 269
222 virtual void GetTestData(size_t* data_count, TestURLInfo** test_data); 270 virtual void GetTestData(size_t* data_count, TestURLInfo** test_data);
223 271
224 // Fills test data into the history system. 272 // Fills test data into the history system.
225 void FillData(); 273 void FillData();
226 274
227 // Runs an autocomplete query on |text| and checks to see that the returned 275 // Runs an autocomplete query on |text| and checks to see that the returned
228 // results' destination URLs match those provided. |expected_urls| does not 276 // results' destination URLs match those provided. |expected_urls| does not
(...skipping 13 matching lines...) Expand all
242 bool can_inline_top_result, 290 bool can_inline_top_result,
243 base::string16 expected_fill_into_edit, 291 base::string16 expected_fill_into_edit,
244 base::string16 autocompletion); 292 base::string16 autocompletion);
245 293
246 // TODO(shess): From history_service.h in reference to history_backend: 294 // TODO(shess): From history_service.h in reference to history_backend:
247 // > This class has most of the implementation and runs on the 'thread_'. 295 // > This class has most of the implementation and runs on the 'thread_'.
248 // > You MUST communicate with this class ONLY through the thread_'s 296 // > You MUST communicate with this class ONLY through the thread_'s
249 // > message_loop(). 297 // > message_loop().
250 // Direct use of this object in tests is almost certainly not thread-safe. 298 // Direct use of this object in tests is almost certainly not thread-safe.
251 history::HistoryBackend* history_backend() { 299 history::HistoryBackend* history_backend() {
252 return history_service_->history_backend_.get(); 300 return client_->GetHistoryService()->history_backend_.get();
253 } 301 }
254 302
255 // Call history_backend()->GetURL(url, NULL) on the history thread, returning 303 // Call history_backend()->GetURL(url, NULL) on the history thread, returning
256 // the result. 304 // the result.
257 bool GetURLProxy(const GURL& url); 305 bool GetURLProxy(const GURL& url);
258 306
259 base::MessageLoopForUI message_loop_; 307 // Helper functions to initialize the HistoryService.
260 content::TestBrowserThread ui_thread_; 308 bool InitializeHistoryService(bool delete_file, bool no_db);
261 content::TestBrowserThread file_thread_; 309 void CreateInMemoryURLIndex();
310 void BlockUntilHistoryProcessesPendingRequests();
311 void BlockUntilHistoryIndexIsRefreshed();
262 312
263 scoped_ptr<TestingProfile> profile_; 313 base::MessageLoop message_loop_;
264 scoped_ptr<ChromeAutocompleteProviderClient> client_; 314 base::SequencedWorkerPoolOwner pool_owner_;
265 history::HistoryService* history_service_; 315
Peter Kasting 2016/01/26 16:21:45 Nit: Another curious blank line
rohitrao (ping after 24h) 2016/01/27 13:55:43 Done.
316 base::ScopedTempDir history_dir_;
317 scoped_ptr<FakeAutocompleteProviderClient> client_;
266 318
267 ACMatches ac_matches_; // The resulting matches after running RunTest. 319 ACMatches ac_matches_; // The resulting matches after running RunTest.
268 320
269 scoped_refptr<HistoryQuickProvider> provider_; 321 scoped_refptr<HistoryQuickProvider> provider_;
270 }; 322 };
271 323
272 void HistoryQuickProviderTest::SetUp() { 324 void HistoryQuickProviderTest::SetUp() {
273 profile_.reset(new TestingProfile()); 325 client_.reset(new FakeAutocompleteProviderClient());
274 client_.reset(new ChromeAutocompleteProviderClient(profile_.get())); 326 ASSERT_TRUE(InitializeHistoryService(true, false));
275 ASSERT_TRUE(profile_->CreateHistoryService(true, false)); 327 FillData();
276 profile_->CreateBookmarkModel(true); 328
277 bookmarks::test::WaitForBookmarkModelToLoad( 329 // |FillData()| must be called before the InMemoryURLIndex is created.
Peter Kasting 2016/01/26 16:21:45 Nit: It would be nice to motivate this with a "why
rohitrao (ping after 24h) 2016/01/27 13:55:43 Done.
278 BookmarkModelFactory::GetForProfile(profile_.get())); 330 CreateInMemoryURLIndex();
279 profile_->BlockUntilHistoryIndexIsRefreshed(); 331 BlockUntilHistoryIndexIsRefreshed();
280 // History index refresh creates rebuilt tasks to run on history thread. 332 // History index refresh creates rebuilt tasks to run on history thread.
281 // Block here to make sure that all of them are complete. 333 // Block here to make sure that all of them are complete.
282 profile_->BlockUntilHistoryProcessesPendingRequests(); 334 BlockUntilHistoryProcessesPendingRequests();
283 history_service_ = HistoryServiceFactory::GetForProfile( 335
284 profile_.get(), ServiceAccessType::EXPLICIT_ACCESS);
285 EXPECT_TRUE(history_service_);
286 provider_ = new HistoryQuickProvider(client_.get()); 336 provider_ = new HistoryQuickProvider(client_.get());
287 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
288 profile_.get(), &HistoryQuickProviderTest::CreateTemplateURLService);
289 FillData();
290 InMemoryURLIndex* index =
291 InMemoryURLIndexFactory::GetForProfile(profile_.get());
292 EXPECT_TRUE(index);
293 index->RebuildFromHistory(history_backend()->db());
294 } 337 }
295 338
296 void HistoryQuickProviderTest::TearDown() { 339 void HistoryQuickProviderTest::TearDown() {
297 provider_ = NULL; 340 provider_ = NULL;
341 // The InMemoryURLIndex must be explicitly shut down or it will DCHECK() in
342 // its destructor.
343 client_->GetInMemoryURLIndex()->Shutdown();
344 client_->set_in_memory_url_index(nullptr);
298 // History index rebuild task is created from main thread during SetUp, 345 // History index rebuild task is created from main thread during SetUp,
299 // performed on DB thread and must be deleted on main thread. 346 // performed on DB thread and must be deleted on main thread.
300 // Run main loop to process delete task, to prevent leaks. 347 // Run main loop to process delete task, to prevent leaks.
301 base::MessageLoop::current()->RunUntilIdle(); 348 base::MessageLoop::current()->RunUntilIdle();
302 } 349 }
303 350
304 void HistoryQuickProviderTest::GetTestData(size_t* data_count, 351 void HistoryQuickProviderTest::GetTestData(size_t* data_count,
305 TestURLInfo** test_data) { 352 TestURLInfo** test_data) {
306 DCHECK(data_count); 353 DCHECK(data_count);
307 DCHECK(test_data); 354 DCHECK(test_data);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 bool prevent_inline_autocomplete, 431 bool prevent_inline_autocomplete,
385 std::vector<std::string> expected_urls, 432 std::vector<std::string> expected_urls,
386 bool can_inline_top_result, 433 bool can_inline_top_result,
387 base::string16 expected_fill_into_edit, 434 base::string16 expected_fill_into_edit,
388 base::string16 expected_autocompletion) { 435 base::string16 expected_autocompletion) {
389 SCOPED_TRACE(text); // Minimal hint to query being run. 436 SCOPED_TRACE(text); // Minimal hint to query being run.
390 base::MessageLoop::current()->RunUntilIdle(); 437 base::MessageLoop::current()->RunUntilIdle();
391 AutocompleteInput input(text, cursor_position, std::string(), GURL(), 438 AutocompleteInput input(text, cursor_position, std::string(), GURL(),
392 metrics::OmniboxEventProto::INVALID_SPEC, 439 metrics::OmniboxEventProto::INVALID_SPEC,
393 prevent_inline_autocomplete, false, true, true, false, 440 prevent_inline_autocomplete, false, true, true, false,
394 ChromeAutocompleteSchemeClassifier(profile_.get())); 441 TestSchemeClassifier());
395 provider_->Start(input, false); 442 provider_->Start(input, false);
396 EXPECT_TRUE(provider_->done()); 443 EXPECT_TRUE(provider_->done());
397 444
398 ac_matches_ = provider_->matches(); 445 ac_matches_ = provider_->matches();
399 446
400 // We should have gotten back at most AutocompleteProvider::kMaxMatches. 447 // We should have gotten back at most AutocompleteProvider::kMaxMatches.
401 EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches); 448 EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches);
402 449
403 // If the number of expected and actual matches aren't equal then we need 450 // If the number of expected and actual matches aren't equal then we need
404 // test no further, but let's do anyway so that we know which URLs failed. 451 // test no further, but let's do anyway so that we know which URLs failed.
405 EXPECT_EQ(expected_urls.size(), ac_matches_.size()); 452 EXPECT_EQ(expected_urls.size(), ac_matches_.size());
406 453
407 // Verify that all expected URLs were found and that all found URLs 454 // Verify that all expected URLs were found and that all found URLs
408 // were expected. 455 // were expected.
409 std::set<std::string> leftovers = 456 std::set<std::string> leftovers =
410 for_each(expected_urls.begin(), expected_urls.end(), 457 for_each(expected_urls.begin(), expected_urls.end(),
411 SetShouldContain(ac_matches_)).LeftOvers(); 458 SetShouldContain(ac_matches_)).LeftOvers();
412 EXPECT_EQ(0U, leftovers.size()) << "There were " << leftovers.size() 459 EXPECT_EQ(0U, leftovers.size()) << "There were " << leftovers.size()
413 << " unexpected results, one of which was: '" 460 << " unexpected results, one of which was: '"
414 << *(leftovers.begin()) << "'."; 461 << *(leftovers.begin()) << "'.";
415 462
416 if (expected_urls.empty()) 463 if (expected_urls.empty())
417 return; 464 return;
418 465
466 ASSERT_GT(ac_matches_.size(), 0U);
Peter Kasting 2016/01/26 16:21:45 Nit: ASSERT_FALSE(ac_matches.empty()), since the o
rohitrao (ping after 24h) 2016/01/27 13:55:43 Done.
419 // Verify that we got the results in the order expected. 467 // Verify that we got the results in the order expected.
420 int best_score = ac_matches_.begin()->relevance + 1; 468 int best_score = ac_matches_.begin()->relevance + 1;
421 int i = 0; 469 int i = 0;
422 std::vector<std::string>::const_iterator expected = expected_urls.begin(); 470 std::vector<std::string>::const_iterator expected = expected_urls.begin();
423 for (ACMatches::const_iterator actual = ac_matches_.begin(); 471 for (ACMatches::const_iterator actual = ac_matches_.begin();
424 actual != ac_matches_.end() && expected != expected_urls.end(); 472 actual != ac_matches_.end() && expected != expected_urls.end();
425 ++actual, ++expected, ++i) { 473 ++actual, ++expected, ++i) {
426 EXPECT_EQ(*expected, actual->destination_url.spec()) 474 EXPECT_EQ(*expected, actual->destination_url.spec())
427 << "For result #" << i << " we got '" << actual->destination_url.spec() 475 << "For result #" << i << " we got '" << actual->destination_url.spec()
428 << "' but expected '" << *expected << "'."; 476 << "' but expected '" << *expected << "'.";
429 EXPECT_LT(actual->relevance, best_score) 477 EXPECT_LT(actual->relevance, best_score)
430 << "At result #" << i << " (url=" << actual->destination_url.spec() 478 << "At result #" << i << " (url=" << actual->destination_url.spec()
431 << "), we noticed scores are not monotonically decreasing."; 479 << "), we noticed scores are not monotonically decreasing.";
432 best_score = actual->relevance; 480 best_score = actual->relevance;
433 } 481 }
434 482
435 EXPECT_EQ(can_inline_top_result, ac_matches_[0].allowed_to_be_default_match); 483 EXPECT_EQ(can_inline_top_result, ac_matches_[0].allowed_to_be_default_match);
436 if (can_inline_top_result) 484 if (can_inline_top_result)
437 EXPECT_EQ(expected_autocompletion, ac_matches_[0].inline_autocompletion); 485 EXPECT_EQ(expected_autocompletion, ac_matches_[0].inline_autocompletion);
438 EXPECT_EQ(expected_fill_into_edit, ac_matches_[0].fill_into_edit); 486 EXPECT_EQ(expected_fill_into_edit, ac_matches_[0].fill_into_edit);
439 } 487 }
440 488
441 bool HistoryQuickProviderTest::GetURLProxy(const GURL& url) { 489 bool HistoryQuickProviderTest::GetURLProxy(const GURL& url) {
442 base::CancelableTaskTracker task_tracker; 490 base::CancelableTaskTracker task_tracker;
443 bool result = false; 491 bool result = false;
444 history_service_->ScheduleDBTask( 492 client_->GetHistoryService()->ScheduleDBTask(
445 scoped_ptr<history::HistoryDBTask>(new GetURLTask(url, &result)), 493 scoped_ptr<history::HistoryDBTask>(new GetURLTask(url, &result)),
446 &task_tracker); 494 &task_tracker);
447 // Run the message loop until GetURLTask::DoneRunOnMainThread stops it. If 495 // Run the message loop until GetURLTask::DoneRunOnMainThread stops it. If
448 // the test hangs, DoneRunOnMainThread isn't being invoked correctly. 496 // the test hangs, DoneRunOnMainThread isn't being invoked correctly.
449 base::MessageLoop::current()->Run(); 497 base::MessageLoop::current()->Run();
450 return result; 498 return result;
451 } 499 }
452 500
501 bool HistoryQuickProviderTest::InitializeHistoryService(bool delete_file,
502 bool no_db) {
503 if (!history_dir_.CreateUniqueTempDir())
Peter Kasting 2016/01/26 16:21:45 Nit: Might as well combine these two conditionals
rohitrao (ping after 24h) 2016/01/27 13:55:43 Done.
504 return false;
505
506 if (!client_->GetHistoryService()->Init(
507 no_db, client_->GetAcceptLanguages(),
508 history::TestHistoryDatabaseParamsForPath(history_dir_.path())))
509 return false;
510
511 if (!no_db)
Peter Kasting 2016/01/26 16:21:45 Nit: I still think it would likely be nice to reve
rohitrao (ping after 24h) 2016/01/27 13:55:43 Agreed. In this particular case, the parameter is
512 BlockUntilHistoryProcessesPendingRequests();
513
514 return true;
515 }
516
517 void HistoryQuickProviderTest::CreateInMemoryURLIndex() {
518 scoped_ptr<InMemoryURLIndex> in_memory_url_index(new InMemoryURLIndex(
519 client_->GetBookmarkModel(), client_->GetHistoryService(),
520 pool_owner_.pool().get(), history_dir_.path(),
521 client_->GetAcceptLanguages(), SchemeSet()));
522 in_memory_url_index->Init();
523 in_memory_url_index->RebuildFromHistory(history_backend()->db());
524 client_->set_in_memory_url_index(std::move(in_memory_url_index));
525 }
526
527 void HistoryQuickProviderTest::BlockUntilHistoryProcessesPendingRequests() {
528 base::CancelableTaskTracker tracker;
529 client_->GetHistoryService()->ScheduleDBTask(
530 scoped_ptr<history::HistoryDBTask>(new QuitTask()), &tracker);
531 base::MessageLoop::current()->Run();
532 }
533
534 void HistoryQuickProviderTest::BlockUntilHistoryIndexIsRefreshed() {
535 InMemoryURLIndex* index = client_->GetInMemoryURLIndex();
536 if (!index || index->restored())
537 return;
538 base::RunLoop run_loop;
539 HistoryIndexRestoreObserver observer(run_loop.QuitClosure());
540 index->set_restore_cache_observer(&observer);
541 run_loop.Run();
542 index->set_restore_cache_observer(NULL);
Peter Kasting 2016/01/26 16:21:45 Nit: nullptr
rohitrao (ping after 24h) 2016/01/27 13:55:43 Done.
543 DCHECK(index->restored());
544 }
545
453 TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) { 546 TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) {
454 std::vector<std::string> expected_urls; 547 std::vector<std::string> expected_urls;
455 expected_urls.push_back("http://slashdot.org/favorite_page.html"); 548 expected_urls.push_back("http://slashdot.org/favorite_page.html");
456 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, 549 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true,
457 ASCIIToUTF16("slashdot.org/favorite_page.html"), 550 ASCIIToUTF16("slashdot.org/favorite_page.html"),
458 ASCIIToUTF16(".org/favorite_page.html")); 551 ASCIIToUTF16(".org/favorite_page.html"));
459 } 552 }
460 553
461 TEST_F(HistoryQuickProviderTest, SingleMatchWithCursor) { 554 TEST_F(HistoryQuickProviderTest, SingleMatchWithCursor) {
462 std::vector<std::string> expected_urls; 555 std::vector<std::string> expected_urls;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 EXPECT_EQ(1U, ac_matches_.size()); 767 EXPECT_EQ(1U, ac_matches_.size());
675 EXPECT_TRUE(GetURLProxy(test_url)); 768 EXPECT_TRUE(GetURLProxy(test_url));
676 provider_->DeleteMatch(ac_matches_[0]); 769 provider_->DeleteMatch(ac_matches_[0]);
677 770
678 // Check that the underlying URL is deleted from the history DB (this implies 771 // Check that the underlying URL is deleted from the history DB (this implies
679 // that all visits are gone as well). Also verify that a deletion notification 772 // that all visits are gone as well). Also verify that a deletion notification
680 // is sent, in response to which the secondary data stores (InMemoryDatabase, 773 // is sent, in response to which the secondary data stores (InMemoryDatabase,
681 // InMemoryURLIndex) will drop any data they might have pertaining to the URL. 774 // InMemoryURLIndex) will drop any data they might have pertaining to the URL.
682 // To ensure that the deletion has been propagated everywhere before we start 775 // To ensure that the deletion has been propagated everywhere before we start
683 // verifying post-deletion states, first wait until we see the notification. 776 // verifying post-deletion states, first wait until we see the notification.
684 WaitForURLsDeletedNotification(history_service_); 777 WaitForURLsDeletedNotification(client_->GetHistoryService());
685 EXPECT_FALSE(GetURLProxy(test_url)); 778 EXPECT_FALSE(GetURLProxy(test_url));
686 779
687 // Just to be on the safe side, explicitly verify that we have deleted enough 780 // Just to be on the safe side, explicitly verify that we have deleted enough
688 // data so that we will not be serving the same result again. 781 // data so that we will not be serving the same result again.
689 expected_urls.clear(); 782 expected_urls.clear();
690 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, 783 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true,
691 ASCIIToUTF16("NONE EXPECTED"), base::string16()); 784 ASCIIToUTF16("NONE EXPECTED"), base::string16());
692 } 785 }
693 786
694 TEST_F(HistoryQuickProviderTest, PreventBeatingURLWhatYouTypedMatch) { 787 TEST_F(HistoryQuickProviderTest, PreventBeatingURLWhatYouTypedMatch) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 RunTest(ASCIIToUTF16("popularsitewithroot.com/"), true, expected_urls, true, 882 RunTest(ASCIIToUTF16("popularsitewithroot.com/"), true, expected_urls, true,
790 ASCIIToUTF16("popularsitewithroot.com"), base::string16()); 883 ASCIIToUTF16("popularsitewithroot.com"), base::string16());
791 } 884 }
792 885
793 TEST_F(HistoryQuickProviderTest, CullSearchResults) { 886 TEST_F(HistoryQuickProviderTest, CullSearchResults) {
794 // Set up a default search engine. 887 // Set up a default search engine.
795 TemplateURLData data; 888 TemplateURLData data;
796 data.SetShortName(ASCIIToUTF16("TestEngine")); 889 data.SetShortName(ASCIIToUTF16("TestEngine"));
797 data.SetKeyword(ASCIIToUTF16("TestEngine")); 890 data.SetKeyword(ASCIIToUTF16("TestEngine"));
798 data.SetURL("http://testsearch.com/?q={searchTerms}"); 891 data.SetURL("http://testsearch.com/?q={searchTerms}");
799 TemplateURLService* template_url_service = 892 TemplateURLService* template_url_service = client_->GetTemplateURLService();
800 TemplateURLServiceFactory::GetForProfile(profile_.get());
801 TemplateURL* template_url = new TemplateURL(data); 893 TemplateURL* template_url = new TemplateURL(data);
802 template_url_service->Add(template_url); 894 template_url_service->Add(template_url);
803 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); 895 template_url_service->SetUserSelectedDefaultSearchProvider(template_url);
804 template_url_service->Load(); 896 template_url_service->Load();
805 897
806 // A search results page should not be returned when typing a query. 898 // A search results page should not be returned when typing a query.
807 std::vector<std::string> expected_urls; 899 std::vector<std::string> expected_urls;
808 RunTest(ASCIIToUTF16("thequery"), false, expected_urls, false, 900 RunTest(ASCIIToUTF16("thequery"), false, expected_urls, false,
809 ASCIIToUTF16("anotherengine.com/?q=thequery"), base::string16()); 901 ASCIIToUTF16("anotherengine.com/?q=thequery"), base::string16());
810 902
811 // A search results page should not be returned when typing the engine URL. 903 // A search results page should not be returned when typing the engine URL.
812 expected_urls.clear(); 904 expected_urls.clear();
813 expected_urls.push_back("http://testsearch.com/"); 905 expected_urls.push_back("http://testsearch.com/");
814 RunTest(ASCIIToUTF16("testsearch"), false, expected_urls, true, 906 RunTest(ASCIIToUTF16("testsearch"), false, expected_urls, true,
815 ASCIIToUTF16("testsearch.com"), 907 ASCIIToUTF16("testsearch.com"),
816 ASCIIToUTF16(".com")); 908 ASCIIToUTF16(".com"));
817 } 909 }
818 910
819 TEST_F(HistoryQuickProviderTest, DoesNotProvideMatchesOnFocus) { 911 TEST_F(HistoryQuickProviderTest, DoesNotProvideMatchesOnFocus) {
820 AutocompleteInput input( 912 AutocompleteInput input(ASCIIToUTF16("popularsite"), base::string16::npos,
821 ASCIIToUTF16("popularsite"), base::string16::npos, std::string(), GURL(), 913 std::string(), GURL(),
822 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, true, 914 metrics::OmniboxEventProto::INVALID_SPEC, false,
823 ChromeAutocompleteSchemeClassifier(profile_.get())); 915 false, true, true, true, TestSchemeClassifier());
824 provider_->Start(input, false); 916 provider_->Start(input, false);
825 EXPECT_TRUE(provider_->matches().empty()); 917 EXPECT_TRUE(provider_->matches().empty());
826 } 918 }
827 919
828 // HQPOrderingTest ------------------------------------------------------------- 920 // HQPOrderingTest -------------------------------------------------------------
829 921
830 TestURLInfo ordering_test_db[] = { 922 TestURLInfo ordering_test_db[] = {
831 {"http://www.teamliquid.net/tlpd/korean/games/21648_bisu_vs_iris", "", 6, 3, 923 {"http://www.teamliquid.net/tlpd/korean/games/21648_bisu_vs_iris", "", 6, 3,
832 256}, 924 256},
833 {"http://www.amazon.com/", "amazon.com: online shopping for electronics, " 925 {"http://www.amazon.com/", "amazon.com: online shopping for electronics, "
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 978
887 TEST_F(HQPOrderingTest, TEAMatch) { 979 TEST_F(HQPOrderingTest, TEAMatch) {
888 std::vector<std::string> expected_urls; 980 std::vector<std::string> expected_urls;
889 expected_urls.push_back("http://www.teamliquid.net/"); 981 expected_urls.push_back("http://www.teamliquid.net/");
890 expected_urls.push_back("http://www.teamliquid.net/tlpd"); 982 expected_urls.push_back("http://www.teamliquid.net/tlpd");
891 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); 983 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players");
892 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, 984 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true,
893 ASCIIToUTF16("www.teamliquid.net"), 985 ASCIIToUTF16("www.teamliquid.net"),
894 ASCIIToUTF16("mliquid.net")); 986 ASCIIToUTF16("mliquid.net"));
895 } 987 }
OLDNEW
« no previous file with comments | « components/omnibox/browser/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698