OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/run_loop.h" |
10 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "base/test/mock_time_provider.h" | 14 #include "base/test/mock_time_provider.h" |
14 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "chrome/browser/extensions/extension_service_unittest.h" | 17 #include "chrome/browser/extensions/extension_service_unittest.h" |
17 #include "chrome/browser/history/history_notifications.h" | 18 #include "chrome/browser/history/history_notifications.h" |
18 #include "chrome/browser/history/history_service.h" | 19 #include "chrome/browser/history/history_service.h" |
19 #include "chrome/browser/history/history_service_factory.h" | 20 #include "chrome/browser/history/history_service_factory.h" |
(...skipping 14 matching lines...) Expand all Loading... |
34 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
35 | 36 |
36 using base::Time; | 37 using base::Time; |
37 using base::TimeDelta; | 38 using base::TimeDelta; |
38 using content::BrowserThread; | 39 using content::BrowserThread; |
39 using ::testing::Return; | 40 using ::testing::Return; |
40 using ::testing::StrictMock; | 41 using ::testing::StrictMock; |
41 | 42 |
42 namespace { | 43 namespace { |
43 | 44 |
44 // TestGenerateSearchURL ------------------------------------------------------ | |
45 | |
46 // Test the GenerateSearchURL on a thread or the main thread. | |
47 class TestGenerateSearchURL | |
48 : public base::RefCountedThreadSafe<TestGenerateSearchURL> { | |
49 public: | |
50 explicit TestGenerateSearchURL(SearchTermsData* search_terms_data); | |
51 | |
52 // Run the test cases for GenerateSearchURL. | |
53 void RunTest(); | |
54 | |
55 // Did the test pass? | |
56 bool passed() const { return passed_; } | |
57 | |
58 private: | |
59 friend class base::RefCountedThreadSafe<TestGenerateSearchURL>; | |
60 ~TestGenerateSearchURL(); | |
61 | |
62 SearchTermsData* search_terms_data_; | |
63 bool passed_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(TestGenerateSearchURL); | |
66 }; | |
67 | |
68 TestGenerateSearchURL::TestGenerateSearchURL(SearchTermsData* search_terms_data) | |
69 : search_terms_data_(search_terms_data), | |
70 passed_(false) { | |
71 } | |
72 | |
73 void TestGenerateSearchURL::RunTest() { | |
74 struct GenerateSearchURLCase { | |
75 const char* test_name; | |
76 const char* url; | |
77 const char* expected; | |
78 } generate_url_cases[] = { | |
79 { "invalid URL", "foo{searchTerms}", "" }, | |
80 { "URL with no replacements", "http://foo/", "http://foo/" }, | |
81 { "basic functionality", "http://foo/{searchTerms}", | |
82 "http://foo/blah.blah.blah.blah.blah" } | |
83 }; | |
84 | |
85 // Don't use ASSERT/EXPECT since this is run on a thread in one test | |
86 // and those macros aren't meant for threads at this time according to | |
87 // gtest documentation. | |
88 bool everything_passed = true; | |
89 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generate_url_cases); ++i) { | |
90 TemplateURLData data; | |
91 data.SetURL(generate_url_cases[i].url); | |
92 TemplateURL t_url(NULL, data); | |
93 std::string result = (search_terms_data_ ? | |
94 TemplateURLService::GenerateSearchURLUsingTermsData(&t_url, | |
95 *search_terms_data_) : | |
96 TemplateURLService::GenerateSearchURL(&t_url)).spec(); | |
97 if (result != generate_url_cases[i].expected) { | |
98 LOG(ERROR) << generate_url_cases[i].test_name << " failed. Expected " << | |
99 generate_url_cases[i].expected << " Actual " << result; | |
100 everything_passed = false; | |
101 } | |
102 } | |
103 passed_ = everything_passed; | |
104 } | |
105 | |
106 TestGenerateSearchURL::~TestGenerateSearchURL() { | |
107 } | |
108 | |
109 | |
110 // TestSearchTermsData -------------------------------------------------------- | 45 // TestSearchTermsData -------------------------------------------------------- |
111 | 46 |
112 // Simple implementation of SearchTermsData. | 47 // Simple implementation of SearchTermsData. |
113 class TestSearchTermsData : public SearchTermsData { | 48 class TestSearchTermsData : public SearchTermsData { |
114 public: | 49 public: |
115 explicit TestSearchTermsData(const char* google_base_url); | 50 explicit TestSearchTermsData(const char* google_base_url); |
116 | 51 |
117 virtual std::string GoogleBaseURLValue() const OVERRIDE; | 52 virtual std::string GoogleBaseURLValue() const OVERRIDE; |
118 | 53 |
119 private: | 54 private: |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 | 231 |
297 // Helper methods to make calling TemplateURLServiceTestUtil methods less | 232 // Helper methods to make calling TemplateURLServiceTestUtil methods less |
298 // visually noisy in the test code. | 233 // visually noisy in the test code. |
299 void VerifyObserverCount(int expected_changed_count); | 234 void VerifyObserverCount(int expected_changed_count); |
300 void VerifyObserverFired(); | 235 void VerifyObserverFired(); |
301 TemplateURLService* model() { return test_util_.model(); } | 236 TemplateURLService* model() { return test_util_.model(); } |
302 | 237 |
303 protected: | 238 protected: |
304 TemplateURLServiceTestUtil test_util_; | 239 TemplateURLServiceTestUtil test_util_; |
305 | 240 |
| 241 void TestGenerateSearchURL(SearchTermsData* search_terms_data) { |
| 242 struct GenerateSearchURLCase { |
| 243 const char* test_name; |
| 244 const char* url; |
| 245 const char* expected; |
| 246 } generate_url_cases[] = { |
| 247 { "invalid URL", "foo{searchTerms}", "" }, |
| 248 { "URL with no replacements", "http://foo/", "http://foo/" }, |
| 249 { "basic functionality", "http://foo/{searchTerms}", |
| 250 "http://foo/blah.blah.blah.blah.blah" } |
| 251 }; |
| 252 |
| 253 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generate_url_cases); ++i) { |
| 254 TemplateURLData data; |
| 255 data.SetURL(generate_url_cases[i].url); |
| 256 TemplateURL t_url(NULL, data); |
| 257 std::string result; |
| 258 if (search_terms_data) { |
| 259 result = TemplateURLService::GenerateSearchURLUsingTermsData( |
| 260 &t_url, *search_terms_data).spec(); |
| 261 } else { |
| 262 result = TemplateURLService::GenerateSearchURL(&t_url).spec(); |
| 263 } |
| 264 EXPECT_EQ(result, generate_url_cases[i].expected) |
| 265 << generate_url_cases[i].test_name << " failed. Expected " |
| 266 << generate_url_cases[i].expected << " Actual " << result; |
| 267 } |
| 268 } |
| 269 |
| 270 |
306 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTest); | 271 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTest); |
307 }; | 272 }; |
308 | 273 |
309 TemplateURLServiceTest::TemplateURLServiceTest() { | 274 TemplateURLServiceTest::TemplateURLServiceTest() { |
310 } | 275 } |
311 | 276 |
312 void TemplateURLServiceTest::SetUp() { | 277 void TemplateURLServiceTest::SetUp() { |
313 test_util_.SetUp(); | 278 test_util_.SetUp(); |
314 } | 279 } |
315 | 280 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 EXPECT_NE(prepopulated_url, original_url); | 363 EXPECT_NE(prepopulated_url, original_url); |
399 | 364 |
400 // Then add it to the model and save it all. | 365 // Then add it to the model and save it all. |
401 test_util_.ChangeModelToLoadState(); | 366 test_util_.ChangeModelToLoadState(); |
402 model()->Add(t_url); | 367 model()->Add(t_url); |
403 const TemplateURL* keyword_url = | 368 const TemplateURL* keyword_url = |
404 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 369 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
405 ASSERT_TRUE(keyword_url != NULL); | 370 ASSERT_TRUE(keyword_url != NULL); |
406 EXPECT_EQ(t_url, keyword_url); | 371 EXPECT_EQ(t_url, keyword_url); |
407 EXPECT_EQ(original_url, keyword_url->url_ref().DisplayURL()); | 372 EXPECT_EQ(original_url, keyword_url->url_ref().DisplayURL()); |
408 test_util_.BlockTillServiceProcessesRequests(); | 373 base::RunLoop().RunUntilIdle(); |
409 | 374 |
410 // Now reload the model and verify that the merge updates the url, and | 375 // Now reload the model and verify that the merge updates the url, and |
411 // preserves the sync GUID. | 376 // preserves the sync GUID. |
412 test_util_.ResetModel(true); | 377 test_util_.ResetModel(true); |
413 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 378 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
414 ASSERT_TRUE(keyword_url != NULL); | 379 ASSERT_TRUE(keyword_url != NULL); |
415 EXPECT_EQ(prepopulated_url, keyword_url->url_ref().DisplayURL()); | 380 EXPECT_EQ(prepopulated_url, keyword_url->url_ref().DisplayURL()); |
416 EXPECT_EQ(original_guid, keyword_url->sync_guid()); | 381 EXPECT_EQ(original_guid, keyword_url->sync_guid()); |
417 | 382 |
418 // Wait for any saves to finish. | 383 // Wait for any saves to finish. |
419 test_util_.BlockTillServiceProcessesRequests(); | 384 base::RunLoop().RunUntilIdle(); |
420 | 385 |
421 // Reload the model to verify that change was saved correctly. | 386 // Reload the model to verify that change was saved correctly. |
422 test_util_.ResetModel(true); | 387 test_util_.ResetModel(true); |
423 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 388 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
424 ASSERT_TRUE(keyword_url != NULL); | 389 ASSERT_TRUE(keyword_url != NULL); |
425 EXPECT_EQ(prepopulated_url, keyword_url->url_ref().DisplayURL()); | 390 EXPECT_EQ(prepopulated_url, keyword_url->url_ref().DisplayURL()); |
426 EXPECT_EQ(original_guid, keyword_url->sync_guid()); | 391 EXPECT_EQ(original_guid, keyword_url->sync_guid()); |
427 } | 392 } |
428 | 393 |
429 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { | 394 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { |
(...skipping 25 matching lines...) Expand all Loading... |
455 data.favicon_url = GURL("http://favicon.url"); | 420 data.favicon_url = GURL("http://favicon.url"); |
456 data.safe_for_autoreplace = true; | 421 data.safe_for_autoreplace = true; |
457 data.date_created = Time::FromTimeT(100); | 422 data.date_created = Time::FromTimeT(100); |
458 data.last_modified = Time::FromTimeT(100); | 423 data.last_modified = Time::FromTimeT(100); |
459 data.sync_guid = "00000000-0000-0000-0000-000000000001"; | 424 data.sync_guid = "00000000-0000-0000-0000-000000000001"; |
460 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); | 425 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); |
461 model()->Add(t_url); | 426 model()->Add(t_url); |
462 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), | 427 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), |
463 NULL)); | 428 NULL)); |
464 VerifyObserverCount(1); | 429 VerifyObserverCount(1); |
465 test_util_.BlockTillServiceProcessesRequests(); | 430 base::RunLoop().RunUntilIdle(); |
466 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 431 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
467 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword())); | 432 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword())); |
468 // We need to make a second copy as the model takes ownership of |t_url| and | 433 // We need to make a second copy as the model takes ownership of |t_url| and |
469 // will delete it. We have to do this after calling Add() since that gives | 434 // will delete it. We have to do this after calling Add() since that gives |
470 // |t_url| its ID. | 435 // |t_url| its ID. |
471 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), | 436 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), |
472 t_url->data())); | 437 t_url->data())); |
473 | 438 |
474 // Reload the model to verify it was actually saved to the database. | 439 // Reload the model to verify it was actually saved to the database. |
475 test_util_.ResetModel(true); | 440 test_util_.ResetModel(true); |
(...skipping 16 matching lines...) Expand all Loading... |
492 model()->ResetTemplateURL(loaded_url, ASCIIToUTF16("a"), ASCIIToUTF16("b"), | 457 model()->ResetTemplateURL(loaded_url, ASCIIToUTF16("a"), ASCIIToUTF16("b"), |
493 "c"); | 458 "c"); |
494 ASSERT_EQ(ASCIIToUTF16("a"), loaded_url->short_name()); | 459 ASSERT_EQ(ASCIIToUTF16("a"), loaded_url->short_name()); |
495 ASSERT_EQ(ASCIIToUTF16("b"), loaded_url->keyword()); | 460 ASSERT_EQ(ASCIIToUTF16("b"), loaded_url->keyword()); |
496 ASSERT_EQ("c", loaded_url->url()); | 461 ASSERT_EQ("c", loaded_url->url()); |
497 ASSERT_FALSE(loaded_url->safe_for_autoreplace()); | 462 ASSERT_FALSE(loaded_url->safe_for_autoreplace()); |
498 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), | 463 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), |
499 NULL)); | 464 NULL)); |
500 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL)); | 465 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL)); |
501 cloned_url.reset(new TemplateURL(loaded_url->profile(), loaded_url->data())); | 466 cloned_url.reset(new TemplateURL(loaded_url->profile(), loaded_url->data())); |
502 test_util_.BlockTillServiceProcessesRequests(); | 467 base::RunLoop().RunUntilIdle(); |
503 test_util_.ResetModel(true); | 468 test_util_.ResetModel(true); |
504 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 469 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
505 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")); | 470 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")); |
506 ASSERT_TRUE(loaded_url != NULL); | 471 ASSERT_TRUE(loaded_url != NULL); |
507 AssertEquals(*cloned_url, *loaded_url); | 472 AssertEquals(*cloned_url, *loaded_url); |
508 // We changed a TemplateURL in the service, so ensure that the time was | 473 // We changed a TemplateURL in the service, so ensure that the time was |
509 // updated. | 474 // updated. |
510 ASSERT_EQ(base::Time::FromDoubleT(1337), loaded_url->last_modified()); | 475 ASSERT_EQ(base::Time::FromDoubleT(1337), loaded_url->last_modified()); |
511 | 476 |
512 // Remove an element and verify it succeeded. | 477 // Remove an element and verify it succeeded. |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 TemplateURLService::GenerateKeyword(GURL("http://www.foo"))); | 634 TemplateURLService::GenerateKeyword(GURL("http://www.foo"))); |
670 // Make sure we don't get a trailing '/'. | 635 // Make sure we don't get a trailing '/'. |
671 ASSERT_EQ(ASCIIToUTF16("blah"), | 636 ASSERT_EQ(ASCIIToUTF16("blah"), |
672 TemplateURLService::GenerateKeyword(GURL("http://blah/"))); | 637 TemplateURLService::GenerateKeyword(GURL("http://blah/"))); |
673 // Don't generate the empty string. | 638 // Don't generate the empty string. |
674 ASSERT_EQ(ASCIIToUTF16("www"), | 639 ASSERT_EQ(ASCIIToUTF16("www"), |
675 TemplateURLService::GenerateKeyword(GURL("http://www."))); | 640 TemplateURLService::GenerateKeyword(GURL("http://www."))); |
676 } | 641 } |
677 | 642 |
678 TEST_F(TemplateURLServiceTest, GenerateSearchURL) { | 643 TEST_F(TemplateURLServiceTest, GenerateSearchURL) { |
679 scoped_refptr<TestGenerateSearchURL> test_generate_search_url( | 644 TestGenerateSearchURL(NULL); |
680 new TestGenerateSearchURL(NULL)); | |
681 test_generate_search_url->RunTest(); | |
682 EXPECT_TRUE(test_generate_search_url->passed()); | |
683 } | 645 } |
684 | 646 |
685 TEST_F(TemplateURLServiceTest, GenerateSearchURLUsingTermsData) { | 647 TEST_F(TemplateURLServiceTest, GenerateSearchURLUsingTermsData) { |
686 // Run the test for GenerateSearchURLUsingTermsData on the "IO" thread and | 648 // Run the test for GenerateSearchURLUsingTermsData on the "IO" thread and |
687 // wait for it to finish. | 649 // wait for it to finish. |
688 TestSearchTermsData search_terms_data("http://google.com/"); | 650 TestSearchTermsData search_terms_data("http://google.com/"); |
689 scoped_refptr<TestGenerateSearchURL> test_generate_search_url( | 651 TestGenerateSearchURL(&search_terms_data); |
690 new TestGenerateSearchURL(&search_terms_data)); | |
691 | |
692 test_util_.StartIOThread(); | |
693 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)->PostTask( | |
694 FROM_HERE, base::Bind(&TestGenerateSearchURL::RunTest, | |
695 test_generate_search_url.get())); | |
696 TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests(); | |
697 EXPECT_TRUE(test_generate_search_url->passed()); | |
698 } | 652 } |
699 | 653 |
700 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) { | 654 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) { |
701 Time now = Time::Now(); | 655 Time now = Time::Now(); |
702 TimeDelta one_day = TimeDelta::FromDays(1); | 656 TimeDelta one_day = TimeDelta::FromDays(1); |
703 Time month_ago = now - TimeDelta::FromDays(30); | 657 Time month_ago = now - TimeDelta::FromDays(30); |
704 | 658 |
705 // Nothing has been added. | 659 // Nothing has been added. |
706 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); | 660 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); |
707 | 661 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 data.short_name = ASCIIToUTF16("google"); | 773 data.short_name = ASCIIToUTF16("google"); |
820 data.SetKeyword(ASCIIToUTF16("keyword")); | 774 data.SetKeyword(ASCIIToUTF16("keyword")); |
821 data.SetURL("http://www.google.com/foo/bar"); | 775 data.SetURL("http://www.google.com/foo/bar"); |
822 data.favicon_url = GURL("http://favicon.url"); | 776 data.favicon_url = GURL("http://favicon.url"); |
823 data.date_created = Time::FromTimeT(100); | 777 data.date_created = Time::FromTimeT(100); |
824 data.last_modified = Time::FromTimeT(100); | 778 data.last_modified = Time::FromTimeT(100); |
825 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); | 779 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); |
826 model()->Add(t_url); | 780 model()->Add(t_url); |
827 | 781 |
828 VerifyObserverCount(1); | 782 VerifyObserverCount(1); |
829 test_util_.BlockTillServiceProcessesRequests(); | 783 base::RunLoop().RunUntilIdle(); |
830 | 784 |
831 StrictMock<base::MockTimeProvider> mock_time; | 785 StrictMock<base::MockTimeProvider> mock_time; |
832 model()->set_time_provider(&base::MockTimeProvider::StaticNow); | 786 model()->set_time_provider(&base::MockTimeProvider::StaticNow); |
833 EXPECT_CALL(mock_time, Now()).WillOnce(Return(base::Time::FromDoubleT(1337))); | 787 EXPECT_CALL(mock_time, Now()).WillOnce(Return(base::Time::FromDoubleT(1337))); |
834 | 788 |
835 // Reset the short name, keyword, url and make sure it takes. | 789 // Reset the short name, keyword, url and make sure it takes. |
836 const string16 new_short_name(ASCIIToUTF16("a")); | 790 const string16 new_short_name(ASCIIToUTF16("a")); |
837 const string16 new_keyword(ASCIIToUTF16("b")); | 791 const string16 new_keyword(ASCIIToUTF16("b")); |
838 const std::string new_url("c"); | 792 const std::string new_url("c"); |
839 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); | 793 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); |
(...skipping 27 matching lines...) Expand all Loading... |
867 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); | 821 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); |
868 test_util_.ResetObserverCount(); | 822 test_util_.ResetObserverCount(); |
869 | 823 |
870 model()->SetDefaultSearchProvider(t_url); | 824 model()->SetDefaultSearchProvider(t_url); |
871 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); | 825 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); |
872 ASSERT_TRUE(t_url->safe_for_autoreplace()); | 826 ASSERT_TRUE(t_url->safe_for_autoreplace()); |
873 ASSERT_TRUE(t_url->show_in_default_list()); | 827 ASSERT_TRUE(t_url->show_in_default_list()); |
874 | 828 |
875 // Setting the default search provider should have caused notification. | 829 // Setting the default search provider should have caused notification. |
876 VerifyObserverCount(1); | 830 VerifyObserverCount(1); |
877 test_util_.BlockTillServiceProcessesRequests(); | 831 base::RunLoop().RunUntilIdle(); |
878 | 832 |
879 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), | 833 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), |
880 t_url->data())); | 834 t_url->data())); |
881 | 835 |
882 // Make sure when we reload we get a default search provider. | 836 // Make sure when we reload we get a default search provider. |
883 test_util_.ResetModel(true); | 837 test_util_.ResetModel(true); |
884 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 838 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
885 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 839 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
886 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); | 840 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); |
887 } | 841 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 data.SetURL("http://url/{searchTerms}"); | 900 data.SetURL("http://url/{searchTerms}"); |
947 data.suggestions_url = "http://url2"; | 901 data.suggestions_url = "http://url2"; |
948 data.instant_url = "http://instant"; | 902 data.instant_url = "http://instant"; |
949 data.date_created = Time::FromTimeT(100); | 903 data.date_created = Time::FromTimeT(100); |
950 data.last_modified = Time::FromTimeT(100); | 904 data.last_modified = Time::FromTimeT(100); |
951 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); | 905 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); |
952 model()->Add(t_url); | 906 model()->Add(t_url); |
953 const TemplateURLID id = t_url->id(); | 907 const TemplateURLID id = t_url->id(); |
954 | 908 |
955 model()->SetDefaultSearchProvider(t_url); | 909 model()->SetDefaultSearchProvider(t_url); |
956 test_util_.BlockTillServiceProcessesRequests(); | 910 base::RunLoop().RunUntilIdle(); |
957 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), | 911 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), |
958 t_url->data())); | 912 t_url->data())); |
959 | 913 |
960 // Reset the model and don't load it. The template url we set as the default | 914 // Reset the model and don't load it. The template url we set as the default |
961 // should be pulled from prefs now. | 915 // should be pulled from prefs now. |
962 test_util_.ResetModel(false); | 916 test_util_.ResetModel(false); |
963 | 917 |
964 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs | 918 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs |
965 // value are persisted to prefs. | 919 // value are persisted to prefs. |
966 const TemplateURL* default_turl = model()->GetDefaultSearchProvider(); | 920 const TemplateURL* default_turl = model()->GetDefaultSearchProvider(); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1236 // Make sure that the load routine deletes prepopulated engines that no longer | 1190 // Make sure that the load routine deletes prepopulated engines that no longer |
1237 // exist in the prepopulate data. | 1191 // exist in the prepopulate data. |
1238 TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) { | 1192 TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) { |
1239 // Create a preloaded template url. Add it to a loaded model and wait for the | 1193 // Create a preloaded template url. Add it to a loaded model and wait for the |
1240 // saves to finish. | 1194 // saves to finish. |
1241 TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999); | 1195 TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999); |
1242 test_util_.ChangeModelToLoadState(); | 1196 test_util_.ChangeModelToLoadState(); |
1243 model()->Add(t_url); | 1197 model()->Add(t_url); |
1244 ASSERT_TRUE( | 1198 ASSERT_TRUE( |
1245 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); | 1199 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); |
1246 test_util_.BlockTillServiceProcessesRequests(); | 1200 base::RunLoop().RunUntilIdle(); |
1247 | 1201 |
1248 // Ensure that merging clears this engine. | 1202 // Ensure that merging clears this engine. |
1249 test_util_.ResetModel(true); | 1203 test_util_.ResetModel(true); |
1250 ASSERT_TRUE( | 1204 ASSERT_TRUE( |
1251 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); | 1205 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); |
1252 | 1206 |
1253 // Wait for any saves to finish. | 1207 // Wait for any saves to finish. |
1254 test_util_.BlockTillServiceProcessesRequests(); | 1208 base::RunLoop().RunUntilIdle(); |
1255 | 1209 |
1256 // Reload the model to verify that the database was updated as a result of the | 1210 // Reload the model to verify that the database was updated as a result of the |
1257 // merge. | 1211 // merge. |
1258 test_util_.ResetModel(true); | 1212 test_util_.ResetModel(true); |
1259 ASSERT_TRUE( | 1213 ASSERT_TRUE( |
1260 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); | 1214 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); |
1261 } | 1215 } |
1262 | 1216 |
1263 // Make sure that load routine doesn't delete prepopulated engines that no | 1217 // Make sure that load routine doesn't delete prepopulated engines that no |
1264 // longer exist in the prepopulate data if it has been modified by the user. | 1218 // longer exist in the prepopulate data if it has been modified by the user. |
1265 TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) { | 1219 TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) { |
1266 // Create a preloaded template url and add it to a loaded model. | 1220 // Create a preloaded template url and add it to a loaded model. |
1267 TemplateURL* t_url = CreatePreloadedTemplateURL(false, 999999); | 1221 TemplateURL* t_url = CreatePreloadedTemplateURL(false, 999999); |
1268 test_util_.ChangeModelToLoadState(); | 1222 test_util_.ChangeModelToLoadState(); |
1269 model()->Add(t_url); | 1223 model()->Add(t_url); |
1270 | 1224 |
1271 // Do the copy after t_url is added so that the id is set. | 1225 // Do the copy after t_url is added so that the id is set. |
1272 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), | 1226 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), |
1273 t_url->data())); | 1227 t_url->data())); |
1274 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); | 1228 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); |
1275 | 1229 |
1276 // Wait for any saves to finish. | 1230 // Wait for any saves to finish. |
1277 test_util_.BlockTillServiceProcessesRequests(); | 1231 base::RunLoop().RunUntilIdle(); |
1278 | 1232 |
1279 // Ensure that merging won't clear it if the user has edited it. | 1233 // Ensure that merging won't clear it if the user has edited it. |
1280 test_util_.ResetModel(true); | 1234 test_util_.ResetModel(true); |
1281 const TemplateURL* url_for_unittest = | 1235 const TemplateURL* url_for_unittest = |
1282 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 1236 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
1283 ASSERT_TRUE(url_for_unittest != NULL); | 1237 ASSERT_TRUE(url_for_unittest != NULL); |
1284 AssertEquals(*cloned_url, *url_for_unittest); | 1238 AssertEquals(*cloned_url, *url_for_unittest); |
1285 | 1239 |
1286 // Wait for any saves to finish. | 1240 // Wait for any saves to finish. |
1287 test_util_.BlockTillServiceProcessesRequests(); | 1241 base::RunLoop().RunUntilIdle(); |
1288 | 1242 |
1289 // Reload the model to verify that save/reload retains the item. | 1243 // Reload the model to verify that save/reload retains the item. |
1290 test_util_.ResetModel(true); | 1244 test_util_.ResetModel(true); |
1291 ASSERT_TRUE( | 1245 ASSERT_TRUE( |
1292 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); | 1246 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); |
1293 } | 1247 } |
1294 | 1248 |
1295 // Make sure that load routine doesn't delete | 1249 // Make sure that load routine doesn't delete |
1296 // prepopulated engines that no longer exist in the prepopulate data if | 1250 // prepopulated engines that no longer exist in the prepopulate data if |
1297 // it has been modified by the user. | 1251 // it has been modified by the user. |
1298 TEST_F(TemplateURLServiceTest, LoadSavesPrepopulatedDefaultSearchProvider) { | 1252 TEST_F(TemplateURLServiceTest, LoadSavesPrepopulatedDefaultSearchProvider) { |
1299 test_util_.VerifyLoad(); | 1253 test_util_.VerifyLoad(); |
1300 // Verify that the default search provider is set to something. | 1254 // Verify that the default search provider is set to something. |
1301 TemplateURL* default_search = model()->GetDefaultSearchProvider(); | 1255 TemplateURL* default_search = model()->GetDefaultSearchProvider(); |
1302 ASSERT_TRUE(default_search != NULL); | 1256 ASSERT_TRUE(default_search != NULL); |
1303 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(default_search->profile(), | 1257 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(default_search->profile(), |
1304 default_search->data())); | 1258 default_search->data())); |
1305 | 1259 |
1306 // Wait for any saves to finish. | 1260 // Wait for any saves to finish. |
1307 test_util_.BlockTillServiceProcessesRequests(); | 1261 base::RunLoop().RunUntilIdle(); |
1308 | 1262 |
1309 // Reload the model and check that the default search provider | 1263 // Reload the model and check that the default search provider |
1310 // was properly saved. | 1264 // was properly saved. |
1311 test_util_.ResetModel(true); | 1265 test_util_.ResetModel(true); |
1312 default_search = model()->GetDefaultSearchProvider(); | 1266 default_search = model()->GetDefaultSearchProvider(); |
1313 ASSERT_TRUE(default_search != NULL); | 1267 ASSERT_TRUE(default_search != NULL); |
1314 AssertEquals(*cloned_url, *default_search); | 1268 AssertEquals(*cloned_url, *default_search); |
1315 } | 1269 } |
1316 | 1270 |
1317 TEST_F(TemplateURLServiceTest, FindNewDefaultSearchProvider) { | 1271 TEST_F(TemplateURLServiceTest, FindNewDefaultSearchProvider) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 test_util_.ChangeModelToLoadState(); | 1315 test_util_.ChangeModelToLoadState(); |
1362 model()->Add(t_url); | 1316 model()->Add(t_url); |
1363 model()->SetDefaultSearchProvider(t_url); | 1317 model()->SetDefaultSearchProvider(t_url); |
1364 // Do the copy after t_url is added and set as default so that its | 1318 // Do the copy after t_url is added and set as default so that its |
1365 // internal state is correct. | 1319 // internal state is correct. |
1366 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), | 1320 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), |
1367 t_url->data())); | 1321 t_url->data())); |
1368 | 1322 |
1369 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); | 1323 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); |
1370 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); | 1324 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); |
1371 test_util_.BlockTillServiceProcessesRequests(); | 1325 base::RunLoop().RunUntilIdle(); |
1372 | 1326 |
1373 // Ensure that merging won't clear the prepopulated template url | 1327 // Ensure that merging won't clear the prepopulated template url |
1374 // which is no longer present if it's the default engine. | 1328 // which is no longer present if it's the default engine. |
1375 test_util_.ResetModel(true); | 1329 test_util_.ResetModel(true); |
1376 { | 1330 { |
1377 const TemplateURL* keyword_url = | 1331 const TemplateURL* keyword_url = |
1378 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 1332 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
1379 ASSERT_TRUE(keyword_url != NULL); | 1333 ASSERT_TRUE(keyword_url != NULL); |
1380 AssertEquals(*cloned_url, *keyword_url); | 1334 AssertEquals(*cloned_url, *keyword_url); |
1381 ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); | 1335 ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); |
1382 } | 1336 } |
1383 | 1337 |
1384 // Wait for any saves to finish. | 1338 // Wait for any saves to finish. |
1385 test_util_.BlockTillServiceProcessesRequests(); | 1339 base::RunLoop().RunUntilIdle(); |
1386 | 1340 |
1387 // Reload the model to verify that the update was saved. | 1341 // Reload the model to verify that the update was saved. |
1388 test_util_.ResetModel(true); | 1342 test_util_.ResetModel(true); |
1389 { | 1343 { |
1390 const TemplateURL* keyword_url = | 1344 const TemplateURL* keyword_url = |
1391 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 1345 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
1392 ASSERT_TRUE(keyword_url != NULL); | 1346 ASSERT_TRUE(keyword_url != NULL); |
1393 AssertEquals(*cloned_url, *keyword_url); | 1347 AssertEquals(*cloned_url, *keyword_url); |
1394 ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); | 1348 ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); |
1395 } | 1349 } |
(...skipping 15 matching lines...) Expand all Loading... |
1411 // missing and not managed. | 1365 // missing and not managed. |
1412 TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) { | 1366 TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) { |
1413 // Force the model to load and make sure we have a default search provider. | 1367 // Force the model to load and make sure we have a default search provider. |
1414 test_util_.VerifyLoad(); | 1368 test_util_.VerifyLoad(); |
1415 TemplateURL* old_default = model()->GetDefaultSearchProvider(); | 1369 TemplateURL* old_default = model()->GetDefaultSearchProvider(); |
1416 EXPECT_TRUE(old_default); | 1370 EXPECT_TRUE(old_default); |
1417 | 1371 |
1418 // Now remove it. | 1372 // Now remove it. |
1419 model()->SetDefaultSearchProvider(NULL); | 1373 model()->SetDefaultSearchProvider(NULL); |
1420 model()->Remove(old_default); | 1374 model()->Remove(old_default); |
1421 test_util_.BlockTillServiceProcessesRequests(); | 1375 base::RunLoop().RunUntilIdle(); |
1422 | 1376 |
1423 EXPECT_FALSE(model()->GetDefaultSearchProvider()); | 1377 EXPECT_FALSE(model()->GetDefaultSearchProvider()); |
1424 | 1378 |
1425 // Reset the model and load it. There should be a default search provider. | 1379 // Reset the model and load it. There should be a default search provider. |
1426 test_util_.ResetModel(true); | 1380 test_util_.ResetModel(true); |
1427 | 1381 |
1428 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 1382 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
1429 EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement()); | 1383 EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement()); |
1430 | 1384 |
1431 // Make default search provider unusable (no search terms). | 1385 // Make default search provider unusable (no search terms). |
1432 model()->ResetTemplateURL(model()->GetDefaultSearchProvider(), | 1386 model()->ResetTemplateURL(model()->GetDefaultSearchProvider(), |
1433 ASCIIToUTF16("test"), ASCIIToUTF16("test"), | 1387 ASCIIToUTF16("test"), ASCIIToUTF16("test"), |
1434 "http://example.com/"); | 1388 "http://example.com/"); |
1435 test_util_.BlockTillServiceProcessesRequests(); | 1389 base::RunLoop().RunUntilIdle(); |
1436 | 1390 |
1437 // Reset the model and load it. There should be a usable default search | 1391 // Reset the model and load it. There should be a usable default search |
1438 // provider. | 1392 // provider. |
1439 test_util_.ResetModel(true); | 1393 test_util_.ResetModel(true); |
1440 | 1394 |
1441 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 1395 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
1442 EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement()); | 1396 EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement()); |
1443 } | 1397 } |
1444 | 1398 |
1445 // Simulates failing to load the webdb and makes sure the default search | 1399 // Simulates failing to load the webdb and makes sure the default search |
1446 // provider is valid. | 1400 // provider is valid. |
1447 TEST_F(TemplateURLServiceTest, FailedInit) { | 1401 TEST_F(TemplateURLServiceTest, FailedInit) { |
1448 test_util_.VerifyLoad(); | 1402 test_util_.VerifyLoad(); |
1449 | 1403 |
1450 test_util_.ClearModel(); | 1404 test_util_.ClearModel(); |
1451 scoped_refptr<WebDataService> web_service = | 1405 scoped_refptr<WebDataService> web_service = |
1452 WebDataService::FromBrowserContext(test_util_.profile()); | 1406 WebDataService::FromBrowserContext(test_util_.profile()); |
1453 web_service->ShutdownDatabase(); | 1407 web_service->ShutdownDatabase(); |
1454 | 1408 |
1455 test_util_.ResetModel(false); | 1409 test_util_.ResetModel(false); |
1456 model()->Load(); | 1410 model()->Load(); |
1457 test_util_.BlockTillServiceProcessesRequests(); | 1411 base::RunLoop().RunUntilIdle(); |
1458 | 1412 |
1459 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 1413 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
1460 } | 1414 } |
1461 | 1415 |
1462 // Verifies that if the default search URL preference is managed, we report | 1416 // Verifies that if the default search URL preference is managed, we report |
1463 // the default search as managed. Also check that we are getting the right | 1417 // the default search as managed. Also check that we are getting the right |
1464 // values. | 1418 // values. |
1465 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { | 1419 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { |
1466 test_util_.VerifyLoad(); | 1420 test_util_.VerifyLoad(); |
1467 const size_t initial_count = model()->GetTemplateURLs().size(); | 1421 const size_t initial_count = model()->GetTemplateURLs().size(); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1603 | 1557 |
1604 TemplateURLData data; | 1558 TemplateURLData data; |
1605 data.short_name = ASCIIToUTF16("google"); | 1559 data.short_name = ASCIIToUTF16("google"); |
1606 data.SetKeyword(ASCIIToUTF16("keyword")); | 1560 data.SetKeyword(ASCIIToUTF16("keyword")); |
1607 data.SetURL("http://www.google.com/foo/bar"); | 1561 data.SetURL("http://www.google.com/foo/bar"); |
1608 data.sync_guid.clear(); | 1562 data.sync_guid.clear(); |
1609 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); | 1563 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); |
1610 model()->Add(t_url); | 1564 model()->Add(t_url); |
1611 | 1565 |
1612 VerifyObserverCount(1); | 1566 VerifyObserverCount(1); |
1613 test_util_.BlockTillServiceProcessesRequests(); | 1567 base::RunLoop().RunUntilIdle(); |
1614 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1568 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
1615 | 1569 |
1616 // Reload the model to verify it was actually saved to the database and | 1570 // Reload the model to verify it was actually saved to the database and |
1617 // assigned a new GUID when brought back. | 1571 // assigned a new GUID when brought back. |
1618 test_util_.ResetModel(true); | 1572 test_util_.ResetModel(true); |
1619 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1573 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
1620 const TemplateURL* loaded_url = | 1574 const TemplateURL* loaded_url = |
1621 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1575 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
1622 ASSERT_FALSE(loaded_url == NULL); | 1576 ASSERT_FALSE(loaded_url == NULL); |
1623 ASSERT_FALSE(loaded_url->sync_guid().empty()); | 1577 ASSERT_FALSE(loaded_url->sync_guid().empty()); |
(...skipping 16 matching lines...) Expand all Loading... |
1640 data.input_encodings.push_back("UTF-16"); | 1594 data.input_encodings.push_back("UTF-16"); |
1641 data.input_encodings.push_back("UTF-8"); | 1595 data.input_encodings.push_back("UTF-8"); |
1642 data.input_encodings.push_back("Big5"); | 1596 data.input_encodings.push_back("Big5"); |
1643 data.input_encodings.push_back("UTF-16"); | 1597 data.input_encodings.push_back("UTF-16"); |
1644 data.input_encodings.push_back("Big5"); | 1598 data.input_encodings.push_back("Big5"); |
1645 data.input_encodings.push_back("Windows-1252"); | 1599 data.input_encodings.push_back("Windows-1252"); |
1646 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); | 1600 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); |
1647 model()->Add(t_url); | 1601 model()->Add(t_url); |
1648 | 1602 |
1649 VerifyObserverCount(1); | 1603 VerifyObserverCount(1); |
1650 test_util_.BlockTillServiceProcessesRequests(); | 1604 base::RunLoop().RunUntilIdle(); |
1651 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1605 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
1652 const TemplateURL* loaded_url = | 1606 const TemplateURL* loaded_url = |
1653 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1607 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
1654 ASSERT_TRUE(loaded_url != NULL); | 1608 ASSERT_TRUE(loaded_url != NULL); |
1655 EXPECT_EQ(8U, loaded_url->input_encodings().size()); | 1609 EXPECT_EQ(8U, loaded_url->input_encodings().size()); |
1656 | 1610 |
1657 // Reload the model to verify it was actually saved to the database and the | 1611 // Reload the model to verify it was actually saved to the database and the |
1658 // duplicate encodings were removed. | 1612 // duplicate encodings were removed. |
1659 test_util_.ResetModel(true); | 1613 test_util_.ResetModel(true); |
1660 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1614 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
1661 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1615 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
1662 ASSERT_FALSE(loaded_url == NULL); | 1616 ASSERT_FALSE(loaded_url == NULL); |
1663 EXPECT_EQ(4U, loaded_url->input_encodings().size()); | 1617 EXPECT_EQ(4U, loaded_url->input_encodings().size()); |
1664 } | 1618 } |
OLD | NEW |