| 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 "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" |
| 11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/task/cancelable_task_tracker.h" | 14 #include "base/task/cancelable_task_tracker.h" |
| 15 #include "base/test/mock_time_provider.h" | 15 #include "base/test/mock_time_provider.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "chrome/browser/history/history_notifications.h" | |
| 19 #include "chrome/browser/history/history_service.h" | 18 #include "chrome/browser/history/history_service.h" |
| 20 #include "chrome/browser/history/history_service_factory.h" | 19 #include "chrome/browser/history/history_service_factory.h" |
| 21 #include "chrome/browser/search_engines/search_host_to_urls_map.h" | 20 #include "chrome/browser/search_engines/search_host_to_urls_map.h" |
| 22 #include "chrome/browser/search_engines/template_url_service.h" | 21 #include "chrome/browser/search_engines/template_url_service.h" |
| 23 #include "chrome/browser/search_engines/template_url_service_test_util.h" | 22 #include "chrome/browser/search_engines/template_url_service_test_util.h" |
| 24 #include "chrome/browser/webdata/keyword_web_data_service.h" | 23 #include "chrome/browser/webdata/keyword_web_data_service.h" |
| 25 #include "chrome/browser/webdata/web_data_service_factory.h" | 24 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 26 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
| 27 #include "components/search_engines/search_terms_data.h" | 26 #include "components/search_engines/search_terms_data.h" |
| 28 #include "components/search_engines/template_url.h" | 27 #include "components/search_engines/template_url.h" |
| (...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 { "http://x/foo?q=b#q=xx", ASCIIToUTF16("b") }, | 887 { "http://x/foo?q=b#q=xx", ASCIIToUTF16("b") }, |
| 889 { "http://x/foo?query=b#q=xx", base::string16() }, | 888 { "http://x/foo?query=b#q=xx", base::string16() }, |
| 890 }; | 889 }; |
| 891 | 890 |
| 892 test_util_.ChangeModelToLoadState(); | 891 test_util_.ChangeModelToLoadState(); |
| 893 AddKeywordWithDate("name", "x", "http://x/foo?q={searchTerms}", | 892 AddKeywordWithDate("name", "x", "http://x/foo?q={searchTerms}", |
| 894 "http://sugg1", "http://x/foo#query={searchTerms}", | 893 "http://sugg1", "http://x/foo#query={searchTerms}", |
| 895 "http://icon1", false, "UTF-8;UTF-16", Time(), Time()); | 894 "http://icon1", false, "UTF-8;UTF-16", Time(), Time()); |
| 896 | 895 |
| 897 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 896 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
| 898 history::URLVisitedDetails details; | 897 TemplateURLService::URLVisitedDetails details = { |
| 899 details.row = history::URLRow(GURL(data[i].url)); | 898 GURL(data[i].url), false |
| 900 details.transition = content::PageTransitionFromInt(0); | 899 }; |
| 901 model()->UpdateKeywordSearchTermsForURL(details); | 900 model()->UpdateKeywordSearchTermsForURL(details); |
| 902 EXPECT_EQ(data[i].term, test_util_.GetAndClearSearchTerm()); | 901 EXPECT_EQ(data[i].term, test_util_.GetAndClearSearchTerm()); |
| 903 } | 902 } |
| 904 } | 903 } |
| 905 | 904 |
| 906 TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) { | 905 TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) { |
| 907 struct TestData { | 906 struct TestData { |
| 908 const std::string url; | 907 const std::string url; |
| 909 } data[] = { | 908 } data[] = { |
| 910 { "http://foo/" }, | 909 { "http://foo/" }, |
| 911 { "http://x/bar?q=xx" }, | 910 { "http://x/bar?q=xx" }, |
| 912 { "http://x/foo?y=xx" }, | 911 { "http://x/foo?y=xx" }, |
| 913 }; | 912 }; |
| 914 | 913 |
| 915 test_util_.ChangeModelToLoadState(); | 914 test_util_.ChangeModelToLoadState(); |
| 916 AddKeywordWithDate("name", "x", "http://x/foo", "http://sugg1", std::string(), | 915 AddKeywordWithDate("name", "x", "http://x/foo", "http://sugg1", std::string(), |
| 917 "http://icon1", false, "UTF-8;UTF-16", Time(), Time()); | 916 "http://icon1", false, "UTF-8;UTF-16", Time(), Time()); |
| 918 | 917 |
| 919 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 918 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
| 920 history::URLVisitedDetails details; | 919 TemplateURLService::URLVisitedDetails details = { |
| 921 details.row = history::URLRow(GURL(data[i].url)); | 920 GURL(data[i].url), false |
| 922 details.transition = content::PageTransitionFromInt(0); | 921 }; |
| 923 model()->UpdateKeywordSearchTermsForURL(details); | 922 model()->UpdateKeywordSearchTermsForURL(details); |
| 924 ASSERT_EQ(base::string16(), test_util_.GetAndClearSearchTerm()); | 923 ASSERT_EQ(base::string16(), test_util_.GetAndClearSearchTerm()); |
| 925 } | 924 } |
| 926 } | 925 } |
| 927 | 926 |
| 928 TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) { | 927 TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) { |
| 929 // NOTE: Do not load the prepopulate data, which also has a {google:baseURL} | 928 // NOTE: Do not load the prepopulate data, which also has a {google:baseURL} |
| 930 // keyword in it and would confuse this test. | 929 // keyword in it and would confuse this test. |
| 931 test_util_.ChangeModelToLoadState(); | 930 test_util_.ChangeModelToLoadState(); |
| 932 | 931 |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1493 scoped_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1492 scoped_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
| 1494 new TemplateURL::AssociatedExtensionInfo( | 1493 new TemplateURL::AssociatedExtensionInfo( |
| 1495 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); | 1494 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); |
| 1496 extension_info->wants_to_be_default_engine = true; | 1495 extension_info->wants_to_be_default_engine = true; |
| 1497 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); | 1496 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); |
| 1498 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1497 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
| 1499 EXPECT_TRUE(model()->is_default_search_managed()); | 1498 EXPECT_TRUE(model()->is_default_search_managed()); |
| 1500 actual_managed_default = model()->GetDefaultSearchProvider(); | 1499 actual_managed_default = model()->GetDefaultSearchProvider(); |
| 1501 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1500 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
| 1502 } | 1501 } |
| OLD | NEW |