| 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_input.h" | 5 #include "components/omnibox/autocomplete_input.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 { ASCIIToUTF16("filesystem:http"), metrics::OmniboxInputType::QUERY }, | 150 { ASCIIToUTF16("filesystem:http"), metrics::OmniboxInputType::QUERY }, |
| 151 { ASCIIToUTF16("filesystem:"), metrics::OmniboxInputType::QUERY }, | 151 { ASCIIToUTF16("filesystem:"), metrics::OmniboxInputType::QUERY }, |
| 152 { ASCIIToUTF16("chrome-search://"), metrics::OmniboxInputType::QUERY }, | 152 { ASCIIToUTF16("chrome-search://"), metrics::OmniboxInputType::QUERY }, |
| 153 { ASCIIToUTF16("chrome-devtools:"), metrics::OmniboxInputType::QUERY }, | 153 { ASCIIToUTF16("chrome-devtools:"), metrics::OmniboxInputType::QUERY }, |
| 154 { ASCIIToUTF16("about://f;"), metrics::OmniboxInputType::QUERY }, | 154 { ASCIIToUTF16("about://f;"), metrics::OmniboxInputType::QUERY }, |
| 155 { ASCIIToUTF16("://w"), metrics::OmniboxInputType::QUERY }, | 155 { ASCIIToUTF16("://w"), metrics::OmniboxInputType::QUERY }, |
| 156 { ASCIIToUTF16(":w"), metrics::OmniboxInputType::QUERY }, | 156 { ASCIIToUTF16(":w"), metrics::OmniboxInputType::QUERY }, |
| 157 { base::WideToUTF16(L".\u062A"), metrics::OmniboxInputType::UNKNOWN }, | 157 { base::WideToUTF16(L".\u062A"), metrics::OmniboxInputType::UNKNOWN }, |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { | 160 for (size_t i = 0; i < arraysize(input_cases); ++i) { |
| 161 SCOPED_TRACE(input_cases[i].input); | 161 SCOPED_TRACE(input_cases[i].input); |
| 162 AutocompleteInput input(input_cases[i].input, base::string16::npos, | 162 AutocompleteInput input(input_cases[i].input, base::string16::npos, |
| 163 std::string(), GURL(), | 163 std::string(), GURL(), |
| 164 OmniboxEventProto::INVALID_SPEC, true, false, true, | 164 OmniboxEventProto::INVALID_SPEC, true, false, true, |
| 165 true, TestSchemeClassifier()); | 165 true, TestSchemeClassifier()); |
| 166 EXPECT_EQ(input_cases[i].type, input.type()); | 166 EXPECT_EQ(input_cases[i].type, input.type()); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| 170 TEST(AutocompleteInputTest, InputTypeWithDesiredTLD) { | 170 TEST(AutocompleteInputTest, InputTypeWithDesiredTLD) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 190 { ASCIIToUTF16("x@y.com"), metrics::OmniboxInputType::URL, | 190 { ASCIIToUTF16("x@y.com"), metrics::OmniboxInputType::URL, |
| 191 std::string("http://x@y.com/") }, | 191 std::string("http://x@y.com/") }, |
| 192 { ASCIIToUTF16("y/z z"), metrics::OmniboxInputType::URL, | 192 { ASCIIToUTF16("y/z z"), metrics::OmniboxInputType::URL, |
| 193 std::string("http://www.y.com/z%20z") }, | 193 std::string("http://www.y.com/z%20z") }, |
| 194 { ASCIIToUTF16("abc.com"), metrics::OmniboxInputType::URL, | 194 { ASCIIToUTF16("abc.com"), metrics::OmniboxInputType::URL, |
| 195 std::string("http://abc.com/") }, | 195 std::string("http://abc.com/") }, |
| 196 { ASCIIToUTF16("foo bar"), metrics::OmniboxInputType::QUERY, | 196 { ASCIIToUTF16("foo bar"), metrics::OmniboxInputType::QUERY, |
| 197 std::string() }, | 197 std::string() }, |
| 198 }; | 198 }; |
| 199 | 199 |
| 200 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { | 200 for (size_t i = 0; i < arraysize(input_cases); ++i) { |
| 201 SCOPED_TRACE(input_cases[i].input); | 201 SCOPED_TRACE(input_cases[i].input); |
| 202 AutocompleteInput input(input_cases[i].input, base::string16::npos, "com", | 202 AutocompleteInput input(input_cases[i].input, base::string16::npos, "com", |
| 203 GURL(), OmniboxEventProto::INVALID_SPEC, true, | 203 GURL(), OmniboxEventProto::INVALID_SPEC, true, |
| 204 false, true, true, TestSchemeClassifier()); | 204 false, true, true, TestSchemeClassifier()); |
| 205 EXPECT_EQ(input_cases[i].type, input.type()); | 205 EXPECT_EQ(input_cases[i].type, input.type()); |
| 206 if (input_cases[i].type == metrics::OmniboxInputType::URL) | 206 if (input_cases[i].type == metrics::OmniboxInputType::URL) |
| 207 EXPECT_EQ(input_cases[i].spec, input.canonicalized_url().spec()); | 207 EXPECT_EQ(input_cases[i].spec, input.canonicalized_url().spec()); |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 | 210 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 Component(12, 11) }, | 242 Component(12, 11) }, |
| 243 { ASCIIToUTF16("view-source:"), Component(0, 11), kInvalidComponent }, | 243 { ASCIIToUTF16("view-source:"), Component(0, 11), kInvalidComponent }, |
| 244 { ASCIIToUTF16("view-source:garbage"), kInvalidComponent, | 244 { ASCIIToUTF16("view-source:garbage"), kInvalidComponent, |
| 245 Component(12, 7) }, | 245 Component(12, 7) }, |
| 246 { ASCIIToUTF16("view-source:http://http://foo"), Component(12, 4), | 246 { ASCIIToUTF16("view-source:http://http://foo"), Component(12, 4), |
| 247 Component(19, 4) }, | 247 Component(19, 4) }, |
| 248 { ASCIIToUTF16("view-source:view-source:http://example.com/"), | 248 { ASCIIToUTF16("view-source:view-source:http://example.com/"), |
| 249 Component(12, 11), kInvalidComponent } | 249 Component(12, 11), kInvalidComponent } |
| 250 }; | 250 }; |
| 251 | 251 |
| 252 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { | 252 for (size_t i = 0; i < arraysize(input_cases); ++i) { |
| 253 SCOPED_TRACE(input_cases[i].input); | 253 SCOPED_TRACE(input_cases[i].input); |
| 254 Component scheme, host; | 254 Component scheme, host; |
| 255 AutocompleteInput::ParseForEmphasizeComponents(input_cases[i].input, | 255 AutocompleteInput::ParseForEmphasizeComponents(input_cases[i].input, |
| 256 TestSchemeClassifier(), | 256 TestSchemeClassifier(), |
| 257 &scheme, | 257 &scheme, |
| 258 &host); | 258 &host); |
| 259 AutocompleteInput input(input_cases[i].input, base::string16::npos, | 259 AutocompleteInput input(input_cases[i].input, base::string16::npos, |
| 260 std::string(), GURL(), | 260 std::string(), GURL(), |
| 261 OmniboxEventProto::INVALID_SPEC, true, | 261 OmniboxEventProto::INVALID_SPEC, true, |
| 262 false, true, true, TestSchemeClassifier()); | 262 false, true, true, TestSchemeClassifier()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 285 { ASCIIToUTF16(" foo bar"), 3, ASCIIToUTF16("foo bar"), 0 }, | 285 { ASCIIToUTF16(" foo bar"), 3, ASCIIToUTF16("foo bar"), 0 }, |
| 286 { ASCIIToUTF16(" foo bar "), 2, ASCIIToUTF16("foo bar "), 0 }, | 286 { ASCIIToUTF16(" foo bar "), 2, ASCIIToUTF16("foo bar "), 0 }, |
| 287 | 287 |
| 288 // forced query. | 288 // forced query. |
| 289 { ASCIIToUTF16("?foo bar"), 2, ASCIIToUTF16("foo bar"), 1 }, | 289 { ASCIIToUTF16("?foo bar"), 2, ASCIIToUTF16("foo bar"), 1 }, |
| 290 { ASCIIToUTF16(" ?foo bar"), 4, ASCIIToUTF16("foo bar"), 1 }, | 290 { ASCIIToUTF16(" ?foo bar"), 4, ASCIIToUTF16("foo bar"), 1 }, |
| 291 { ASCIIToUTF16("? foo bar"), 4, ASCIIToUTF16("foo bar"), 1 }, | 291 { ASCIIToUTF16("? foo bar"), 4, ASCIIToUTF16("foo bar"), 1 }, |
| 292 { ASCIIToUTF16(" ? foo bar"), 6, ASCIIToUTF16("foo bar"), 1 }, | 292 { ASCIIToUTF16(" ? foo bar"), 6, ASCIIToUTF16("foo bar"), 1 }, |
| 293 }; | 293 }; |
| 294 | 294 |
| 295 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { | 295 for (size_t i = 0; i < arraysize(input_cases); ++i) { |
| 296 SCOPED_TRACE(input_cases[i].input); | 296 SCOPED_TRACE(input_cases[i].input); |
| 297 AutocompleteInput input(input_cases[i].input, | 297 AutocompleteInput input(input_cases[i].input, |
| 298 input_cases[i].cursor_position, std::string(), | 298 input_cases[i].cursor_position, std::string(), |
| 299 GURL(), OmniboxEventProto::INVALID_SPEC, true, | 299 GURL(), OmniboxEventProto::INVALID_SPEC, true, |
| 300 false, true, true, TestSchemeClassifier()); | 300 false, true, true, TestSchemeClassifier()); |
| 301 EXPECT_EQ(input_cases[i].normalized_input, input.text()); | 301 EXPECT_EQ(input_cases[i].normalized_input, input.text()); |
| 302 EXPECT_EQ(input_cases[i].normalized_cursor_position, | 302 EXPECT_EQ(input_cases[i].normalized_cursor_position, |
| 303 input.cursor_position()); | 303 input.cursor_position()); |
| 304 } | 304 } |
| 305 } | 305 } |
| OLD | NEW |