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

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

Issue 231863008: Rename SetDefaultSearchProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 8 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 | Annotate | Revision Log
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 "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/run_loop.h"
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 786
787 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) { 787 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) {
788 // Add a new TemplateURL. 788 // Add a new TemplateURL.
789 test_util_.VerifyLoad(); 789 test_util_.VerifyLoad();
790 const size_t initial_count = model()->GetTemplateURLs().size(); 790 const size_t initial_count = model()->GetTemplateURLs().size();
791 TemplateURL* t_url = AddKeywordWithDate( 791 TemplateURL* t_url = AddKeywordWithDate(
792 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1", 792 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1",
793 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); 793 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time());
794 test_util_.ResetObserverCount(); 794 test_util_.ResetObserverCount();
795 795
796 model()->SetDefaultSearchProvider(t_url); 796 model()->SetUserSelectedDefaultSearchProvider(t_url);
797 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); 797 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider());
798 ASSERT_TRUE(t_url->safe_for_autoreplace()); 798 ASSERT_TRUE(t_url->safe_for_autoreplace());
799 ASSERT_TRUE(t_url->show_in_default_list()); 799 ASSERT_TRUE(t_url->show_in_default_list());
800 800
801 // Setting the default search provider should have caused notification. 801 // Setting the default search provider should have caused notification.
802 VerifyObserverCount(1); 802 VerifyObserverCount(1);
803 base::RunLoop().RunUntilIdle(); 803 base::RunLoop().RunUntilIdle();
804 804
805 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), 805 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(),
806 t_url->data())); 806 t_url->data()));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 data.safe_for_autoreplace = true; 871 data.safe_for_autoreplace = true;
872 data.SetURL("http://url/{searchTerms}"); 872 data.SetURL("http://url/{searchTerms}");
873 data.suggestions_url = "http://url2"; 873 data.suggestions_url = "http://url2";
874 data.instant_url = "http://instant"; 874 data.instant_url = "http://instant";
875 data.date_created = Time::FromTimeT(100); 875 data.date_created = Time::FromTimeT(100);
876 data.last_modified = Time::FromTimeT(100); 876 data.last_modified = Time::FromTimeT(100);
877 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); 877 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data);
878 model()->Add(t_url); 878 model()->Add(t_url);
879 const TemplateURLID id = t_url->id(); 879 const TemplateURLID id = t_url->id();
880 880
881 model()->SetDefaultSearchProvider(t_url); 881 model()->SetUserSelectedDefaultSearchProvider(t_url);
882 base::RunLoop().RunUntilIdle(); 882 base::RunLoop().RunUntilIdle();
883 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), 883 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(),
884 t_url->data())); 884 t_url->data()));
885 885
886 // Reset the model and don't load it. The template url we set as the default 886 // Reset the model and don't load it. The template url we set as the default
887 // should be pulled from prefs now. 887 // should be pulled from prefs now.
888 test_util_.ResetModel(false); 888 test_util_.ResetModel(false);
889 889
890 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs 890 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs
891 // value are persisted to prefs. 891 // value are persisted to prefs.
(...skipping 22 matching lines...) Expand all
914 model()->ResetTemplateURL(google, ASCIIToUTF16("trash"), ASCIIToUTF16("xxx"), 914 model()->ResetTemplateURL(google, ASCIIToUTF16("trash"), ASCIIToUTF16("xxx"),
915 "http://www.foo.com/s?q={searchTerms}"); 915 "http://www.foo.com/s?q={searchTerms}");
916 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name()); 916 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name());
917 EXPECT_EQ(ASCIIToUTF16("xxx"), google->keyword()); 917 EXPECT_EQ(ASCIIToUTF16("xxx"), google->keyword());
918 918
919 // Add third-party default search engine. 919 // Add third-party default search engine.
920 TemplateURL* user_dse = AddKeywordWithDate( 920 TemplateURL* user_dse = AddKeywordWithDate(
921 "malware", "google.com", "http://www.goo.com/s?q={searchTerms}", 921 "malware", "google.com", "http://www.goo.com/s?q={searchTerms}",
922 std::string(), std::string(), std::string(), 922 std::string(), std::string(), std::string(),
923 true, "UTF-8", Time(), Time()); 923 true, "UTF-8", Time(), Time());
924 model()->SetDefaultSearchProvider(user_dse); 924 model()->SetUserSelectedDefaultSearchProvider(user_dse);
925 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); 925 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider());
926 926
927 // Remove bing. 927 // Remove bing.
928 TemplateURL* bing = model()->GetTemplateURLForKeyword( 928 TemplateURL* bing = model()->GetTemplateURLForKeyword(
929 ASCIIToUTF16("bing.com")); 929 ASCIIToUTF16("bing.com"));
930 ASSERT_TRUE(bing); 930 ASSERT_TRUE(bing);
931 model()->Remove(bing); 931 model()->Remove(bing);
932 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); 932 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com")));
933 933
934 // Register an extension with bing keyword. 934 // Register an extension with bing keyword.
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 // Make sure that the load routine doesn't delete 1268 // Make sure that the load routine doesn't delete
1269 // prepopulated engines that no longer exist in the prepopulate data if 1269 // prepopulated engines that no longer exist in the prepopulate data if
1270 // it is the default search provider. 1270 // it is the default search provider.
1271 TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) { 1271 TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) {
1272 // Set the default search provider to a preloaded template url which 1272 // Set the default search provider to a preloaded template url which
1273 // is not in the current set of preloaded template urls and save 1273 // is not in the current set of preloaded template urls and save
1274 // the result. 1274 // the result.
1275 TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999); 1275 TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999);
1276 test_util_.ChangeModelToLoadState(); 1276 test_util_.ChangeModelToLoadState();
1277 model()->Add(t_url); 1277 model()->Add(t_url);
1278 model()->SetDefaultSearchProvider(t_url); 1278 model()->SetUserSelectedDefaultSearchProvider(t_url);
1279 // Do the copy after t_url is added and set as default so that its 1279 // Do the copy after t_url is added and set as default so that its
1280 // internal state is correct. 1280 // internal state is correct.
1281 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), 1281 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(),
1282 t_url->data())); 1282 t_url->data()));
1283 1283
1284 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); 1284 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")));
1285 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); 1285 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider());
1286 base::RunLoop().RunUntilIdle(); 1286 base::RunLoop().RunUntilIdle();
1287 1287
1288 // Ensure that merging won't clear the prepopulated template url 1288 // Ensure that merging won't clear the prepopulated template url
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 1324
1325 // Make sure that the load routine sets a default search provider if it was 1325 // Make sure that the load routine sets a default search provider if it was
1326 // missing and not managed. 1326 // missing and not managed.
1327 TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) { 1327 TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) {
1328 // Force the model to load and make sure we have a default search provider. 1328 // Force the model to load and make sure we have a default search provider.
1329 test_util_.VerifyLoad(); 1329 test_util_.VerifyLoad();
1330 TemplateURL* old_default = model()->GetDefaultSearchProvider(); 1330 TemplateURL* old_default = model()->GetDefaultSearchProvider();
1331 EXPECT_TRUE(old_default); 1331 EXPECT_TRUE(old_default);
1332 1332
1333 // Now remove it. 1333 // Now remove it.
1334 model()->SetDefaultSearchProvider(NULL); 1334 model()->SetUserSelectedDefaultSearchProvider(NULL);
1335 model()->Remove(old_default); 1335 model()->Remove(old_default);
1336 base::RunLoop().RunUntilIdle(); 1336 base::RunLoop().RunUntilIdle();
1337 1337
1338 EXPECT_FALSE(model()->GetDefaultSearchProvider()); 1338 EXPECT_FALSE(model()->GetDefaultSearchProvider());
1339 1339
1340 // Reset the model and load it. There should be a default search provider. 1340 // Reset the model and load it. There should be a default search provider.
1341 test_util_.ResetModel(true); 1341 test_util_.ResetModel(true);
1342 1342
1343 ASSERT_TRUE(model()->GetDefaultSearchProvider()); 1343 ASSERT_TRUE(model()->GetDefaultSearchProvider());
1344 EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement()); 1344 EXPECT_TRUE(model()->GetDefaultSearchProvider()->SupportsReplacement());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { 1380 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) {
1381 test_util_.VerifyLoad(); 1381 test_util_.VerifyLoad();
1382 const size_t initial_count = model()->GetTemplateURLs().size(); 1382 const size_t initial_count = model()->GetTemplateURLs().size();
1383 test_util_.ResetObserverCount(); 1383 test_util_.ResetObserverCount();
1384 1384
1385 // Set a regular default search provider. 1385 // Set a regular default search provider.
1386 TemplateURL* regular_default = AddKeywordWithDate( 1386 TemplateURL* regular_default = AddKeywordWithDate(
1387 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1", 1387 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1",
1388 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); 1388 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time());
1389 VerifyObserverCount(1); 1389 VerifyObserverCount(1);
1390 model()->SetDefaultSearchProvider(regular_default); 1390 model()->SetUserSelectedDefaultSearchProvider(regular_default);
1391 // Adding the URL and setting the default search provider should have caused 1391 // Adding the URL and setting the default search provider should have caused
1392 // notifications. 1392 // notifications.
1393 VerifyObserverCount(1); 1393 VerifyObserverCount(1);
1394 EXPECT_FALSE(model()->is_default_search_managed()); 1394 EXPECT_FALSE(model()->is_default_search_managed());
1395 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 1395 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
1396 1396
1397 // Set a managed preference that establishes a default search provider. 1397 // Set a managed preference that establishes a default search provider.
1398 const char kName[] = "test1"; 1398 const char kName[] = "test1";
1399 const char kKeyword[] = "test.com"; 1399 const char kKeyword[] = "test.com";
1400 const char kSearchURL[] = "http://test.com/search?t={searchTerms}"; 1400 const char kSearchURL[] = "http://test.com/search?t={searchTerms}";
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 // Clear the model and disable the default search provider through policy. 1489 // Clear the model and disable the default search provider through policy.
1490 // Verify that there is no default search provider after loading the model. 1490 // Verify that there is no default search provider after loading the model.
1491 // This checks against regressions of http://crbug.com/67180 1491 // This checks against regressions of http://crbug.com/67180
1492 1492
1493 // First, remove the preferences, reset the model, and set a default. 1493 // First, remove the preferences, reset the model, and set a default.
1494 test_util_.RemoveManagedDefaultSearchPreferences(); 1494 test_util_.RemoveManagedDefaultSearchPreferences();
1495 test_util_.ResetModel(true); 1495 test_util_.ResetModel(true);
1496 TemplateURL* new_default = 1496 TemplateURL* new_default =
1497 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); 1497 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1"));
1498 ASSERT_FALSE(new_default == NULL); 1498 ASSERT_FALSE(new_default == NULL);
1499 model()->SetDefaultSearchProvider(new_default); 1499 model()->SetUserSelectedDefaultSearchProvider(new_default);
1500 EXPECT_EQ(new_default, model()->GetDefaultSearchProvider()); 1500 EXPECT_EQ(new_default, model()->GetDefaultSearchProvider());
1501 1501
1502 // Now reset the model again but load it after setting the preferences. 1502 // Now reset the model again but load it after setting the preferences.
1503 test_util_.ResetModel(false); 1503 test_util_.ResetModel(false);
1504 test_util_.SetManagedDefaultSearchPreferences(false, std::string(), 1504 test_util_.SetManagedDefaultSearchPreferences(false, std::string(),
1505 std::string(), std::string(), std::string(), std::string(), 1505 std::string(), std::string(), std::string(), std::string(),
1506 std::string(), std::string(), std::string()); 1506 std::string(), std::string(), std::string());
1507 test_util_.VerifyLoad(); 1507 test_util_.VerifyLoad();
1508 EXPECT_TRUE(model()->is_default_search_managed()); 1508 EXPECT_TRUE(model()->is_default_search_managed());
1509 EXPECT_TRUE(model()->GetDefaultSearchProvider() == NULL); 1509 EXPECT_TRUE(model()->GetDefaultSearchProvider() == NULL);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1578 EXPECT_EQ(4U, loaded_url->input_encodings().size()); 1578 EXPECT_EQ(4U, loaded_url->input_encodings().size());
1579 } 1579 }
1580 1580
1581 TEST_F(TemplateURLServiceTest, DefaultExtensionEngine) { 1581 TEST_F(TemplateURLServiceTest, DefaultExtensionEngine) {
1582 test_util_.VerifyLoad(); 1582 test_util_.VerifyLoad();
1583 // Add third-party default search engine. 1583 // Add third-party default search engine.
1584 TemplateURL* user_dse = AddKeywordWithDate( 1584 TemplateURL* user_dse = AddKeywordWithDate(
1585 "user", "user", "http://www.goo.com/s?q={searchTerms}", 1585 "user", "user", "http://www.goo.com/s?q={searchTerms}",
1586 std::string(), std::string(), std::string(), 1586 std::string(), std::string(), std::string(),
1587 true, "UTF-8", Time(), Time()); 1587 true, "UTF-8", Time(), Time());
1588 model()->SetDefaultSearchProvider(user_dse); 1588 model()->SetUserSelectedDefaultSearchProvider(user_dse);
1589 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); 1589 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider());
1590 1590
1591 TemplateURL* ext_dse = CreateKeywordWithDate( 1591 TemplateURL* ext_dse = CreateKeywordWithDate(
1592 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}", 1592 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}",
1593 std::string(), std::string(), std::string(), 1593 std::string(), std::string(), std::string(),
1594 true, true, "UTF-8", Time(), Time()); 1594 true, true, "UTF-8", Time(), Time());
1595 scoped_ptr<AssociatedExtensionInfo> extension_info( 1595 scoped_ptr<AssociatedExtensionInfo> extension_info(
1596 new AssociatedExtensionInfo); 1596 new AssociatedExtensionInfo);
1597 extension_info->wants_to_be_default_engine = true; 1597 extension_info->wants_to_be_default_engine = true;
1598 extension_info->extension_id = "ext"; 1598 extension_info->extension_id = "ext";
1599 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); 1599 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass());
1600 EXPECT_EQ(ext_dse, model()->GetDefaultSearchProvider()); 1600 EXPECT_EQ(ext_dse, model()->GetDefaultSearchProvider());
1601 1601
1602 model()->RemoveExtensionControlledTURL("ext"); 1602 model()->RemoveExtensionControlledTURL("ext");
1603 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); 1603 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider());
1604 } 1604 }
1605 1605
1606 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) { 1606 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) {
1607 test_util_.VerifyLoad(); 1607 test_util_.VerifyLoad();
1608 // Add third-party default search engine. 1608 // Add third-party default search engine.
1609 TemplateURL* user_dse = AddKeywordWithDate( 1609 TemplateURL* user_dse = AddKeywordWithDate(
1610 "user", "user", "http://www.goo.com/s?q={searchTerms}", 1610 "user", "user", "http://www.goo.com/s?q={searchTerms}",
1611 std::string(), std::string(), std::string(), 1611 std::string(), std::string(), std::string(),
1612 true, "UTF-8", Time(), Time()); 1612 true, "UTF-8", Time(), Time());
1613 model()->SetDefaultSearchProvider(user_dse); 1613 model()->SetUserSelectedDefaultSearchProvider(user_dse);
1614 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); 1614 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider());
1615 1615
1616 TemplateURL* ext_dse = CreateKeywordWithDate( 1616 TemplateURL* ext_dse = CreateKeywordWithDate(
1617 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", 1617 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}",
1618 std::string(), std::string(), std::string(), 1618 std::string(), std::string(), std::string(),
1619 true, false, "UTF-8", Time(), Time()); 1619 true, false, "UTF-8", Time(), Time());
1620 scoped_ptr<AssociatedExtensionInfo> extension_info( 1620 scoped_ptr<AssociatedExtensionInfo> extension_info(
1621 new AssociatedExtensionInfo); 1621 new AssociatedExtensionInfo);
1622 extension_info->wants_to_be_default_engine = false; 1622 extension_info->wants_to_be_default_engine = false;
1623 extension_info->extension_id = "ext1"; 1623 extension_info->extension_id = "ext1";
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 scoped_ptr<AssociatedExtensionInfo> extension_info( 1678 scoped_ptr<AssociatedExtensionInfo> extension_info(
1679 new AssociatedExtensionInfo); 1679 new AssociatedExtensionInfo);
1680 extension_info->wants_to_be_default_engine = true; 1680 extension_info->wants_to_be_default_engine = true;
1681 extension_info->extension_id = "ext1"; 1681 extension_info->extension_id = "ext1";
1682 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); 1682 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass());
1683 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); 1683 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1")));
1684 EXPECT_TRUE(model()->is_default_search_managed()); 1684 EXPECT_TRUE(model()->is_default_search_managed());
1685 actual_managed_default = model()->GetDefaultSearchProvider(); 1685 actual_managed_default = model()->GetDefaultSearchProvider();
1686 ExpectSimilar(expected_managed_default.get(), actual_managed_default); 1686 ExpectSimilar(expected_managed_default.get(), actual_managed_default);
1687 } 1687 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698