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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 { ASCIIToUTF16("http:user:pass@foo.com"), AutocompleteInput::URL }, | 99 { ASCIIToUTF16("http:user:pass@foo.com"), AutocompleteInput::URL }, |
100 { ASCIIToUTF16("http://user:pass@foo.com"), AutocompleteInput::URL }, | 100 { ASCIIToUTF16("http://user:pass@foo.com"), AutocompleteInput::URL }, |
101 { ASCIIToUTF16("http://1.2"), AutocompleteInput::URL }, | 101 { ASCIIToUTF16("http://1.2"), AutocompleteInput::URL }, |
102 { ASCIIToUTF16("http://1.2/45"), AutocompleteInput::URL }, | 102 { ASCIIToUTF16("http://1.2/45"), AutocompleteInput::URL }, |
103 { ASCIIToUTF16("http:ps/2 games"), AutocompleteInput::URL }, | 103 { ASCIIToUTF16("http:ps/2 games"), AutocompleteInput::URL }, |
104 { ASCIIToUTF16("https://foo.com"), AutocompleteInput::URL }, | 104 { ASCIIToUTF16("https://foo.com"), AutocompleteInput::URL }, |
105 { ASCIIToUTF16("127.0.0.1"), AutocompleteInput::URL }, | 105 { ASCIIToUTF16("127.0.0.1"), AutocompleteInput::URL }, |
106 { ASCIIToUTF16("127.0.1"), AutocompleteInput::UNKNOWN }, | 106 { ASCIIToUTF16("127.0.1"), AutocompleteInput::UNKNOWN }, |
107 { ASCIIToUTF16("127.0.1/"), AutocompleteInput::URL }, | 107 { ASCIIToUTF16("127.0.1/"), AutocompleteInput::URL }, |
108 { ASCIIToUTF16("browser.tabs.closeButtons"), AutocompleteInput::UNKNOWN }, | 108 { ASCIIToUTF16("browser.tabs.closeButtons"), AutocompleteInput::UNKNOWN }, |
109 { WideToUTF16(L"\u6d4b\u8bd5"), AutocompleteInput::UNKNOWN }, | 109 { base::WideToUTF16(L"\u6d4b\u8bd5"), AutocompleteInput::UNKNOWN }, |
110 { ASCIIToUTF16("[2001:]"), AutocompleteInput::QUERY }, | 110 { ASCIIToUTF16("[2001:]"), AutocompleteInput::QUERY }, |
111 { ASCIIToUTF16("[2001:dB8::1]"), AutocompleteInput::URL }, | 111 { ASCIIToUTF16("[2001:dB8::1]"), AutocompleteInput::URL }, |
112 { ASCIIToUTF16("192.168.0.256"), AutocompleteInput::QUERY }, | 112 { ASCIIToUTF16("192.168.0.256"), AutocompleteInput::QUERY }, |
113 { ASCIIToUTF16("[foo.com]"), AutocompleteInput::QUERY }, | 113 { ASCIIToUTF16("[foo.com]"), AutocompleteInput::QUERY }, |
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 }, |
(...skipping 23 matching lines...) Expand all Loading... |
143 AutocompleteInput input(input_cases[i].input, string16::npos, | 143 AutocompleteInput input(input_cases[i].input, string16::npos, |
144 ASCIIToUTF16("com"), true, false, true, | 144 ASCIIToUTF16("com"), true, false, true, |
145 AutocompleteInput::ALL_MATCHES); | 145 AutocompleteInput::ALL_MATCHES); |
146 EXPECT_EQ(input_cases[i].type, input.type()); | 146 EXPECT_EQ(input_cases[i].type, input.type()); |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 // 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 |
151 // 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. |
152 TEST(AutocompleteInputTest, InputCrash) { | 152 TEST(AutocompleteInputTest, InputCrash) { |
153 AutocompleteInput input(WideToUTF16(L"\uff65@s"), string16::npos, string16(), | 153 AutocompleteInput input(base::WideToUTF16(L"\uff65@s"), string16::npos, |
154 true, false, true, AutocompleteInput::ALL_MATCHES); | 154 string16(), true, false, true, |
| 155 AutocompleteInput::ALL_MATCHES); |
155 } | 156 } |
156 | 157 |
157 TEST(AutocompleteInputTest, ParseForEmphasizeComponent) { | 158 TEST(AutocompleteInputTest, ParseForEmphasizeComponent) { |
158 using url_parse::Component; | 159 using url_parse::Component; |
159 Component kInvalidComponent(0, -1); | 160 Component kInvalidComponent(0, -1); |
160 struct test_data { | 161 struct test_data { |
161 const string16 input; | 162 const string16 input; |
162 const Component scheme; | 163 const Component scheme; |
163 const Component host; | 164 const Component host; |
164 } input_cases[] = { | 165 } input_cases[] = { |
165 { string16(), kInvalidComponent, kInvalidComponent }, | 166 { string16(), kInvalidComponent, kInvalidComponent }, |
166 { ASCIIToUTF16("?"), kInvalidComponent, kInvalidComponent }, | 167 { ASCIIToUTF16("?"), kInvalidComponent, kInvalidComponent }, |
167 { ASCIIToUTF16("?http://foo.com/bar"), kInvalidComponent, | 168 { ASCIIToUTF16("?http://foo.com/bar"), kInvalidComponent, |
168 kInvalidComponent }, | 169 kInvalidComponent }, |
169 { ASCIIToUTF16("foo/bar baz"), kInvalidComponent, Component(0, 3) }, | 170 { ASCIIToUTF16("foo/bar baz"), kInvalidComponent, Component(0, 3) }, |
170 { ASCIIToUTF16("http://foo/bar baz"), Component(0, 4), Component(7, 3) }, | 171 { ASCIIToUTF16("http://foo/bar baz"), Component(0, 4), Component(7, 3) }, |
171 { ASCIIToUTF16("link:foo.com"), Component(0, 4), kInvalidComponent }, | 172 { ASCIIToUTF16("link:foo.com"), Component(0, 4), kInvalidComponent }, |
172 { ASCIIToUTF16("www.foo.com:81"), kInvalidComponent, Component(0, 11) }, | 173 { ASCIIToUTF16("www.foo.com:81"), kInvalidComponent, Component(0, 11) }, |
173 { WideToUTF16(L"\u6d4b\u8bd5"), kInvalidComponent, Component(0, 2) }, | 174 { base::WideToUTF16(L"\u6d4b\u8bd5"), kInvalidComponent, Component(0, 2) }, |
174 { ASCIIToUTF16("view-source:http://www.foo.com/"), Component(12, 4), | 175 { ASCIIToUTF16("view-source:http://www.foo.com/"), Component(12, 4), |
175 Component(19, 11) }, | 176 Component(19, 11) }, |
176 { ASCIIToUTF16("view-source:https://example.com/"), | 177 { ASCIIToUTF16("view-source:https://example.com/"), |
177 Component(12, 5), Component(20, 11) }, | 178 Component(12, 5), Component(20, 11) }, |
178 { ASCIIToUTF16("view-source:www.foo.com"), kInvalidComponent, | 179 { ASCIIToUTF16("view-source:www.foo.com"), kInvalidComponent, |
179 Component(12, 11) }, | 180 Component(12, 11) }, |
180 { ASCIIToUTF16("view-source:"), Component(0, 11), kInvalidComponent }, | 181 { ASCIIToUTF16("view-source:"), Component(0, 11), kInvalidComponent }, |
181 { ASCIIToUTF16("view-source:garbage"), kInvalidComponent, | 182 { ASCIIToUTF16("view-source:garbage"), kInvalidComponent, |
182 Component(12, 7) }, | 183 Component(12, 7) }, |
183 { ASCIIToUTF16("view-source:http://http://foo"), Component(12, 4), | 184 { ASCIIToUTF16("view-source:http://http://foo"), Component(12, 4), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 SCOPED_TRACE(input_cases[i].input); | 232 SCOPED_TRACE(input_cases[i].input); |
232 AutocompleteInput input(input_cases[i].input, | 233 AutocompleteInput input(input_cases[i].input, |
233 input_cases[i].cursor_position, | 234 input_cases[i].cursor_position, |
234 string16(), true, false, true, | 235 string16(), true, false, true, |
235 AutocompleteInput::ALL_MATCHES); | 236 AutocompleteInput::ALL_MATCHES); |
236 EXPECT_EQ(input_cases[i].normalized_input, input.text()); | 237 EXPECT_EQ(input_cases[i].normalized_input, input.text()); |
237 EXPECT_EQ(input_cases[i].normalized_cursor_position, | 238 EXPECT_EQ(input_cases[i].normalized_cursor_position, |
238 input.cursor_position()); | 239 input.cursor_position()); |
239 } | 240 } |
240 } | 241 } |
OLD | NEW |