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

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: 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"
blundell 2016/01/26 08:40:25 Did you double-check that all of the dependencies
rohitrao (ping after 24h) 2016/01/26 14:15:47 Added "//base/test:test_support". Everything else
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 {
blundell 2016/01/26 08:40:25 How much duplication is there between this stuff a
rohitrao (ping after 24h) 2016/01/26 14:15:47 QuitTask is identical, FakeAutocompleteProviderCli
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
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
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 CreateInMemoryURLIndex();
278 BookmarkModelFactory::GetForProfile(profile_.get())); 330 BlockUntilHistoryIndexIsRefreshed();
279 profile_->BlockUntilHistoryIndexIsRefreshed();
280 // History index refresh creates rebuilt tasks to run on history thread. 331 // History index refresh creates rebuilt tasks to run on history thread.
281 // Block here to make sure that all of them are complete. 332 // Block here to make sure that all of them are complete.
282 profile_->BlockUntilHistoryProcessesPendingRequests(); 333 BlockUntilHistoryProcessesPendingRequests();
283 history_service_ = HistoryServiceFactory::GetForProfile( 334
284 profile_.get(), ServiceAccessType::EXPLICIT_ACCESS);
285 EXPECT_TRUE(history_service_);
286 provider_ = new HistoryQuickProvider(client_.get()); 335 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 } 336 }
295 337
296 void HistoryQuickProviderTest::TearDown() { 338 void HistoryQuickProviderTest::TearDown() {
297 provider_ = NULL; 339 provider_ = NULL;
340 client_->GetInMemoryURLIndex()->Shutdown();
blundell 2016/01/26 08:40:25 Comment on why these two lines are necessary?
rohitrao (ping after 24h) 2016/01/26 14:15:48 Done.
341 client_->set_in_memory_url_index(nullptr);
298 // History index rebuild task is created from main thread during SetUp, 342 // History index rebuild task is created from main thread during SetUp,
299 // performed on DB thread and must be deleted on main thread. 343 // performed on DB thread and must be deleted on main thread.
300 // Run main loop to process delete task, to prevent leaks. 344 // Run main loop to process delete task, to prevent leaks.
301 base::MessageLoop::current()->RunUntilIdle(); 345 base::MessageLoop::current()->RunUntilIdle();
302 } 346 }
303 347
304 void HistoryQuickProviderTest::GetTestData(size_t* data_count, 348 void HistoryQuickProviderTest::GetTestData(size_t* data_count,
305 TestURLInfo** test_data) { 349 TestURLInfo** test_data) {
306 DCHECK(data_count); 350 DCHECK(data_count);
307 DCHECK(test_data); 351 DCHECK(test_data);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 bool prevent_inline_autocomplete, 428 bool prevent_inline_autocomplete,
385 std::vector<std::string> expected_urls, 429 std::vector<std::string> expected_urls,
386 bool can_inline_top_result, 430 bool can_inline_top_result,
387 base::string16 expected_fill_into_edit, 431 base::string16 expected_fill_into_edit,
388 base::string16 expected_autocompletion) { 432 base::string16 expected_autocompletion) {
389 SCOPED_TRACE(text); // Minimal hint to query being run. 433 SCOPED_TRACE(text); // Minimal hint to query being run.
390 base::MessageLoop::current()->RunUntilIdle(); 434 base::MessageLoop::current()->RunUntilIdle();
391 AutocompleteInput input(text, cursor_position, std::string(), GURL(), 435 AutocompleteInput input(text, cursor_position, std::string(), GURL(),
392 metrics::OmniboxEventProto::INVALID_SPEC, 436 metrics::OmniboxEventProto::INVALID_SPEC,
393 prevent_inline_autocomplete, false, true, true, false, 437 prevent_inline_autocomplete, false, true, true, false,
394 ChromeAutocompleteSchemeClassifier(profile_.get())); 438 TestSchemeClassifier());
395 provider_->Start(input, false); 439 provider_->Start(input, false);
396 EXPECT_TRUE(provider_->done()); 440 EXPECT_TRUE(provider_->done());
397 441
398 ac_matches_ = provider_->matches(); 442 ac_matches_ = provider_->matches();
399 443
400 // We should have gotten back at most AutocompleteProvider::kMaxMatches. 444 // We should have gotten back at most AutocompleteProvider::kMaxMatches.
401 EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches); 445 EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches);
402 446
403 // If the number of expected and actual matches aren't equal then we need 447 // 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. 448 // test no further, but let's do anyway so that we know which URLs failed.
405 EXPECT_EQ(expected_urls.size(), ac_matches_.size()); 449 EXPECT_EQ(expected_urls.size(), ac_matches_.size());
406 450
407 // Verify that all expected URLs were found and that all found URLs 451 // Verify that all expected URLs were found and that all found URLs
408 // were expected. 452 // were expected.
409 std::set<std::string> leftovers = 453 std::set<std::string> leftovers =
410 for_each(expected_urls.begin(), expected_urls.end(), 454 for_each(expected_urls.begin(), expected_urls.end(),
411 SetShouldContain(ac_matches_)).LeftOvers(); 455 SetShouldContain(ac_matches_)).LeftOvers();
412 EXPECT_EQ(0U, leftovers.size()) << "There were " << leftovers.size() 456 EXPECT_EQ(0U, leftovers.size()) << "There were " << leftovers.size()
413 << " unexpected results, one of which was: '" 457 << " unexpected results, one of which was: '"
414 << *(leftovers.begin()) << "'."; 458 << *(leftovers.begin()) << "'.";
415 459
416 if (expected_urls.empty()) 460 if (expected_urls.empty())
417 return; 461 return;
418 462
463 ASSERT_GT(ac_matches_.size(), 0U);
419 // Verify that we got the results in the order expected. 464 // Verify that we got the results in the order expected.
420 int best_score = ac_matches_.begin()->relevance + 1; 465 int best_score = ac_matches_.begin()->relevance + 1;
421 int i = 0; 466 int i = 0;
422 std::vector<std::string>::const_iterator expected = expected_urls.begin(); 467 std::vector<std::string>::const_iterator expected = expected_urls.begin();
423 for (ACMatches::const_iterator actual = ac_matches_.begin(); 468 for (ACMatches::const_iterator actual = ac_matches_.begin();
424 actual != ac_matches_.end() && expected != expected_urls.end(); 469 actual != ac_matches_.end() && expected != expected_urls.end();
425 ++actual, ++expected, ++i) { 470 ++actual, ++expected, ++i) {
426 EXPECT_EQ(*expected, actual->destination_url.spec()) 471 EXPECT_EQ(*expected, actual->destination_url.spec())
427 << "For result #" << i << " we got '" << actual->destination_url.spec() 472 << "For result #" << i << " we got '" << actual->destination_url.spec()
428 << "' but expected '" << *expected << "'."; 473 << "' but expected '" << *expected << "'.";
429 EXPECT_LT(actual->relevance, best_score) 474 EXPECT_LT(actual->relevance, best_score)
430 << "At result #" << i << " (url=" << actual->destination_url.spec() 475 << "At result #" << i << " (url=" << actual->destination_url.spec()
431 << "), we noticed scores are not monotonically decreasing."; 476 << "), we noticed scores are not monotonically decreasing.";
432 best_score = actual->relevance; 477 best_score = actual->relevance;
433 } 478 }
434 479
435 EXPECT_EQ(can_inline_top_result, ac_matches_[0].allowed_to_be_default_match); 480 EXPECT_EQ(can_inline_top_result, ac_matches_[0].allowed_to_be_default_match);
436 if (can_inline_top_result) 481 if (can_inline_top_result)
437 EXPECT_EQ(expected_autocompletion, ac_matches_[0].inline_autocompletion); 482 EXPECT_EQ(expected_autocompletion, ac_matches_[0].inline_autocompletion);
438 EXPECT_EQ(expected_fill_into_edit, ac_matches_[0].fill_into_edit); 483 EXPECT_EQ(expected_fill_into_edit, ac_matches_[0].fill_into_edit);
439 } 484 }
440 485
441 bool HistoryQuickProviderTest::GetURLProxy(const GURL& url) { 486 bool HistoryQuickProviderTest::GetURLProxy(const GURL& url) {
442 base::CancelableTaskTracker task_tracker; 487 base::CancelableTaskTracker task_tracker;
443 bool result = false; 488 bool result = false;
444 history_service_->ScheduleDBTask( 489 client_->GetHistoryService()->ScheduleDBTask(
445 scoped_ptr<history::HistoryDBTask>(new GetURLTask(url, &result)), 490 scoped_ptr<history::HistoryDBTask>(new GetURLTask(url, &result)),
446 &task_tracker); 491 &task_tracker);
447 // Run the message loop until GetURLTask::DoneRunOnMainThread stops it. If 492 // Run the message loop until GetURLTask::DoneRunOnMainThread stops it. If
448 // the test hangs, DoneRunOnMainThread isn't being invoked correctly. 493 // the test hangs, DoneRunOnMainThread isn't being invoked correctly.
449 base::MessageLoop::current()->Run(); 494 base::MessageLoop::current()->Run();
450 return result; 495 return result;
451 } 496 }
452 497
498 bool HistoryQuickProviderTest::InitializeHistoryService(bool delete_file,
499 bool no_db) {
500 if (!history_dir_.CreateUniqueTempDir())
501 return false;
502
503 if (!client_->GetHistoryService()->Init(
504 no_db, client_->GetAcceptLanguages(),
505 history::TestHistoryDatabaseParamsForPath(history_dir_.path())))
506 return false;
507
508 if (!no_db)
509 BlockUntilHistoryProcessesPendingRequests();
510
511 return true;
512 }
513
514 void HistoryQuickProviderTest::CreateInMemoryURLIndex() {
515 scoped_ptr<InMemoryURLIndex> in_memory_url_index(new InMemoryURLIndex(
516 client_->GetBookmarkModel(), client_->GetHistoryService(),
517 pool_owner_.pool().get(), history_dir_.path(),
518 client_->GetAcceptLanguages(), SchemeSet()));
519 in_memory_url_index->Init();
520 in_memory_url_index->RebuildFromHistory(history_backend()->db());
521 client_->set_in_memory_url_index(std::move(in_memory_url_index));
522 }
523
524 void HistoryQuickProviderTest::BlockUntilHistoryProcessesPendingRequests() {
blundell 2016/01/26 08:40:25 Same question as above.
rohitrao (ping after 24h) 2016/01/26 14:15:47 This will go into the shared test code, but I have
525 base::CancelableTaskTracker tracker;
526 client_->GetHistoryService()->ScheduleDBTask(
527 scoped_ptr<history::HistoryDBTask>(new QuitTask()), &tracker);
528 base::MessageLoop::current()->Run();
529 }
530
531 void HistoryQuickProviderTest::BlockUntilHistoryIndexIsRefreshed() {
532 InMemoryURLIndex* index = client_->GetInMemoryURLIndex();
533 if (!index || index->restored())
534 return;
535 base::RunLoop run_loop;
536 HistoryIndexRestoreObserver observer(run_loop.QuitClosure());
537 index->set_restore_cache_observer(&observer);
538 run_loop.Run();
539 index->set_restore_cache_observer(NULL);
540 DCHECK(index->restored());
541 }
542
453 TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) { 543 TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) {
454 std::vector<std::string> expected_urls; 544 std::vector<std::string> expected_urls;
455 expected_urls.push_back("http://slashdot.org/favorite_page.html"); 545 expected_urls.push_back("http://slashdot.org/favorite_page.html");
456 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, 546 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true,
457 ASCIIToUTF16("slashdot.org/favorite_page.html"), 547 ASCIIToUTF16("slashdot.org/favorite_page.html"),
458 ASCIIToUTF16(".org/favorite_page.html")); 548 ASCIIToUTF16(".org/favorite_page.html"));
459 } 549 }
460 550
461 TEST_F(HistoryQuickProviderTest, SingleMatchWithCursor) { 551 TEST_F(HistoryQuickProviderTest, SingleMatchWithCursor) {
462 std::vector<std::string> expected_urls; 552 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()); 764 EXPECT_EQ(1U, ac_matches_.size());
675 EXPECT_TRUE(GetURLProxy(test_url)); 765 EXPECT_TRUE(GetURLProxy(test_url));
676 provider_->DeleteMatch(ac_matches_[0]); 766 provider_->DeleteMatch(ac_matches_[0]);
677 767
678 // Check that the underlying URL is deleted from the history DB (this implies 768 // 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 769 // 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, 770 // is sent, in response to which the secondary data stores (InMemoryDatabase,
681 // InMemoryURLIndex) will drop any data they might have pertaining to the URL. 771 // 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 772 // To ensure that the deletion has been propagated everywhere before we start
683 // verifying post-deletion states, first wait until we see the notification. 773 // verifying post-deletion states, first wait until we see the notification.
684 WaitForURLsDeletedNotification(history_service_); 774 WaitForURLsDeletedNotification(client_->GetHistoryService());
685 EXPECT_FALSE(GetURLProxy(test_url)); 775 EXPECT_FALSE(GetURLProxy(test_url));
686 776
687 // Just to be on the safe side, explicitly verify that we have deleted enough 777 // 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. 778 // data so that we will not be serving the same result again.
689 expected_urls.clear(); 779 expected_urls.clear();
690 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, 780 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true,
691 ASCIIToUTF16("NONE EXPECTED"), base::string16()); 781 ASCIIToUTF16("NONE EXPECTED"), base::string16());
692 } 782 }
693 783
694 TEST_F(HistoryQuickProviderTest, PreventBeatingURLWhatYouTypedMatch) { 784 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, 879 RunTest(ASCIIToUTF16("popularsitewithroot.com/"), true, expected_urls, true,
790 ASCIIToUTF16("popularsitewithroot.com"), base::string16()); 880 ASCIIToUTF16("popularsitewithroot.com"), base::string16());
791 } 881 }
792 882
793 TEST_F(HistoryQuickProviderTest, CullSearchResults) { 883 TEST_F(HistoryQuickProviderTest, CullSearchResults) {
794 // Set up a default search engine. 884 // Set up a default search engine.
795 TemplateURLData data; 885 TemplateURLData data;
796 data.SetShortName(ASCIIToUTF16("TestEngine")); 886 data.SetShortName(ASCIIToUTF16("TestEngine"));
797 data.SetKeyword(ASCIIToUTF16("TestEngine")); 887 data.SetKeyword(ASCIIToUTF16("TestEngine"));
798 data.SetURL("http://testsearch.com/?q={searchTerms}"); 888 data.SetURL("http://testsearch.com/?q={searchTerms}");
799 TemplateURLService* template_url_service = 889 TemplateURLService* template_url_service = client_->GetTemplateURLService();
800 TemplateURLServiceFactory::GetForProfile(profile_.get());
801 TemplateURL* template_url = new TemplateURL(data); 890 TemplateURL* template_url = new TemplateURL(data);
802 template_url_service->Add(template_url); 891 template_url_service->Add(template_url);
803 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); 892 template_url_service->SetUserSelectedDefaultSearchProvider(template_url);
804 template_url_service->Load(); 893 template_url_service->Load();
805 894
806 // A search results page should not be returned when typing a query. 895 // A search results page should not be returned when typing a query.
807 std::vector<std::string> expected_urls; 896 std::vector<std::string> expected_urls;
808 RunTest(ASCIIToUTF16("thequery"), false, expected_urls, false, 897 RunTest(ASCIIToUTF16("thequery"), false, expected_urls, false,
809 ASCIIToUTF16("anotherengine.com/?q=thequery"), base::string16()); 898 ASCIIToUTF16("anotherengine.com/?q=thequery"), base::string16());
810 899
811 // A search results page should not be returned when typing the engine URL. 900 // A search results page should not be returned when typing the engine URL.
812 expected_urls.clear(); 901 expected_urls.clear();
813 expected_urls.push_back("http://testsearch.com/"); 902 expected_urls.push_back("http://testsearch.com/");
814 RunTest(ASCIIToUTF16("testsearch"), false, expected_urls, true, 903 RunTest(ASCIIToUTF16("testsearch"), false, expected_urls, true,
815 ASCIIToUTF16("testsearch.com"), 904 ASCIIToUTF16("testsearch.com"),
816 ASCIIToUTF16(".com")); 905 ASCIIToUTF16(".com"));
817 } 906 }
818 907
819 TEST_F(HistoryQuickProviderTest, DoesNotProvideMatchesOnFocus) { 908 TEST_F(HistoryQuickProviderTest, DoesNotProvideMatchesOnFocus) {
820 AutocompleteInput input( 909 AutocompleteInput input(ASCIIToUTF16("popularsite"), base::string16::npos,
821 ASCIIToUTF16("popularsite"), base::string16::npos, std::string(), GURL(), 910 std::string(), GURL(),
822 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, true, 911 metrics::OmniboxEventProto::INVALID_SPEC, false,
823 ChromeAutocompleteSchemeClassifier(profile_.get())); 912 false, true, true, true, TestSchemeClassifier());
824 provider_->Start(input, false); 913 provider_->Start(input, false);
825 EXPECT_TRUE(provider_->matches().empty()); 914 EXPECT_TRUE(provider_->matches().empty());
826 } 915 }
827 916
828 // HQPOrderingTest ------------------------------------------------------------- 917 // HQPOrderingTest -------------------------------------------------------------
829 918
830 TestURLInfo ordering_test_db[] = { 919 TestURLInfo ordering_test_db[] = {
831 {"http://www.teamliquid.net/tlpd/korean/games/21648_bisu_vs_iris", "", 6, 3, 920 {"http://www.teamliquid.net/tlpd/korean/games/21648_bisu_vs_iris", "", 6, 3,
832 256}, 921 256},
833 {"http://www.amazon.com/", "amazon.com: online shopping for electronics, " 922 {"http://www.amazon.com/", "amazon.com: online shopping for electronics, "
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 975
887 TEST_F(HQPOrderingTest, TEAMatch) { 976 TEST_F(HQPOrderingTest, TEAMatch) {
888 std::vector<std::string> expected_urls; 977 std::vector<std::string> expected_urls;
889 expected_urls.push_back("http://www.teamliquid.net/"); 978 expected_urls.push_back("http://www.teamliquid.net/");
890 expected_urls.push_back("http://www.teamliquid.net/tlpd"); 979 expected_urls.push_back("http://www.teamliquid.net/tlpd");
891 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); 980 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players");
892 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, 981 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true,
893 ASCIIToUTF16("www.teamliquid.net"), 982 ASCIIToUTF16("www.teamliquid.net"),
894 ASCIIToUTF16("mliquid.net")); 983 ASCIIToUTF16("mliquid.net"));
895 } 984 }
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