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/history/history_notifications.h" | 17 #include "chrome/browser/history/history_notifications.h" |
17 #include "chrome/browser/history/history_service.h" | 18 #include "chrome/browser/history/history_service.h" |
18 #include "chrome/browser/history/history_service_factory.h" | 19 #include "chrome/browser/history/history_service_factory.h" |
19 #include "chrome/browser/search_engines/search_host_to_urls_map.h" | 20 #include "chrome/browser/search_engines/search_host_to_urls_map.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
32 | 33 |
33 using base::Time; | 34 using base::Time; |
34 using base::TimeDelta; | 35 using base::TimeDelta; |
35 using content::BrowserThread; | 36 using content::BrowserThread; |
36 using ::testing::Return; | 37 using ::testing::Return; |
37 using ::testing::StrictMock; | 38 using ::testing::StrictMock; |
38 | 39 |
39 namespace { | 40 namespace { |
40 | 41 |
41 // TestGenerateSearchURL ------------------------------------------------------ | |
42 | |
43 // Test the GenerateSearchURL on a thread or the main thread. | |
44 class TestGenerateSearchURL | |
45 : public base::RefCountedThreadSafe<TestGenerateSearchURL> { | |
46 public: | |
47 explicit TestGenerateSearchURL(SearchTermsData* search_terms_data); | |
48 | |
49 // Run the test cases for GenerateSearchURL. | |
50 void RunTest(); | |
51 | |
52 // Did the test pass? | |
53 bool passed() const { return passed_; } | |
54 | |
55 private: | |
56 friend class base::RefCountedThreadSafe<TestGenerateSearchURL>; | |
57 ~TestGenerateSearchURL(); | |
58 | |
59 SearchTermsData* search_terms_data_; | |
60 bool passed_; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(TestGenerateSearchURL); | |
63 }; | |
64 | |
65 TestGenerateSearchURL::TestGenerateSearchURL(SearchTermsData* search_terms_data) | |
66 : search_terms_data_(search_terms_data), | |
67 passed_(false) { | |
68 } | |
69 | |
70 void TestGenerateSearchURL::RunTest() { | |
71 struct GenerateSearchURLCase { | |
72 const char* test_name; | |
73 const char* url; | |
74 const char* expected; | |
75 } generate_url_cases[] = { | |
76 { "invalid URL", "foo{searchTerms}", "" }, | |
77 { "URL with no replacements", "http://foo/", "http://foo/" }, | |
78 { "basic functionality", "http://foo/{searchTerms}", | |
79 "http://foo/blah.blah.blah.blah.blah" } | |
80 }; | |
81 | |
82 // Don't use ASSERT/EXPECT since this is run on a thread in one test | |
83 // and those macros aren't meant for threads at this time according to | |
84 // gtest documentation. | |
85 bool everything_passed = true; | |
86 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generate_url_cases); ++i) { | |
87 TemplateURLData data; | |
88 data.SetURL(generate_url_cases[i].url); | |
89 TemplateURL t_url(NULL, data); | |
90 std::string result = (search_terms_data_ ? | |
91 TemplateURLService::GenerateSearchURLUsingTermsData(&t_url, | |
92 *search_terms_data_) : | |
93 TemplateURLService::GenerateSearchURL(&t_url)).spec(); | |
94 if (result != generate_url_cases[i].expected) { | |
95 LOG(ERROR) << generate_url_cases[i].test_name << " failed. Expected " << | |
96 generate_url_cases[i].expected << " Actual " << result; | |
97 everything_passed = false; | |
98 } | |
99 } | |
100 passed_ = everything_passed; | |
101 } | |
102 | |
103 TestGenerateSearchURL::~TestGenerateSearchURL() { | |
104 } | |
105 | |
106 | |
107 // TestSearchTermsData -------------------------------------------------------- | 42 // TestSearchTermsData -------------------------------------------------------- |
108 | 43 |
109 // Simple implementation of SearchTermsData. | 44 // Simple implementation of SearchTermsData. |
110 class TestSearchTermsData : public SearchTermsData { | 45 class TestSearchTermsData : public SearchTermsData { |
111 public: | 46 public: |
112 explicit TestSearchTermsData(const char* google_base_url); | 47 explicit TestSearchTermsData(const char* google_base_url); |
113 | 48 |
114 virtual std::string GoogleBaseURLValue() const OVERRIDE; | 49 virtual std::string GoogleBaseURLValue() const OVERRIDE; |
115 | 50 |
116 private: | 51 private: |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 | 136 |
202 // Helper methods to make calling TemplateURLServiceTestUtil methods less | 137 // Helper methods to make calling TemplateURLServiceTestUtil methods less |
203 // visually noisy in the test code. | 138 // visually noisy in the test code. |
204 void VerifyObserverCount(int expected_changed_count); | 139 void VerifyObserverCount(int expected_changed_count); |
205 void VerifyObserverFired(); | 140 void VerifyObserverFired(); |
206 TemplateURLService* model() { return test_util_.model(); } | 141 TemplateURLService* model() { return test_util_.model(); } |
207 | 142 |
208 protected: | 143 protected: |
209 TemplateURLServiceTestUtil test_util_; | 144 TemplateURLServiceTestUtil test_util_; |
210 | 145 |
146 void TestGenerateSearchURL(SearchTermsData* search_terms_data) { | |
147 struct GenerateSearchURLCase { | |
148 const char* test_name; | |
149 const char* url; | |
150 const char* expected; | |
151 } generate_url_cases[] = { | |
152 { "invalid URL", "foo{searchTerms}", "" }, | |
153 { "URL with no replacements", "http://foo/", "http://foo/" }, | |
154 { "basic functionality", "http://foo/{searchTerms}", | |
155 "http://foo/blah.blah.blah.blah.blah" } | |
156 }; | |
157 | |
158 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generate_url_cases); ++i) { | |
159 TemplateURLData data; | |
160 data.SetURL(generate_url_cases[i].url); | |
161 TemplateURL t_url(NULL, data); | |
162 std::string result = (search_terms_data ? | |
163 TemplateURLService::GenerateSearchURLUsingTermsData(&t_url, | |
Peter Kasting
2013/07/12 01:20:20
Nit: Put first arg on next line with second arg, s
awong
2013/07/16 21:27:28
Broke the ternary into an if statement. Seemed san
| |
164 *search_terms_data) : | |
165 TemplateURLService::GenerateSearchURL(&t_url)).spec(); | |
166 EXPECT_EQ(result, generate_url_cases[i].expected) | |
167 << generate_url_cases[i].test_name << " failed. Expected " | |
168 << generate_url_cases[i].expected << " Actual " << result; | |
169 } | |
170 } | |
171 | |
172 | |
211 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTest); | 173 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTest); |
212 }; | 174 }; |
213 | 175 |
214 TemplateURLServiceTest::TemplateURLServiceTest() { | 176 TemplateURLServiceTest::TemplateURLServiceTest() { |
215 } | 177 } |
216 | 178 |
217 void TemplateURLServiceTest::SetUp() { | 179 void TemplateURLServiceTest::SetUp() { |
218 test_util_.SetUp(); | 180 test_util_.SetUp(); |
219 } | 181 } |
220 | 182 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 EXPECT_NE(prepopulated_url, original_url); | 295 EXPECT_NE(prepopulated_url, original_url); |
334 | 296 |
335 // Then add it to the model and save it all. | 297 // Then add it to the model and save it all. |
336 test_util_.ChangeModelToLoadState(); | 298 test_util_.ChangeModelToLoadState(); |
337 model()->Add(t_url); | 299 model()->Add(t_url); |
338 const TemplateURL* keyword_url = | 300 const TemplateURL* keyword_url = |
339 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 301 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
340 ASSERT_TRUE(keyword_url != NULL); | 302 ASSERT_TRUE(keyword_url != NULL); |
341 EXPECT_EQ(t_url, keyword_url); | 303 EXPECT_EQ(t_url, keyword_url); |
342 EXPECT_EQ(original_url, keyword_url->url_ref().DisplayURL()); | 304 EXPECT_EQ(original_url, keyword_url->url_ref().DisplayURL()); |
343 test_util_.BlockTillServiceProcessesRequests(); | 305 base::RunLoop().RunUntilIdle(); |
344 | 306 |
345 // Now reload the model and verify that the merge updates the url, and | 307 // Now reload the model and verify that the merge updates the url, and |
346 // preserves the sync GUID. | 308 // preserves the sync GUID. |
347 test_util_.ResetModel(true); | 309 test_util_.ResetModel(true); |
348 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 310 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
349 ASSERT_TRUE(keyword_url != NULL); | 311 ASSERT_TRUE(keyword_url != NULL); |
350 EXPECT_EQ(prepopulated_url, keyword_url->url_ref().DisplayURL()); | 312 EXPECT_EQ(prepopulated_url, keyword_url->url_ref().DisplayURL()); |
351 EXPECT_EQ(original_guid, keyword_url->sync_guid()); | 313 EXPECT_EQ(original_guid, keyword_url->sync_guid()); |
352 | 314 |
353 // Wait for any saves to finish. | 315 // Wait for any saves to finish. |
354 test_util_.BlockTillServiceProcessesRequests(); | 316 base::RunLoop().RunUntilIdle(); |
355 | 317 |
356 // Reload the model to verify that change was saved correctly. | 318 // Reload the model to verify that change was saved correctly. |
357 test_util_.ResetModel(true); | 319 test_util_.ResetModel(true); |
358 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 320 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
359 ASSERT_TRUE(keyword_url != NULL); | 321 ASSERT_TRUE(keyword_url != NULL); |
360 EXPECT_EQ(prepopulated_url, keyword_url->url_ref().DisplayURL()); | 322 EXPECT_EQ(prepopulated_url, keyword_url->url_ref().DisplayURL()); |
361 EXPECT_EQ(original_guid, keyword_url->sync_guid()); | 323 EXPECT_EQ(original_guid, keyword_url->sync_guid()); |
362 } | 324 } |
363 | 325 |
364 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { | 326 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { |
(...skipping 25 matching lines...) Expand all Loading... | |
390 data.favicon_url = GURL("http://favicon.url"); | 352 data.favicon_url = GURL("http://favicon.url"); |
391 data.safe_for_autoreplace = true; | 353 data.safe_for_autoreplace = true; |
392 data.date_created = Time::FromTimeT(100); | 354 data.date_created = Time::FromTimeT(100); |
393 data.last_modified = Time::FromTimeT(100); | 355 data.last_modified = Time::FromTimeT(100); |
394 data.sync_guid = "00000000-0000-0000-0000-000000000001"; | 356 data.sync_guid = "00000000-0000-0000-0000-000000000001"; |
395 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); | 357 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); |
396 model()->Add(t_url); | 358 model()->Add(t_url); |
397 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), | 359 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), |
398 NULL)); | 360 NULL)); |
399 VerifyObserverCount(1); | 361 VerifyObserverCount(1); |
400 test_util_.BlockTillServiceProcessesRequests(); | 362 base::RunLoop().RunUntilIdle(); |
401 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 363 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
402 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword())); | 364 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword())); |
403 // We need to make a second copy as the model takes ownership of |t_url| and | 365 // We need to make a second copy as the model takes ownership of |t_url| and |
404 // will delete it. We have to do this after calling Add() since that gives | 366 // will delete it. We have to do this after calling Add() since that gives |
405 // |t_url| its ID. | 367 // |t_url| its ID. |
406 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), | 368 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), |
407 t_url->data())); | 369 t_url->data())); |
408 | 370 |
409 // Reload the model to verify it was actually saved to the database. | 371 // Reload the model to verify it was actually saved to the database. |
410 test_util_.ResetModel(true); | 372 test_util_.ResetModel(true); |
(...skipping 16 matching lines...) Expand all Loading... | |
427 model()->ResetTemplateURL(loaded_url, ASCIIToUTF16("a"), ASCIIToUTF16("b"), | 389 model()->ResetTemplateURL(loaded_url, ASCIIToUTF16("a"), ASCIIToUTF16("b"), |
428 "c"); | 390 "c"); |
429 ASSERT_EQ(ASCIIToUTF16("a"), loaded_url->short_name()); | 391 ASSERT_EQ(ASCIIToUTF16("a"), loaded_url->short_name()); |
430 ASSERT_EQ(ASCIIToUTF16("b"), loaded_url->keyword()); | 392 ASSERT_EQ(ASCIIToUTF16("b"), loaded_url->keyword()); |
431 ASSERT_EQ("c", loaded_url->url()); | 393 ASSERT_EQ("c", loaded_url->url()); |
432 ASSERT_FALSE(loaded_url->safe_for_autoreplace()); | 394 ASSERT_FALSE(loaded_url->safe_for_autoreplace()); |
433 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), | 395 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), |
434 NULL)); | 396 NULL)); |
435 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL)); | 397 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL)); |
436 cloned_url.reset(new TemplateURL(loaded_url->profile(), loaded_url->data())); | 398 cloned_url.reset(new TemplateURL(loaded_url->profile(), loaded_url->data())); |
437 test_util_.BlockTillServiceProcessesRequests(); | 399 base::RunLoop().RunUntilIdle(); |
438 test_util_.ResetModel(true); | 400 test_util_.ResetModel(true); |
439 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 401 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
440 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")); | 402 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")); |
441 ASSERT_TRUE(loaded_url != NULL); | 403 ASSERT_TRUE(loaded_url != NULL); |
442 AssertEquals(*cloned_url, *loaded_url); | 404 AssertEquals(*cloned_url, *loaded_url); |
443 // We changed a TemplateURL in the service, so ensure that the time was | 405 // We changed a TemplateURL in the service, so ensure that the time was |
444 // updated. | 406 // updated. |
445 ASSERT_EQ(base::Time::FromDoubleT(1337), loaded_url->last_modified()); | 407 ASSERT_EQ(base::Time::FromDoubleT(1337), loaded_url->last_modified()); |
446 | 408 |
447 // Remove an element and verify it succeeded. | 409 // Remove an element and verify it succeeded. |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 TemplateURLService::GenerateKeyword(GURL("http://www.foo"))); | 566 TemplateURLService::GenerateKeyword(GURL("http://www.foo"))); |
605 // Make sure we don't get a trailing '/'. | 567 // Make sure we don't get a trailing '/'. |
606 ASSERT_EQ(ASCIIToUTF16("blah"), | 568 ASSERT_EQ(ASCIIToUTF16("blah"), |
607 TemplateURLService::GenerateKeyword(GURL("http://blah/"))); | 569 TemplateURLService::GenerateKeyword(GURL("http://blah/"))); |
608 // Don't generate the empty string. | 570 // Don't generate the empty string. |
609 ASSERT_EQ(ASCIIToUTF16("www"), | 571 ASSERT_EQ(ASCIIToUTF16("www"), |
610 TemplateURLService::GenerateKeyword(GURL("http://www."))); | 572 TemplateURLService::GenerateKeyword(GURL("http://www."))); |
611 } | 573 } |
612 | 574 |
613 TEST_F(TemplateURLServiceTest, GenerateSearchURL) { | 575 TEST_F(TemplateURLServiceTest, GenerateSearchURL) { |
614 scoped_refptr<TestGenerateSearchURL> test_generate_search_url( | 576 TestGenerateSearchURL(NULL); |
615 new TestGenerateSearchURL(NULL)); | |
616 test_generate_search_url->RunTest(); | |
617 EXPECT_TRUE(test_generate_search_url->passed()); | |
618 } | 577 } |
619 | 578 |
620 TEST_F(TemplateURLServiceTest, GenerateSearchURLUsingTermsData) { | 579 TEST_F(TemplateURLServiceTest, GenerateSearchURLUsingTermsData) { |
621 // Run the test for GenerateSearchURLUsingTermsData on the "IO" thread and | 580 // Run the test for GenerateSearchURLUsingTermsData on the "IO" thread and |
622 // wait for it to finish. | 581 // wait for it to finish. |
623 TestSearchTermsData search_terms_data("http://google.com/"); | 582 TestSearchTermsData search_terms_data("http://google.com/"); |
624 scoped_refptr<TestGenerateSearchURL> test_generate_search_url( | 583 TestGenerateSearchURL(&search_terms_data); |
625 new TestGenerateSearchURL(&search_terms_data)); | |
626 | |
627 test_util_.StartIOThread(); | |
628 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)->PostTask( | |
629 FROM_HERE, base::Bind(&TestGenerateSearchURL::RunTest, | |
630 test_generate_search_url.get())); | |
631 TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests(); | |
632 EXPECT_TRUE(test_generate_search_url->passed()); | |
633 } | 584 } |
634 | 585 |
635 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) { | 586 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) { |
636 Time now = Time::Now(); | 587 Time now = Time::Now(); |
637 TimeDelta one_day = TimeDelta::FromDays(1); | 588 TimeDelta one_day = TimeDelta::FromDays(1); |
638 Time month_ago = now - TimeDelta::FromDays(30); | 589 Time month_ago = now - TimeDelta::FromDays(30); |
639 | 590 |
640 // Nothing has been added. | 591 // Nothing has been added. |
641 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); | 592 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); |
642 | 593 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
754 data.short_name = ASCIIToUTF16("google"); | 705 data.short_name = ASCIIToUTF16("google"); |
755 data.SetKeyword(ASCIIToUTF16("keyword")); | 706 data.SetKeyword(ASCIIToUTF16("keyword")); |
756 data.SetURL("http://www.google.com/foo/bar"); | 707 data.SetURL("http://www.google.com/foo/bar"); |
757 data.favicon_url = GURL("http://favicon.url"); | 708 data.favicon_url = GURL("http://favicon.url"); |
758 data.date_created = Time::FromTimeT(100); | 709 data.date_created = Time::FromTimeT(100); |
759 data.last_modified = Time::FromTimeT(100); | 710 data.last_modified = Time::FromTimeT(100); |
760 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); | 711 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); |
761 model()->Add(t_url); | 712 model()->Add(t_url); |
762 | 713 |
763 VerifyObserverCount(1); | 714 VerifyObserverCount(1); |
764 test_util_.BlockTillServiceProcessesRequests(); | 715 base::RunLoop().RunUntilIdle(); |
765 | 716 |
766 StrictMock<base::MockTimeProvider> mock_time; | 717 StrictMock<base::MockTimeProvider> mock_time; |
767 model()->set_time_provider(&base::MockTimeProvider::StaticNow); | 718 model()->set_time_provider(&base::MockTimeProvider::StaticNow); |
768 EXPECT_CALL(mock_time, Now()).WillOnce(Return(base::Time::FromDoubleT(1337))); | 719 EXPECT_CALL(mock_time, Now()).WillOnce(Return(base::Time::FromDoubleT(1337))); |
769 | 720 |
770 // Reset the short name, keyword, url and make sure it takes. | 721 // Reset the short name, keyword, url and make sure it takes. |
771 const string16 new_short_name(ASCIIToUTF16("a")); | 722 const string16 new_short_name(ASCIIToUTF16("a")); |
772 const string16 new_keyword(ASCIIToUTF16("b")); | 723 const string16 new_keyword(ASCIIToUTF16("b")); |
773 const std::string new_url("c"); | 724 const std::string new_url("c"); |
774 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); | 725 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); |
(...skipping 27 matching lines...) Expand all Loading... | |
802 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); | 753 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); |
803 test_util_.ResetObserverCount(); | 754 test_util_.ResetObserverCount(); |
804 | 755 |
805 model()->SetDefaultSearchProvider(t_url); | 756 model()->SetDefaultSearchProvider(t_url); |
806 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); | 757 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); |
807 ASSERT_TRUE(t_url->safe_for_autoreplace()); | 758 ASSERT_TRUE(t_url->safe_for_autoreplace()); |
808 ASSERT_TRUE(t_url->show_in_default_list()); | 759 ASSERT_TRUE(t_url->show_in_default_list()); |
809 | 760 |
810 // Setting the default search provider should have caused notification. | 761 // Setting the default search provider should have caused notification. |
811 VerifyObserverCount(1); | 762 VerifyObserverCount(1); |
812 test_util_.BlockTillServiceProcessesRequests(); | 763 base::RunLoop().RunUntilIdle(); |
813 | 764 |
814 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), | 765 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), |
815 t_url->data())); | 766 t_url->data())); |
816 | 767 |
817 // Make sure when we reload we get a default search provider. | 768 // Make sure when we reload we get a default search provider. |
818 test_util_.ResetModel(true); | 769 test_util_.ResetModel(true); |
819 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 770 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
820 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 771 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
821 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); | 772 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); |
822 } | 773 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
881 data.SetURL("http://url/{searchTerms}"); | 832 data.SetURL("http://url/{searchTerms}"); |
882 data.suggestions_url = "http://url2"; | 833 data.suggestions_url = "http://url2"; |
883 data.instant_url = "http://instant"; | 834 data.instant_url = "http://instant"; |
884 data.date_created = Time::FromTimeT(100); | 835 data.date_created = Time::FromTimeT(100); |
885 data.last_modified = Time::FromTimeT(100); | 836 data.last_modified = Time::FromTimeT(100); |
886 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); | 837 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); |
887 model()->Add(t_url); | 838 model()->Add(t_url); |
888 const TemplateURLID id = t_url->id(); | 839 const TemplateURLID id = t_url->id(); |
889 | 840 |
890 model()->SetDefaultSearchProvider(t_url); | 841 model()->SetDefaultSearchProvider(t_url); |
891 test_util_.BlockTillServiceProcessesRequests(); | 842 base::RunLoop().RunUntilIdle(); |
892 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), | 843 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), |
893 t_url->data())); | 844 t_url->data())); |
894 | 845 |
895 // Reset the model and don't load it. The template url we set as the default | 846 // Reset the model and don't load it. The template url we set as the default |
896 // should be pulled from prefs now. | 847 // should be pulled from prefs now. |
897 test_util_.ResetModel(false); | 848 test_util_.ResetModel(false); |
898 | 849 |
899 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs | 850 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs |
900 // value are persisted to prefs. | 851 // value are persisted to prefs. |
901 const TemplateURL* default_turl = model()->GetDefaultSearchProvider(); | 852 const TemplateURL* default_turl = model()->GetDefaultSearchProvider(); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1147 // Make sure that the load routine deletes prepopulated engines that no longer | 1098 // Make sure that the load routine deletes prepopulated engines that no longer |
1148 // exist in the prepopulate data. | 1099 // exist in the prepopulate data. |
1149 TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) { | 1100 TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) { |
1150 // Create a preloaded template url. Add it to a loaded model and wait for the | 1101 // Create a preloaded template url. Add it to a loaded model and wait for the |
1151 // saves to finish. | 1102 // saves to finish. |
1152 TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999); | 1103 TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999); |
1153 test_util_.ChangeModelToLoadState(); | 1104 test_util_.ChangeModelToLoadState(); |
1154 model()->Add(t_url); | 1105 model()->Add(t_url); |
1155 ASSERT_TRUE( | 1106 ASSERT_TRUE( |
1156 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); | 1107 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); |
1157 test_util_.BlockTillServiceProcessesRequests(); | 1108 base::RunLoop().RunUntilIdle(); |
1158 | 1109 |
1159 // Ensure that merging clears this engine. | 1110 // Ensure that merging clears this engine. |
1160 test_util_.ResetModel(true); | 1111 test_util_.ResetModel(true); |
1161 ASSERT_TRUE( | 1112 ASSERT_TRUE( |
1162 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); | 1113 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); |
1163 | 1114 |
1164 // Wait for any saves to finish. | 1115 // Wait for any saves to finish. |
1165 test_util_.BlockTillServiceProcessesRequests(); | 1116 base::RunLoop().RunUntilIdle(); |
1166 | 1117 |
1167 // Reload the model to verify that the database was updated as a result of the | 1118 // Reload the model to verify that the database was updated as a result of the |
1168 // merge. | 1119 // merge. |
1169 test_util_.ResetModel(true); | 1120 test_util_.ResetModel(true); |
1170 ASSERT_TRUE( | 1121 ASSERT_TRUE( |
1171 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); | 1122 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); |
1172 } | 1123 } |
1173 | 1124 |
1174 // Make sure that load routine doesn't delete prepopulated engines that no | 1125 // Make sure that load routine doesn't delete prepopulated engines that no |
1175 // longer exist in the prepopulate data if it has been modified by the user. | 1126 // longer exist in the prepopulate data if it has been modified by the user. |
1176 TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) { | 1127 TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) { |
1177 // Create a preloaded template url and add it to a loaded model. | 1128 // Create a preloaded template url and add it to a loaded model. |
1178 TemplateURL* t_url = CreatePreloadedTemplateURL(false, 999999); | 1129 TemplateURL* t_url = CreatePreloadedTemplateURL(false, 999999); |
1179 test_util_.ChangeModelToLoadState(); | 1130 test_util_.ChangeModelToLoadState(); |
1180 model()->Add(t_url); | 1131 model()->Add(t_url); |
1181 | 1132 |
1182 // Do the copy after t_url is added so that the id is set. | 1133 // Do the copy after t_url is added so that the id is set. |
1183 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), | 1134 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), |
1184 t_url->data())); | 1135 t_url->data())); |
1185 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); | 1136 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); |
1186 | 1137 |
1187 // Wait for any saves to finish. | 1138 // Wait for any saves to finish. |
1188 test_util_.BlockTillServiceProcessesRequests(); | 1139 base::RunLoop().RunUntilIdle(); |
1189 | 1140 |
1190 // Ensure that merging won't clear it if the user has edited it. | 1141 // Ensure that merging won't clear it if the user has edited it. |
1191 test_util_.ResetModel(true); | 1142 test_util_.ResetModel(true); |
1192 const TemplateURL* url_for_unittest = | 1143 const TemplateURL* url_for_unittest = |
1193 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 1144 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
1194 ASSERT_TRUE(url_for_unittest != NULL); | 1145 ASSERT_TRUE(url_for_unittest != NULL); |
1195 AssertEquals(*cloned_url, *url_for_unittest); | 1146 AssertEquals(*cloned_url, *url_for_unittest); |
1196 | 1147 |
1197 // Wait for any saves to finish. | 1148 // Wait for any saves to finish. |
1198 test_util_.BlockTillServiceProcessesRequests(); | 1149 base::RunLoop().RunUntilIdle(); |
1199 | 1150 |
1200 // Reload the model to verify that save/reload retains the item. | 1151 // Reload the model to verify that save/reload retains the item. |
1201 test_util_.ResetModel(true); | 1152 test_util_.ResetModel(true); |
1202 ASSERT_TRUE( | 1153 ASSERT_TRUE( |
1203 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); | 1154 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); |
1204 } | 1155 } |
1205 | 1156 |
1206 // Make sure that load routine doesn't delete | 1157 // Make sure that load routine doesn't delete |
1207 // prepopulated engines that no longer exist in the prepopulate data if | 1158 // prepopulated engines that no longer exist in the prepopulate data if |
1208 // it has been modified by the user. | 1159 // it has been modified by the user. |
1209 TEST_F(TemplateURLServiceTest, LoadSavesPrepopulatedDefaultSearchProvider) { | 1160 TEST_F(TemplateURLServiceTest, LoadSavesPrepopulatedDefaultSearchProvider) { |
1210 test_util_.VerifyLoad(); | 1161 test_util_.VerifyLoad(); |
1211 // Verify that the default search provider is set to something. | 1162 // Verify that the default search provider is set to something. |
1212 TemplateURL* default_search = model()->GetDefaultSearchProvider(); | 1163 TemplateURL* default_search = model()->GetDefaultSearchProvider(); |
1213 ASSERT_TRUE(default_search != NULL); | 1164 ASSERT_TRUE(default_search != NULL); |
1214 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(default_search->profile(), | 1165 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(default_search->profile(), |
1215 default_search->data())); | 1166 default_search->data())); |
1216 | 1167 |
1217 // Wait for any saves to finish. | 1168 // Wait for any saves to finish. |
1218 test_util_.BlockTillServiceProcessesRequests(); | 1169 base::RunLoop().RunUntilIdle(); |
1219 | 1170 |
1220 // Reload the model and check that the default search provider | 1171 // Reload the model and check that the default search provider |
1221 // was properly saved. | 1172 // was properly saved. |
1222 test_util_.ResetModel(true); | 1173 test_util_.ResetModel(true); |
1223 default_search = model()->GetDefaultSearchProvider(); | 1174 default_search = model()->GetDefaultSearchProvider(); |
1224 ASSERT_TRUE(default_search != NULL); | 1175 ASSERT_TRUE(default_search != NULL); |
1225 AssertEquals(*cloned_url, *default_search); | 1176 AssertEquals(*cloned_url, *default_search); |
1226 } | 1177 } |
1227 | 1178 |
1228 TEST_F(TemplateURLServiceTest, FindNewDefaultSearchProvider) { | 1179 TEST_F(TemplateURLServiceTest, FindNewDefaultSearchProvider) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1272 test_util_.ChangeModelToLoadState(); | 1223 test_util_.ChangeModelToLoadState(); |
1273 model()->Add(t_url); | 1224 model()->Add(t_url); |
1274 model()->SetDefaultSearchProvider(t_url); | 1225 model()->SetDefaultSearchProvider(t_url); |
1275 // Do the copy after t_url is added and set as default so that its | 1226 // Do the copy after t_url is added and set as default so that its |
1276 // internal state is correct. | 1227 // internal state is correct. |
1277 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), | 1228 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), |
1278 t_url->data())); | 1229 t_url->data())); |
1279 | 1230 |
1280 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); | 1231 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); |
1281 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); | 1232 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); |
1282 test_util_.BlockTillServiceProcessesRequests(); | 1233 base::RunLoop().RunUntilIdle(); |
1283 | 1234 |
1284 // Ensure that merging won't clear the prepopulated template url | 1235 // Ensure that merging won't clear the prepopulated template url |
1285 // which is no longer present if it's the default engine. | 1236 // which is no longer present if it's the default engine. |
1286 test_util_.ResetModel(true); | 1237 test_util_.ResetModel(true); |
1287 { | 1238 { |
1288 const TemplateURL* keyword_url = | 1239 const TemplateURL* keyword_url = |
1289 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 1240 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
1290 ASSERT_TRUE(keyword_url != NULL); | 1241 ASSERT_TRUE(keyword_url != NULL); |
1291 AssertEquals(*cloned_url, *keyword_url); | 1242 AssertEquals(*cloned_url, *keyword_url); |
1292 ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); | 1243 ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); |
1293 } | 1244 } |
1294 | 1245 |
1295 // Wait for any saves to finish. | 1246 // Wait for any saves to finish. |
1296 test_util_.BlockTillServiceProcessesRequests(); | 1247 base::RunLoop().RunUntilIdle(); |
1297 | 1248 |
1298 // Reload the model to verify that the update was saved. | 1249 // Reload the model to verify that the update was saved. |
1299 test_util_.ResetModel(true); | 1250 test_util_.ResetModel(true); |
1300 { | 1251 { |
1301 const TemplateURL* keyword_url = | 1252 const TemplateURL* keyword_url = |
1302 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 1253 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
1303 ASSERT_TRUE(keyword_url != NULL); | 1254 ASSERT_TRUE(keyword_url != NULL); |
1304 AssertEquals(*cloned_url, *keyword_url); | 1255 AssertEquals(*cloned_url, *keyword_url); |
1305 ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); | 1256 ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); |
1306 } | 1257 } |
(...skipping 15 matching lines...) Expand all Loading... | |
1322 // missing and not managed. | 1273 // missing and not managed. |
1323 TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) { | 1274 TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) { |
1324 // Force the model to load and make sure we have a default search provider. | 1275 // Force the model to load and make sure we have a default search provider. |
1325 test_util_.VerifyLoad(); | 1276 test_util_.VerifyLoad(); |
1326 TemplateURL* old_default = model()->GetDefaultSearchProvider(); | 1277 TemplateURL* old_default = model()->GetDefaultSearchProvider(); |
1327 EXPECT_TRUE(old_default); | 1278 EXPECT_TRUE(old_default); |
1328 | 1279 |
1329 // Now remove it. | 1280 // Now remove it. |
1330 model()->SetDefaultSearchProvider(NULL); | 1281 model()->SetDefaultSearchProvider(NULL); |
1331 model()->Remove(old_default); | 1282 model()->Remove(old_default); |
1332 test_util_.BlockTillServiceProcessesRequests(); | 1283 base::RunLoop().RunUntilIdle(); |
1333 | 1284 |
1334 EXPECT_FALSE(model()->GetDefaultSearchProvider()); | 1285 EXPECT_FALSE(model()->GetDefaultSearchProvider()); |
1335 | 1286 |
1336 // Reset the model and load it. There should be a default search provider. | 1287 // Reset the model and load it. There should be a default search provider. |
1337 test_util_.ResetModel(true); | 1288 test_util_.ResetModel(true); |
1338 | 1289 |
1339 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 1290 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
1340 EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement()); | 1291 EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement()); |
1341 | 1292 |
1342 // Make default search provider unusable (no search terms). | 1293 // Make default search provider unusable (no search terms). |
1343 model()->ResetTemplateURL(model()->GetDefaultSearchProvider(), | 1294 model()->ResetTemplateURL(model()->GetDefaultSearchProvider(), |
1344 ASCIIToUTF16("test"), ASCIIToUTF16("test"), | 1295 ASCIIToUTF16("test"), ASCIIToUTF16("test"), |
1345 "http://example.com/"); | 1296 "http://example.com/"); |
1346 test_util_.BlockTillServiceProcessesRequests(); | 1297 base::RunLoop().RunUntilIdle(); |
1347 | 1298 |
1348 // Reset the model and load it. There should be a usable default search | 1299 // Reset the model and load it. There should be a usable default search |
1349 // provider. | 1300 // provider. |
1350 test_util_.ResetModel(true); | 1301 test_util_.ResetModel(true); |
1351 | 1302 |
1352 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 1303 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
1353 EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement()); | 1304 EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement()); |
1354 } | 1305 } |
1355 | 1306 |
1356 // Simulates failing to load the webdb and makes sure the default search | 1307 // Simulates failing to load the webdb and makes sure the default search |
1357 // provider is valid. | 1308 // provider is valid. |
1358 TEST_F(TemplateURLServiceTest, FailedInit) { | 1309 TEST_F(TemplateURLServiceTest, FailedInit) { |
1359 test_util_.VerifyLoad(); | 1310 test_util_.VerifyLoad(); |
1360 | 1311 |
1361 test_util_.ClearModel(); | 1312 test_util_.ClearModel(); |
1362 scoped_refptr<WebDataService> web_service = | 1313 scoped_refptr<WebDataService> web_service = |
1363 WebDataService::FromBrowserContext(test_util_.profile()); | 1314 WebDataService::FromBrowserContext(test_util_.profile()); |
1364 web_service->ShutdownDatabase(); | 1315 web_service->ShutdownDatabase(); |
1365 | 1316 |
1366 test_util_.ResetModel(false); | 1317 test_util_.ResetModel(false); |
1367 model()->Load(); | 1318 model()->Load(); |
1368 test_util_.BlockTillServiceProcessesRequests(); | 1319 base::RunLoop().RunUntilIdle(); |
1369 | 1320 |
1370 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 1321 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
1371 } | 1322 } |
1372 | 1323 |
1373 // Verifies that if the default search URL preference is managed, we report | 1324 // Verifies that if the default search URL preference is managed, we report |
1374 // the default search as managed. Also check that we are getting the right | 1325 // the default search as managed. Also check that we are getting the right |
1375 // values. | 1326 // values. |
1376 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { | 1327 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { |
1377 test_util_.VerifyLoad(); | 1328 test_util_.VerifyLoad(); |
1378 const size_t initial_count = model()->GetTemplateURLs().size(); | 1329 const size_t initial_count = model()->GetTemplateURLs().size(); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1514 | 1465 |
1515 TemplateURLData data; | 1466 TemplateURLData data; |
1516 data.short_name = ASCIIToUTF16("google"); | 1467 data.short_name = ASCIIToUTF16("google"); |
1517 data.SetKeyword(ASCIIToUTF16("keyword")); | 1468 data.SetKeyword(ASCIIToUTF16("keyword")); |
1518 data.SetURL("http://www.google.com/foo/bar"); | 1469 data.SetURL("http://www.google.com/foo/bar"); |
1519 data.sync_guid.clear(); | 1470 data.sync_guid.clear(); |
1520 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); | 1471 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); |
1521 model()->Add(t_url); | 1472 model()->Add(t_url); |
1522 | 1473 |
1523 VerifyObserverCount(1); | 1474 VerifyObserverCount(1); |
1524 test_util_.BlockTillServiceProcessesRequests(); | 1475 base::RunLoop().RunUntilIdle(); |
1525 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1476 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
1526 | 1477 |
1527 // Reload the model to verify it was actually saved to the database and | 1478 // Reload the model to verify it was actually saved to the database and |
1528 // assigned a new GUID when brought back. | 1479 // assigned a new GUID when brought back. |
1529 test_util_.ResetModel(true); | 1480 test_util_.ResetModel(true); |
1530 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1481 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
1531 const TemplateURL* loaded_url = | 1482 const TemplateURL* loaded_url = |
1532 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1483 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
1533 ASSERT_FALSE(loaded_url == NULL); | 1484 ASSERT_FALSE(loaded_url == NULL); |
1534 ASSERT_FALSE(loaded_url->sync_guid().empty()); | 1485 ASSERT_FALSE(loaded_url->sync_guid().empty()); |
(...skipping 16 matching lines...) Expand all Loading... | |
1551 data.input_encodings.push_back("UTF-16"); | 1502 data.input_encodings.push_back("UTF-16"); |
1552 data.input_encodings.push_back("UTF-8"); | 1503 data.input_encodings.push_back("UTF-8"); |
1553 data.input_encodings.push_back("Big5"); | 1504 data.input_encodings.push_back("Big5"); |
1554 data.input_encodings.push_back("UTF-16"); | 1505 data.input_encodings.push_back("UTF-16"); |
1555 data.input_encodings.push_back("Big5"); | 1506 data.input_encodings.push_back("Big5"); |
1556 data.input_encodings.push_back("Windows-1252"); | 1507 data.input_encodings.push_back("Windows-1252"); |
1557 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); | 1508 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); |
1558 model()->Add(t_url); | 1509 model()->Add(t_url); |
1559 | 1510 |
1560 VerifyObserverCount(1); | 1511 VerifyObserverCount(1); |
1561 test_util_.BlockTillServiceProcessesRequests(); | 1512 base::RunLoop().RunUntilIdle(); |
1562 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1513 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
1563 const TemplateURL* loaded_url = | 1514 const TemplateURL* loaded_url = |
1564 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1515 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
1565 ASSERT_TRUE(loaded_url != NULL); | 1516 ASSERT_TRUE(loaded_url != NULL); |
1566 EXPECT_EQ(8U, loaded_url->input_encodings().size()); | 1517 EXPECT_EQ(8U, loaded_url->input_encodings().size()); |
1567 | 1518 |
1568 // Reload the model to verify it was actually saved to the database and the | 1519 // Reload the model to verify it was actually saved to the database and the |
1569 // duplicate encodings were removed. | 1520 // duplicate encodings were removed. |
1570 test_util_.ResetModel(true); | 1521 test_util_.ResetModel(true); |
1571 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1522 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
1572 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1523 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
1573 ASSERT_FALSE(loaded_url == NULL); | 1524 ASSERT_FALSE(loaded_url == NULL); |
1574 EXPECT_EQ(4U, loaded_url->input_encodings().size()); | 1525 EXPECT_EQ(4U, loaded_url->input_encodings().size()); |
1575 } | 1526 } |
OLD | NEW |