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 XHRCrossOriginTest; | 5 library XHRCrossOriginTest; |
6 import '../../pkg/unittest/lib/unittest.dart'; | 6 import '../../pkg/unittest/lib/unittest.dart'; |
7 import '../../pkg/unittest/lib/html_config.dart'; | 7 import '../../pkg/unittest/lib/html_config.dart'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 import 'dart:json' as json; | 9 import 'dart:json' as json; |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 return int.parse(searchUrl.substring(index + crossOriginStr.length, | 23 return int.parse(searchUrl.substring(index + crossOriginStr.length, |
24 nextArg == -1 ? searchUrl.length : nextArg)); | 24 nextArg == -1 ? searchUrl.length : nextArg)); |
25 } | 25 } |
26 | 26 |
27 main() { | 27 main() { |
28 useHtmlConfiguration(); | 28 useHtmlConfiguration(); |
29 | 29 |
30 var port = crossOriginPort; | 30 var port = crossOriginPort; |
31 | 31 |
32 test('XHR Cross-domain', () { | 32 test('XHR Cross-domain', () { |
33 var url = "http://localhost:$port/tests/html/xhr_cross_origin_data.txt"; | 33 var url = "http://localhost:$port/" |
| 34 "root_dart/tests/html/xhr_cross_origin_data.txt"; |
34 var xhr = new HttpRequest(); | 35 var xhr = new HttpRequest(); |
35 xhr.open('GET', url, true); | 36 xhr.open('GET', url, true); |
36 var validate = expectAsync1((data) { | 37 var validate = expectAsync1((data) { |
37 expect(data, contains('feed')); | 38 expect(data, contains('feed')); |
38 expect(data['feed'], contains('entry')); | 39 expect(data['feed'], contains('entry')); |
39 expect(data, isMap); | 40 expect(data, isMap); |
40 }); | 41 }); |
41 xhr.onReadyStateChange.listen((e) { | 42 xhr.onReadyStateChange.listen((e) { |
42 guardAsync(() { | 43 guardAsync(() { |
43 if (xhr.readyState == HttpRequest.DONE) { | 44 if (xhr.readyState == HttpRequest.DONE) { |
44 validate(json.parse(xhr.response)); | 45 validate(json.parse(xhr.response)); |
45 } | 46 } |
46 }); | 47 }); |
47 }); | 48 }); |
48 xhr.send(); | 49 xhr.send(); |
49 }); | 50 }); |
50 | 51 |
51 test('XHR.get Cross-domain', () { | 52 test('XHR.get Cross-domain', () { |
52 var url = "http://localhost:$port/tests/html/xhr_cross_origin_data.txt"; | 53 var url = "http://localhost:$port/" |
| 54 "root_dart/tests/html/xhr_cross_origin_data.txt"; |
53 HttpRequest.request(url).then(expectAsync1((xhr) { | 55 HttpRequest.request(url).then(expectAsync1((xhr) { |
54 var data = json.parse(xhr.response); | 56 var data = json.parse(xhr.response); |
55 expect(data, contains('feed')); | 57 expect(data, contains('feed')); |
56 expect(data['feed'], contains('entry')); | 58 expect(data['feed'], contains('entry')); |
57 expect(data, isMap); | 59 expect(data, isMap); |
58 })); | 60 })); |
59 }); | 61 }); |
60 | 62 |
61 test('XHR.getWithCredentials Cross-domain', () { | 63 test('XHR.getWithCredentials Cross-domain', () { |
62 var url = "http://localhost:$port/tests/html/xhr_cross_origin_data.txt"; | 64 var url = "http://localhost:$port/" |
| 65 "root_dart/tests/html/xhr_cross_origin_data.txt"; |
63 HttpRequest.request(url, withCredentials: true).then(expectAsync1((xhr) { | 66 HttpRequest.request(url, withCredentials: true).then(expectAsync1((xhr) { |
64 var data = json.parse(xhr.response); | 67 var data = json.parse(xhr.response); |
65 expect(data, contains('feed')); | 68 expect(data, contains('feed')); |
66 expect(data['feed'], contains('entry')); | 69 expect(data['feed'], contains('entry')); |
67 expect(data, isMap); | 70 expect(data, isMap); |
68 })); | 71 })); |
69 }); | 72 }); |
70 } | 73 } |
OLD | NEW |