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 #include <utility> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
16 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 ASSERT_TRUE(loaded_url != NULL); | 318 ASSERT_TRUE(loaded_url != NULL); |
318 AssertEquals(*cloned_url, *loaded_url); | 319 AssertEquals(*cloned_url, *loaded_url); |
319 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"), | 320 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"), |
320 GURL(), NULL)); | 321 GURL(), NULL)); |
321 | 322 |
322 // We expect the last_modified time to be updated to the present time on an | 323 // We expect the last_modified time to be updated to the present time on an |
323 // explicit reset. | 324 // explicit reset. |
324 base::Time now = base::Time::Now(); | 325 base::Time now = base::Time::Now(); |
325 scoped_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); | 326 scoped_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); |
326 clock->SetNow(now); | 327 clock->SetNow(now); |
327 model()->set_clock(clock.Pass()); | 328 model()->set_clock(std::move(clock)); |
328 | 329 |
329 // Mutate an element and verify it succeeded. | 330 // Mutate an element and verify it succeeded. |
330 model()->ResetTemplateURL(loaded_url, ASCIIToUTF16("a"), ASCIIToUTF16("b"), | 331 model()->ResetTemplateURL(loaded_url, ASCIIToUTF16("a"), ASCIIToUTF16("b"), |
331 "c"); | 332 "c"); |
332 ASSERT_EQ(ASCIIToUTF16("a"), loaded_url->short_name()); | 333 ASSERT_EQ(ASCIIToUTF16("a"), loaded_url->short_name()); |
333 ASSERT_EQ(ASCIIToUTF16("b"), loaded_url->keyword()); | 334 ASSERT_EQ(ASCIIToUTF16("b"), loaded_url->keyword()); |
334 ASSERT_EQ("c", loaded_url->url()); | 335 ASSERT_EQ("c", loaded_url->url()); |
335 ASSERT_FALSE(loaded_url->safe_for_autoreplace()); | 336 ASSERT_FALSE(loaded_url->safe_for_autoreplace()); |
336 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"), | 337 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"), |
337 GURL(), NULL)); | 338 GURL(), NULL)); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 data.last_modified = Time::FromTimeT(100); | 633 data.last_modified = Time::FromTimeT(100); |
633 TemplateURL* t_url = new TemplateURL(data); | 634 TemplateURL* t_url = new TemplateURL(data); |
634 model()->Add(t_url); | 635 model()->Add(t_url); |
635 | 636 |
636 VerifyObserverCount(1); | 637 VerifyObserverCount(1); |
637 base::RunLoop().RunUntilIdle(); | 638 base::RunLoop().RunUntilIdle(); |
638 | 639 |
639 base::Time now = base::Time::Now(); | 640 base::Time now = base::Time::Now(); |
640 scoped_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); | 641 scoped_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); |
641 clock->SetNow(now); | 642 clock->SetNow(now); |
642 model()->set_clock(clock.Pass()); | 643 model()->set_clock(std::move(clock)); |
643 | 644 |
644 // Reset the short name, keyword, url and make sure it takes. | 645 // Reset the short name, keyword, url and make sure it takes. |
645 const base::string16 new_short_name(ASCIIToUTF16("a")); | 646 const base::string16 new_short_name(ASCIIToUTF16("a")); |
646 const base::string16 new_keyword(ASCIIToUTF16("b")); | 647 const base::string16 new_keyword(ASCIIToUTF16("b")); |
647 const std::string new_url("c"); | 648 const std::string new_url("c"); |
648 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); | 649 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); |
649 ASSERT_EQ(new_short_name, t_url->short_name()); | 650 ASSERT_EQ(new_short_name, t_url->short_name()); |
650 ASSERT_EQ(new_keyword, t_url->keyword()); | 651 ASSERT_EQ(new_keyword, t_url->keyword()); |
651 ASSERT_EQ(new_url, t_url->url()); | 652 ASSERT_EQ(new_url, t_url->url()); |
652 | 653 |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1409 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1410 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
1410 | 1411 |
1411 TemplateURL* ext_dse = CreateKeywordWithDate( | 1412 TemplateURL* ext_dse = CreateKeywordWithDate( |
1412 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}", | 1413 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}", |
1413 std::string(), std::string(), std::string(), | 1414 std::string(), std::string(), std::string(), |
1414 true, true, "UTF-8", Time(), Time()); | 1415 true, true, "UTF-8", Time(), Time()); |
1415 scoped_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1416 scoped_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
1416 new TemplateURL::AssociatedExtensionInfo( | 1417 new TemplateURL::AssociatedExtensionInfo( |
1417 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext")); | 1418 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext")); |
1418 extension_info->wants_to_be_default_engine = true; | 1419 extension_info->wants_to_be_default_engine = true; |
1419 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); | 1420 model()->AddExtensionControlledTURL(ext_dse, std::move(extension_info)); |
1420 EXPECT_EQ(ext_dse, model()->GetDefaultSearchProvider()); | 1421 EXPECT_EQ(ext_dse, model()->GetDefaultSearchProvider()); |
1421 | 1422 |
1422 model()->RemoveExtensionControlledTURL( | 1423 model()->RemoveExtensionControlledTURL( |
1423 "ext", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1424 "ext", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); |
1424 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); | 1425 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); |
1425 } | 1426 } |
1426 | 1427 |
1427 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) { | 1428 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) { |
1428 test_util()->VerifyLoad(); | 1429 test_util()->VerifyLoad(); |
1429 // Add third-party default search engine. | 1430 // Add third-party default search engine. |
1430 TemplateURL* user_dse = AddKeywordWithDate( | 1431 TemplateURL* user_dse = AddKeywordWithDate( |
1431 "user", "user", "http://www.goo.com/s?q={searchTerms}", | 1432 "user", "user", "http://www.goo.com/s?q={searchTerms}", |
1432 std::string(), std::string(), std::string(), | 1433 std::string(), std::string(), std::string(), |
1433 true, "UTF-8", Time(), Time()); | 1434 true, "UTF-8", Time(), Time()); |
1434 model()->SetUserSelectedDefaultSearchProvider(user_dse); | 1435 model()->SetUserSelectedDefaultSearchProvider(user_dse); |
1435 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1436 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
1436 | 1437 |
1437 TemplateURL* ext_dse = CreateKeywordWithDate( | 1438 TemplateURL* ext_dse = CreateKeywordWithDate( |
1438 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", | 1439 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", |
1439 std::string(), std::string(), std::string(), | 1440 std::string(), std::string(), std::string(), |
1440 true, false, "UTF-8", Time(), Time()); | 1441 true, false, "UTF-8", Time(), Time()); |
1441 scoped_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1442 scoped_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
1442 new TemplateURL::AssociatedExtensionInfo( | 1443 new TemplateURL::AssociatedExtensionInfo( |
1443 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); | 1444 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); |
1444 extension_info->wants_to_be_default_engine = false; | 1445 extension_info->wants_to_be_default_engine = false; |
1445 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); | 1446 model()->AddExtensionControlledTURL(ext_dse, std::move(extension_info)); |
1446 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1447 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
1447 | 1448 |
1448 ext_dse = CreateKeywordWithDate( | 1449 ext_dse = CreateKeywordWithDate( |
1449 model(), "ext2", "ext2", "http://www.ext2.com/s?q={searchTerms}", | 1450 model(), "ext2", "ext2", "http://www.ext2.com/s?q={searchTerms}", |
1450 std::string(), std::string(), std::string(), | 1451 std::string(), std::string(), std::string(), |
1451 true, true, "UTF-8", Time(), Time()); | 1452 true, true, "UTF-8", Time(), Time()); |
1452 extension_info.reset(new TemplateURL::AssociatedExtensionInfo( | 1453 extension_info.reset(new TemplateURL::AssociatedExtensionInfo( |
1453 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext2")); | 1454 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext2")); |
1454 extension_info->wants_to_be_default_engine = true; | 1455 extension_info->wants_to_be_default_engine = true; |
1455 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); | 1456 model()->AddExtensionControlledTURL(ext_dse, std::move(extension_info)); |
1456 EXPECT_EQ(ext_dse, model()->GetDefaultSearchProvider()); | 1457 EXPECT_EQ(ext_dse, model()->GetDefaultSearchProvider()); |
1457 | 1458 |
1458 test_util()->ResetModel(true); | 1459 test_util()->ResetModel(true); |
1459 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); | 1460 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); |
1460 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); | 1461 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); |
1461 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1462 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
1462 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext2"))); | 1463 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext2"))); |
1463 } | 1464 } |
1464 | 1465 |
1465 TEST_F(TemplateURLServiceTest, ExtensionEngineVsPolicy) { | 1466 TEST_F(TemplateURLServiceTest, ExtensionEngineVsPolicy) { |
(...skipping 27 matching lines...) Expand all Loading... |
1493 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1494 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
1494 | 1495 |
1495 TemplateURL* ext_dse = CreateKeywordWithDate( | 1496 TemplateURL* ext_dse = CreateKeywordWithDate( |
1496 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", | 1497 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", |
1497 std::string(), std::string(), std::string(), | 1498 std::string(), std::string(), std::string(), |
1498 true, true, "UTF-8", Time(), Time()); | 1499 true, true, "UTF-8", Time(), Time()); |
1499 scoped_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1500 scoped_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
1500 new TemplateURL::AssociatedExtensionInfo( | 1501 new TemplateURL::AssociatedExtensionInfo( |
1501 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); | 1502 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); |
1502 extension_info->wants_to_be_default_engine = true; | 1503 extension_info->wants_to_be_default_engine = true; |
1503 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); | 1504 model()->AddExtensionControlledTURL(ext_dse, std::move(extension_info)); |
1504 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1505 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
1505 EXPECT_TRUE(model()->is_default_search_managed()); | 1506 EXPECT_TRUE(model()->is_default_search_managed()); |
1506 actual_managed_default = model()->GetDefaultSearchProvider(); | 1507 actual_managed_default = model()->GetDefaultSearchProvider(); |
1507 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1508 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
1508 } | 1509 } |
OLD | NEW |