Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: chrome/browser/search_engines/template_url_service_unittest.cc

Issue 2347973002: Enable Chrome to tweak search engines for some locales (Closed)
Patch Set: final nits Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 const std::string& short_name, 66 const std::string& short_name,
67 const std::string& keyword, 67 const std::string& keyword,
68 const std::string& url, 68 const std::string& url,
69 const std::string& suggest_url, 69 const std::string& suggest_url,
70 const std::string& alternate_url, 70 const std::string& alternate_url,
71 const std::string& favicon_url, 71 const std::string& favicon_url,
72 bool safe_for_autoreplace, 72 bool safe_for_autoreplace,
73 bool show_in_default_list, 73 bool show_in_default_list,
74 const std::string& encodings, 74 const std::string& encodings,
75 Time date_created, 75 Time date_created,
76 Time last_modified) { 76 Time last_modified,
77 TemplateURL::Type type = TemplateURL::NORMAL) {
77 TemplateURLData data; 78 TemplateURLData data;
78 data.SetShortName(base::UTF8ToUTF16(short_name)); 79 data.SetShortName(base::UTF8ToUTF16(short_name));
79 data.SetKeyword(base::UTF8ToUTF16(keyword)); 80 data.SetKeyword(base::UTF8ToUTF16(keyword));
80 data.SetURL(url); 81 data.SetURL(url);
81 data.suggestions_url = suggest_url; 82 data.suggestions_url = suggest_url;
82 if (!alternate_url.empty()) 83 if (!alternate_url.empty())
83 data.alternate_urls.push_back(alternate_url); 84 data.alternate_urls.push_back(alternate_url);
84 data.favicon_url = GURL(favicon_url); 85 data.favicon_url = GURL(favicon_url);
85 data.safe_for_autoreplace = safe_for_autoreplace; 86 data.safe_for_autoreplace = safe_for_autoreplace;
86 data.show_in_default_list = show_in_default_list; 87 data.show_in_default_list = show_in_default_list;
87 data.input_encodings = base::SplitString( 88 data.input_encodings = base::SplitString(
88 encodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 89 encodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
89 data.date_created = date_created; 90 data.date_created = date_created;
90 data.last_modified = last_modified; 91 data.last_modified = last_modified;
91 return base::MakeUnique<TemplateURL>(data); 92 return base::MakeUnique<TemplateURL>(data, type);
92 } 93 }
93 94
94 TemplateURL* AddKeywordWithDate( 95 TemplateURL* AddKeywordWithDate(
95 TemplateURLService* model, 96 TemplateURLService* model,
96 const std::string& short_name, 97 const std::string& short_name,
97 const std::string& keyword, 98 const std::string& keyword,
98 const std::string& url, 99 const std::string& url,
99 const std::string& suggest_url, 100 const std::string& suggest_url,
100 const std::string& alternate_url, 101 const std::string& alternate_url,
101 const std::string& favicon_url, 102 const std::string& favicon_url,
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 // Google is default. 828 // Google is default.
828 ASSERT_EQ(google, model()->GetDefaultSearchProvider()); 829 ASSERT_EQ(google, model()->GetDefaultSearchProvider());
829 // The keyword wasn't reverted. 830 // The keyword wasn't reverted.
830 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name()); 831 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name());
831 EXPECT_EQ("www.google.com", 832 EXPECT_EQ("www.google.com",
832 google->GenerateSearchURL(model()->search_terms_data()).host()); 833 google->GenerateSearchURL(model()->search_terms_data()).host());
833 834
834 // Bing was repaired. 835 // Bing was repaired.
835 bing = model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com")); 836 bing = model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"));
836 ASSERT_TRUE(bing); 837 ASSERT_TRUE(bing);
837 EXPECT_EQ(TemplateURL::NORMAL, bing->GetType()); 838 EXPECT_EQ(TemplateURL::NORMAL, bing->type());
838 839
839 // User search engine is preserved. 840 // User search engine is preserved.
840 EXPECT_EQ(user_dse, model()->GetTemplateURLForHost("www.goo.com")); 841 EXPECT_EQ(user_dse, model()->GetTemplateURLForHost("www.goo.com"));
841 EXPECT_EQ(ASCIIToUTF16("google.com"), user_dse->keyword()); 842 EXPECT_EQ(ASCIIToUTF16("google.com"), user_dse->keyword());
842 } 843 }
843 844
844 TEST_F(TemplateURLServiceTest, RepairSearchEnginesWithManagedDefault) { 845 TEST_F(TemplateURLServiceTest, RepairSearchEnginesWithManagedDefault) {
845 // Set a managed preference that establishes a default search provider. 846 // Set a managed preference that establishes a default search provider.
846 const char kName[] = "test1"; 847 const char kName[] = "test1";
847 const char kKeyword[] = "test.com"; 848 const char kKeyword[] = "test.com";
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 TemplateURL* user_dse = AddKeywordWithDate( 1409 TemplateURL* user_dse = AddKeywordWithDate(
1409 "user", "user", "http://www.goo.com/s?q={searchTerms}", 1410 "user", "user", "http://www.goo.com/s?q={searchTerms}",
1410 std::string(), std::string(), std::string(), 1411 std::string(), std::string(), std::string(),
1411 true, "UTF-8", Time(), Time()); 1412 true, "UTF-8", Time(), Time());
1412 model()->SetUserSelectedDefaultSearchProvider(user_dse); 1413 model()->SetUserSelectedDefaultSearchProvider(user_dse);
1413 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); 1414 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider());
1414 1415
1415 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( 1416 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate(
1416 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}", 1417 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}",
1417 std::string(), std::string(), std::string(), true, true, "UTF-8", Time(), 1418 std::string(), std::string(), std::string(), true, true, "UTF-8", Time(),
1418 Time()); 1419 Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
1419 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( 1420 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info(
1420 new TemplateURL::AssociatedExtensionInfo( 1421 new TemplateURL::AssociatedExtensionInfo("ext"));
1421 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext"));
1422 extension_info->wants_to_be_default_engine = true; 1422 extension_info->wants_to_be_default_engine = true;
1423 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( 1423 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL(
1424 std::move(ext_dse), std::move(extension_info)); 1424 std::move(ext_dse), std::move(extension_info));
1425 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); 1425 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider());
1426 1426
1427 model()->RemoveExtensionControlledTURL( 1427 model()->RemoveExtensionControlledTURL(
1428 "ext", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); 1428 "ext", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
1429 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); 1429 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider());
1430 } 1430 }
1431 1431
1432 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) { 1432 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) {
1433 test_util()->VerifyLoad(); 1433 test_util()->VerifyLoad();
1434 // Add third-party default search engine. 1434 // Add third-party default search engine.
1435 TemplateURL* user_dse = AddKeywordWithDate( 1435 TemplateURL* user_dse = AddKeywordWithDate(
1436 "user", "user", "http://www.goo.com/s?q={searchTerms}", 1436 "user", "user", "http://www.goo.com/s?q={searchTerms}",
1437 std::string(), std::string(), std::string(), 1437 std::string(), std::string(), std::string(),
1438 true, "UTF-8", Time(), Time()); 1438 true, "UTF-8", Time(), Time());
1439 model()->SetUserSelectedDefaultSearchProvider(user_dse); 1439 model()->SetUserSelectedDefaultSearchProvider(user_dse);
1440 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); 1440 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider());
1441 1441
1442 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( 1442 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate(
1443 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", 1443 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}",
1444 std::string(), std::string(), std::string(), true, false, "UTF-8", Time(), 1444 std::string(), std::string(), std::string(), true, false, "UTF-8", Time(),
1445 Time()); 1445 Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
1446 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( 1446 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info(
1447 new TemplateURL::AssociatedExtensionInfo( 1447 new TemplateURL::AssociatedExtensionInfo("ext1"));
1448 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1"));
1449 extension_info->wants_to_be_default_engine = false; 1448 extension_info->wants_to_be_default_engine = false;
1450 model()->AddExtensionControlledTURL(std::move(ext_dse), 1449 model()->AddExtensionControlledTURL(std::move(ext_dse),
1451 std::move(extension_info)); 1450 std::move(extension_info));
1452 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); 1451 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider());
1453 1452
1454 ext_dse = CreateKeywordWithDate(model(), "ext2", "ext2", 1453 ext_dse = CreateKeywordWithDate(
1455 "http://www.ext2.com/s?q={searchTerms}", 1454 model(), "ext2", "ext2", "http://www.ext2.com/s?q={searchTerms}",
1456 std::string(), std::string(), std::string(), 1455 std::string(), std::string(), std::string(), true, true, "UTF-8", Time(),
1457 true, true, "UTF-8", Time(), Time()); 1456 Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
1458 extension_info.reset(new TemplateURL::AssociatedExtensionInfo( 1457 extension_info.reset(new TemplateURL::AssociatedExtensionInfo("ext2"));
1459 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext2"));
1460 extension_info->wants_to_be_default_engine = true; 1458 extension_info->wants_to_be_default_engine = true;
1461 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( 1459 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL(
1462 std::move(ext_dse), std::move(extension_info)); 1460 std::move(ext_dse), std::move(extension_info));
1463 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); 1461 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider());
1464 1462
1465 test_util()->ResetModel(true); 1463 test_util()->ResetModel(true);
1466 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); 1464 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user"));
1467 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); 1465 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider());
1468 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); 1466 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1")));
1469 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext2"))); 1467 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext2")));
(...skipping 25 matching lines...) Expand all
1495 data.search_terms_replacement_key = kSearchTermsReplacementKey; 1493 data.search_terms_replacement_key = kSearchTermsReplacementKey;
1496 std::unique_ptr<TemplateURL> expected_managed_default(new TemplateURL(data)); 1494 std::unique_ptr<TemplateURL> expected_managed_default(new TemplateURL(data));
1497 EXPECT_TRUE(model()->is_default_search_managed()); 1495 EXPECT_TRUE(model()->is_default_search_managed());
1498 const TemplateURL* actual_managed_default = 1496 const TemplateURL* actual_managed_default =
1499 model()->GetDefaultSearchProvider(); 1497 model()->GetDefaultSearchProvider();
1500 ExpectSimilar(expected_managed_default.get(), actual_managed_default); 1498 ExpectSimilar(expected_managed_default.get(), actual_managed_default);
1501 1499
1502 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( 1500 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate(
1503 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", 1501 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}",
1504 std::string(), std::string(), std::string(), true, true, "UTF-8", Time(), 1502 std::string(), std::string(), std::string(), true, true, "UTF-8", Time(),
1505 Time()); 1503 Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
1506 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( 1504 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info(
1507 new TemplateURL::AssociatedExtensionInfo( 1505 new TemplateURL::AssociatedExtensionInfo("ext1"));
1508 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1"));
1509 extension_info->wants_to_be_default_engine = true; 1506 extension_info->wants_to_be_default_engine = true;
1510 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( 1507 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL(
1511 std::move(ext_dse), std::move(extension_info)); 1508 std::move(ext_dse), std::move(extension_info));
1512 EXPECT_EQ(ext_dse_ptr, 1509 EXPECT_EQ(ext_dse_ptr,
1513 model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); 1510 model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1")));
1514 EXPECT_TRUE(model()->is_default_search_managed()); 1511 EXPECT_TRUE(model()->is_default_search_managed());
1515 actual_managed_default = model()->GetDefaultSearchProvider(); 1512 actual_managed_default = model()->GetDefaultSearchProvider();
1516 ExpectSimilar(expected_managed_default.get(), actual_managed_default); 1513 ExpectSimilar(expected_managed_default.get(), actual_managed_default);
1517 } 1514 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698