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

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: fix browsertests compile error (sigh) 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
« no previous file with comments | « components/omnibox/autocomplete_match.cc ('k') | components/omnibox/autocomplete_result.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Don't allow URLs with different schemes to be considered duplicates for
155 // certain inputs.
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 // If the user types unicode that matches the beginning of a
174 // punycode-encoded hostname then consider that a match.
175 { L"x", "http://xn--1lq90ic7f1rc.cn/",
176 "https://xn--1lq90ic7f1rc.cn/", true },
177 { L"http://\x5317 x", "http://xn--1lq90ic7f1rc.cn/",
178 "https://xn--1lq90ic7f1rc.cn/", false },
179 { L"http://\x89c6 x", "http://xn--1lq90ic7f1rc.cn/",
180 "https://xn--1lq90ic7f1rc.cn/", true },
181 };
182
183 for (size_t i = 0; i < arraysize(cases); ++i) {
184 SCOPED_TRACE("input=" + base::WideToUTF8(cases[i].input) +
185 " url1=" + cases[i].url1 + " url2=" + cases[i].url2);
186 AutocompleteInput input(
187 base::WideToUTF16(cases[i].input), base::string16::npos, std::string(),
188 GURL(), metrics::OmniboxEventProto::INVALID_SPEC, false, false, true,
189 true, false, TestSchemeClassifier());
190 AutocompleteMatch m1(NULL, 100, false,
191 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
192 m1.destination_url = GURL(cases[i].url1);
193 m1.ComputeStrippedDestinationURL(input, "zh-CN", NULL);
194 AutocompleteMatch m2(NULL, 100, false,
195 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
196 m2.destination_url = GURL(cases[i].url2);
197 m2.ComputeStrippedDestinationURL(input, "zh-CN", NULL);
198 EXPECT_EQ(cases[i].expected_duplicate,
199 AutocompleteMatch::DestinationsEqual(m1, m2));
200 }
201 }
OLDNEW
« no previous file with comments | « components/omnibox/autocomplete_match.cc ('k') | components/omnibox/autocomplete_result.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698