Chromium Code Reviews| 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 "chrome/browser/autocomplete/shortcuts_provider.h" | 5 #include "chrome/browser/autocomplete/shortcuts_provider.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <functional> | 10 #include <functional> |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #include "chrome/browser/autocomplete/shortcuts_backend.h" | 25 #include "chrome/browser/autocomplete/shortcuts_backend.h" |
| 26 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" | 26 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" |
| 27 #include "chrome/browser/chrome_notification_types.h" | 27 #include "chrome/browser/chrome_notification_types.h" |
| 28 #include "chrome/browser/history/history_service.h" | 28 #include "chrome/browser/history/history_service.h" |
| 29 #include "chrome/browser/history/in_memory_url_index.h" | 29 #include "chrome/browser/history/in_memory_url_index.h" |
| 30 #include "chrome/browser/history/url_database.h" | 30 #include "chrome/browser/history/url_database.h" |
| 31 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 32 #include "chrome/test/base/testing_profile.h" | 32 #include "chrome/test/base/testing_profile.h" |
| 33 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
| 34 #include "content/public/test/test_browser_thread.h" | 34 #include "content/public/test/test_browser_thread.h" |
| 35 #include "extensions/browser/extension_registry.h" | |
| 35 #include "extensions/common/extension.h" | 36 #include "extensions/common/extension.h" |
| 36 #include "extensions/common/extension_builder.h" | 37 #include "extensions/common/extension_builder.h" |
| 37 #include "extensions/common/value_builder.h" | 38 #include "extensions/common/value_builder.h" |
| 38 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
| 39 | 40 |
| 40 using base::ASCIIToUTF16; | 41 using base::ASCIIToUTF16; |
| 41 | 42 |
| 42 // TestShortcutInfo ----------------------------------------------------------- | 43 // TestShortcutInfo ----------------------------------------------------------- |
| 43 | 44 |
| 44 namespace { | 45 namespace { |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 | 282 |
| 282 // Passthrough to the private function in provider_. | 283 // Passthrough to the private function in provider_. |
| 283 int CalculateScore(const std::string& terms, | 284 int CalculateScore(const std::string& terms, |
| 284 const history::ShortcutsDatabase::Shortcut& shortcut, | 285 const history::ShortcutsDatabase::Shortcut& shortcut, |
| 285 int max_relevance); | 286 int max_relevance); |
| 286 | 287 |
| 287 base::MessageLoopForUI message_loop_; | 288 base::MessageLoopForUI message_loop_; |
| 288 content::TestBrowserThread ui_thread_; | 289 content::TestBrowserThread ui_thread_; |
| 289 content::TestBrowserThread file_thread_; | 290 content::TestBrowserThread file_thread_; |
| 290 | 291 |
| 291 TestingProfile profile_; | 292 scoped_ptr<TestingProfile> profile_; |
| 292 | 293 |
| 293 ACMatches ac_matches_; // The resulting matches after running RunTest. | 294 ACMatches ac_matches_; // The resulting matches after running RunTest. |
| 294 | 295 |
| 295 scoped_refptr<ShortcutsBackend> backend_; | 296 scoped_refptr<ShortcutsBackend> backend_; |
| 296 scoped_refptr<ShortcutsProvider> provider_; | 297 scoped_refptr<ShortcutsProvider> provider_; |
| 297 }; | 298 }; |
| 298 | 299 |
| 299 ShortcutsProviderTest::ShortcutsProviderTest() | 300 ShortcutsProviderTest::ShortcutsProviderTest() |
| 300 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 301 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 301 file_thread_(content::BrowserThread::FILE, &message_loop_) { | 302 file_thread_(content::BrowserThread::FILE, &message_loop_), |
| 303 profile_(new TestingProfile) { | |
|
not at google - send to devlin
2014/05/12 17:59:00
ditto, though in this case it's basically the same
Peter Kasting
2014/05/12 19:46:55
I'm wondering this too.
limasdf
2014/05/13 14:38:44
for consistent with extension_app_provider_unittes
| |
| 302 } | 304 } |
| 303 | 305 |
| 304 void ShortcutsProviderTest::OnProviderUpdate(bool updated_matches) {} | 306 void ShortcutsProviderTest::OnProviderUpdate(bool updated_matches) {} |
| 305 | 307 |
| 306 void ShortcutsProviderTest::SetUp() { | 308 void ShortcutsProviderTest::SetUp() { |
| 307 ShortcutsBackendFactory::GetInstance()->SetTestingFactoryAndUse( | 309 ShortcutsBackendFactory::GetInstance()->SetTestingFactoryAndUse( |
| 308 &profile_, &ShortcutsBackendFactory::BuildProfileNoDatabaseForTesting); | 310 profile_.get(), |
| 309 backend_ = ShortcutsBackendFactory::GetForProfile(&profile_); | 311 &ShortcutsBackendFactory::BuildProfileNoDatabaseForTesting); |
| 312 backend_ = ShortcutsBackendFactory::GetForProfile(profile_.get()); | |
| 310 ASSERT_TRUE(backend_.get()); | 313 ASSERT_TRUE(backend_.get()); |
| 311 ASSERT_TRUE(profile_.CreateHistoryService(true, false)); | 314 ASSERT_TRUE(profile_.get()->CreateHistoryService(true, false)); |
|
Peter Kasting
2014/05/12 19:46:55
There's no need to use "get()" before "->".
limasdf
2014/05/13 14:38:44
back to original. Done.
| |
| 312 provider_ = new ShortcutsProvider(this, &profile_); | 315 provider_ = new ShortcutsProvider(this, profile_.get()); |
| 313 FillData(shortcut_test_db, arraysize(shortcut_test_db)); | 316 FillData(shortcut_test_db, arraysize(shortcut_test_db)); |
| 314 } | 317 } |
| 315 | 318 |
| 316 void ShortcutsProviderTest::TearDown() { | 319 void ShortcutsProviderTest::TearDown() { |
| 317 // Run all pending tasks or else some threads hold on to the message loop | 320 // Run all pending tasks or else some threads hold on to the message loop |
| 318 // and prevent it from being deleted. | 321 // and prevent it from being deleted. |
| 319 message_loop_.RunUntilIdle(); | 322 message_loop_.RunUntilIdle(); |
| 320 provider_ = NULL; | 323 provider_ = NULL; |
| 321 } | 324 } |
| 322 | 325 |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 834 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(" echo")); | 837 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(" echo")); |
| 835 | 838 |
| 836 // Claim the extension has been unloaded. | 839 // Claim the extension has been unloaded. |
| 837 scoped_refptr<const extensions::Extension> extension = | 840 scoped_refptr<const extensions::Extension> extension = |
| 838 extensions::ExtensionBuilder() | 841 extensions::ExtensionBuilder() |
| 839 .SetManifest(extensions::DictionaryBuilder() | 842 .SetManifest(extensions::DictionaryBuilder() |
| 840 .Set("name", "Echo") | 843 .Set("name", "Echo") |
| 841 .Set("version", "1.0")) | 844 .Set("version", "1.0")) |
| 842 .SetID("cedabbhfglmiikkmdgcpjdkocfcmbkee") | 845 .SetID("cedabbhfglmiikkmdgcpjdkocfcmbkee") |
| 843 .Build(); | 846 .Build(); |
| 844 extensions::UnloadedExtensionInfo details( | 847 extensions::ExtensionRegistry* registry = |
| 848 extensions::ExtensionRegistry::Get(profile_.get()); | |
| 849 registry->TriggerOnUnloaded( | |
| 845 extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL); | 850 extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL); |
| 846 content::NotificationService::current()->Notify( | |
| 847 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | |
| 848 content::Source<Profile>(&profile_), | |
| 849 content::Details<extensions::UnloadedExtensionInfo>(&details)); | |
| 850 | 851 |
| 851 // Now the URL should have disappeared. | 852 // Now the URL should have disappeared. |
| 852 RunTest(text, false, ExpectedURLs(), std::string(), base::string16()); | 853 RunTest(text, false, ExpectedURLs(), std::string(), base::string16()); |
| 853 } | 854 } |
| OLD | NEW |