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 "components/search_engines/template_url_service.h" | 5 #include "components/search_engines/template_url_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 AddKeywordWithDate("name3", "key3", "http://foo3", std::string(), | 587 AddKeywordWithDate("name3", "key3", "http://foo3", std::string(), |
588 std::string(), std::string(), true, std::string(), | 588 std::string(), std::string(), true, std::string(), |
589 now + one_day, Time()); | 589 now + one_day, Time()); |
590 | 590 |
591 // We just added a few items, validate them. | 591 // We just added a few items, validate them. |
592 EXPECT_EQ(3U, model()->GetTemplateURLs().size()); | 592 EXPECT_EQ(3U, model()->GetTemplateURLs().size()); |
593 | 593 |
594 // Try removing foo2. This should delete foo2, but leave foo1 and 3 untouched. | 594 // Try removing foo2. This should delete foo2, but leave foo1 and 3 untouched. |
595 GURL url2("http://foo2"); | 595 GURL url2("http://foo2"); |
596 model()->RemoveAutoGeneratedForUrlsBetween( | 596 model()->RemoveAutoGeneratedForUrlsBetween( |
597 base::Bind(&GURL::operator==, base::Unretained(&url2)), month_ago, | 597 base::Bind(static_cast<bool (*)(const GURL&, const GURL&)>(operator==), |
598 now + one_day); | 598 url2), |
| 599 month_ago, now + one_day); |
599 EXPECT_EQ(2U, model()->GetTemplateURLs().size()); | 600 EXPECT_EQ(2U, model()->GetTemplateURLs().size()); |
600 EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword()); | 601 EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword()); |
601 EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace()); | 602 EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace()); |
602 EXPECT_EQ(ASCIIToUTF16("key3"), model()->GetTemplateURLs()[1]->keyword()); | 603 EXPECT_EQ(ASCIIToUTF16("key3"), model()->GetTemplateURLs()[1]->keyword()); |
603 EXPECT_TRUE(model()->GetTemplateURLs()[1]->safe_for_autoreplace()); | 604 EXPECT_TRUE(model()->GetTemplateURLs()[1]->safe_for_autoreplace()); |
604 | 605 |
605 // Try removing foo1, but outside the range in which it was modified. It | 606 // Try removing foo1, but outside the range in which it was modified. It |
606 // should remain untouched. | 607 // should remain untouched. |
607 GURL url1("http://foo1"); | 608 GURL url1("http://foo1"); |
608 model()->RemoveAutoGeneratedForUrlsBetween( | 609 model()->RemoveAutoGeneratedForUrlsBetween( |
609 base::Bind(&GURL::operator==, base::Unretained(&url1)), now, | 610 base::Bind(static_cast<bool (*)(const GURL&, const GURL&)>(operator==), |
610 now + one_day); | 611 url1), |
| 612 now, now + one_day); |
611 EXPECT_EQ(2U, model()->GetTemplateURLs().size()); | 613 EXPECT_EQ(2U, model()->GetTemplateURLs().size()); |
612 EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword()); | 614 EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword()); |
613 EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace()); | 615 EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace()); |
614 EXPECT_EQ(ASCIIToUTF16("key3"), model()->GetTemplateURLs()[1]->keyword()); | 616 EXPECT_EQ(ASCIIToUTF16("key3"), model()->GetTemplateURLs()[1]->keyword()); |
615 EXPECT_TRUE(model()->GetTemplateURLs()[1]->safe_for_autoreplace()); | 617 EXPECT_TRUE(model()->GetTemplateURLs()[1]->safe_for_autoreplace()); |
616 | 618 |
617 // Try removing foo3. This should delete foo3, but leave foo1 untouched. | 619 // Try removing foo3. This should delete foo3, but leave foo1 untouched. |
618 GURL url3("http://foo3"); | 620 GURL url3("http://foo3"); |
619 model()->RemoveAutoGeneratedForUrlsBetween( | 621 model()->RemoveAutoGeneratedForUrlsBetween( |
620 base::Bind(&GURL::operator==, base::Unretained(&url3)), month_ago, | 622 base::Bind(static_cast<bool (*)(const GURL&, const GURL&)>(operator==), |
621 now + one_day + one_day); | 623 url3), |
| 624 month_ago, now + one_day + one_day); |
622 EXPECT_EQ(1U, model()->GetTemplateURLs().size()); | 625 EXPECT_EQ(1U, model()->GetTemplateURLs().size()); |
623 EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword()); | 626 EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword()); |
624 EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace()); | 627 EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace()); |
625 } | 628 } |
626 | 629 |
627 TEST_F(TemplateURLServiceTest, Reset) { | 630 TEST_F(TemplateURLServiceTest, Reset) { |
628 // Add a new TemplateURL. | 631 // Add a new TemplateURL. |
629 test_util()->VerifyLoad(); | 632 test_util()->VerifyLoad(); |
630 const size_t initial_count = model()->GetTemplateURLs().size(); | 633 const size_t initial_count = model()->GetTemplateURLs().size(); |
631 TemplateURLData data; | 634 TemplateURLData data; |
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1505 new TemplateURL::AssociatedExtensionInfo("ext1")); | 1508 new TemplateURL::AssociatedExtensionInfo("ext1")); |
1506 extension_info->wants_to_be_default_engine = true; | 1509 extension_info->wants_to_be_default_engine = true; |
1507 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( | 1510 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( |
1508 std::move(ext_dse), std::move(extension_info)); | 1511 std::move(ext_dse), std::move(extension_info)); |
1509 EXPECT_EQ(ext_dse_ptr, | 1512 EXPECT_EQ(ext_dse_ptr, |
1510 model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1513 model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
1511 EXPECT_TRUE(model()->is_default_search_managed()); | 1514 EXPECT_TRUE(model()->is_default_search_managed()); |
1512 actual_managed_default = model()->GetDefaultSearchProvider(); | 1515 actual_managed_default = model()->GetDefaultSearchProvider(); |
1513 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1516 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
1514 } | 1517 } |
OLD | NEW |