OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "url/third_party/mozilla/url_parse.h" | 9 #include "url/third_party/mozilla/url_parse.h" |
10 #include "url/url_canon.h" | 10 #include "url/url_canon.h" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 "pqrstuvwxyz{|}~\x7f/"}, | 207 "pqrstuvwxyz{|}~\x7f/"}, |
208 // Test un-UTF-8-ization. | 208 // Test un-UTF-8-ization. |
209 {"%e4%bd%a0%e5%a5%bd", "\xe4\xbd\xa0\xe5\xa5\xbd"}, | 209 {"%e4%bd%a0%e5%a5%bd", "\xe4\xbd\xa0\xe5\xa5\xbd"}, |
210 }; | 210 }; |
211 | 211 |
212 for (size_t i = 0; i < arraysize(decode_cases); i++) { | 212 for (size_t i = 0; i < arraysize(decode_cases); i++) { |
213 const char* input = decode_cases[i].input; | 213 const char* input = decode_cases[i].input; |
214 RawCanonOutputT<base::char16> output; | 214 RawCanonOutputT<base::char16> output; |
215 DecodeURLEscapeSequences(input, strlen(input), &output); | 215 DecodeURLEscapeSequences(input, strlen(input), &output); |
216 EXPECT_EQ(decode_cases[i].output, | 216 EXPECT_EQ(decode_cases[i].output, |
217 test_utils::ConvertUTF16ToUTF8(base::string16(output.data(), | 217 base::UTF16ToUTF8(base::string16(output.data(), |
218 output.length()))); | 218 output.length()))); |
219 } | 219 } |
220 | 220 |
221 // Our decode should decode %00 | 221 // Our decode should decode %00 |
222 const char zero_input[] = "%00"; | 222 const char zero_input[] = "%00"; |
223 RawCanonOutputT<base::char16> zero_output; | 223 RawCanonOutputT<base::char16> zero_output; |
224 DecodeURLEscapeSequences(zero_input, strlen(zero_input), &zero_output); | 224 DecodeURLEscapeSequences(zero_input, strlen(zero_input), &zero_output); |
225 EXPECT_NE("%00", test_utils::ConvertUTF16ToUTF8( | 225 EXPECT_NE("%00", base::UTF16ToUTF8( |
226 base::string16(zero_output.data(), zero_output.length()))); | 226 base::string16(zero_output.data(), zero_output.length()))); |
227 | 227 |
228 // Test the error behavior for invalid UTF-8. | 228 // Test the error behavior for invalid UTF-8. |
229 const char invalid_input[] = "%e4%a0%e5%a5%bd"; | 229 const char invalid_input[] = "%e4%a0%e5%a5%bd"; |
230 const base::char16 invalid_expected[4] = {0x00e4, 0x00a0, 0x597d, 0}; | 230 const base::char16 invalid_expected[4] = {0x00e4, 0x00a0, 0x597d, 0}; |
231 RawCanonOutputT<base::char16> invalid_output; | 231 RawCanonOutputT<base::char16> invalid_output; |
232 DecodeURLEscapeSequences(invalid_input, strlen(invalid_input), | 232 DecodeURLEscapeSequences(invalid_input, strlen(invalid_input), |
233 &invalid_output); | 233 &invalid_output); |
234 EXPECT_EQ(base::string16(invalid_expected), | 234 EXPECT_EQ(base::string16(invalid_expected), |
235 base::string16(invalid_output.data(), invalid_output.length())); | 235 base::string16(invalid_output.data(), invalid_output.length())); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 << test_case.canonicalized_host << ", " | 411 << test_case.canonicalized_host << ", " |
412 << test_case.lower_ascii_domain << ")"); | 412 << test_case.lower_ascii_domain << ")"); |
413 | 413 |
414 EXPECT_EQ( | 414 EXPECT_EQ( |
415 test_case.expected_domain_is, | 415 test_case.expected_domain_is, |
416 DomainIs(test_case.canonicalized_host, test_case.lower_ascii_domain)); | 416 DomainIs(test_case.canonicalized_host, test_case.lower_ascii_domain)); |
417 } | 417 } |
418 } | 418 } |
419 | 419 |
420 } // namespace url | 420 } // namespace url |
OLD | NEW |