| 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; |
| 163 if (search_terms_data) { |
| 164 result = TemplateURLService::GenerateSearchURLUsingTermsData( |
| 165 &t_url, *search_terms_data).spec(); |
| 166 } else { |
| 167 result = TemplateURLService::GenerateSearchURL(&t_url).spec(); |
| 168 } |
| 169 EXPECT_EQ(result, generate_url_cases[i].expected) |
| 170 << generate_url_cases[i].test_name << " failed. Expected " |
| 171 << generate_url_cases[i].expected << " Actual " << result; |
| 172 } |
| 173 } |
| 174 |
| 175 |
| 211 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTest); | 176 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTest); |
| 212 }; | 177 }; |
| 213 | 178 |
| 214 TemplateURLServiceTest::TemplateURLServiceTest() { | 179 TemplateURLServiceTest::TemplateURLServiceTest() { |
| 215 } | 180 } |
| 216 | 181 |
| 217 void TemplateURLServiceTest::SetUp() { | 182 void TemplateURLServiceTest::SetUp() { |
| 218 test_util_.SetUp(); | 183 test_util_.SetUp(); |
| 219 } | 184 } |
| 220 | 185 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 EXPECT_NE(prepopulated_url, original_url); | 298 EXPECT_NE(prepopulated_url, original_url); |
| 334 | 299 |
| 335 // Then add it to the model and save it all. | 300 // Then add it to the model and save it all. |
| 336 test_util_.ChangeModelToLoadState(); | 301 test_util_.ChangeModelToLoadState(); |
| 337 model()->Add(t_url); | 302 model()->Add(t_url); |
| 338 const TemplateURL* keyword_url = | 303 const TemplateURL* keyword_url = |
| 339 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 304 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
| 340 ASSERT_TRUE(keyword_url != NULL); | 305 ASSERT_TRUE(keyword_url != NULL); |
| 341 EXPECT_EQ(t_url, keyword_url); | 306 EXPECT_EQ(t_url, keyword_url); |
| 342 EXPECT_EQ(original_url, keyword_url->url_ref().DisplayURL()); | 307 EXPECT_EQ(original_url, keyword_url->url_ref().DisplayURL()); |
| 343 test_util_.BlockTillServiceProcessesRequests(); | 308 base::RunLoop().RunUntilIdle(); |
| 344 | 309 |
| 345 // Now reload the model and verify that the merge updates the url, and | 310 // Now reload the model and verify that the merge updates the url, and |
| 346 // preserves the sync GUID. | 311 // preserves the sync GUID. |
| 347 test_util_.ResetModel(true); | 312 test_util_.ResetModel(true); |
| 348 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 313 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
| 349 ASSERT_TRUE(keyword_url != NULL); | 314 ASSERT_TRUE(keyword_url != NULL); |
| 350 EXPECT_EQ(prepopulated_url, keyword_url->url_ref().DisplayURL()); | 315 EXPECT_EQ(prepopulated_url, keyword_url->url_ref().DisplayURL()); |
| 351 EXPECT_EQ(original_guid, keyword_url->sync_guid()); | 316 EXPECT_EQ(original_guid, keyword_url->sync_guid()); |
| 352 | 317 |
| 353 // Wait for any saves to finish. | 318 // Wait for any saves to finish. |
| 354 test_util_.BlockTillServiceProcessesRequests(); | 319 base::RunLoop().RunUntilIdle(); |
| 355 | 320 |
| 356 // Reload the model to verify that change was saved correctly. | 321 // Reload the model to verify that change was saved correctly. |
| 357 test_util_.ResetModel(true); | 322 test_util_.ResetModel(true); |
| 358 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 323 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
| 359 ASSERT_TRUE(keyword_url != NULL); | 324 ASSERT_TRUE(keyword_url != NULL); |
| 360 EXPECT_EQ(prepopulated_url, keyword_url->url_ref().DisplayURL()); | 325 EXPECT_EQ(prepopulated_url, keyword_url->url_ref().DisplayURL()); |
| 361 EXPECT_EQ(original_guid, keyword_url->sync_guid()); | 326 EXPECT_EQ(original_guid, keyword_url->sync_guid()); |
| 362 } | 327 } |
| 363 | 328 |
| 364 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { | 329 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 390 data.favicon_url = GURL("http://favicon.url"); | 355 data.favicon_url = GURL("http://favicon.url"); |
| 391 data.safe_for_autoreplace = true; | 356 data.safe_for_autoreplace = true; |
| 392 data.date_created = Time::FromTimeT(100); | 357 data.date_created = Time::FromTimeT(100); |
| 393 data.last_modified = Time::FromTimeT(100); | 358 data.last_modified = Time::FromTimeT(100); |
| 394 data.sync_guid = "00000000-0000-0000-0000-000000000001"; | 359 data.sync_guid = "00000000-0000-0000-0000-000000000001"; |
| 395 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); | 360 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); |
| 396 model()->Add(t_url); | 361 model()->Add(t_url); |
| 397 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), | 362 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), |
| 398 NULL)); | 363 NULL)); |
| 399 VerifyObserverCount(1); | 364 VerifyObserverCount(1); |
| 400 test_util_.BlockTillServiceProcessesRequests(); | 365 base::RunLoop().RunUntilIdle(); |
| 401 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 366 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 402 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword())); | 367 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 | 368 // 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 | 369 // will delete it. We have to do this after calling Add() since that gives |
| 405 // |t_url| its ID. | 370 // |t_url| its ID. |
| 406 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), | 371 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), |
| 407 t_url->data())); | 372 t_url->data())); |
| 408 | 373 |
| 409 // Reload the model to verify it was actually saved to the database. | 374 // Reload the model to verify it was actually saved to the database. |
| 410 test_util_.ResetModel(true); | 375 test_util_.ResetModel(true); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 427 model()->ResetTemplateURL(loaded_url, ASCIIToUTF16("a"), ASCIIToUTF16("b"), | 392 model()->ResetTemplateURL(loaded_url, ASCIIToUTF16("a"), ASCIIToUTF16("b"), |
| 428 "c"); | 393 "c"); |
| 429 ASSERT_EQ(ASCIIToUTF16("a"), loaded_url->short_name()); | 394 ASSERT_EQ(ASCIIToUTF16("a"), loaded_url->short_name()); |
| 430 ASSERT_EQ(ASCIIToUTF16("b"), loaded_url->keyword()); | 395 ASSERT_EQ(ASCIIToUTF16("b"), loaded_url->keyword()); |
| 431 ASSERT_EQ("c", loaded_url->url()); | 396 ASSERT_EQ("c", loaded_url->url()); |
| 432 ASSERT_FALSE(loaded_url->safe_for_autoreplace()); | 397 ASSERT_FALSE(loaded_url->safe_for_autoreplace()); |
| 433 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), | 398 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), |
| 434 NULL)); | 399 NULL)); |
| 435 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL)); | 400 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL)); |
| 436 cloned_url.reset(new TemplateURL(loaded_url->profile(), loaded_url->data())); | 401 cloned_url.reset(new TemplateURL(loaded_url->profile(), loaded_url->data())); |
| 437 test_util_.BlockTillServiceProcessesRequests(); | 402 base::RunLoop().RunUntilIdle(); |
| 438 test_util_.ResetModel(true); | 403 test_util_.ResetModel(true); |
| 439 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 404 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 440 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")); | 405 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")); |
| 441 ASSERT_TRUE(loaded_url != NULL); | 406 ASSERT_TRUE(loaded_url != NULL); |
| 442 AssertEquals(*cloned_url, *loaded_url); | 407 AssertEquals(*cloned_url, *loaded_url); |
| 443 // We changed a TemplateURL in the service, so ensure that the time was | 408 // We changed a TemplateURL in the service, so ensure that the time was |
| 444 // updated. | 409 // updated. |
| 445 ASSERT_EQ(base::Time::FromDoubleT(1337), loaded_url->last_modified()); | 410 ASSERT_EQ(base::Time::FromDoubleT(1337), loaded_url->last_modified()); |
| 446 | 411 |
| 447 // Remove an element and verify it succeeded. | 412 // 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"))); | 569 TemplateURLService::GenerateKeyword(GURL("http://www.foo"))); |
| 605 // Make sure we don't get a trailing '/'. | 570 // Make sure we don't get a trailing '/'. |
| 606 ASSERT_EQ(ASCIIToUTF16("blah"), | 571 ASSERT_EQ(ASCIIToUTF16("blah"), |
| 607 TemplateURLService::GenerateKeyword(GURL("http://blah/"))); | 572 TemplateURLService::GenerateKeyword(GURL("http://blah/"))); |
| 608 // Don't generate the empty string. | 573 // Don't generate the empty string. |
| 609 ASSERT_EQ(ASCIIToUTF16("www"), | 574 ASSERT_EQ(ASCIIToUTF16("www"), |
| 610 TemplateURLService::GenerateKeyword(GURL("http://www."))); | 575 TemplateURLService::GenerateKeyword(GURL("http://www."))); |
| 611 } | 576 } |
| 612 | 577 |
| 613 TEST_F(TemplateURLServiceTest, GenerateSearchURL) { | 578 TEST_F(TemplateURLServiceTest, GenerateSearchURL) { |
| 614 scoped_refptr<TestGenerateSearchURL> test_generate_search_url( | 579 TestGenerateSearchURL(NULL); |
| 615 new TestGenerateSearchURL(NULL)); | |
| 616 test_generate_search_url->RunTest(); | |
| 617 EXPECT_TRUE(test_generate_search_url->passed()); | |
| 618 } | 580 } |
| 619 | 581 |
| 620 TEST_F(TemplateURLServiceTest, GenerateSearchURLUsingTermsData) { | 582 TEST_F(TemplateURLServiceTest, GenerateSearchURLUsingTermsData) { |
| 621 // Run the test for GenerateSearchURLUsingTermsData on the "IO" thread and | 583 // Run the test for GenerateSearchURLUsingTermsData on the "IO" thread and |
| 622 // wait for it to finish. | 584 // wait for it to finish. |
| 623 TestSearchTermsData search_terms_data("http://google.com/"); | 585 TestSearchTermsData search_terms_data("http://google.com/"); |
| 624 scoped_refptr<TestGenerateSearchURL> test_generate_search_url( | 586 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 } | 587 } |
| 634 | 588 |
| 635 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) { | 589 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) { |
| 636 Time now = Time::Now(); | 590 Time now = Time::Now(); |
| 637 TimeDelta one_day = TimeDelta::FromDays(1); | 591 TimeDelta one_day = TimeDelta::FromDays(1); |
| 638 Time month_ago = now - TimeDelta::FromDays(30); | 592 Time month_ago = now - TimeDelta::FromDays(30); |
| 639 | 593 |
| 640 // Nothing has been added. | 594 // Nothing has been added. |
| 641 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); | 595 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); |
| 642 | 596 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 data.short_name = ASCIIToUTF16("google"); | 708 data.short_name = ASCIIToUTF16("google"); |
| 755 data.SetKeyword(ASCIIToUTF16("keyword")); | 709 data.SetKeyword(ASCIIToUTF16("keyword")); |
| 756 data.SetURL("http://www.google.com/foo/bar"); | 710 data.SetURL("http://www.google.com/foo/bar"); |
| 757 data.favicon_url = GURL("http://favicon.url"); | 711 data.favicon_url = GURL("http://favicon.url"); |
| 758 data.date_created = Time::FromTimeT(100); | 712 data.date_created = Time::FromTimeT(100); |
| 759 data.last_modified = Time::FromTimeT(100); | 713 data.last_modified = Time::FromTimeT(100); |
| 760 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); | 714 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); |
| 761 model()->Add(t_url); | 715 model()->Add(t_url); |
| 762 | 716 |
| 763 VerifyObserverCount(1); | 717 VerifyObserverCount(1); |
| 764 test_util_.BlockTillServiceProcessesRequests(); | 718 base::RunLoop().RunUntilIdle(); |
| 765 | 719 |
| 766 StrictMock<base::MockTimeProvider> mock_time; | 720 StrictMock<base::MockTimeProvider> mock_time; |
| 767 model()->set_time_provider(&base::MockTimeProvider::StaticNow); | 721 model()->set_time_provider(&base::MockTimeProvider::StaticNow); |
| 768 EXPECT_CALL(mock_time, Now()).WillOnce(Return(base::Time::FromDoubleT(1337))); | 722 EXPECT_CALL(mock_time, Now()).WillOnce(Return(base::Time::FromDoubleT(1337))); |
| 769 | 723 |
| 770 // Reset the short name, keyword, url and make sure it takes. | 724 // Reset the short name, keyword, url and make sure it takes. |
| 771 const string16 new_short_name(ASCIIToUTF16("a")); | 725 const string16 new_short_name(ASCIIToUTF16("a")); |
| 772 const string16 new_keyword(ASCIIToUTF16("b")); | 726 const string16 new_keyword(ASCIIToUTF16("b")); |
| 773 const std::string new_url("c"); | 727 const std::string new_url("c"); |
| 774 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); | 728 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()); | 756 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); |
| 803 test_util_.ResetObserverCount(); | 757 test_util_.ResetObserverCount(); |
| 804 | 758 |
| 805 model()->SetDefaultSearchProvider(t_url); | 759 model()->SetDefaultSearchProvider(t_url); |
| 806 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); | 760 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); |
| 807 ASSERT_TRUE(t_url->safe_for_autoreplace()); | 761 ASSERT_TRUE(t_url->safe_for_autoreplace()); |
| 808 ASSERT_TRUE(t_url->show_in_default_list()); | 762 ASSERT_TRUE(t_url->show_in_default_list()); |
| 809 | 763 |
| 810 // Setting the default search provider should have caused notification. | 764 // Setting the default search provider should have caused notification. |
| 811 VerifyObserverCount(1); | 765 VerifyObserverCount(1); |
| 812 test_util_.BlockTillServiceProcessesRequests(); | 766 base::RunLoop().RunUntilIdle(); |
| 813 | 767 |
| 814 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), | 768 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), |
| 815 t_url->data())); | 769 t_url->data())); |
| 816 | 770 |
| 817 // Make sure when we reload we get a default search provider. | 771 // Make sure when we reload we get a default search provider. |
| 818 test_util_.ResetModel(true); | 772 test_util_.ResetModel(true); |
| 819 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 773 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 820 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 774 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
| 821 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); | 775 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); |
| 822 } | 776 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 data.SetURL("http://url/{searchTerms}"); | 835 data.SetURL("http://url/{searchTerms}"); |
| 882 data.suggestions_url = "http://url2"; | 836 data.suggestions_url = "http://url2"; |
| 883 data.instant_url = "http://instant"; | 837 data.instant_url = "http://instant"; |
| 884 data.date_created = Time::FromTimeT(100); | 838 data.date_created = Time::FromTimeT(100); |
| 885 data.last_modified = Time::FromTimeT(100); | 839 data.last_modified = Time::FromTimeT(100); |
| 886 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); | 840 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); |
| 887 model()->Add(t_url); | 841 model()->Add(t_url); |
| 888 const TemplateURLID id = t_url->id(); | 842 const TemplateURLID id = t_url->id(); |
| 889 | 843 |
| 890 model()->SetDefaultSearchProvider(t_url); | 844 model()->SetDefaultSearchProvider(t_url); |
| 891 test_util_.BlockTillServiceProcessesRequests(); | 845 base::RunLoop().RunUntilIdle(); |
| 892 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), | 846 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), |
| 893 t_url->data())); | 847 t_url->data())); |
| 894 | 848 |
| 895 // Reset the model and don't load it. The template url we set as the default | 849 // Reset the model and don't load it. The template url we set as the default |
| 896 // should be pulled from prefs now. | 850 // should be pulled from prefs now. |
| 897 test_util_.ResetModel(false); | 851 test_util_.ResetModel(false); |
| 898 | 852 |
| 899 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs | 853 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs |
| 900 // value are persisted to prefs. | 854 // value are persisted to prefs. |
| 901 const TemplateURL* default_turl = model()->GetDefaultSearchProvider(); | 855 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 | 1101 // Make sure that the load routine deletes prepopulated engines that no longer |
| 1148 // exist in the prepopulate data. | 1102 // exist in the prepopulate data. |
| 1149 TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) { | 1103 TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) { |
| 1150 // Create a preloaded template url. Add it to a loaded model and wait for the | 1104 // Create a preloaded template url. Add it to a loaded model and wait for the |
| 1151 // saves to finish. | 1105 // saves to finish. |
| 1152 TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999); | 1106 TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999); |
| 1153 test_util_.ChangeModelToLoadState(); | 1107 test_util_.ChangeModelToLoadState(); |
| 1154 model()->Add(t_url); | 1108 model()->Add(t_url); |
| 1155 ASSERT_TRUE( | 1109 ASSERT_TRUE( |
| 1156 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); | 1110 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); |
| 1157 test_util_.BlockTillServiceProcessesRequests(); | 1111 base::RunLoop().RunUntilIdle(); |
| 1158 | 1112 |
| 1159 // Ensure that merging clears this engine. | 1113 // Ensure that merging clears this engine. |
| 1160 test_util_.ResetModel(true); | 1114 test_util_.ResetModel(true); |
| 1161 ASSERT_TRUE( | 1115 ASSERT_TRUE( |
| 1162 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); | 1116 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); |
| 1163 | 1117 |
| 1164 // Wait for any saves to finish. | 1118 // Wait for any saves to finish. |
| 1165 test_util_.BlockTillServiceProcessesRequests(); | 1119 base::RunLoop().RunUntilIdle(); |
| 1166 | 1120 |
| 1167 // Reload the model to verify that the database was updated as a result of the | 1121 // Reload the model to verify that the database was updated as a result of the |
| 1168 // merge. | 1122 // merge. |
| 1169 test_util_.ResetModel(true); | 1123 test_util_.ResetModel(true); |
| 1170 ASSERT_TRUE( | 1124 ASSERT_TRUE( |
| 1171 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); | 1125 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); |
| 1172 } | 1126 } |
| 1173 | 1127 |
| 1174 // Make sure that load routine doesn't delete prepopulated engines that no | 1128 // 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. | 1129 // longer exist in the prepopulate data if it has been modified by the user. |
| 1176 TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) { | 1130 TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) { |
| 1177 // Create a preloaded template url and add it to a loaded model. | 1131 // Create a preloaded template url and add it to a loaded model. |
| 1178 TemplateURL* t_url = CreatePreloadedTemplateURL(false, 999999); | 1132 TemplateURL* t_url = CreatePreloadedTemplateURL(false, 999999); |
| 1179 test_util_.ChangeModelToLoadState(); | 1133 test_util_.ChangeModelToLoadState(); |
| 1180 model()->Add(t_url); | 1134 model()->Add(t_url); |
| 1181 | 1135 |
| 1182 // Do the copy after t_url is added so that the id is set. | 1136 // 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(), | 1137 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), |
| 1184 t_url->data())); | 1138 t_url->data())); |
| 1185 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); | 1139 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); |
| 1186 | 1140 |
| 1187 // Wait for any saves to finish. | 1141 // Wait for any saves to finish. |
| 1188 test_util_.BlockTillServiceProcessesRequests(); | 1142 base::RunLoop().RunUntilIdle(); |
| 1189 | 1143 |
| 1190 // Ensure that merging won't clear it if the user has edited it. | 1144 // Ensure that merging won't clear it if the user has edited it. |
| 1191 test_util_.ResetModel(true); | 1145 test_util_.ResetModel(true); |
| 1192 const TemplateURL* url_for_unittest = | 1146 const TemplateURL* url_for_unittest = |
| 1193 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 1147 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
| 1194 ASSERT_TRUE(url_for_unittest != NULL); | 1148 ASSERT_TRUE(url_for_unittest != NULL); |
| 1195 AssertEquals(*cloned_url, *url_for_unittest); | 1149 AssertEquals(*cloned_url, *url_for_unittest); |
| 1196 | 1150 |
| 1197 // Wait for any saves to finish. | 1151 // Wait for any saves to finish. |
| 1198 test_util_.BlockTillServiceProcessesRequests(); | 1152 base::RunLoop().RunUntilIdle(); |
| 1199 | 1153 |
| 1200 // Reload the model to verify that save/reload retains the item. | 1154 // Reload the model to verify that save/reload retains the item. |
| 1201 test_util_.ResetModel(true); | 1155 test_util_.ResetModel(true); |
| 1202 ASSERT_TRUE( | 1156 ASSERT_TRUE( |
| 1203 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); | 1157 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); |
| 1204 } | 1158 } |
| 1205 | 1159 |
| 1206 // Make sure that load routine doesn't delete | 1160 // Make sure that load routine doesn't delete |
| 1207 // prepopulated engines that no longer exist in the prepopulate data if | 1161 // prepopulated engines that no longer exist in the prepopulate data if |
| 1208 // it has been modified by the user. | 1162 // it has been modified by the user. |
| 1209 TEST_F(TemplateURLServiceTest, LoadSavesPrepopulatedDefaultSearchProvider) { | 1163 TEST_F(TemplateURLServiceTest, LoadSavesPrepopulatedDefaultSearchProvider) { |
| 1210 test_util_.VerifyLoad(); | 1164 test_util_.VerifyLoad(); |
| 1211 // Verify that the default search provider is set to something. | 1165 // Verify that the default search provider is set to something. |
| 1212 TemplateURL* default_search = model()->GetDefaultSearchProvider(); | 1166 TemplateURL* default_search = model()->GetDefaultSearchProvider(); |
| 1213 ASSERT_TRUE(default_search != NULL); | 1167 ASSERT_TRUE(default_search != NULL); |
| 1214 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(default_search->profile(), | 1168 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(default_search->profile(), |
| 1215 default_search->data())); | 1169 default_search->data())); |
| 1216 | 1170 |
| 1217 // Wait for any saves to finish. | 1171 // Wait for any saves to finish. |
| 1218 test_util_.BlockTillServiceProcessesRequests(); | 1172 base::RunLoop().RunUntilIdle(); |
| 1219 | 1173 |
| 1220 // Reload the model and check that the default search provider | 1174 // Reload the model and check that the default search provider |
| 1221 // was properly saved. | 1175 // was properly saved. |
| 1222 test_util_.ResetModel(true); | 1176 test_util_.ResetModel(true); |
| 1223 default_search = model()->GetDefaultSearchProvider(); | 1177 default_search = model()->GetDefaultSearchProvider(); |
| 1224 ASSERT_TRUE(default_search != NULL); | 1178 ASSERT_TRUE(default_search != NULL); |
| 1225 AssertEquals(*cloned_url, *default_search); | 1179 AssertEquals(*cloned_url, *default_search); |
| 1226 } | 1180 } |
| 1227 | 1181 |
| 1228 TEST_F(TemplateURLServiceTest, FindNewDefaultSearchProvider) { | 1182 TEST_F(TemplateURLServiceTest, FindNewDefaultSearchProvider) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 test_util_.ChangeModelToLoadState(); | 1226 test_util_.ChangeModelToLoadState(); |
| 1273 model()->Add(t_url); | 1227 model()->Add(t_url); |
| 1274 model()->SetDefaultSearchProvider(t_url); | 1228 model()->SetDefaultSearchProvider(t_url); |
| 1275 // Do the copy after t_url is added and set as default so that its | 1229 // Do the copy after t_url is added and set as default so that its |
| 1276 // internal state is correct. | 1230 // internal state is correct. |
| 1277 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), | 1231 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), |
| 1278 t_url->data())); | 1232 t_url->data())); |
| 1279 | 1233 |
| 1280 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); | 1234 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); |
| 1281 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); | 1235 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); |
| 1282 test_util_.BlockTillServiceProcessesRequests(); | 1236 base::RunLoop().RunUntilIdle(); |
| 1283 | 1237 |
| 1284 // Ensure that merging won't clear the prepopulated template url | 1238 // Ensure that merging won't clear the prepopulated template url |
| 1285 // which is no longer present if it's the default engine. | 1239 // which is no longer present if it's the default engine. |
| 1286 test_util_.ResetModel(true); | 1240 test_util_.ResetModel(true); |
| 1287 { | 1241 { |
| 1288 const TemplateURL* keyword_url = | 1242 const TemplateURL* keyword_url = |
| 1289 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 1243 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
| 1290 ASSERT_TRUE(keyword_url != NULL); | 1244 ASSERT_TRUE(keyword_url != NULL); |
| 1291 AssertEquals(*cloned_url, *keyword_url); | 1245 AssertEquals(*cloned_url, *keyword_url); |
| 1292 ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); | 1246 ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); |
| 1293 } | 1247 } |
| 1294 | 1248 |
| 1295 // Wait for any saves to finish. | 1249 // Wait for any saves to finish. |
| 1296 test_util_.BlockTillServiceProcessesRequests(); | 1250 base::RunLoop().RunUntilIdle(); |
| 1297 | 1251 |
| 1298 // Reload the model to verify that the update was saved. | 1252 // Reload the model to verify that the update was saved. |
| 1299 test_util_.ResetModel(true); | 1253 test_util_.ResetModel(true); |
| 1300 { | 1254 { |
| 1301 const TemplateURL* keyword_url = | 1255 const TemplateURL* keyword_url = |
| 1302 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 1256 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
| 1303 ASSERT_TRUE(keyword_url != NULL); | 1257 ASSERT_TRUE(keyword_url != NULL); |
| 1304 AssertEquals(*cloned_url, *keyword_url); | 1258 AssertEquals(*cloned_url, *keyword_url); |
| 1305 ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); | 1259 ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); |
| 1306 } | 1260 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1322 // missing and not managed. | 1276 // missing and not managed. |
| 1323 TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) { | 1277 TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) { |
| 1324 // Force the model to load and make sure we have a default search provider. | 1278 // Force the model to load and make sure we have a default search provider. |
| 1325 test_util_.VerifyLoad(); | 1279 test_util_.VerifyLoad(); |
| 1326 TemplateURL* old_default = model()->GetDefaultSearchProvider(); | 1280 TemplateURL* old_default = model()->GetDefaultSearchProvider(); |
| 1327 EXPECT_TRUE(old_default); | 1281 EXPECT_TRUE(old_default); |
| 1328 | 1282 |
| 1329 // Now remove it. | 1283 // Now remove it. |
| 1330 model()->SetDefaultSearchProvider(NULL); | 1284 model()->SetDefaultSearchProvider(NULL); |
| 1331 model()->Remove(old_default); | 1285 model()->Remove(old_default); |
| 1332 test_util_.BlockTillServiceProcessesRequests(); | 1286 base::RunLoop().RunUntilIdle(); |
| 1333 | 1287 |
| 1334 EXPECT_FALSE(model()->GetDefaultSearchProvider()); | 1288 EXPECT_FALSE(model()->GetDefaultSearchProvider()); |
| 1335 | 1289 |
| 1336 // Reset the model and load it. There should be a default search provider. | 1290 // Reset the model and load it. There should be a default search provider. |
| 1337 test_util_.ResetModel(true); | 1291 test_util_.ResetModel(true); |
| 1338 | 1292 |
| 1339 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 1293 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
| 1340 EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement()); | 1294 EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement()); |
| 1341 | 1295 |
| 1342 // Make default search provider unusable (no search terms). | 1296 // Make default search provider unusable (no search terms). |
| 1343 model()->ResetTemplateURL(model()->GetDefaultSearchProvider(), | 1297 model()->ResetTemplateURL(model()->GetDefaultSearchProvider(), |
| 1344 ASCIIToUTF16("test"), ASCIIToUTF16("test"), | 1298 ASCIIToUTF16("test"), ASCIIToUTF16("test"), |
| 1345 "http://example.com/"); | 1299 "http://example.com/"); |
| 1346 test_util_.BlockTillServiceProcessesRequests(); | 1300 base::RunLoop().RunUntilIdle(); |
| 1347 | 1301 |
| 1348 // Reset the model and load it. There should be a usable default search | 1302 // Reset the model and load it. There should be a usable default search |
| 1349 // provider. | 1303 // provider. |
| 1350 test_util_.ResetModel(true); | 1304 test_util_.ResetModel(true); |
| 1351 | 1305 |
| 1352 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 1306 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
| 1353 EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement()); | 1307 EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement()); |
| 1354 } | 1308 } |
| 1355 | 1309 |
| 1356 // Simulates failing to load the webdb and makes sure the default search | 1310 // Simulates failing to load the webdb and makes sure the default search |
| 1357 // provider is valid. | 1311 // provider is valid. |
| 1358 TEST_F(TemplateURLServiceTest, FailedInit) { | 1312 TEST_F(TemplateURLServiceTest, FailedInit) { |
| 1359 test_util_.VerifyLoad(); | 1313 test_util_.VerifyLoad(); |
| 1360 | 1314 |
| 1361 test_util_.ClearModel(); | 1315 test_util_.ClearModel(); |
| 1362 scoped_refptr<WebDataService> web_service = | 1316 scoped_refptr<WebDataService> web_service = |
| 1363 WebDataService::FromBrowserContext(test_util_.profile()); | 1317 WebDataService::FromBrowserContext(test_util_.profile()); |
| 1364 web_service->ShutdownDatabase(); | 1318 web_service->ShutdownDatabase(); |
| 1365 | 1319 |
| 1366 test_util_.ResetModel(false); | 1320 test_util_.ResetModel(false); |
| 1367 model()->Load(); | 1321 model()->Load(); |
| 1368 test_util_.BlockTillServiceProcessesRequests(); | 1322 base::RunLoop().RunUntilIdle(); |
| 1369 | 1323 |
| 1370 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 1324 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
| 1371 } | 1325 } |
| 1372 | 1326 |
| 1373 // Verifies that if the default search URL preference is managed, we report | 1327 // 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 | 1328 // the default search as managed. Also check that we are getting the right |
| 1375 // values. | 1329 // values. |
| 1376 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { | 1330 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { |
| 1377 test_util_.VerifyLoad(); | 1331 test_util_.VerifyLoad(); |
| 1378 const size_t initial_count = model()->GetTemplateURLs().size(); | 1332 const size_t initial_count = model()->GetTemplateURLs().size(); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 | 1468 |
| 1515 TemplateURLData data; | 1469 TemplateURLData data; |
| 1516 data.short_name = ASCIIToUTF16("google"); | 1470 data.short_name = ASCIIToUTF16("google"); |
| 1517 data.SetKeyword(ASCIIToUTF16("keyword")); | 1471 data.SetKeyword(ASCIIToUTF16("keyword")); |
| 1518 data.SetURL("http://www.google.com/foo/bar"); | 1472 data.SetURL("http://www.google.com/foo/bar"); |
| 1519 data.sync_guid.clear(); | 1473 data.sync_guid.clear(); |
| 1520 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); | 1474 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); |
| 1521 model()->Add(t_url); | 1475 model()->Add(t_url); |
| 1522 | 1476 |
| 1523 VerifyObserverCount(1); | 1477 VerifyObserverCount(1); |
| 1524 test_util_.BlockTillServiceProcessesRequests(); | 1478 base::RunLoop().RunUntilIdle(); |
| 1525 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1479 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 1526 | 1480 |
| 1527 // Reload the model to verify it was actually saved to the database and | 1481 // Reload the model to verify it was actually saved to the database and |
| 1528 // assigned a new GUID when brought back. | 1482 // assigned a new GUID when brought back. |
| 1529 test_util_.ResetModel(true); | 1483 test_util_.ResetModel(true); |
| 1530 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1484 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 1531 const TemplateURL* loaded_url = | 1485 const TemplateURL* loaded_url = |
| 1532 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1486 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
| 1533 ASSERT_FALSE(loaded_url == NULL); | 1487 ASSERT_FALSE(loaded_url == NULL); |
| 1534 ASSERT_FALSE(loaded_url->sync_guid().empty()); | 1488 ASSERT_FALSE(loaded_url->sync_guid().empty()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1551 data.input_encodings.push_back("UTF-16"); | 1505 data.input_encodings.push_back("UTF-16"); |
| 1552 data.input_encodings.push_back("UTF-8"); | 1506 data.input_encodings.push_back("UTF-8"); |
| 1553 data.input_encodings.push_back("Big5"); | 1507 data.input_encodings.push_back("Big5"); |
| 1554 data.input_encodings.push_back("UTF-16"); | 1508 data.input_encodings.push_back("UTF-16"); |
| 1555 data.input_encodings.push_back("Big5"); | 1509 data.input_encodings.push_back("Big5"); |
| 1556 data.input_encodings.push_back("Windows-1252"); | 1510 data.input_encodings.push_back("Windows-1252"); |
| 1557 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); | 1511 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); |
| 1558 model()->Add(t_url); | 1512 model()->Add(t_url); |
| 1559 | 1513 |
| 1560 VerifyObserverCount(1); | 1514 VerifyObserverCount(1); |
| 1561 test_util_.BlockTillServiceProcessesRequests(); | 1515 base::RunLoop().RunUntilIdle(); |
| 1562 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1516 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 1563 const TemplateURL* loaded_url = | 1517 const TemplateURL* loaded_url = |
| 1564 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1518 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
| 1565 ASSERT_TRUE(loaded_url != NULL); | 1519 ASSERT_TRUE(loaded_url != NULL); |
| 1566 EXPECT_EQ(8U, loaded_url->input_encodings().size()); | 1520 EXPECT_EQ(8U, loaded_url->input_encodings().size()); |
| 1567 | 1521 |
| 1568 // Reload the model to verify it was actually saved to the database and the | 1522 // Reload the model to verify it was actually saved to the database and the |
| 1569 // duplicate encodings were removed. | 1523 // duplicate encodings were removed. |
| 1570 test_util_.ResetModel(true); | 1524 test_util_.ResetModel(true); |
| 1571 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1525 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
| 1572 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1526 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
| 1573 ASSERT_FALSE(loaded_url == NULL); | 1527 ASSERT_FALSE(loaded_url == NULL); |
| 1574 EXPECT_EQ(4U, loaded_url->input_encodings().size()); | 1528 EXPECT_EQ(4U, loaded_url->input_encodings().size()); |
| 1575 } | 1529 } |
| OLD | NEW |