| 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 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 // Google is default. | 827 // Google is default. |
| 828 ASSERT_EQ(google, model()->GetDefaultSearchProvider()); | 828 ASSERT_EQ(google, model()->GetDefaultSearchProvider()); |
| 829 // The keyword wasn't reverted. | 829 // The keyword wasn't reverted. |
| 830 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name()); | 830 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name()); |
| 831 EXPECT_EQ("www.google.com", | 831 EXPECT_EQ("www.google.com", |
| 832 google->GenerateSearchURL(model()->search_terms_data()).host()); | 832 google->GenerateSearchURL(model()->search_terms_data()).host()); |
| 833 | 833 |
| 834 // Bing was repaired. | 834 // Bing was repaired. |
| 835 bing = model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com")); | 835 bing = model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com")); |
| 836 ASSERT_TRUE(bing); | 836 ASSERT_TRUE(bing); |
| 837 EXPECT_EQ(TemplateURL::NORMAL, bing->GetType()); | 837 EXPECT_EQ(TemplateURL::NORMAL, bing->type()); |
| 838 | 838 |
| 839 // User search engine is preserved. | 839 // User search engine is preserved. |
| 840 EXPECT_EQ(user_dse, model()->GetTemplateURLForHost("www.goo.com")); | 840 EXPECT_EQ(user_dse, model()->GetTemplateURLForHost("www.goo.com")); |
| 841 EXPECT_EQ(ASCIIToUTF16("google.com"), user_dse->keyword()); | 841 EXPECT_EQ(ASCIIToUTF16("google.com"), user_dse->keyword()); |
| 842 } | 842 } |
| 843 | 843 |
| 844 TEST_F(TemplateURLServiceTest, RepairSearchEnginesWithManagedDefault) { | 844 TEST_F(TemplateURLServiceTest, RepairSearchEnginesWithManagedDefault) { |
| 845 // Set a managed preference that establishes a default search provider. | 845 // Set a managed preference that establishes a default search provider. |
| 846 const char kName[] = "test1"; | 846 const char kName[] = "test1"; |
| 847 const char kKeyword[] = "test.com"; | 847 const char kKeyword[] = "test.com"; |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1410 std::string(), std::string(), std::string(), | 1410 std::string(), std::string(), std::string(), |
| 1411 true, "UTF-8", Time(), Time()); | 1411 true, "UTF-8", Time(), Time()); |
| 1412 model()->SetUserSelectedDefaultSearchProvider(user_dse); | 1412 model()->SetUserSelectedDefaultSearchProvider(user_dse); |
| 1413 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1413 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
| 1414 | 1414 |
| 1415 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( | 1415 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( |
| 1416 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}", | 1416 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}", |
| 1417 std::string(), std::string(), std::string(), true, true, "UTF-8", Time(), | 1417 std::string(), std::string(), std::string(), true, true, "UTF-8", Time(), |
| 1418 Time()); | 1418 Time()); |
| 1419 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1419 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
| 1420 new TemplateURL::AssociatedExtensionInfo( | 1420 new TemplateURL::AssociatedExtensionInfo("ext")); |
| 1421 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext")); | |
| 1422 extension_info->wants_to_be_default_engine = true; | 1421 extension_info->wants_to_be_default_engine = true; |
| 1423 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( | 1422 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( |
| 1424 std::move(ext_dse), std::move(extension_info)); | 1423 std::move(ext_dse), std::move(extension_info)); |
| 1425 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); | 1424 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); |
| 1426 | 1425 |
| 1427 model()->RemoveExtensionControlledTURL( | 1426 model()->RemoveExtensionControlledTURL( |
| 1428 "ext", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1427 "ext", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); |
| 1429 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); | 1428 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); |
| 1430 } | 1429 } |
| 1431 | 1430 |
| 1432 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) { | 1431 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) { |
| 1433 test_util()->VerifyLoad(); | 1432 test_util()->VerifyLoad(); |
| 1434 // Add third-party default search engine. | 1433 // Add third-party default search engine. |
| 1435 TemplateURL* user_dse = AddKeywordWithDate( | 1434 TemplateURL* user_dse = AddKeywordWithDate( |
| 1436 "user", "user", "http://www.goo.com/s?q={searchTerms}", | 1435 "user", "user", "http://www.goo.com/s?q={searchTerms}", |
| 1437 std::string(), std::string(), std::string(), | 1436 std::string(), std::string(), std::string(), |
| 1438 true, "UTF-8", Time(), Time()); | 1437 true, "UTF-8", Time(), Time()); |
| 1439 model()->SetUserSelectedDefaultSearchProvider(user_dse); | 1438 model()->SetUserSelectedDefaultSearchProvider(user_dse); |
| 1440 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1439 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
| 1441 | 1440 |
| 1442 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( | 1441 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( |
| 1443 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", | 1442 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", |
| 1444 std::string(), std::string(), std::string(), true, false, "UTF-8", Time(), | 1443 std::string(), std::string(), std::string(), true, false, "UTF-8", Time(), |
| 1445 Time()); | 1444 Time()); |
| 1446 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1445 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
| 1447 new TemplateURL::AssociatedExtensionInfo( | 1446 new TemplateURL::AssociatedExtensionInfo("ext1")); |
| 1448 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); | |
| 1449 extension_info->wants_to_be_default_engine = false; | 1447 extension_info->wants_to_be_default_engine = false; |
| 1450 model()->AddExtensionControlledTURL(std::move(ext_dse), | 1448 model()->AddExtensionControlledTURL(std::move(ext_dse), |
| 1451 std::move(extension_info)); | 1449 std::move(extension_info)); |
| 1452 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1450 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
| 1453 | 1451 |
| 1454 ext_dse = CreateKeywordWithDate(model(), "ext2", "ext2", | 1452 ext_dse = CreateKeywordWithDate(model(), "ext2", "ext2", |
| 1455 "http://www.ext2.com/s?q={searchTerms}", | 1453 "http://www.ext2.com/s?q={searchTerms}", |
| 1456 std::string(), std::string(), std::string(), | 1454 std::string(), std::string(), std::string(), |
| 1457 true, true, "UTF-8", Time(), Time()); | 1455 true, true, "UTF-8", Time(), Time()); |
| 1458 extension_info.reset(new TemplateURL::AssociatedExtensionInfo( | 1456 extension_info.reset(new TemplateURL::AssociatedExtensionInfo("ext2")); |
| 1459 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext2")); | |
| 1460 extension_info->wants_to_be_default_engine = true; | 1457 extension_info->wants_to_be_default_engine = true; |
| 1461 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( | 1458 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( |
| 1462 std::move(ext_dse), std::move(extension_info)); | 1459 std::move(ext_dse), std::move(extension_info)); |
| 1463 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); | 1460 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); |
| 1464 | 1461 |
| 1465 test_util()->ResetModel(true); | 1462 test_util()->ResetModel(true); |
| 1466 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); | 1463 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); |
| 1467 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); | 1464 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); |
| 1468 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1465 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
| 1469 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext2"))); | 1466 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext2"))); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1497 EXPECT_TRUE(model()->is_default_search_managed()); | 1494 EXPECT_TRUE(model()->is_default_search_managed()); |
| 1498 const TemplateURL* actual_managed_default = | 1495 const TemplateURL* actual_managed_default = |
| 1499 model()->GetDefaultSearchProvider(); | 1496 model()->GetDefaultSearchProvider(); |
| 1500 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1497 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
| 1501 | 1498 |
| 1502 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( | 1499 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( |
| 1503 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", | 1500 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", |
| 1504 std::string(), std::string(), std::string(), true, true, "UTF-8", Time(), | 1501 std::string(), std::string(), std::string(), true, true, "UTF-8", Time(), |
| 1505 Time()); | 1502 Time()); |
| 1506 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1503 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
| 1507 new TemplateURL::AssociatedExtensionInfo( | 1504 new TemplateURL::AssociatedExtensionInfo("ext1")); |
| 1508 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); | |
| 1509 extension_info->wants_to_be_default_engine = true; | 1505 extension_info->wants_to_be_default_engine = true; |
| 1510 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( | 1506 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( |
| 1511 std::move(ext_dse), std::move(extension_info)); | 1507 std::move(ext_dse), std::move(extension_info)); |
| 1512 EXPECT_EQ(ext_dse_ptr, | 1508 EXPECT_EQ(ext_dse_ptr, |
| 1513 model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1509 model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
| 1514 EXPECT_TRUE(model()->is_default_search_managed()); | 1510 EXPECT_TRUE(model()->is_default_search_managed()); |
| 1515 actual_managed_default = model()->GetDefaultSearchProvider(); | 1511 actual_managed_default = model()->GetDefaultSearchProvider(); |
| 1516 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1512 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
| 1517 } | 1513 } |
| OLD | NEW |