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

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: Initial upload. 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/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()->InstallTimeProvider(&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);
456
457 model()->UninstallTimeProvider();
437 } 458 }
438 459
439 TEST_F(TemplateURLServiceTest, GenerateKeyword) { 460 TEST_F(TemplateURLServiceTest, GenerateKeyword) {
440 ASSERT_EQ(string16(), TemplateURLService::GenerateKeyword(GURL(), true)); 461 ASSERT_EQ(string16(), TemplateURLService::GenerateKeyword(GURL(), true));
441 // Shouldn't generate keywords for https. 462 // Shouldn't generate keywords for https.
442 ASSERT_EQ(string16(), 463 ASSERT_EQ(string16(),
443 TemplateURLService::GenerateKeyword(GURL("https://blah"), true)); 464 TemplateURLService::GenerateKeyword(GURL("https://blah"), true));
444 ASSERT_EQ(ASCIIToUTF16("foo"), 465 ASSERT_EQ(ASCIIToUTF16("foo"),
445 TemplateURLService::GenerateKeyword(GURL("http://foo"), true)); 466 TemplateURLService::GenerateKeyword(GURL("http://foo"), true));
446 // www. should be stripped. 467 // www. should be stripped.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) { 506 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) {
486 Time now = Time::Now(); 507 Time now = Time::Now();
487 TimeDelta one_day = TimeDelta::FromDays(1); 508 TimeDelta one_day = TimeDelta::FromDays(1);
488 Time month_ago = now - TimeDelta::FromDays(30); 509 Time month_ago = now - TimeDelta::FromDays(30);
489 510
490 // Nothing has been added. 511 // Nothing has been added.
491 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); 512 EXPECT_EQ(0U, model()->GetTemplateURLs().size());
492 513
493 // Create one with a 0 time. 514 // Create one with a 0 time.
494 AddKeywordWithDate("key1", false, "http://foo1", "http://suggest1", 515 AddKeywordWithDate("key1", false, "http://foo1", "http://suggest1",
495 "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); 516 "http://icon1", "UTF-8;UTF-16", "name1", true, Time(),
517 Time());
496 // Create one for now and +/- 1 day. 518 // Create one for now and +/- 1 day.
497 AddKeywordWithDate("key2", false, "http://foo2", "http://suggest2", 519 AddKeywordWithDate("key2", false, "http://foo2", "http://suggest2",
498 "http://icon2", "UTF-8;UTF-16", "name2", true, 520 "http://icon2", "UTF-8;UTF-16", "name2", true,
499 now - one_day); 521 now - one_day, Time());
500 AddKeywordWithDate("key3", false, "http://foo3", "", "", "", "name3", 522 AddKeywordWithDate("key3", false, "http://foo3", "", "", "", "name3",
501 true, now); 523 true, now, Time());
502 AddKeywordWithDate("key4", false, "http://foo4", "", "", "", "name4", 524 AddKeywordWithDate("key4", false, "http://foo4", "", "", "", "name4",
503 true, now + one_day); 525 true, now + one_day, Time());
504 // Try the other three states. 526 // Try the other three states.
505 AddKeywordWithDate("key5", false, "http://foo5", "http://suggest5", 527 AddKeywordWithDate("key5", false, "http://foo5", "http://suggest5",
506 "http://icon5", "UTF-8;UTF-16", "name5", false, now); 528 "http://icon5", "UTF-8;UTF-16", "name5", false, now,
529 Time());
507 AddKeywordWithDate("key6", false, "http://foo6", "http://suggest6", 530 AddKeywordWithDate("key6", false, "http://foo6", "http://suggest6",
508 "http://icon6", "UTF-8;UTF-16", "name6", false, 531 "http://icon6", "UTF-8;UTF-16", "name6", false,
509 month_ago); 532 month_ago, Time());
510 533
511 // We just added a few items, validate them. 534 // We just added a few items, validate them.
512 EXPECT_EQ(6U, model()->GetTemplateURLs().size()); 535 EXPECT_EQ(6U, model()->GetTemplateURLs().size());
513 536
514 // Try removing from current timestamp. This should delete the one in the 537 // Try removing from current timestamp. This should delete the one in the
515 // future and one very recent one. 538 // future and one very recent one.
516 model()->RemoveAutoGeneratedSince(now); 539 model()->RemoveAutoGeneratedSince(now);
517 EXPECT_EQ(4U, model()->GetTemplateURLs().size()); 540 EXPECT_EQ(4U, model()->GetTemplateURLs().size());
518 541
519 // Try removing from two months ago. This should only delete items that are 542 // Try removing from two months ago. This should only delete items that are
(...skipping 26 matching lines...) Expand all
546 // Add a new TemplateURL. 569 // Add a new TemplateURL.
547 VerifyLoad(); 570 VerifyLoad();
548 const size_t initial_count = model()->GetTemplateURLs().size(); 571 const size_t initial_count = model()->GetTemplateURLs().size();
549 TemplateURL* t_url = new TemplateURL(); 572 TemplateURL* t_url = new TemplateURL();
550 t_url->SetURL("http://www.google.com/foo/bar", 0, 0); 573 t_url->SetURL("http://www.google.com/foo/bar", 0, 0);
551 t_url->set_keyword(ASCIIToUTF16("keyword")); 574 t_url->set_keyword(ASCIIToUTF16("keyword"));
552 t_url->set_short_name(ASCIIToUTF16("google")); 575 t_url->set_short_name(ASCIIToUTF16("google"));
553 GURL favicon_url("http://favicon.url"); 576 GURL favicon_url("http://favicon.url");
554 t_url->SetFaviconURL(favicon_url); 577 t_url->SetFaviconURL(favicon_url);
555 t_url->set_date_created(Time::FromTimeT(100)); 578 t_url->set_date_created(Time::FromTimeT(100));
579 t_url->set_last_modified(Time::FromTimeT(100));
556 model()->Add(t_url); 580 model()->Add(t_url);
557 581
558 VerifyObserverCount(1); 582 VerifyObserverCount(1);
559 BlockTillServiceProcessesRequests(); 583 BlockTillServiceProcessesRequests();
560 584
585 StrictMock<base::MockTimeProvider> mock_time;
586 model()->InstallTimeProvider(&base::MockTimeProvider::StaticNow);
587 EXPECT_CALL(mock_time, Now())
588 .WillOnce(Return(base::Time::FromDoubleT(1337)));
589
561 // Reset the short name, keyword, url and make sure it takes. 590 // Reset the short name, keyword, url and make sure it takes.
562 const string16 new_short_name(ASCIIToUTF16("a")); 591 const string16 new_short_name(ASCIIToUTF16("a"));
563 const string16 new_keyword(ASCIIToUTF16("b")); 592 const string16 new_keyword(ASCIIToUTF16("b"));
564 const std::string new_url("c"); 593 const std::string new_url("c");
565 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); 594 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url);
566 ASSERT_EQ(new_short_name, t_url->short_name()); 595 ASSERT_EQ(new_short_name, t_url->short_name());
567 ASSERT_EQ(new_keyword, t_url->keyword()); 596 ASSERT_EQ(new_keyword, t_url->keyword());
568 ASSERT_EQ(new_url, t_url->url()->url()); 597 ASSERT_EQ(new_url, t_url->url()->url());
569 598
570 // Make sure the mappings in the model were updated. 599 // Make sure the mappings in the model were updated.
571 ASSERT_TRUE(model()->GetTemplateURLForKeyword(new_keyword) == t_url); 600 ASSERT_TRUE(model()->GetTemplateURLForKeyword(new_keyword) == t_url);
572 ASSERT_TRUE( 601 ASSERT_TRUE(
573 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")) == NULL); 602 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")) == NULL);
574 603
575 TemplateURL last_url = *t_url; 604 TemplateURL last_url = *t_url;
576 605
577 // Reload the model from the database and make sure the change took. 606 // Reload the model from the database and make sure the change took.
578 ResetModel(true); 607 ResetModel(true);
579 t_url = NULL; 608 t_url = NULL;
580 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 609 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
581 const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword); 610 const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword);
582 ASSERT_TRUE(read_url); 611 ASSERT_TRUE(read_url);
583 AssertEquals(last_url, *read_url); 612 AssertEquals(last_url, *read_url);
613 ASSERT_EQ(read_url->last_modified(), base::Time::FromDoubleT(1337));
614
615 model()->UninstallTimeProvider();
584 } 616 }
585 617
586 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) { 618 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) {
587 // Add a new TemplateURL. 619 // Add a new TemplateURL.
588 VerifyLoad(); 620 VerifyLoad();
589 const size_t initial_count = model()->GetTemplateURLs().size(); 621 const size_t initial_count = model()->GetTemplateURLs().size();
590 TemplateURL* t_url = AddKeywordWithDate("key1", false, "http://foo1", 622 TemplateURL* t_url = AddKeywordWithDate("key1", false, "http://foo1",
591 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); 623 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time(),
624 Time());
592 625
593 test_util_.ResetObserverCount(); 626 test_util_.ResetObserverCount();
594 model()->SetDefaultSearchProvider(t_url); 627 model()->SetDefaultSearchProvider(t_url);
595 628
596 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); 629 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider());
597 630
598 ASSERT_TRUE(t_url->safe_for_autoreplace()); 631 ASSERT_TRUE(t_url->safe_for_autoreplace());
599 ASSERT_TRUE(t_url->show_in_default_list()); 632 ASSERT_TRUE(t_url->show_in_default_list());
600 633
601 // Setting the default search provider should have caused notification. 634 // Setting the default search provider should have caused notification.
(...skipping 11 matching lines...) Expand all
613 ASSERT_TRUE(model()->GetDefaultSearchProvider()); 646 ASSERT_TRUE(model()->GetDefaultSearchProvider());
614 AssertEquals(cloned_url, *model()->GetDefaultSearchProvider()); 647 AssertEquals(cloned_url, *model()->GetDefaultSearchProvider());
615 } 648 }
616 649
617 TEST_F(TemplateURLServiceTest, TemplateURLWithNoKeyword) { 650 TEST_F(TemplateURLServiceTest, TemplateURLWithNoKeyword) {
618 VerifyLoad(); 651 VerifyLoad();
619 652
620 const size_t initial_count = model()->GetTemplateURLs().size(); 653 const size_t initial_count = model()->GetTemplateURLs().size();
621 654
622 AddKeywordWithDate("", false, "http://foo1", "http://sugg1", 655 AddKeywordWithDate("", false, "http://foo1", "http://sugg1",
623 "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); 656 "http://icon1", "UTF-8;UTF-16", "name1", true, Time(), Time());
624 657
625 // We just added a few items, validate them. 658 // We just added a few items, validate them.
626 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 659 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
627 660
628 // Reload the model from the database and make sure we get the url back. 661 // Reload the model from the database and make sure we get the url back.
629 ResetModel(true); 662 ResetModel(true);
630 663
631 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); 664 ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size());
632 665
633 bool found_keyword = false; 666 bool found_keyword = false;
634 for (size_t i = 0; i < initial_count + 1; ++i) { 667 for (size_t i = 0; i < initial_count + 1; ++i) {
635 if (model()->GetTemplateURLs()[i]->keyword().empty()) { 668 if (model()->GetTemplateURLs()[i]->keyword().empty()) {
636 found_keyword = true; 669 found_keyword = true;
637 break; 670 break;
638 } 671 }
639 } 672 }
640 ASSERT_TRUE(found_keyword); 673 ASSERT_TRUE(found_keyword);
641 } 674 }
642 675
643 TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) { 676 TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) {
644 ChangeModelToLoadState(); 677 ChangeModelToLoadState();
645 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), GURL(), NULL)); 678 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), GURL(), NULL));
646 TemplateURL* t_url = AddKeywordWithDate("foo", false, "http://foo1", 679 TemplateURL* t_url = AddKeywordWithDate("foo", false, "http://foo1",
647 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); 680 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time(),
681 Time());
648 682
649 // Can still replace, newly added template url is marked safe to replace. 683 // Can still replace, newly added template url is marked safe to replace.
650 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), 684 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"),
651 GURL("http://foo2"), NULL)); 685 GURL("http://foo2"), NULL));
652 686
653 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should 687 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should
654 // no longer be replaceable. 688 // no longer be replaceable.
655 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), 689 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(),
656 t_url->url()->url()); 690 t_url->url()->url());
657 691
658 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), 692 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"),
659 GURL("http://foo2"), NULL)); 693 GURL("http://foo2"), NULL));
660 } 694 }
661 695
662 TEST_F(TemplateURLServiceTest, CantReplaceWithSameHosts) { 696 TEST_F(TemplateURLServiceTest, CantReplaceWithSameHosts) {
663 ChangeModelToLoadState(); 697 ChangeModelToLoadState();
664 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), 698 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"),
665 GURL("http://foo.com"), NULL)); 699 GURL("http://foo.com"), NULL));
666 TemplateURL* t_url = AddKeywordWithDate("foo", false, "http://foo.com", 700 TemplateURL* t_url = AddKeywordWithDate("foo", false, "http://foo.com",
667 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); 701 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time(),
702 Time());
668 703
669 // Can still replace, newly added template url is marked safe to replace. 704 // Can still replace, newly added template url is marked safe to replace.
670 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"), 705 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"),
671 GURL("http://foo.com"), NULL)); 706 GURL("http://foo.com"), NULL));
672 707
673 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should 708 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should
674 // no longer be replaceable. 709 // no longer be replaceable.
675 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), 710 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(),
676 t_url->url()->url()); 711 t_url->url()->url());
677 712
678 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"), 713 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"),
679 GURL("http://foo.com"), NULL)); 714 GURL("http://foo.com"), NULL));
680 } 715 }
681 716
682 TEST_F(TemplateURLServiceTest, HasDefaultSearchProvider) { 717 TEST_F(TemplateURLServiceTest, HasDefaultSearchProvider) {
683 // We should have a default search provider even if we haven't loaded. 718 // We should have a default search provider even if we haven't loaded.
684 ASSERT_TRUE(model()->GetDefaultSearchProvider()); 719 ASSERT_TRUE(model()->GetDefaultSearchProvider());
685 720
686 // Now force the model to load and make sure we still have a default. 721 // Now force the model to load and make sure we still have a default.
687 VerifyLoad(); 722 VerifyLoad();
688 723
689 ASSERT_TRUE(model()->GetDefaultSearchProvider()); 724 ASSERT_TRUE(model()->GetDefaultSearchProvider());
690 } 725 }
691 726
692 TEST_F(TemplateURLServiceTest, DefaultSearchProviderLoadedFromPrefs) { 727 TEST_F(TemplateURLServiceTest, DefaultSearchProviderLoadedFromPrefs) {
693 VerifyLoad(); 728 VerifyLoad();
694 729
695 TemplateURL* template_url = new TemplateURL(); 730 TemplateURL* template_url = new TemplateURL();
696 template_url->SetURL("http://url", 0, 0); 731 template_url->SetURL("http://url", 0, 0);
697 template_url->SetSuggestionsURL("http://url2", 0, 0); 732 template_url->SetSuggestionsURL("http://url2", 0, 0);
698 template_url->SetInstantURL("http://instant", 0, 0); 733 template_url->SetInstantURL("http://instant", 0, 0);
699 template_url->set_short_name(ASCIIToUTF16("a")); 734 template_url->set_short_name(ASCIIToUTF16("a"));
700 template_url->set_safe_for_autoreplace(true); 735 template_url->set_safe_for_autoreplace(true);
701 template_url->set_date_created(Time::FromTimeT(100)); 736 template_url->set_date_created(Time::FromTimeT(100));
737 template_url->set_last_modified(Time::FromTimeT(100));
702 738
703 model()->Add(template_url); 739 model()->Add(template_url);
704 740
705 const TemplateURLID id = template_url->id(); 741 const TemplateURLID id = template_url->id();
706 742
707 model()->SetDefaultSearchProvider(template_url); 743 model()->SetDefaultSearchProvider(template_url);
708 744
709 BlockTillServiceProcessesRequests(); 745 BlockTillServiceProcessesRequests();
710 746
711 TemplateURL first_default_search_provider = *template_url; 747 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() }, 828 { "http://foo/foo?q=xx", string16() },
793 { "http://x/bar?q=xx", string16() }, 829 { "http://x/bar?q=xx", string16() },
794 { "http://x/foo?y=xx", string16() }, 830 { "http://x/foo?y=xx", string16() },
795 { "http://x/foo?q=xx", ASCIIToUTF16("xx") }, 831 { "http://x/foo?q=xx", ASCIIToUTF16("xx") },
796 { "http://x/foo?a=b&q=xx", ASCIIToUTF16("xx") }, 832 { "http://x/foo?a=b&q=xx", ASCIIToUTF16("xx") },
797 { "http://x/foo?q=b&q=xx", string16() }, 833 { "http://x/foo?q=b&q=xx", string16() },
798 }; 834 };
799 835
800 ChangeModelToLoadState(); 836 ChangeModelToLoadState();
801 AddKeywordWithDate("x", false, "http://x/foo?q={searchTerms}", 837 AddKeywordWithDate("x", false, "http://x/foo?q={searchTerms}",
802 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name", false, Time()); 838 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name", false, Time(),
839 Time());
803 840
804 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { 841 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
805 history::URLVisitedDetails details; 842 history::URLVisitedDetails details;
806 details.row = history::URLRow(GURL(data[i].url)); 843 details.row = history::URLRow(GURL(data[i].url));
807 details.transition = 0; 844 details.transition = 0;
808 model()->UpdateKeywordSearchTermsForURL(details); 845 model()->UpdateKeywordSearchTermsForURL(details);
809 EXPECT_EQ(data[i].term, GetAndClearSearchTerm()); 846 EXPECT_EQ(data[i].term, GetAndClearSearchTerm());
810 } 847 }
811 } 848 }
812 849
813 TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) { 850 TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) {
814 struct TestData { 851 struct TestData {
815 const std::string url; 852 const std::string url;
816 } data[] = { 853 } data[] = {
817 { "http://foo/" }, 854 { "http://foo/" },
818 { "http://x/bar?q=xx" }, 855 { "http://x/bar?q=xx" },
819 { "http://x/foo?y=xx" }, 856 { "http://x/foo?y=xx" },
820 }; 857 };
821 858
822 ChangeModelToLoadState(); 859 ChangeModelToLoadState();
823 AddKeywordWithDate("x", false, "http://x/foo", "http://sugg1", 860 AddKeywordWithDate("x", false, "http://x/foo", "http://sugg1",
824 "http://icon1", "UTF-8;UTF-16", "name", false, Time()); 861 "http://icon1", "UTF-8;UTF-16", "name", false, Time(), Time());
825 862
826 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { 863 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
827 history::URLVisitedDetails details; 864 history::URLVisitedDetails details;
828 details.row = history::URLRow(GURL(data[i].url)); 865 details.row = history::URLRow(GURL(data[i].url));
829 details.transition = 0; 866 details.transition = 0;
830 model()->UpdateKeywordSearchTermsForURL(details); 867 model()->UpdateKeywordSearchTermsForURL(details);
831 ASSERT_EQ(string16(), GetAndClearSearchTerm()); 868 ASSERT_EQ(string16(), GetAndClearSearchTerm());
832 } 869 }
833 } 870 }
834 871
835 TEST_F(TemplateURLServiceTest, ChangeGoogleBaseValue) { 872 TEST_F(TemplateURLServiceTest, ChangeGoogleBaseValue) {
836 // NOTE: Do not do a VerifyLoad() here as it will load the prepopulate data, 873 // 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 874 // which also has a {google:baseURL} keyword in it, which will confuse this
838 // test. 875 // test.
839 ChangeModelToLoadState(); 876 ChangeModelToLoadState();
840 SetGoogleBaseURL("http://google.com/"); 877 SetGoogleBaseURL("http://google.com/");
841 const TemplateURL* t_url = AddKeywordWithDate("", true, 878 const TemplateURL* t_url = AddKeywordWithDate("", true,
842 "{google:baseURL}?q={searchTerms}", "http://sugg1", "http://icon1", 879 "{google:baseURL}?q={searchTerms}", "http://sugg1", "http://icon1",
843 "UTF-8;UTF-16", "name", false, Time()); 880 "UTF-8;UTF-16", "name", false, Time(), Time());
844 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.com")); 881 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.com"));
845 EXPECT_EQ("google.com", t_url->url()->GetHost()); 882 EXPECT_EQ("google.com", t_url->url()->GetHost());
846 EXPECT_EQ(ASCIIToUTF16("google.com"), t_url->keyword()); 883 EXPECT_EQ(ASCIIToUTF16("google.com"), t_url->keyword());
847 884
848 // Change the Google base url. 885 // Change the Google base url.
849 test_util_.ResetObserverCount(); 886 test_util_.ResetObserverCount();
850 SetGoogleBaseURL("http://foo.com/"); 887 SetGoogleBaseURL("http://foo.com/");
851 VerifyObserverCount(1); 888 VerifyObserverCount(1);
852 889
853 // Make sure the host->TemplateURL map was updated appropriately. 890 // 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 917 // Make sure TemplateURLService generates a KEYWORD_GENERATED visit for
881 // KEYWORD visits. 918 // KEYWORD visits.
882 TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) { 919 TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) {
883 VerifyLoad(); 920 VerifyLoad();
884 profile()->CreateHistoryService(true, false); 921 profile()->CreateHistoryService(true, false);
885 922
886 // Create a keyword. 923 // Create a keyword.
887 TemplateURL* t_url = AddKeywordWithDate( 924 TemplateURL* t_url = AddKeywordWithDate(
888 "keyword", false, "http://foo.com/foo?query={searchTerms}", 925 "keyword", false, "http://foo.com/foo?query={searchTerms}",
889 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "keyword", 926 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "keyword",
890 true, base::Time::Now()); 927 true, base::Time::Now(), base::Time::Now());
891 928
892 // Add a visit that matches the url of the keyword. 929 // Add a visit that matches the url of the keyword.
893 HistoryService* history = 930 HistoryService* history =
894 profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); 931 profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
895 history->AddPage( 932 history->AddPage(
896 GURL(t_url->url()->ReplaceSearchTerms(*t_url, ASCIIToUTF16("blah"), 0, 933 GURL(t_url->url()->ReplaceSearchTerms(*t_url, ASCIIToUTF16("blah"), 0,
897 string16())), 934 string16())),
898 NULL, 0, GURL(), PageTransition::KEYWORD, history::RedirectList(), 935 NULL, 0, GURL(), PageTransition::KEYWORD, history::RedirectList(),
899 history::SOURCE_BROWSED, false); 936 history::SOURCE_BROWSED, false);
900 937
(...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 1132 // the default search as managed. Also check that we are getting the right
1096 // values. 1133 // values.
1097 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { 1134 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) {
1098 VerifyLoad(); 1135 VerifyLoad();
1099 const size_t initial_count = model()->GetTemplateURLs().size(); 1136 const size_t initial_count = model()->GetTemplateURLs().size();
1100 test_util_.ResetObserverCount(); 1137 test_util_.ResetObserverCount();
1101 1138
1102 // Set a regular default search provider. 1139 // Set a regular default search provider.
1103 TemplateURL* regular_default = AddKeywordWithDate("key1", false, 1140 TemplateURL* regular_default = AddKeywordWithDate("key1", false,
1104 "http://foo1", "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", 1141 "http://foo1", "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1",
1105 true, Time()); 1142 true, Time(), Time());
1106 VerifyObserverCount(1); 1143 VerifyObserverCount(1);
1107 model()->SetDefaultSearchProvider(regular_default); 1144 model()->SetDefaultSearchProvider(regular_default);
1108 // Adding the URL and setting the default search provider should have caused 1145 // Adding the URL and setting the default search provider should have caused
1109 // notifications. 1146 // notifications.
1110 VerifyObserverCount(1); 1147 VerifyObserverCount(1);
1111 EXPECT_FALSE(model()->is_default_search_managed()); 1148 EXPECT_FALSE(model()->is_default_search_managed());
1112 EXPECT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); 1149 EXPECT_EQ(1 + initial_count, model()->GetTemplateURLs().size());
1113 1150
1114 // Set a managed preference that establishes a default search provider. 1151 // Set a managed preference that establishes a default search provider.
1115 const char kName[] = "test1"; 1152 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); 1226 EXPECT_EQ(actual_managed_default->show_in_default_list(), true);
1190 1227
1191 // Clear the model and disable the default search provider through policy. 1228 // Clear the model and disable the default search provider through policy.
1192 // Verify that there is no default search provider after loading the model. 1229 // Verify that there is no default search provider after loading the model.
1193 // This checks against regressions of http://crbug.com/67180 1230 // This checks against regressions of http://crbug.com/67180
1194 1231
1195 // First, remove the preferences, reset the model, and set a default. 1232 // First, remove the preferences, reset the model, and set a default.
1196 RemoveManagedDefaultSearchPreferences(); 1233 RemoveManagedDefaultSearchPreferences();
1197 ResetModel(true); 1234 ResetModel(true);
1198 TemplateURL* t_url = AddKeywordWithDate("key1", false, "http://foo1", 1235 TemplateURL* t_url = AddKeywordWithDate("key1", false, "http://foo1",
1199 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); 1236 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time(),
1237 Time());
1200 model()->SetDefaultSearchProvider(t_url); 1238 model()->SetDefaultSearchProvider(t_url);
1201 EXPECT_EQ(t_url, model()->GetDefaultSearchProvider()); 1239 EXPECT_EQ(t_url, model()->GetDefaultSearchProvider());
1202 1240
1203 // Now reset the model again but load it after setting the preferences. 1241 // Now reset the model again but load it after setting the preferences.
1204 ResetModel(false); 1242 ResetModel(false);
1205 SetManagedDefaultSearchPreferences(false, "", "", "", "", "", ""); 1243 SetManagedDefaultSearchPreferences(false, "", "", "", "", "", "");
1206 VerifyLoad(); 1244 VerifyLoad();
1207 EXPECT_TRUE(model()->is_default_search_managed()); 1245 EXPECT_TRUE(model()->is_default_search_managed());
1208 EXPECT_TRUE(model()->GetDefaultSearchProvider() == NULL); 1246 EXPECT_TRUE(model()->GetDefaultSearchProvider() == NULL);
1209 } 1247 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698