Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #library('uriTest'); | 5 #library('uriTest'); |
| 6 | 6 |
| 7 #import('../../lib/utf/utf.dart'); | 7 #import('../../lib/utf/utf.dart'); |
| 8 #import('../../lib/uri/uri.dart'); | 8 #import('../../lib/uri/uri.dart'); |
| 9 | 9 |
| 10 testUri(String uri, bool isAbsolute) { | 10 testUri(String uri, bool isAbsolute) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 Expect.stringEquals("http://a/b/c/g#s/./x", | 99 Expect.stringEquals("http://a/b/c/g#s/./x", |
| 100 base.resolve("g#s/./x").toString()); | 100 base.resolve("g#s/./x").toString()); |
| 101 Expect.stringEquals("http://a/b/c/g#s/../x", | 101 Expect.stringEquals("http://a/b/c/g#s/../x", |
| 102 base.resolve("g#s/../x").toString()); | 102 base.resolve("g#s/../x").toString()); |
| 103 Expect.stringEquals("http:g", base.resolve("http:g").toString()); | 103 Expect.stringEquals("http:g", base.resolve("http:g").toString()); |
| 104 | 104 |
| 105 // Additional tests (not from RFC 3986). | 105 // Additional tests (not from RFC 3986). |
| 106 Expect.stringEquals("http://a/b/g;p/h;s", | 106 Expect.stringEquals("http://a/b/g;p/h;s", |
| 107 base.resolve("../g;p/h;s").toString()); | 107 base.resolve("../g;p/h;s").toString()); |
| 108 | 108 |
| 109 Expect.stringEquals( | |
| 110 "http://example.com", | |
| 111 new Uri.fromString("http://example.com/a/b/c").origin); | |
| 112 Expect.stringEquals( | |
| 113 "https://example.com", | |
| 114 new Uri.fromString("https://example.com/a/b/c").origin); | |
| 115 Expect.stringEquals( | |
| 116 "http://example.com:1234", | |
| 117 new Uri.fromString("http://example.com:1234/a/b/c").origin); | |
| 118 Expect.stringEquals( | |
| 119 "https://example.com:1234", | |
| 120 new Uri.fromString("https://example.com:1234/a/b/c").origin); | |
| 121 Expect.throws( | |
| 122 () => new Uri.fromString("http:").origin, | |
| 123 (e) { return e is IllegalArgumentException; }, | |
| 124 "origin for uri with empty domain should fail"); | |
| 125 Expect.throws( | |
| 126 () => const Uri("http", null, "", 80, "/a/b/c", | |
|
ahe
2012/08/21 20:36:28
You probably need to update this to use fromCompon
| |
| 127 "query", "fragment").origin, | |
| 128 (e) { return e is IllegalArgumentException; }, | |
| 129 "origin for uri with empty domain should fail"); | |
| 130 Expect.throws( | |
| 131 () => const Uri(null, null, "", 80, "/a/b/c", | |
| 132 "query", "fragment").origin, | |
| 133 (e) { return e is IllegalArgumentException; }, | |
| 134 "origin for uri with empty scheme should fail"); | |
| 135 Expect.throws( | |
| 136 () => const Uri("http", null, null, 80, "/a/b/c", | |
| 137 "query", "fragment").origin, | |
| 138 (e) { return e is IllegalArgumentException; }, | |
| 139 "origin for uri with empty domain should fail"); | |
| 140 Expect.throws( | |
| 141 () => new Uri.fromString("http://:80").origin, | |
| 142 (e) { return e is IllegalArgumentException; }, | |
| 143 "origin for uri with empty domain should fail"); | |
| 144 Expect.throws( | |
| 145 () => new Uri.fromString("file://localhost/test.txt").origin, | |
| 146 (e) { return e is IllegalArgumentException; }, | |
| 147 "origin for non-http/https uri should fail"); | |
| 148 | |
| 109 // URI encode tests | 149 // URI encode tests |
| 110 // Note: dart2js won't handle '\ud800\udc00' and frog | 150 // Note: dart2js won't handle '\ud800\udc00' and frog |
| 111 // won't handle '\u{10000}'. So we cons this up synthetically... | 151 // won't handle '\u{10000}'. So we cons this up synthetically... |
| 112 var s = decodeUtf8([0xf0, 0x90, 0x80, 0x80]); | 152 var s = decodeUtf8([0xf0, 0x90, 0x80, 0x80]); |
| 113 | 153 |
| 114 testEncodeDecode("\uFFFE", "%EF%BF%BE"); | 154 testEncodeDecode("\uFFFE", "%EF%BF%BE"); |
| 115 testEncodeDecode("\uFFFF", "%EF%BF%BF"); | 155 testEncodeDecode("\uFFFF", "%EF%BF%BF"); |
| 116 testEncodeDecode("\uFFFE", "%EF%BF%BE"); | 156 testEncodeDecode("\uFFFE", "%EF%BF%BE"); |
| 117 testEncodeDecode("\uFFFF", "%EF%BF%BF"); | 157 testEncodeDecode("\uFFFF", "%EF%BF%BF"); |
| 118 testEncodeDecode("\x7f", "%7F"); | 158 testEncodeDecode("\x7f", "%7F"); |
| 119 testEncodeDecode("\x80", "%C2%80"); | 159 testEncodeDecode("\x80", "%C2%80"); |
| 120 testEncodeDecode("\u0800", "%E0%A0%80"); | 160 testEncodeDecode("\u0800", "%E0%A0%80"); |
| 121 testEncodeDecode(":/@',;?&=+\$", ":/@',;?&=+\$"); | 161 testEncodeDecode(":/@',;?&=+\$", ":/@',;?&=+\$"); |
| 122 testEncodeDecode(s, "%F0%90%80%80"); | 162 testEncodeDecode(s, "%F0%90%80%80"); |
| 123 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); | 163 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); |
| 124 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); | 164 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); |
| 125 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); | 165 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); |
| 126 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); | 166 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); |
| 127 testEncodeDecodeComponent("\x7f", "%7F"); | 167 testEncodeDecodeComponent("\x7f", "%7F"); |
| 128 testEncodeDecodeComponent("\x80", "%C2%80"); | 168 testEncodeDecodeComponent("\x80", "%C2%80"); |
| 129 testEncodeDecodeComponent("\u0800", "%E0%A0%80"); | 169 testEncodeDecodeComponent("\u0800", "%E0%A0%80"); |
| 130 testEncodeDecodeComponent(":/@',;?&=+\$", "%3A%2F%40'%2C%3B%3F%26%3D%2B%24"); | 170 testEncodeDecodeComponent(":/@',;?&=+\$", "%3A%2F%40'%2C%3B%3F%26%3D%2B%24"); |
| 131 testEncodeDecodeComponent(s, "%F0%90%80%80"); | 171 testEncodeDecodeComponent(s, "%F0%90%80%80"); |
| 132 } | 172 } |
| OLD | NEW |