OLD | NEW |
---|---|
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" | |
brettw
2015/06/26 04:43:18
Ah, your problem is you included a .cc file here i
Mark P
2015/06/26 04:46:59
Doh!
Thanks for catching that.
| |
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 Loading... | |
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 std::string input; | |
136 const std::string url1; | |
137 const std::string url2; | |
138 const 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://google.com/", | |
157 "https://google.com/", false }, | |
158 { "http://g", "http://blah.com/", | |
159 "https://blah.com/", true }, | |
160 { "http://g", "http://google.com/1", | |
161 "https://google.com/1", false }, | |
162 { "http://g hello", "http://google.com/", | |
163 "https://google.com/", false }, | |
164 { "hello http://g", "http://google.com/", | |
165 "https://google.com/", false }, | |
166 { "hello http://g", "http://blah.com/", | |
167 "https://blah.com/", true }, | |
168 { "http://b http://g", "http://google.com/", | |
169 "https://google.com/", false }, | |
170 { "http://b http://g", "http://blah.com/", | |
171 "https://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, false, 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 } | |
OLD | NEW |