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

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: possible fix for mac code (cannot compile mac code myself) Created 5 years, 5 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.h"
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 const wchar_t* input;
136 const std::string url1;
137 const std::string url2;
138 const bool expected_duplicate;
139 } cases[] = {
140 { L"g", "http://www.google.com/", "https://www.google.com/", true },
141 { L"g", "http://www.google.com/", "http://www.google.com", true },
142 { L"g", "http://google.com/", "http://www.google.com/", true },
143 { L"g", "http://www.google.com/", "HTTP://www.GOOGLE.com/", true },
144 { L"g", "http://www.google.com/1", "http://www.google.com/1/", true },
145 { L"g", "http://www.google.com/", "http://www.google.com", true },
146 { L"g", "https://www.google.com/", "http://google.com", true },
147 { L"g", "http://www.google.com/", "wss://www.google.com/", false },
148 { L"g", "http://www.google.com/", "http://www.google.com/1", false },
149 { L"g", "http://www.google.com/", "http://www.goo.com/", false },
150 { L"g", "http://www.google.com/", "http://w2.google.com/", false },
151 { L"g", "http://www.google.com/", "http://m.google.com/", false },
152 { L"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 { L"http://g", "http://google.com/",
157 "https://google.com/", false },
158 { L"http://g", "http://blah.com/",
159 "https://blah.com/", true },
160 { L"http://g", "http://google.com/1",
161 "https://google.com/1", false },
162 { L"http://g hello", "http://google.com/",
163 "https://google.com/", false },
164 { L"hello http://g", "http://google.com/",
165 "https://google.com/", false },
166 { L"hello http://g", "http://blah.com/",
167 "https://blah.com/", true },
168 { L"http://b http://g", "http://google.com/",
169 "https://google.com/", false },
170 { L"http://b http://g", "http://blah.com/",
171 "https://blah.com/", false },
172
173 // A simple test to verify that if the user types unicode that matches
174 // the beginning of a punycode-encoded hostname then we consider that
175 // a match.
Peter Kasting 2015/06/29 05:04:59 Nit: For both of the comments here, you could shor
Mark P 2015/06/30 04:23:17 Done.
176 { L"x", "http://xn--1lq90ic7f1rc.cn/",
177 "https://xn--1lq90ic7f1rc.cn/", true },
178 { L"http://\x5317 x", "http://xn--1lq90ic7f1rc.cn/",
179 "https://xn--1lq90ic7f1rc.cn/", false },
180 { L"http://\x89c6 x", "http://xn--1lq90ic7f1rc.cn/",
181 "https://xn--1lq90ic7f1rc.cn/", true },
182 { L"http://x", "http://xn--1lq90ic7f1rc.cn/",
183 "https://xn--1lq90ic7f1rc.cn/", false },
184 };
185
186 for (size_t i = 0; i < arraysize(cases); ++i) {
187 SCOPED_TRACE(std::string("input=") + base::WideToUTF8(cases[i].input) +
Peter Kasting 2015/06/29 05:04:59 Nit: I _think_ this compiles without the explicit
Mark P 2015/06/30 04:23:17 Right you are. (You found remnants of an earlier
188 " url1=" + cases[i].url1 + " url2=" + cases[i].url2);
189 AutocompleteInput input(
190 base::WideToUTF16(cases[i].input), base::string16::npos, std::string(),
191 GURL(), metrics::OmniboxEventProto::INVALID_SPEC, false, false, true,
192 true, false, TestSchemeClassifier());
193 AutocompleteMatch m1(NULL, 100, false,
194 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
195 m1.destination_url = GURL(cases[i].url1);
196 m1.ComputeStrippedDestinationURL(input, "zh-CN", NULL);
197 AutocompleteMatch m2(NULL, 100, false,
198 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
199 m2.destination_url = GURL(cases[i].url2);
200 m2.ComputeStrippedDestinationURL(input, "zh-CN", NULL);
201 EXPECT_EQ(cases[i].expected_duplicate,
202 AutocompleteMatch::DestinationsEqual(m1, m2));
203 }
204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698