| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/autocomplete/autocomplete_input.h" | 5 #include "chrome/browser/autocomplete/autocomplete_input.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 { ASCIIToUTF16("filesystem:http://a.com/t/bar"), AutocompleteInput::URL }, | 114 { ASCIIToUTF16("filesystem:http://a.com/t/bar"), AutocompleteInput::URL }, |
| 115 { ASCIIToUTF16("filesystem:http:foo"), AutocompleteInput::URL }, | 115 { ASCIIToUTF16("filesystem:http:foo"), AutocompleteInput::URL }, |
| 116 { ASCIIToUTF16("filesystem:file://"), AutocompleteInput::URL }, | 116 { ASCIIToUTF16("filesystem:file://"), AutocompleteInput::URL }, |
| 117 { ASCIIToUTF16("filesystem:http"), AutocompleteInput::URL }, | 117 { ASCIIToUTF16("filesystem:http"), AutocompleteInput::URL }, |
| 118 { ASCIIToUTF16("filesystem:"), AutocompleteInput::URL }, | 118 { ASCIIToUTF16("filesystem:"), AutocompleteInput::URL }, |
| 119 { ASCIIToUTF16("ftp:"), AutocompleteInput::URL }, | 119 { ASCIIToUTF16("ftp:"), AutocompleteInput::URL }, |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { | 122 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { |
| 123 SCOPED_TRACE(input_cases[i].input); | 123 SCOPED_TRACE(input_cases[i].input); |
| 124 AutocompleteInput input(input_cases[i].input, string16(), true, false, | 124 AutocompleteInput input(input_cases[i].input, string16::npos, string16(), |
| 125 true, AutocompleteInput::ALL_MATCHES); | 125 true, false, true, AutocompleteInput::ALL_MATCHES); |
| 126 EXPECT_EQ(input_cases[i].type, input.type()); | 126 EXPECT_EQ(input_cases[i].type, input.type()); |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 TEST(AutocompleteInputTest, InputTypeWithDesiredTLD) { | 130 TEST(AutocompleteInputTest, InputTypeWithDesiredTLD) { |
| 131 struct test_data { | 131 struct test_data { |
| 132 const string16 input; | 132 const string16 input; |
| 133 const AutocompleteInput::Type type; | 133 const AutocompleteInput::Type type; |
| 134 } input_cases[] = { | 134 } input_cases[] = { |
| 135 { ASCIIToUTF16("401k"), AutocompleteInput::REQUESTED_URL }, | 135 { ASCIIToUTF16("401k"), AutocompleteInput::REQUESTED_URL }, |
| 136 { ASCIIToUTF16("999999999999999"), AutocompleteInput::REQUESTED_URL }, | 136 { ASCIIToUTF16("999999999999999"), AutocompleteInput::REQUESTED_URL }, |
| 137 { ASCIIToUTF16("x@y"), AutocompleteInput::REQUESTED_URL }, | 137 { ASCIIToUTF16("x@y"), AutocompleteInput::REQUESTED_URL }, |
| 138 { ASCIIToUTF16("y/z z"), AutocompleteInput::REQUESTED_URL }, | 138 { ASCIIToUTF16("y/z z"), AutocompleteInput::REQUESTED_URL }, |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { | 141 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { |
| 142 SCOPED_TRACE(input_cases[i].input); | 142 SCOPED_TRACE(input_cases[i].input); |
| 143 AutocompleteInput input(input_cases[i].input, ASCIIToUTF16("com"), true, | 143 AutocompleteInput input(input_cases[i].input, string16::npos, |
| 144 false, true, AutocompleteInput::ALL_MATCHES); | 144 ASCIIToUTF16("com"), true, false, true, |
| 145 AutocompleteInput::ALL_MATCHES); |
| 145 EXPECT_EQ(input_cases[i].type, input.type()); | 146 EXPECT_EQ(input_cases[i].type, input.type()); |
| 146 } | 147 } |
| 147 } | 148 } |
| 148 | 149 |
| 149 // This tests for a regression where certain input in the omnibox caused us to | 150 // This tests for a regression where certain input in the omnibox caused us to |
| 150 // crash. As long as the test completes without crashing, we're fine. | 151 // crash. As long as the test completes without crashing, we're fine. |
| 151 TEST(AutocompleteInputTest, InputCrash) { | 152 TEST(AutocompleteInputTest, InputCrash) { |
| 152 AutocompleteInput input(WideToUTF16(L"\uff65@s"), string16(), true, false, | 153 AutocompleteInput input(WideToUTF16(L"\uff65@s"), string16::npos, string16(), |
| 153 true, AutocompleteInput::ALL_MATCHES); | 154 true, false, true, AutocompleteInput::ALL_MATCHES); |
| 154 } | 155 } |
| 155 | 156 |
| 156 TEST(AutocompleteInputTest, ParseForEmphasizeComponent) { | 157 TEST(AutocompleteInputTest, ParseForEmphasizeComponent) { |
| 157 using url_parse::Component; | 158 using url_parse::Component; |
| 158 Component kInvalidComponent(0, -1); | 159 Component kInvalidComponent(0, -1); |
| 159 struct test_data { | 160 struct test_data { |
| 160 const string16 input; | 161 const string16 input; |
| 161 const Component scheme; | 162 const Component scheme; |
| 162 const Component host; | 163 const Component host; |
| 163 } input_cases[] = { | 164 } input_cases[] = { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 185 Component(12, 11), kInvalidComponent } | 186 Component(12, 11), kInvalidComponent } |
| 186 }; | 187 }; |
| 187 | 188 |
| 188 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { | 189 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { |
| 189 SCOPED_TRACE(input_cases[i].input); | 190 SCOPED_TRACE(input_cases[i].input); |
| 190 Component scheme, host; | 191 Component scheme, host; |
| 191 AutocompleteInput::ParseForEmphasizeComponents(input_cases[i].input, | 192 AutocompleteInput::ParseForEmphasizeComponents(input_cases[i].input, |
| 192 string16(), | 193 string16(), |
| 193 &scheme, | 194 &scheme, |
| 194 &host); | 195 &host); |
| 195 AutocompleteInput input(input_cases[i].input, string16(), true, false, | 196 AutocompleteInput input(input_cases[i].input, string16::npos, string16(), |
| 196 true, AutocompleteInput::ALL_MATCHES); | 197 true, false, true, AutocompleteInput::ALL_MATCHES); |
| 197 EXPECT_EQ(input_cases[i].scheme.begin, scheme.begin); | 198 EXPECT_EQ(input_cases[i].scheme.begin, scheme.begin); |
| 198 EXPECT_EQ(input_cases[i].scheme.len, scheme.len); | 199 EXPECT_EQ(input_cases[i].scheme.len, scheme.len); |
| 199 EXPECT_EQ(input_cases[i].host.begin, host.begin); | 200 EXPECT_EQ(input_cases[i].host.begin, host.begin); |
| 200 EXPECT_EQ(input_cases[i].host.len, host.len); | 201 EXPECT_EQ(input_cases[i].host.len, host.len); |
| 201 } | 202 } |
| 202 } | 203 } |
| 204 |
| 205 TEST(AutocompleteInputTest, InputTypeWithCursorPosition) { |
| 206 struct test_data { |
| 207 const string16 input; |
| 208 size_t cursor_position; |
| 209 const string16 normalized_input; |
| 210 size_t normalized_cursor_position; |
| 211 } input_cases[] = { |
| 212 { ASCIIToUTF16("foo bar"), string16::npos, |
| 213 ASCIIToUTF16("foo bar"), string16::npos }, |
| 214 |
| 215 // regular case, no changes. |
| 216 { ASCIIToUTF16("foo bar"), 3, ASCIIToUTF16("foo bar"), 3 }, |
| 217 |
| 218 // extra leading space. |
| 219 { ASCIIToUTF16(" foo bar"), 3, ASCIIToUTF16("foo bar"), 1 }, |
| 220 { ASCIIToUTF16(" foo bar"), 3, ASCIIToUTF16("foo bar"), 0 }, |
| 221 { ASCIIToUTF16(" foo bar "), 2, ASCIIToUTF16("foo bar "), 0 }, |
| 222 |
| 223 // forced query. |
| 224 { ASCIIToUTF16("?foo bar"), 2, ASCIIToUTF16("foo bar"), 1 }, |
| 225 }; |
| 226 |
| 227 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { |
| 228 SCOPED_TRACE(input_cases[i].input); |
| 229 AutocompleteInput input(input_cases[i].input, |
| 230 input_cases[i].cursor_position, |
| 231 string16(), true, false, true, |
| 232 AutocompleteInput::ALL_MATCHES); |
| 233 EXPECT_EQ(input_cases[i].normalized_input, input.text()); |
| 234 EXPECT_EQ(input_cases[i].normalized_cursor_position, |
| 235 input.cursor_position()); |
| 236 } |
| 237 } |
| OLD | NEW |