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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/task/cancelable_task_tracker.h" | 14 #include "base/task/cancelable_task_tracker.h" |
| 15 #include "base/test/mock_time_provider.h" | 15 #include "base/test/mock_time_provider.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "chrome/browser/history/history_service.h" | 18 #include "chrome/browser/history/history_service.h" |
| 19 #include "chrome/browser/history/history_service_factory.h" | 19 #include "chrome/browser/history/history_service_factory.h" |
| 20 #include "chrome/browser/search_engines/template_url_service_test_util.h" | 20 #include "chrome/browser/search_engines/template_url_service_test_util.h" |
| 21 #include "chrome/browser/webdata/web_data_service_factory.h" | |
| 22 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 23 #include "components/search_engines/keyword_web_data_service.h" | 22 #include "components/search_engines/keyword_web_data_service.h" |
| 24 #include "components/search_engines/search_host_to_urls_map.h" | 23 #include "components/search_engines/search_host_to_urls_map.h" |
| 25 #include "components/search_engines/search_terms_data.h" | 24 #include "components/search_engines/search_terms_data.h" |
| 26 #include "components/search_engines/template_url.h" | 25 #include "components/search_engines/template_url.h" |
| 27 #include "components/search_engines/template_url_prepopulate_data.h" | 26 #include "components/search_engines/template_url_prepopulate_data.h" |
| 28 #include "components/search_engines/template_url_service.h" | 27 #include "components/search_engines/template_url_service.h" |
| 29 #include "components/webdata/common/web_database.h" | 28 #include "content/public/test/test_browser_thread_bundle.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 30 |
| 32 using base::ASCIIToUTF16; | 31 using base::ASCIIToUTF16; |
| 33 using base::Time; | 32 using base::Time; |
| 34 using base::TimeDelta; | 33 using base::TimeDelta; |
| 35 using ::testing::Return; | 34 using ::testing::Return; |
| 36 using ::testing::StrictMock; | 35 using ::testing::StrictMock; |
| 37 | 36 |
| 38 namespace { | 37 namespace { |
| 39 | 38 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 // Helper methods to make calling TemplateURLServiceTestUtil methods less | 158 // Helper methods to make calling TemplateURLServiceTestUtil methods less |
| 160 // visually noisy in the test code. | 159 // visually noisy in the test code. |
| 161 void VerifyObserverCount(int expected_changed_count); | 160 void VerifyObserverCount(int expected_changed_count); |
| 162 void VerifyObserverFired(); | 161 void VerifyObserverFired(); |
| 163 TemplateURLService* model() { return test_util_->model(); } | 162 TemplateURLService* model() { return test_util_->model(); } |
| 164 const SearchTermsData& search_terms_data() { | 163 const SearchTermsData& search_terms_data() { |
| 165 return model()->search_terms_data(); | 164 return model()->search_terms_data(); |
| 166 } | 165 } |
| 167 | 166 |
| 168 protected: | 167 protected: |
| 168 content::TestBrowserThreadBundle thread_bundle_; | |
|
Peter Kasting
2014/08/28 19:06:20
Nit: Add comments about why we need this.
While h
hashimoto
2014/08/29 08:06:26
Added comments and made all data members private.
| |
| 169 scoped_ptr<TemplateURLServiceTestUtil> test_util_; | 169 scoped_ptr<TemplateURLServiceTestUtil> test_util_; |
| 170 | 170 |
| 171 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTest); | 171 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTest); |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 class TemplateURLServiceWithoutFallbackTest : public TemplateURLServiceTest { | 174 class TemplateURLServiceWithoutFallbackTest : public TemplateURLServiceTest { |
| 175 public: | 175 public: |
| 176 TemplateURLServiceWithoutFallbackTest() : TemplateURLServiceTest() {} | 176 TemplateURLServiceWithoutFallbackTest() : TemplateURLServiceTest() {} |
| 177 | 177 |
| 178 virtual void SetUp() OVERRIDE { | 178 virtual void SetUp() OVERRIDE { |
| (...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1169 EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement( | 1169 EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement( |
| 1170 search_terms_data())); | 1170 search_terms_data())); |
| 1171 } | 1171 } |
| 1172 | 1172 |
| 1173 // Simulates failing to load the webdb and makes sure the default search | 1173 // Simulates failing to load the webdb and makes sure the default search |
| 1174 // provider is valid. | 1174 // provider is valid. |
| 1175 TEST_F(TemplateURLServiceTest, FailedInit) { | 1175 TEST_F(TemplateURLServiceTest, FailedInit) { |
| 1176 test_util_->VerifyLoad(); | 1176 test_util_->VerifyLoad(); |
| 1177 | 1177 |
| 1178 test_util_->ClearModel(); | 1178 test_util_->ClearModel(); |
| 1179 WebDataServiceFactory::GetKeywordWebDataForProfile( | 1179 test_util_->web_data_service()->ShutdownDatabase(); |
| 1180 test_util_->profile(), Profile::EXPLICIT_ACCESS)->ShutdownDatabase(); | |
| 1181 | 1180 |
| 1182 test_util_->ResetModel(false); | 1181 test_util_->ResetModel(false); |
| 1183 model()->Load(); | 1182 model()->Load(); |
| 1184 base::RunLoop().RunUntilIdle(); | 1183 base::RunLoop().RunUntilIdle(); |
| 1185 | 1184 |
| 1186 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 1185 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
| 1187 } | 1186 } |
| 1188 | 1187 |
| 1189 // Verifies that if the default search URL preference is managed, we report | 1188 // Verifies that if the default search URL preference is managed, we report |
| 1190 // the default search as managed. Also check that we are getting the right | 1189 // the default search as managed. Also check that we are getting the right |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1487 scoped_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1486 scoped_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
| 1488 new TemplateURL::AssociatedExtensionInfo( | 1487 new TemplateURL::AssociatedExtensionInfo( |
| 1489 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); | 1488 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); |
| 1490 extension_info->wants_to_be_default_engine = true; | 1489 extension_info->wants_to_be_default_engine = true; |
| 1491 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); | 1490 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); |
| 1492 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1491 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
| 1493 EXPECT_TRUE(model()->is_default_search_managed()); | 1492 EXPECT_TRUE(model()->is_default_search_managed()); |
| 1494 actual_managed_default = model()->GetDefaultSearchProvider(); | 1493 actual_managed_default = model()->GetDefaultSearchProvider(); |
| 1495 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1494 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
| 1496 } | 1495 } |
| OLD | NEW |