OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 16 matching lines...) Expand all Loading... |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 // Basic tests that verify our KURL's interface behaves the same as the | 31 // Basic tests that verify our KURL's interface behaves the same as the |
32 // original KURL's. | 32 // original KURL's. |
33 | 33 |
34 #include "platform/weborigin/KURL.h" | 34 #include "platform/weborigin/KURL.h" |
35 | 35 |
36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 37 #include "wtf/StdLibExtras.h" |
37 #include "wtf/text/CString.h" | 38 #include "wtf/text/CString.h" |
38 #include "wtf/text/WTFString.h" | 39 #include "wtf/text/WTFString.h" |
39 | 40 |
40 namespace blink { | 41 namespace blink { |
41 | 42 |
42 struct ComponentCase { | 43 struct ComponentCase { |
43 const char* url; | 44 const char* url; |
44 const char* protocol; | 45 const char* protocol; |
45 const char* host; | 46 const char* host; |
46 const int port; | 47 const int port; |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 for (size_t i = 0; i < WTF_ARRAY_LENGTH(decodeCases); i++) { | 289 for (size_t i = 0; i < WTF_ARRAY_LENGTH(decodeCases); i++) { |
289 String input(decodeCases[i].input); | 290 String input(decodeCases[i].input); |
290 String str = decodeURLEscapeSequences(input); | 291 String str = decodeURLEscapeSequences(input); |
291 EXPECT_STREQ(decodeCases[i].output, str.utf8().data()); | 292 EXPECT_STREQ(decodeCases[i].output, str.utf8().data()); |
292 } | 293 } |
293 | 294 |
294 // Our decode should decode %00 | 295 // Our decode should decode %00 |
295 String zero = decodeURLEscapeSequences("%00"); | 296 String zero = decodeURLEscapeSequences("%00"); |
296 EXPECT_STRNE("%00", zero.utf8().data()); | 297 EXPECT_STRNE("%00", zero.utf8().data()); |
297 | 298 |
| 299 // Decode UTF-8. |
| 300 String decoded = decodeURLEscapeSequences("%e6%bc%a2%e5%ad%97"); |
| 301 const UChar decodedExpected[] = {0x6F22, 0x5b57}; |
| 302 EXPECT_EQ(String(decodedExpected, WTF_ARRAY_LENGTH(decodedExpected)), decode
d); |
| 303 |
298 // Test the error behavior for invalid UTF-8 (we differ from WebKit here). | 304 // Test the error behavior for invalid UTF-8 (we differ from WebKit here). |
299 String invalid = decodeURLEscapeSequences("%e4%a0%e5%a5%bd"); | 305 String invalid = decodeURLEscapeSequences("%e4%a0%e5%a5%bd"); |
300 UChar invalidExpectedHelper[4] = { 0x00e4, 0x00a0, 0x597d, 0 }; | 306 UChar invalidExpectedHelper[4] = { 0x00e4, 0x00a0, 0x597d, 0 }; |
301 String invalidExpected( | 307 String invalidExpected( |
302 reinterpret_cast<const ::UChar*>(invalidExpectedHelper), | 308 reinterpret_cast<const ::UChar*>(invalidExpectedHelper), |
303 3); | 309 3); |
304 EXPECT_EQ(invalidExpected, invalid); | 310 EXPECT_EQ(invalidExpected, invalid); |
305 } | 311 } |
306 | 312 |
307 TEST(KURLTest, Encode) | 313 TEST(KURLTest, Encode) |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 }; | 762 }; |
757 | 763 |
758 for (size_t i = 0; i < WTF_ARRAY_LENGTH(referrerCases); i++) { | 764 for (size_t i = 0; i < WTF_ARRAY_LENGTH(referrerCases); i++) { |
759 KURL kurl(ParsedURLString, referrerCases[i].input); | 765 KURL kurl(ParsedURLString, referrerCases[i].input); |
760 String referrer = kurl.strippedForUseAsReferrer(); | 766 String referrer = kurl.strippedForUseAsReferrer(); |
761 EXPECT_STREQ(referrerCases[i].output, referrer.utf8().data()); | 767 EXPECT_STREQ(referrerCases[i].output, referrer.utf8().data()); |
762 } | 768 } |
763 } | 769 } |
764 | 770 |
765 } // namespace blink | 771 } // namespace blink |
OLD | NEW |