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

Side by Side Diff: components/omnibox/autocomplete_match_unittest.cc

Issue 1098843004: Omnibox - Do Not Allow HTTP/HTTPS Equivalence if User Explicitly Entered A Scheme (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use StartsWithASCII Created 5 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/omnibox/autocomplete_match.h" 5 #include "components/omnibox/autocomplete_match.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/strings/utf_string_conversions.cc"
9 #include "components/omnibox/test_scheme_classifier.h"
8 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
9 11
10 TEST(AutocompleteMatchTest, MoreRelevant) { 12 TEST(AutocompleteMatchTest, MoreRelevant) {
11 struct RelevantCases { 13 struct RelevantCases {
12 int r1; 14 int r1;
13 int r2; 15 int r2;
14 bool expected_result; 16 bool expected_result;
15 } cases[] = { 17 } cases[] = {
16 { 10, 0, true }, 18 { 10, 0, true },
17 { 10, -5, true }, 19 { 10, -5, true },
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 NULL, 0, false, AutocompleteMatchType::URL_WHAT_YOU_TYPED)); 122 NULL, 0, false, AutocompleteMatchType::URL_WHAT_YOU_TYPED));
121 m.duplicate_matches.push_back(AutocompleteMatch( 123 m.duplicate_matches.push_back(AutocompleteMatch(
122 NULL, 0, false, AutocompleteMatchType::URL_WHAT_YOU_TYPED)); 124 NULL, 0, false, AutocompleteMatchType::URL_WHAT_YOU_TYPED));
123 EXPECT_FALSE(m.SupportsDeletion()); 125 EXPECT_FALSE(m.SupportsDeletion());
124 126
125 // A non-deletable match, with at least one deletable duplicate. 127 // A non-deletable match, with at least one deletable duplicate.
126 m.duplicate_matches.push_back(AutocompleteMatch( 128 m.duplicate_matches.push_back(AutocompleteMatch(
127 NULL, 0, true, AutocompleteMatchType::URL_WHAT_YOU_TYPED)); 129 NULL, 0, true, AutocompleteMatchType::URL_WHAT_YOU_TYPED));
128 EXPECT_TRUE(m.SupportsDeletion()); 130 EXPECT_TRUE(m.SupportsDeletion());
129 } 131 }
132
133 TEST(AutocompleteMatchTest, Duplicates) {
134 struct DuplicateCases {
135 std::string input;
136 std::string url1;
137 std::string url2;
138 bool expected_duplicate;
139 } cases[] = {
140 { "g", "http://www.google.com/", "https://www.google.com/", true },
141 { "g", "http://www.google.com/", "http://www.google.com", true },
142 { "g", "http://google.com/", "http://www.google.com/", true },
143 { "g", "http://www.google.com/", "HTTP://www.GOOGLE.com/", true },
144 { "g", "http://www.google.com/1", "http://www.google.com/1/", true },
145 { "g", "http://www.google.com/", "http://www.google.com", true },
146 { "g", "https://www.google.com/", "http://google.com", true },
147 { "g", "http://www.google.com/", "wss://www.google.com/", false },
148 { "g", "http://www.google.com/", "http://www.google.com/1", false },
149 { "g", "http://www.google.com/", "http://www.goo.com/", false },
150 { "g", "http://www.google.com/", "http://w2.google.com/", false },
151 { "g", "http://www.google.com/", "http://m.google.com/", false },
152 { "g", "http://www.google.com/", "http://www.google.com/?foo", false },
153
154 // Some tests to verify that, depending on the user's input, we don't
155 // allow URL with different schemes to be considered duplicates.
156 { "http://g", "http://www.google.com/",
157 "https://www.google.com/", false },
158 { "http://g", "http://www.blah.com/",
159 "https://www.blah.com/", true },
160 { "http://g", "http://www.google.com/1",
161 "https://www.google.com/1", false },
162 { "http://g hello", "http://www.google.com/",
163 "https://www.google.com/", false },
164 { "hello http://g", "http://www.google.com/",
165 "https://www.google.com/", false },
166 { "hello http://g", "http://www.blah.com/",
167 "https://www.blah.com/", true },
168 { "http://b http://g", "http://www.google.com/",
169 "https://www.google.com/", false },
170 { "http://b http://g", "http://www.blah.com/",
171 "https://www.blah.com/", false },
172
173 };
174
175 for (size_t i = 0; i < arraysize(cases); ++i) {
176 SCOPED_TRACE("input=" + cases[i].input + " url1=" + cases[i].url1 +
177 " url2=" + cases[i].url2);
178 AutocompleteInput input(
179 base::ASCIIToUTF16(cases[i].input), base::string16::npos, std::string(),
180 GURL(), metrics::OmniboxEventProto::INVALID_SPEC, false, false, true,
181 true, TestSchemeClassifier());
182 AutocompleteMatch m1(NULL, 100, false,
183 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
184 m1.destination_url = GURL(cases[i].url1);
185 m1.ComputeStrippedDestinationURL(input, NULL);
186 AutocompleteMatch m2(NULL, 100, false,
187 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
188 m2.destination_url = GURL(cases[i].url2);
189 m2.ComputeStrippedDestinationURL(input, NULL);
190 EXPECT_EQ(cases[i].expected_duplicate,
191 AutocompleteMatch::DestinationsEqual(m1, m2));
192 }
193 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698