| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/omnibox/browser/shortcuts_provider.h" | 5 #include "components/omnibox/browser/shortcuts_provider.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <functional> | 11 #include <functional> |
| 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" | 16 #include "base/files/scoped_temp_dir.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
| 21 #include "base/run_loop.h" |
| 21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/test/sequenced_worker_pool_owner.h" | 24 #include "base/test/sequenced_worker_pool_owner.h" |
| 24 #include "base/threading/thread.h" | 25 #include "base/threading/thread.h" |
| 25 #include "components/history/core/browser/history_service.h" | 26 #include "components/history/core/browser/history_service.h" |
| 26 #include "components/history/core/browser/url_database.h" | 27 #include "components/history/core/browser/url_database.h" |
| 27 #include "components/history/core/test/history_service_test_util.h" | 28 #include "components/history/core/test/history_service_test_util.h" |
| 28 #include "components/metrics/proto/omnibox_event.pb.h" | 29 #include "components/metrics/proto/omnibox_event.pb.h" |
| 29 #include "components/omnibox/browser/autocomplete_input.h" | 30 #include "components/omnibox/browser/autocomplete_input.h" |
| 30 #include "components/omnibox/browser/autocomplete_match.h" | 31 #include "components/omnibox/browser/autocomplete_match.h" |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 ASSERT_TRUE(client_->GetShortcutsBackend()); | 281 ASSERT_TRUE(client_->GetShortcutsBackend()); |
| 281 provider_ = new ShortcutsProvider(client_.get()); | 282 provider_ = new ShortcutsProvider(client_.get()); |
| 282 PopulateShortcutsBackendWithTestData(client_->GetShortcutsBackend(), | 283 PopulateShortcutsBackendWithTestData(client_->GetShortcutsBackend(), |
| 283 shortcut_test_db, | 284 shortcut_test_db, |
| 284 arraysize(shortcut_test_db)); | 285 arraysize(shortcut_test_db)); |
| 285 } | 286 } |
| 286 | 287 |
| 287 void ShortcutsProviderTest::TearDown() { | 288 void ShortcutsProviderTest::TearDown() { |
| 288 // Run all pending tasks or else some threads hold on to the message loop | 289 // Run all pending tasks or else some threads hold on to the message loop |
| 289 // and prevent it from being deleted. | 290 // and prevent it from being deleted. |
| 290 message_loop_.RunUntilIdle(); | 291 base::RunLoop().RunUntilIdle(); |
| 291 provider_ = NULL; | 292 provider_ = NULL; |
| 292 } | 293 } |
| 293 | 294 |
| 294 int ShortcutsProviderTest::CalculateScore( | 295 int ShortcutsProviderTest::CalculateScore( |
| 295 const std::string& terms, | 296 const std::string& terms, |
| 296 const ShortcutsDatabase::Shortcut& shortcut, | 297 const ShortcutsDatabase::Shortcut& shortcut, |
| 297 int max_relevance) { | 298 int max_relevance) { |
| 298 return provider_->CalculateScore(ASCIIToUTF16(terms), shortcut, | 299 return provider_->CalculateScore(ASCIIToUTF16(terms), shortcut, |
| 299 max_relevance); | 300 max_relevance); |
| 300 } | 301 } |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 } | 745 } |
| 745 | 746 |
| 746 TEST_F(ShortcutsProviderTest, DoesNotProvideOnFocus) { | 747 TEST_F(ShortcutsProviderTest, DoesNotProvideOnFocus) { |
| 747 AutocompleteInput input(ASCIIToUTF16("about:o"), base::string16::npos, | 748 AutocompleteInput input(ASCIIToUTF16("about:o"), base::string16::npos, |
| 748 std::string(), GURL(), | 749 std::string(), GURL(), |
| 749 metrics::OmniboxEventProto::INVALID_SPEC, false, | 750 metrics::OmniboxEventProto::INVALID_SPEC, false, |
| 750 false, true, true, true, TestSchemeClassifier()); | 751 false, true, true, true, TestSchemeClassifier()); |
| 751 provider_->Start(input, false); | 752 provider_->Start(input, false); |
| 752 EXPECT_TRUE(provider_->matches().empty()); | 753 EXPECT_TRUE(provider_->matches().empty()); |
| 753 } | 754 } |
| OLD | NEW |