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

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

Issue 13727003: Remove unused BuildQueryTerms from TemplateURLService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
« no previous file with comments | « chrome/browser/search_engines/template_url_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/string_util.h" 10 #include "base/string_util.h"
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 EXPECT_EQ("http://instant", default_turl->instant_url()); 915 EXPECT_EQ("http://instant", default_turl->instant_url());
916 EXPECT_EQ(id, default_turl->id()); 916 EXPECT_EQ(id, default_turl->id());
917 917
918 // Now do a load and make sure the default search provider really takes. 918 // Now do a load and make sure the default search provider really takes.
919 test_util_.VerifyLoad(); 919 test_util_.VerifyLoad();
920 920
921 ASSERT_TRUE(model()->GetDefaultSearchProvider()); 921 ASSERT_TRUE(model()->GetDefaultSearchProvider());
922 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); 922 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider());
923 } 923 }
924 924
925 TEST_F(TemplateURLServiceTest, BuildQueryTerms) {
926 struct TestData {
927 const std::string url;
928 const bool result;
929 // Keys and values are a semicolon separated list of expected values in the
930 // map.
931 const std::string keys;
932 const std::string values;
933 } data[] = {
934 // No query should return false.
935 { "http://blah/", false, "", "" },
936
937 // Query with empty key should return false.
938 { "http://blah/foo?=y", false, "", "" },
939
940 // Query with key occurring multiple times should return false.
941 { "http://blah/foo?x=y&x=z", false, "", "" },
942
943 { "http://blah/foo?x=y", true, "x", "y" },
944 { "http://blah/foo?x=y&y=z", true, "x;y", "y;z" },
945
946 // Key occurring multiple times should get an empty string.
947 { "http://blah/foo?x=y&x=z&y=z", true, "x;y", ";z" },
948 };
949
950 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
951 TemplateURLService::QueryTerms terms;
952 ASSERT_EQ(data[i].result,
953 TemplateURLService::BuildQueryTerms(GURL(data[i].url), &terms));
954 if (data[i].result) {
955 std::vector<std::string> keys;
956 std::vector<std::string> values;
957 base::SplitString(data[i].keys, ';', &keys);
958 base::SplitString(data[i].values, ';', &values);
959 ASSERT_TRUE(keys.size() == values.size());
960 ASSERT_EQ(keys.size(), terms.size());
961 for (size_t j = 0; j < keys.size(); ++j) {
962 TemplateURLService::QueryTerms::iterator term_iterator =
963 terms.find(keys[j]);
964 ASSERT_TRUE(term_iterator != terms.end());
965 ASSERT_EQ(values[j], term_iterator->second);
966 }
967 }
968 }
969 }
970
971 TEST_F(TemplateURLServiceTest, UpdateKeywordSearchTermsForURL) { 925 TEST_F(TemplateURLServiceTest, UpdateKeywordSearchTermsForURL) {
972 struct TestData { 926 struct TestData {
973 const std::string url; 927 const std::string url;
974 const string16 term; 928 const string16 term;
975 } data[] = { 929 } data[] = {
976 { "http://foo/", string16() }, 930 { "http://foo/", string16() },
977 { "http://foo/foo?q=xx", string16() }, 931 { "http://foo/foo?q=xx", string16() },
978 { "http://x/bar?q=xx", string16() }, 932 { "http://x/bar?q=xx", string16() },
979 { "http://x/foo?y=xx", string16() }, 933 { "http://x/foo?y=xx", string16() },
980 { "http://x/foo?q=xx", ASCIIToUTF16("xx") }, 934 { "http://x/foo?q=xx", ASCIIToUTF16("xx") },
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 EXPECT_EQ(8U, loaded_url->input_encodings().size()); 1498 EXPECT_EQ(8U, loaded_url->input_encodings().size());
1545 1499
1546 // Reload the model to verify it was actually saved to the database and the 1500 // Reload the model to verify it was actually saved to the database and the
1547 // duplicate encodings were removed. 1501 // duplicate encodings were removed.
1548 test_util_.ResetModel(true); 1502 test_util_.ResetModel(true);
1549 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 1503 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
1550 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); 1504 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"));
1551 ASSERT_FALSE(loaded_url == NULL); 1505 ASSERT_FALSE(loaded_url == NULL);
1552 EXPECT_EQ(4U, loaded_url->input_encodings().size()); 1506 EXPECT_EQ(4U, loaded_url->input_encodings().size());
1553 } 1507 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698