| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 5 #include "base/callback.h" |
| 6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
| 7 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
| 8 #include "base/test/mock_time_provider.h" | 8 #include "base/test/mock_time_provider.h" |
| 9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 static TemplateURL* CreatePreloadedTemplateURL() { | 90 static TemplateURL* CreatePreloadedTemplateURL() { |
| 91 TemplateURL* t_url = new TemplateURL(); | 91 TemplateURL* t_url = new TemplateURL(); |
| 92 t_url->SetURL("http://www.unittest.com/", 0, 0); | 92 t_url->SetURL("http://www.unittest.com/", 0, 0); |
| 93 t_url->set_keyword(ASCIIToUTF16("unittest")); | 93 t_url->set_keyword(ASCIIToUTF16("unittest")); |
| 94 t_url->set_short_name(ASCIIToUTF16("unittest")); | 94 t_url->set_short_name(ASCIIToUTF16("unittest")); |
| 95 t_url->set_safe_for_autoreplace(true); | 95 t_url->set_safe_for_autoreplace(true); |
| 96 GURL favicon_url("http://favicon.url"); | 96 GURL favicon_url("http://favicon.url"); |
| 97 t_url->SetFaviconURL(favicon_url); | 97 t_url->SetFaviconURL(favicon_url); |
| 98 t_url->set_date_created(Time::FromTimeT(100)); | 98 t_url->set_date_created(Time::FromTimeT(100)); |
| 99 t_url->set_last_modified(Time::FromTimeT(100)); | 99 t_url->set_last_modified(Time::FromTimeT(100)); |
| 100 t_url->set_prepopulate_id(999999); | 100 t_url->SetPrepopulateId(999999); |
| 101 return t_url; | 101 return t_url; |
| 102 } | 102 } |
| 103 | 103 |
| 104 class TemplateURLServiceTest : public testing::Test { | 104 class TemplateURLServiceTest : public testing::Test { |
| 105 public: | 105 public: |
| 106 TemplateURLServiceTest() {} | 106 TemplateURLServiceTest() {} |
| 107 | 107 |
| 108 virtual void SetUp() { | 108 virtual void SetUp() { |
| 109 test_util_.SetUp(); | 109 test_util_.SetUp(); |
| 110 } | 110 } |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 ScopedVector<TemplateURL> prepopulated_urls; | 329 ScopedVector<TemplateURL> prepopulated_urls; |
| 330 size_t default_search_provider_index = 0; | 330 size_t default_search_provider_index = 0; |
| 331 TemplateURLPrepopulateData::GetPrepopulatedEngines( | 331 TemplateURLPrepopulateData::GetPrepopulatedEngines( |
| 332 profile()->GetPrefs(), | 332 profile()->GetPrefs(), |
| 333 &prepopulated_urls.get(), | 333 &prepopulated_urls.get(), |
| 334 &default_search_provider_index); | 334 &default_search_provider_index); |
| 335 EXPECT_LT(index_offset_from_default, prepopulated_urls.size()); | 335 EXPECT_LT(index_offset_from_default, prepopulated_urls.size()); |
| 336 size_t prepopulated_index = | 336 size_t prepopulated_index = |
| 337 (default_search_provider_index + index_offset_from_default) % | 337 (default_search_provider_index + index_offset_from_default) % |
| 338 prepopulated_urls.size(); | 338 prepopulated_urls.size(); |
| 339 t_url->set_prepopulate_id( | 339 t_url->SetPrepopulateId( |
| 340 prepopulated_urls[prepopulated_index]->prepopulate_id()); | 340 prepopulated_urls[prepopulated_index]->prepopulate_id()); |
| 341 *prepopulated_display_url = | 341 *prepopulated_display_url = |
| 342 prepopulated_urls[prepopulated_index]->url()->DisplayURL(); | 342 prepopulated_urls[prepopulated_index]->url()->DisplayURL(); |
| 343 return t_url; | 343 return t_url; |
| 344 } | 344 } |
| 345 | 345 |
| 346 void TemplateURLServiceTest::TestLoadUpdatingPreloadedURL( | 346 void TemplateURLServiceTest::TestLoadUpdatingPreloadedURL( |
| 347 size_t index_offset_from_default) { | 347 size_t index_offset_from_default) { |
| 348 string16 prepopulated_url; | 348 string16 prepopulated_url; |
| 349 TemplateURL* t_url = CreateReplaceablePreloadedTemplateURL( | 349 TemplateURL* t_url = CreateReplaceablePreloadedTemplateURL( |
| (...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 model()->SetDefaultSearchProvider(t_url); | 1234 model()->SetDefaultSearchProvider(t_url); |
| 1235 EXPECT_EQ(t_url, model()->GetDefaultSearchProvider()); | 1235 EXPECT_EQ(t_url, model()->GetDefaultSearchProvider()); |
| 1236 | 1236 |
| 1237 // Now reset the model again but load it after setting the preferences. | 1237 // Now reset the model again but load it after setting the preferences. |
| 1238 ResetModel(false); | 1238 ResetModel(false); |
| 1239 SetManagedDefaultSearchPreferences(false, "", "", "", "", "", ""); | 1239 SetManagedDefaultSearchPreferences(false, "", "", "", "", "", ""); |
| 1240 VerifyLoad(); | 1240 VerifyLoad(); |
| 1241 EXPECT_TRUE(model()->is_default_search_managed()); | 1241 EXPECT_TRUE(model()->is_default_search_managed()); |
| 1242 EXPECT_TRUE(model()->GetDefaultSearchProvider() == NULL); | 1242 EXPECT_TRUE(model()->GetDefaultSearchProvider() == NULL); |
| 1243 } | 1243 } |
| OLD | NEW |