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

Side by Side Diff: chrome/browser/search_engines/template_url_service_unittest.cc

Issue 7232023: Added last_modified field to TemplateURL and database. Updated unit tests, including refactoring ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 | Annotate | Revision Log
OLDNEW
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/string_split.h" 9 #include "base/string_split.h"
9 #include "base/string_util.h" 10 #include "base/string_util.h"
10 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
11 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/history/history.h" 13 #include "chrome/browser/history/history.h"
13 #include "chrome/browser/history/history_notifications.h" 14 #include "chrome/browser/history/history_notifications.h"
14 #include "chrome/browser/search_engines/search_host_to_urls_map.h" 15 #include "chrome/browser/search_engines/search_host_to_urls_map.h"
15 #include "chrome/browser/search_engines/search_terms_data.h" 16 #include "chrome/browser/search_engines/search_terms_data.h"
16 #include "chrome/browser/search_engines/template_url.h" 17 #include "chrome/browser/search_engines/template_url.h"
17 #include "chrome/browser/search_engines/template_url_service.h" 18 #include "chrome/browser/search_engines/template_url_service.h"
18 #include "chrome/browser/search_engines/template_url_service_test_util.h" 19 #include "chrome/browser/search_engines/template_url_service_test_util.h"
19 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 20 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
20 #include "chrome/browser/webdata/web_database.h" 21 #include "chrome/browser/webdata/web_database.h"
21 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
22 #include "chrome/test/testing_pref_service.h" 23 #include "chrome/test/testing_pref_service.h"
23 #include "chrome/test/testing_profile.h" 24 #include "chrome/test/testing_profile.h"
24 #include "content/browser/browser_thread.h" 25 #include "content/browser/browser_thread.h"
25 #include "content/common/notification_details.h" 26 #include "content/common/notification_details.h"
26 #include "content/common/notification_source.h" 27 #include "content/common/notification_source.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 29
29 using base::Time; 30 using base::Time;
30 using base::TimeDelta; 31 using base::TimeDelta;
32 using ::testing::Return;
33 using ::testing::StrictMock;
31 34
32 // Test the GenerateSearchURL on a thread or the main thread. 35 // Test the GenerateSearchURL on a thread or the main thread.
33 class TestGenerateSearchURL 36 class TestGenerateSearchURL
34 : public base::RefCountedThreadSafe<TestGenerateSearchURL> { 37 : public base::RefCountedThreadSafe<TestGenerateSearchURL> {
35 public: 38 public:
36 explicit TestGenerateSearchURL(SearchTermsData* search_terms_data) 39 explicit TestGenerateSearchURL(SearchTermsData* search_terms_data)
37 : search_terms_data_(search_terms_data), 40 : search_terms_data_(search_terms_data),
38 passed_(false) { 41 passed_(false) {
39 } 42 }
40 43
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // current data. The caller owns the returned TemplateURL*. 89 // current data. The caller owns the returned TemplateURL*.
87 static TemplateURL* CreatePreloadedTemplateURL() { 90 static TemplateURL* CreatePreloadedTemplateURL() {
88 TemplateURL* t_url = new TemplateURL(); 91 TemplateURL* t_url = new TemplateURL();
89 t_url->SetURL("http://www.unittest.com/", 0, 0); 92 t_url->SetURL("http://www.unittest.com/", 0, 0);
90 t_url->set_keyword(ASCIIToUTF16("unittest")); 93 t_url->set_keyword(ASCIIToUTF16("unittest"));
91 t_url->set_short_name(ASCIIToUTF16("unittest")); 94 t_url->set_short_name(ASCIIToUTF16("unittest"));
92 t_url->set_safe_for_autoreplace(true); 95 t_url->set_safe_for_autoreplace(true);
93 GURL favicon_url("http://favicon.url"); 96 GURL favicon_url("http://favicon.url");
94 t_url->SetFaviconURL(favicon_url); 97 t_url->SetFaviconURL(favicon_url);
95 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));
96 t_url->set_prepopulate_id(999999); 100 t_url->set_prepopulate_id(999999);
97 return t_url; 101 return t_url;
98 } 102 }
99 103
100 class TemplateURLServiceTest : public testing::Test { 104 class TemplateURLServiceTest : public testing::Test {
101 public: 105 public:
102 TemplateURLServiceTest() {} 106 TemplateURLServiceTest() {}
103 107
104 virtual void SetUp() { 108 virtual void SetUp() {
105 test_util_.SetUp(); 109 test_util_.SetUp();
106 } 110 }
107 111
108 virtual void TearDown() { 112 virtual void TearDown() {
109 test_util_.TearDown(); 113 test_util_.TearDown();
110 } 114 }
111 115
112 TemplateURL* AddKeywordWithDate(const std::string& keyword, 116 TemplateURL* AddKeywordWithDate(const std::string& keyword,
113 bool autogenerate_keyword, 117 bool autogenerate_keyword,
114 const std::string& url, 118 const std::string& url,
115 const std::string& suggest_url, 119 const std::string& suggest_url,
116 const std::string& favicon_url, 120 const std::string& favicon_url,
117 const std::string& encodings, 121 const std::string& encodings,
118 const std::string& short_name, 122 const std::string& short_name,
119 bool safe_for_autoreplace, 123 bool safe_for_autoreplace,
120 Time created_date) { 124 Time created_date,
125 Time last_modified) {
121 TemplateURL* template_url = new TemplateURL(); 126 TemplateURL* template_url = new TemplateURL();
122 template_url->SetURL(url, 0, 0); 127 template_url->SetURL(url, 0, 0);
123 template_url->SetSuggestionsURL(suggest_url, 0, 0); 128 template_url->SetSuggestionsURL(suggest_url, 0, 0);
124 template_url->SetFaviconURL(GURL(favicon_url)); 129 template_url->SetFaviconURL(GURL(favicon_url));
125 template_url->set_keyword(UTF8ToUTF16(keyword)); 130 template_url->set_keyword(UTF8ToUTF16(keyword));
126 template_url->set_autogenerate_keyword(autogenerate_keyword); 131 template_url->set_autogenerate_keyword(autogenerate_keyword);
127 template_url->set_short_name(UTF8ToUTF16(short_name)); 132 template_url->set_short_name(UTF8ToUTF16(short_name));
128 std::vector<std::string> encodings_vector; 133 std::vector<std::string> encodings_vector;
129 base::SplitString(encodings, ';', &encodings_vector); 134 base::SplitString(encodings, ';', &encodings_vector);
130 template_url->set_input_encodings(encodings_vector); 135 template_url->set_input_encodings(encodings_vector);
131 template_url->set_date_created(created_date); 136 template_url->set_date_created(created_date);
137 template_url->set_last_modified(last_modified);
132 template_url->set_safe_for_autoreplace(safe_for_autoreplace); 138 template_url->set_safe_for_autoreplace(safe_for_autoreplace);
133 model()->Add(template_url); 139 model()->Add(template_url);
134 EXPECT_NE(0, template_url->id()); 140 EXPECT_NE(0, template_url->id());
135 return template_url; 141 return template_url;
136 } 142 }
137 143
138 // Simulate firing by the prefs service specifying that the managed 144 // Simulate firing by the prefs service specifying that the managed
139 // preferences have changed. 145 // preferences have changed.
140 void NotifyManagedPrefsHaveChanged() { 146 void NotifyManagedPrefsHaveChanged() {
141 model()->Observe( 147 model()->Observe(
142 NotificationType::PREF_CHANGED, 148 NotificationType::PREF_CHANGED,
143 Source<PrefService>(profile()->GetTestingPrefService()), 149 Source<PrefService>(profile()->GetTestingPrefService()),
144 Details<std::string>(NULL)); 150 Details<std::string>(NULL));
145 } 151 }
146 152
147 // Verifies the two TemplateURLs are equal. 153 // Verifies the two TemplateURLs are equal.
148 void AssertEquals(const TemplateURL& expected, const TemplateURL& actual) { 154 void AssertEquals(const TemplateURL& expected, const TemplateURL& actual) {
149 ASSERT_TRUE(TemplateURLRef::SameUrlRefs(expected.url(), actual.url())); 155 ASSERT_TRUE(TemplateURLRef::SameUrlRefs(expected.url(), actual.url()));
150 ASSERT_TRUE(TemplateURLRef::SameUrlRefs(expected.suggestions_url(), 156 ASSERT_TRUE(TemplateURLRef::SameUrlRefs(expected.suggestions_url(),
151 actual.suggestions_url())); 157 actual.suggestions_url()));
152 ASSERT_EQ(expected.keyword(), actual.keyword()); 158 ASSERT_EQ(expected.keyword(), actual.keyword());
153 ASSERT_EQ(expected.short_name(), actual.short_name()); 159 ASSERT_EQ(expected.short_name(), actual.short_name());
154 ASSERT_EQ(JoinString(expected.input_encodings(), ';'), 160 ASSERT_EQ(JoinString(expected.input_encodings(), ';'),
155 JoinString(actual.input_encodings(), ';')); 161 JoinString(actual.input_encodings(), ';'));
156 ASSERT_TRUE(expected.GetFaviconURL() == actual.GetFaviconURL()); 162 ASSERT_TRUE(expected.GetFaviconURL() == actual.GetFaviconURL());
157 ASSERT_EQ(expected.id(), actual.id()); 163 ASSERT_EQ(expected.id(), actual.id());
158 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); 164 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace());
159 ASSERT_EQ(expected.show_in_default_list(), actual.show_in_default_list()); 165 ASSERT_EQ(expected.show_in_default_list(), actual.show_in_default_list());
160 ASSERT_TRUE(expected.date_created() == actual.date_created()); 166 ASSERT_TRUE(expected.date_created() == actual.date_created());
167 ASSERT_TRUE(expected.last_modified() == actual.last_modified());
161 } 168 }
162 169
163 // Checks that the two TemplateURLs are similar. It does not check the id 170 // Checks that the two TemplateURLs are similar. It does not check the id, the
164 // and the date_created. Neither pointer should be NULL. 171 // date_created or the last_modified time. Neither pointer should be NULL.
165 void ExpectSimilar(const TemplateURL* expected, const TemplateURL* actual) { 172 void ExpectSimilar(const TemplateURL* expected, const TemplateURL* actual) {
166 ASSERT_TRUE(expected != NULL); 173 ASSERT_TRUE(expected != NULL);
167 ASSERT_TRUE(actual != NULL); 174 ASSERT_TRUE(actual != NULL);
168 EXPECT_TRUE(TemplateURLRef::SameUrlRefs(expected->url(), actual->url())); 175 EXPECT_TRUE(TemplateURLRef::SameUrlRefs(expected->url(), actual->url()));
169 EXPECT_TRUE(TemplateURLRef::SameUrlRefs(expected->suggestions_url(), 176 EXPECT_TRUE(TemplateURLRef::SameUrlRefs(expected->suggestions_url(),
170 actual->suggestions_url())); 177 actual->suggestions_url()));
171 EXPECT_EQ(expected->keyword(), actual->keyword()); 178 EXPECT_EQ(expected->keyword(), actual->keyword());
172 EXPECT_EQ(expected->short_name(), actual->short_name()); 179 EXPECT_EQ(expected->short_name(), actual->short_name());
173 EXPECT_EQ(JoinString(expected->input_encodings(), ';'), 180 EXPECT_EQ(JoinString(expected->input_encodings(), ';'),
174 JoinString(actual->input_encodings(), ';')); 181 JoinString(actual->input_encodings(), ';'));
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 VerifyLoad(); 387 VerifyLoad();
381 const size_t initial_count = model()->GetTemplateURLs().size(); 388 const size_t initial_count = model()->GetTemplateURLs().size();
382 389
383 TemplateURL* t_url = new TemplateURL(); 390 TemplateURL* t_url = new TemplateURL();
384 t_url->SetURL("http://www.google.com/foo/bar", 0, 0); 391 t_url->SetURL("http://www.google.com/foo/bar", 0, 0);
385 t_url->set_keyword(ASCIIToUTF16("keyword")); 392 t_url->set_keyword(ASCIIToUTF16("keyword"));
386 t_url->set_short_name(ASCIIToUTF16("google")); 393 t_url->set_short_name(ASCIIToUTF16("google"));
387 GURL favicon_url("http://favicon.url"); 394 GURL favicon_url("http://favicon.url");
388 t_url->SetFaviconURL(favicon_url); 395 t_url->SetFaviconURL(favicon_url);
389 t_url->set_date_created(Time::FromTimeT(100)); 396 t_url->set_date_created(Time::FromTimeT(100));
397 t_url->set_last_modified(Time::FromTimeT(100));
390 t_url->set_safe_for_autoreplace(true); 398 t_url->set_safe_for_autoreplace(true);
391 model()->Add(t_url); 399 model()->Add(t_url);
392 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), 400 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"),
393 GURL(), NULL)); 401 GURL(), NULL));
394 VerifyObserverCount(1); 402 VerifyObserverCount(1);
395 BlockTillServiceProcessesRequests(); 403 BlockTillServiceProcessesRequests();
396 // We need to clone as model takes ownership of TemplateURL and will 404 // We need to clone as model takes ownership of TemplateURL and will
397 // delete it. 405 // delete it.
398 TemplateURL cloned_url(*t_url); 406 TemplateURL cloned_url(*t_url);
399 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); 407 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size());
400 ASSERT_TRUE(model()->GetTemplateURLForKeyword(t_url->keyword()) == t_url); 408 ASSERT_TRUE(model()->GetTemplateURLForKeyword(t_url->keyword()) == t_url);
401 ASSERT_TRUE(t_url->date_created() == cloned_url.date_created()); 409 ASSERT_TRUE(t_url->date_created() == cloned_url.date_created());
402 410
403 // Reload the model to verify it was actually saved to the database. 411 // Reload the model to verify it was actually saved to the database.
404 ResetModel(true); 412 ResetModel(true);
405 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); 413 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size());
406 const TemplateURL* loaded_url = 414 const TemplateURL* loaded_url =
407 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); 415 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"));
408 ASSERT_TRUE(loaded_url != NULL); 416 ASSERT_TRUE(loaded_url != NULL);
409 AssertEquals(cloned_url, *loaded_url); 417 AssertEquals(cloned_url, *loaded_url);
410 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), 418 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"),
411 GURL(), NULL)); 419 GURL(), NULL));
412 420
421 // We expect the last_modified time to be updated to the present time on an
422 // explicit reset. We have to set up the expectation here because ResetModel
423 // resets the TimeProvider in the TemplateURLService.
424 StrictMock<base::MockTimeProvider> mock_time;
425 model()->set_time_provider(&base::MockTimeProvider::StaticNow);
426 EXPECT_CALL(mock_time, Now())
427 .WillOnce(Return(base::Time::FromDoubleT(1337)));
428
413 // Mutate an element and verify it succeeded. 429 // Mutate an element and verify it succeeded.
414 model()->ResetTemplateURL(loaded_url, ASCIIToUTF16("a"), 430 model()->ResetTemplateURL(loaded_url, ASCIIToUTF16("a"),
415 ASCIIToUTF16("b"), "c"); 431 ASCIIToUTF16("b"), "c");
416 ASSERT_EQ(ASCIIToUTF16("a"), loaded_url->short_name()); 432 ASSERT_EQ(ASCIIToUTF16("a"), loaded_url->short_name());
417 ASSERT_EQ(ASCIIToUTF16("b"), loaded_url->keyword()); 433 ASSERT_EQ(ASCIIToUTF16("b"), loaded_url->keyword());
418 ASSERT_EQ("c", loaded_url->url()->url()); 434 ASSERT_EQ("c", loaded_url->url()->url());
419 ASSERT_FALSE(loaded_url->safe_for_autoreplace()); 435 ASSERT_FALSE(loaded_url->safe_for_autoreplace());
420 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), 436 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"),
421 GURL(), NULL)); 437 GURL(), NULL));
422 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL)); 438 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL));
423 cloned_url = *loaded_url; 439 cloned_url = *loaded_url;
424 BlockTillServiceProcessesRequests(); 440 BlockTillServiceProcessesRequests();
425 ResetModel(true); 441 ResetModel(true);
426 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); 442 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size());
427 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")); 443 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b"));
428 ASSERT_TRUE(loaded_url != NULL); 444 ASSERT_TRUE(loaded_url != NULL);
429 AssertEquals(cloned_url, *loaded_url); 445 AssertEquals(cloned_url, *loaded_url);
446 // We changed a TemplateURL in the service, so ensure that the time was
447 // updated.
448 ASSERT_EQ(loaded_url->last_modified(), base::Time::FromDoubleT(1337));
430 449
431 // Remove an element and verify it succeeded. 450 // Remove an element and verify it succeeded.
432 model()->Remove(loaded_url); 451 model()->Remove(loaded_url);
433 VerifyObserverCount(1); 452 VerifyObserverCount(1);
434 ResetModel(true); 453 ResetModel(true);
435 ASSERT_EQ(initial_count, model()->GetTemplateURLs().size()); 454 ASSERT_EQ(initial_count, model()->GetTemplateURLs().size());
436 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")) == NULL); 455 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")) == NULL);
437 } 456 }
438 457
439 TEST_F(TemplateURLServiceTest, GenerateKeyword) { 458 TEST_F(TemplateURLServiceTest, GenerateKeyword) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) { 504 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) {
486 Time now = Time::Now(); 505 Time now = Time::Now();
487 TimeDelta one_day = TimeDelta::FromDays(1); 506 TimeDelta one_day = TimeDelta::FromDays(1);
488 Time month_ago = now - TimeDelta::FromDays(30); 507 Time month_ago = now - TimeDelta::FromDays(30);
489 508
490 // Nothing has been added. 509 // Nothing has been added.
491 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); 510 EXPECT_EQ(0U, model()->GetTemplateURLs().size());
492 511
493 // Create one with a 0 time. 512 // Create one with a 0 time.
494 AddKeywordWithDate("key1", false, "http://foo1", "http://suggest1", 513 AddKeywordWithDate("key1", false, "http://foo1", "http://suggest1",
495 "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); 514 "http://icon1", "UTF-8;UTF-16", "name1", true, Time(),
515 Time());
496 // Create one for now and +/- 1 day. 516 // Create one for now and +/- 1 day.
497 AddKeywordWithDate("key2", false, "http://foo2", "http://suggest2", 517 AddKeywordWithDate("key2", false, "http://foo2", "http://suggest2",
498 "http://icon2", "UTF-8;UTF-16", "name2", true, 518 "http://icon2", "UTF-8;UTF-16", "name2", true,
499 now - one_day); 519 now - one_day, Time());
500 AddKeywordWithDate("key3", false, "http://foo3", "", "", "", "name3", 520 AddKeywordWithDate("key3", false, "http://foo3", "", "", "", "name3",
501 true, now); 521 true, now, Time());
502 AddKeywordWithDate("key4", false, "http://foo4", "", "", "", "name4", 522 AddKeywordWithDate("key4", false, "http://foo4", "", "", "", "name4",
503 true, now + one_day); 523 true, now + one_day, Time());
504 // Try the other three states. 524 // Try the other three states.
505 AddKeywordWithDate("key5", false, "http://foo5", "http://suggest5", 525 AddKeywordWithDate("key5", false, "http://foo5", "http://suggest5",
506 "http://icon5", "UTF-8;UTF-16", "name5", false, now); 526 "http://icon5", "UTF-8;UTF-16", "name5", false, now,
527 Time());
507 AddKeywordWithDate("key6", false, "http://foo6", "http://suggest6", 528 AddKeywordWithDate("key6", false, "http://foo6", "http://suggest6",
508 "http://icon6", "UTF-8;UTF-16", "name6", false, 529 "http://icon6", "UTF-8;UTF-16", "name6", false,
509 month_ago); 530 month_ago, Time());
510 531
511 // We just added a few items, validate them. 532 // We just added a few items, validate them.
512 EXPECT_EQ(6U, model()->GetTemplateURLs().size()); 533 EXPECT_EQ(6U, model()->GetTemplateURLs().size());
513 534
514 // Try removing from current timestamp. This should delete the one in the 535 // Try removing from current timestamp. This should delete the one in the
515 // future and one very recent one. 536 // future and one very recent one.
516 model()->RemoveAutoGeneratedSince(now); 537 model()->RemoveAutoGeneratedSince(now);
517 EXPECT_EQ(4U, model()->GetTemplateURLs().size()); 538 EXPECT_EQ(4U, model()->GetTemplateURLs().size());
518 539
519 // Try removing from two months ago. This should only delete items that are 540 // Try removing from two months ago. This should only delete items that are
(...skipping 26 matching lines...) Expand all
546 // Add a new TemplateURL. 567 // Add a new TemplateURL.
547 VerifyLoad(); 568 VerifyLoad();
548 const size_t initial_count = model()->GetTemplateURLs().size(); 569 const size_t initial_count = model()->GetTemplateURLs().size();
549 TemplateURL* t_url = new TemplateURL(); 570 TemplateURL* t_url = new TemplateURL();
550 t_url->SetURL("http://www.google.com/foo/bar", 0, 0); 571 t_url->SetURL("http://www.google.com/foo/bar", 0, 0);
551 t_url->set_keyword(ASCIIToUTF16("keyword")); 572 t_url->set_keyword(ASCIIToUTF16("keyword"));
552 t_url->set_short_name(ASCIIToUTF16("google")); 573 t_url->set_short_name(ASCIIToUTF16("google"));
553 GURL favicon_url("http://favicon.url"); 574 GURL favicon_url("http://favicon.url");
554 t_url->SetFaviconURL(favicon_url); 575 t_url->SetFaviconURL(favicon_url);
555 t_url->set_date_created(Time::FromTimeT(100)); 576 t_url->set_date_created(Time::FromTimeT(100));
577 t_url->set_last_modified(Time::FromTimeT(100));
556 model()->Add(t_url); 578 model()->Add(t_url);
557 579
558 VerifyObserverCount(1); 580 VerifyObserverCount(1);
559 BlockTillServiceProcessesRequests(); 581 BlockTillServiceProcessesRequests();
560 582
583 StrictMock<base::MockTimeProvider> mock_time;
584 model()->set_time_provider(&base::MockTimeProvider::StaticNow);
585 EXPECT_CALL(mock_time, Now())
586 .WillOnce(Return(base::Time::FromDoubleT(1337)));
587
561 // Reset the short name, keyword, url and make sure it takes. 588 // Reset the short name, keyword, url and make sure it takes.
562 const string16 new_short_name(ASCIIToUTF16("a")); 589 const string16 new_short_name(ASCIIToUTF16("a"));
563 const string16 new_keyword(ASCIIToUTF16("b")); 590 const string16 new_keyword(ASCIIToUTF16("b"));
564 const std::string new_url("c"); 591 const std::string new_url("c");
565 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); 592 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url);
566 ASSERT_EQ(new_short_name, t_url->short_name()); 593 ASSERT_EQ(new_short_name, t_url->short_name());
567 ASSERT_EQ(new_keyword, t_url->keyword()); 594 ASSERT_EQ(new_keyword, t_url->keyword());
568 ASSERT_EQ(new_url, t_url->url()->url()); 595 ASSERT_EQ(new_url, t_url->url()->url());
569 596
570 // Make sure the mappings in the model were updated. 597 // Make sure the mappings in the model were updated.
571 ASSERT_TRUE(model()->GetTemplateURLForKeyword(new_keyword) == t_url); 598 ASSERT_TRUE(model()->GetTemplateURLForKeyword(new_keyword) == t_url);
572 ASSERT_TRUE( 599 ASSERT_TRUE(
573 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")) == NULL); 600 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")) == NULL);
574 601
575 TemplateURL last_url = *t_url; 602 TemplateURL last_url = *t_url;
576 603
577 // Reload the model from the database and make sure the change took. 604 // Reload the model from the database and make sure the change took.
578 ResetModel(true); 605 ResetModel(true);
579 t_url = NULL; 606 t_url = NULL;
580 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 607 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
581 const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword); 608 const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword);
582 ASSERT_TRUE(read_url); 609 ASSERT_TRUE(read_url);
583 AssertEquals(last_url, *read_url); 610 AssertEquals(last_url, *read_url);
611 ASSERT_EQ(read_url->last_modified(), base::Time::FromDoubleT(1337));
584 } 612 }
585 613
586 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) { 614 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) {
587 // Add a new TemplateURL. 615 // Add a new TemplateURL.
588 VerifyLoad(); 616 VerifyLoad();
589 const size_t initial_count = model()->GetTemplateURLs().size(); 617 const size_t initial_count = model()->GetTemplateURLs().size();
590 TemplateURL* t_url = AddKeywordWithDate("key1", false, "http://foo1", 618 TemplateURL* t_url = AddKeywordWithDate("key1", false, "http://foo1",
591 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); 619 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time(),
620 Time());
592 621
593 test_util_.ResetObserverCount(); 622 test_util_.ResetObserverCount();
594 model()->SetDefaultSearchProvider(t_url); 623 model()->SetDefaultSearchProvider(t_url);
595 624
596 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); 625 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider());
597 626
598 ASSERT_TRUE(t_url->safe_for_autoreplace()); 627 ASSERT_TRUE(t_url->safe_for_autoreplace());
599 ASSERT_TRUE(t_url->show_in_default_list()); 628 ASSERT_TRUE(t_url->show_in_default_list());
600 629
601 // Setting the default search provider should have caused notification. 630 // Setting the default search provider should have caused notification.
(...skipping 11 matching lines...) Expand all
613 ASSERT_TRUE(model()->GetDefaultSearchProvider()); 642 ASSERT_TRUE(model()->GetDefaultSearchProvider());
614 AssertEquals(cloned_url, *model()->GetDefaultSearchProvider()); 643 AssertEquals(cloned_url, *model()->GetDefaultSearchProvider());
615 } 644 }
616 645
617 TEST_F(TemplateURLServiceTest, TemplateURLWithNoKeyword) { 646 TEST_F(TemplateURLServiceTest, TemplateURLWithNoKeyword) {
618 VerifyLoad(); 647 VerifyLoad();
619 648
620 const size_t initial_count = model()->GetTemplateURLs().size(); 649 const size_t initial_count = model()->GetTemplateURLs().size();
621 650
622 AddKeywordWithDate("", false, "http://foo1", "http://sugg1", 651 AddKeywordWithDate("", false, "http://foo1", "http://sugg1",
623 "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); 652 "http://icon1", "UTF-8;UTF-16", "name1", true, Time(), Time());
624 653
625 // We just added a few items, validate them. 654 // We just added a few items, validate them.
626 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 655 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
627 656
628 // Reload the model from the database and make sure we get the url back. 657 // Reload the model from the database and make sure we get the url back.
629 ResetModel(true); 658 ResetModel(true);
630 659
631 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); 660 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size());
632 661
633 bool found_keyword = false; 662 bool found_keyword = false;
634 for (size_t i = 0; i < initial_count + 1; ++i) { 663 for (size_t i = 0; i < initial_count + 1; ++i) {
635 if (model()->GetTemplateURLs()[i]->keyword().empty()) { 664 if (model()->GetTemplateURLs()[i]->keyword().empty()) {
636 found_keyword = true; 665 found_keyword = true;
637 break; 666 break;
638 } 667 }
639 } 668 }
640 ASSERT_TRUE(found_keyword); 669 ASSERT_TRUE(found_keyword);
641 } 670 }
642 671
643 TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) { 672 TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) {
644 ChangeModelToLoadState(); 673 ChangeModelToLoadState();
645 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), GURL(), NULL)); 674 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), GURL(), NULL));
646 TemplateURL* t_url = AddKeywordWithDate("foo", false, "http://foo1", 675 TemplateURL* t_url = AddKeywordWithDate("foo", false, "http://foo1",
647 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); 676 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time(),
677 Time());
648 678
649 // Can still replace, newly added template url is marked safe to replace. 679 // Can still replace, newly added template url is marked safe to replace.
650 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), 680 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"),
651 GURL("http://foo2"), NULL)); 681 GURL("http://foo2"), NULL));
652 682
653 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should 683 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should
654 // no longer be replaceable. 684 // no longer be replaceable.
655 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), 685 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(),
656 t_url->url()->url()); 686 t_url->url()->url());
657 687
658 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), 688 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"),
659 GURL("http://foo2"), NULL)); 689 GURL("http://foo2"), NULL));
660 } 690 }
661 691
662 TEST_F(TemplateURLServiceTest, CantReplaceWithSameHosts) { 692 TEST_F(TemplateURLServiceTest, CantReplaceWithSameHosts) {
663 ChangeModelToLoadState(); 693 ChangeModelToLoadState();
664 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), 694 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"),
665 GURL("http://foo.com"), NULL)); 695 GURL("http://foo.com"), NULL));
666 TemplateURL* t_url = AddKeywordWithDate("foo", false, "http://foo.com", 696 TemplateURL* t_url = AddKeywordWithDate("foo", false, "http://foo.com",
667 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); 697 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time(),
698 Time());
668 699
669 // Can still replace, newly added template url is marked safe to replace. 700 // Can still replace, newly added template url is marked safe to replace.
670 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"), 701 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"),
671 GURL("http://foo.com"), NULL)); 702 GURL("http://foo.com"), NULL));
672 703
673 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should 704 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should
674 // no longer be replaceable. 705 // no longer be replaceable.
675 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), 706 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(),
676 t_url->url()->url()); 707 t_url->url()->url());
677 708
678 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"), 709 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"),
679 GURL("http://foo.com"), NULL)); 710 GURL("http://foo.com"), NULL));
680 } 711 }
681 712
682 TEST_F(TemplateURLServiceTest, HasDefaultSearchProvider) { 713 TEST_F(TemplateURLServiceTest, HasDefaultSearchProvider) {
683 // We should have a default search provider even if we haven't loaded. 714 // We should have a default search provider even if we haven't loaded.
684 ASSERT_TRUE(model()->GetDefaultSearchProvider()); 715 ASSERT_TRUE(model()->GetDefaultSearchProvider());
685 716
686 // Now force the model to load and make sure we still have a default. 717 // Now force the model to load and make sure we still have a default.
687 VerifyLoad(); 718 VerifyLoad();
688 719
689 ASSERT_TRUE(model()->GetDefaultSearchProvider()); 720 ASSERT_TRUE(model()->GetDefaultSearchProvider());
690 } 721 }
691 722
692 TEST_F(TemplateURLServiceTest, DefaultSearchProviderLoadedFromPrefs) { 723 TEST_F(TemplateURLServiceTest, DefaultSearchProviderLoadedFromPrefs) {
693 VerifyLoad(); 724 VerifyLoad();
694 725
695 TemplateURL* template_url = new TemplateURL(); 726 TemplateURL* template_url = new TemplateURL();
696 template_url->SetURL("http://url", 0, 0); 727 template_url->SetURL("http://url", 0, 0);
697 template_url->SetSuggestionsURL("http://url2", 0, 0); 728 template_url->SetSuggestionsURL("http://url2", 0, 0);
698 template_url->SetInstantURL("http://instant", 0, 0); 729 template_url->SetInstantURL("http://instant", 0, 0);
699 template_url->set_short_name(ASCIIToUTF16("a")); 730 template_url->set_short_name(ASCIIToUTF16("a"));
700 template_url->set_safe_for_autoreplace(true); 731 template_url->set_safe_for_autoreplace(true);
701 template_url->set_date_created(Time::FromTimeT(100)); 732 template_url->set_date_created(Time::FromTimeT(100));
733 template_url->set_last_modified(Time::FromTimeT(100));
702 734
703 model()->Add(template_url); 735 model()->Add(template_url);
704 736
705 const TemplateURLID id = template_url->id(); 737 const TemplateURLID id = template_url->id();
706 738
707 model()->SetDefaultSearchProvider(template_url); 739 model()->SetDefaultSearchProvider(template_url);
708 740
709 BlockTillServiceProcessesRequests(); 741 BlockTillServiceProcessesRequests();
710 742
711 TemplateURL first_default_search_provider = *template_url; 743 TemplateURL first_default_search_provider = *template_url;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 { "http://foo/foo?q=xx", string16() }, 824 { "http://foo/foo?q=xx", string16() },
793 { "http://x/bar?q=xx", string16() }, 825 { "http://x/bar?q=xx", string16() },
794 { "http://x/foo?y=xx", string16() }, 826 { "http://x/foo?y=xx", string16() },
795 { "http://x/foo?q=xx", ASCIIToUTF16("xx") }, 827 { "http://x/foo?q=xx", ASCIIToUTF16("xx") },
796 { "http://x/foo?a=b&q=xx", ASCIIToUTF16("xx") }, 828 { "http://x/foo?a=b&q=xx", ASCIIToUTF16("xx") },
797 { "http://x/foo?q=b&q=xx", string16() }, 829 { "http://x/foo?q=b&q=xx", string16() },
798 }; 830 };
799 831
800 ChangeModelToLoadState(); 832 ChangeModelToLoadState();
801 AddKeywordWithDate("x", false, "http://x/foo?q={searchTerms}", 833 AddKeywordWithDate("x", false, "http://x/foo?q={searchTerms}",
802 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name", false, Time()); 834 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name", false, Time(),
835 Time());
803 836
804 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { 837 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
805 history::URLVisitedDetails details; 838 history::URLVisitedDetails details;
806 details.row = history::URLRow(GURL(data[i].url)); 839 details.row = history::URLRow(GURL(data[i].url));
807 details.transition = 0; 840 details.transition = 0;
808 model()->UpdateKeywordSearchTermsForURL(details); 841 model()->UpdateKeywordSearchTermsForURL(details);
809 EXPECT_EQ(data[i].term, GetAndClearSearchTerm()); 842 EXPECT_EQ(data[i].term, GetAndClearSearchTerm());
810 } 843 }
811 } 844 }
812 845
813 TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) { 846 TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) {
814 struct TestData { 847 struct TestData {
815 const std::string url; 848 const std::string url;
816 } data[] = { 849 } data[] = {
817 { "http://foo/" }, 850 { "http://foo/" },
818 { "http://x/bar?q=xx" }, 851 { "http://x/bar?q=xx" },
819 { "http://x/foo?y=xx" }, 852 { "http://x/foo?y=xx" },
820 }; 853 };
821 854
822 ChangeModelToLoadState(); 855 ChangeModelToLoadState();
823 AddKeywordWithDate("x", false, "http://x/foo", "http://sugg1", 856 AddKeywordWithDate("x", false, "http://x/foo", "http://sugg1",
824 "http://icon1", "UTF-8;UTF-16", "name", false, Time()); 857 "http://icon1", "UTF-8;UTF-16", "name", false, Time(), Time());
825 858
826 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { 859 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
827 history::URLVisitedDetails details; 860 history::URLVisitedDetails details;
828 details.row = history::URLRow(GURL(data[i].url)); 861 details.row = history::URLRow(GURL(data[i].url));
829 details.transition = 0; 862 details.transition = 0;
830 model()->UpdateKeywordSearchTermsForURL(details); 863 model()->UpdateKeywordSearchTermsForURL(details);
831 ASSERT_EQ(string16(), GetAndClearSearchTerm()); 864 ASSERT_EQ(string16(), GetAndClearSearchTerm());
832 } 865 }
833 } 866 }
834 867
835 TEST_F(TemplateURLServiceTest, ChangeGoogleBaseValue) { 868 TEST_F(TemplateURLServiceTest, ChangeGoogleBaseValue) {
836 // NOTE: Do not do a VerifyLoad() here as it will load the prepopulate data, 869 // NOTE: Do not do a VerifyLoad() here as it will load the prepopulate data,
837 // which also has a {google:baseURL} keyword in it, which will confuse this 870 // which also has a {google:baseURL} keyword in it, which will confuse this
838 // test. 871 // test.
839 ChangeModelToLoadState(); 872 ChangeModelToLoadState();
840 SetGoogleBaseURL("http://google.com/"); 873 SetGoogleBaseURL("http://google.com/");
841 const TemplateURL* t_url = AddKeywordWithDate("", true, 874 const TemplateURL* t_url = AddKeywordWithDate("", true,
842 "{google:baseURL}?q={searchTerms}", "http://sugg1", "http://icon1", 875 "{google:baseURL}?q={searchTerms}", "http://sugg1", "http://icon1",
843 "UTF-8;UTF-16", "name", false, Time()); 876 "UTF-8;UTF-16", "name", false, Time(), Time());
844 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.com")); 877 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.com"));
845 EXPECT_EQ("google.com", t_url->url()->GetHost()); 878 EXPECT_EQ("google.com", t_url->url()->GetHost());
846 EXPECT_EQ(ASCIIToUTF16("google.com"), t_url->keyword()); 879 EXPECT_EQ(ASCIIToUTF16("google.com"), t_url->keyword());
847 880
848 // Change the Google base url. 881 // Change the Google base url.
849 test_util_.ResetObserverCount(); 882 test_util_.ResetObserverCount();
850 SetGoogleBaseURL("http://foo.com/"); 883 SetGoogleBaseURL("http://foo.com/");
851 VerifyObserverCount(1); 884 VerifyObserverCount(1);
852 885
853 // Make sure the host->TemplateURL map was updated appropriately. 886 // Make sure the host->TemplateURL map was updated appropriately.
(...skipping 26 matching lines...) Expand all
880 // Make sure TemplateURLService generates a KEYWORD_GENERATED visit for 913 // Make sure TemplateURLService generates a KEYWORD_GENERATED visit for
881 // KEYWORD visits. 914 // KEYWORD visits.
882 TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) { 915 TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) {
883 VerifyLoad(); 916 VerifyLoad();
884 profile()->CreateHistoryService(true, false); 917 profile()->CreateHistoryService(true, false);
885 918
886 // Create a keyword. 919 // Create a keyword.
887 TemplateURL* t_url = AddKeywordWithDate( 920 TemplateURL* t_url = AddKeywordWithDate(
888 "keyword", false, "http://foo.com/foo?query={searchTerms}", 921 "keyword", false, "http://foo.com/foo?query={searchTerms}",
889 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "keyword", 922 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "keyword",
890 true, base::Time::Now()); 923 true, base::Time::Now(), base::Time::Now());
891 924
892 // Add a visit that matches the url of the keyword. 925 // Add a visit that matches the url of the keyword.
893 HistoryService* history = 926 HistoryService* history =
894 profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); 927 profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
895 history->AddPage( 928 history->AddPage(
896 GURL(t_url->url()->ReplaceSearchTerms(*t_url, ASCIIToUTF16("blah"), 0, 929 GURL(t_url->url()->ReplaceSearchTerms(*t_url, ASCIIToUTF16("blah"), 0,
897 string16())), 930 string16())),
898 NULL, 0, GURL(), PageTransition::KEYWORD, history::RedirectList(), 931 NULL, 0, GURL(), PageTransition::KEYWORD, history::RedirectList(),
899 history::SOURCE_BROWSED, false); 932 history::SOURCE_BROWSED, false);
900 933
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 // the default search as managed. Also check that we are getting the right 1128 // the default search as managed. Also check that we are getting the right
1096 // values. 1129 // values.
1097 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { 1130 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) {
1098 VerifyLoad(); 1131 VerifyLoad();
1099 const size_t initial_count = model()->GetTemplateURLs().size(); 1132 const size_t initial_count = model()->GetTemplateURLs().size();
1100 test_util_.ResetObserverCount(); 1133 test_util_.ResetObserverCount();
1101 1134
1102 // Set a regular default search provider. 1135 // Set a regular default search provider.
1103 TemplateURL* regular_default = AddKeywordWithDate("key1", false, 1136 TemplateURL* regular_default = AddKeywordWithDate("key1", false,
1104 "http://foo1", "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", 1137 "http://foo1", "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1",
1105 true, Time()); 1138 true, Time(), Time());
1106 VerifyObserverCount(1); 1139 VerifyObserverCount(1);
1107 model()->SetDefaultSearchProvider(regular_default); 1140 model()->SetDefaultSearchProvider(regular_default);
1108 // Adding the URL and setting the default search provider should have caused 1141 // Adding the URL and setting the default search provider should have caused
1109 // notifications. 1142 // notifications.
1110 VerifyObserverCount(1); 1143 VerifyObserverCount(1);
1111 EXPECT_FALSE(model()->is_default_search_managed()); 1144 EXPECT_FALSE(model()->is_default_search_managed());
1112 EXPECT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); 1145 EXPECT_EQ(1 + initial_count, model()->GetTemplateURLs().size());
1113 1146
1114 // Set a managed preference that establishes a default search provider. 1147 // Set a managed preference that establishes a default search provider.
1115 const char kName[] = "test1"; 1148 const char kName[] = "test1";
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 EXPECT_EQ(actual_managed_default->show_in_default_list(), true); 1222 EXPECT_EQ(actual_managed_default->show_in_default_list(), true);
1190 1223
1191 // Clear the model and disable the default search provider through policy. 1224 // Clear the model and disable the default search provider through policy.
1192 // Verify that there is no default search provider after loading the model. 1225 // Verify that there is no default search provider after loading the model.
1193 // This checks against regressions of http://crbug.com/67180 1226 // This checks against regressions of http://crbug.com/67180
1194 1227
1195 // First, remove the preferences, reset the model, and set a default. 1228 // First, remove the preferences, reset the model, and set a default.
1196 RemoveManagedDefaultSearchPreferences(); 1229 RemoveManagedDefaultSearchPreferences();
1197 ResetModel(true); 1230 ResetModel(true);
1198 TemplateURL* t_url = AddKeywordWithDate("key1", false, "http://foo1", 1231 TemplateURL* t_url = AddKeywordWithDate("key1", false, "http://foo1",
1199 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); 1232 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time(),
1233 Time());
1200 model()->SetDefaultSearchProvider(t_url); 1234 model()->SetDefaultSearchProvider(t_url);
1201 EXPECT_EQ(t_url, model()->GetDefaultSearchProvider()); 1235 EXPECT_EQ(t_url, model()->GetDefaultSearchProvider());
1202 1236
1203 // 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.
1204 ResetModel(false); 1238 ResetModel(false);
1205 SetManagedDefaultSearchPreferences(false, "", "", "", "", "", ""); 1239 SetManagedDefaultSearchPreferences(false, "", "", "", "", "", "");
1206 VerifyLoad(); 1240 VerifyLoad();
1207 EXPECT_TRUE(model()->is_default_search_managed()); 1241 EXPECT_TRUE(model()->is_default_search_managed());
1208 EXPECT_TRUE(model()->GetDefaultSearchProvider() == NULL); 1242 EXPECT_TRUE(model()->GetDefaultSearchProvider() == NULL);
1209 } 1243 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url_service.cc ('k') | chrome/browser/webdata/keyword_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698