Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: tests/html/xhr_cross_origin_test.dart

Issue 12827032: Reverting "Adding CORS support to HttpRequest" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/html/html.status ('k') | tools/dom/templates/html/impl/impl_XMLHttpRequest.darttemplate » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_individual_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
11 /** 11 /**
12 * Examine the value of "crossOriginPort" as passed in from the url from 12 * Examine the value of "crossOriginPort" as passed in from the url from
13 * [window.location] to determine what the cross-origin port is for 13 * [window.location] to determine what the cross-origin port is for
14 * this test. 14 * this test.
15 */ 15 */
16 // TODO(efortuna): If we need to use this function frequently, make a 16 // TODO(efortuna): If we need to use this function frequently, make a
17 // url_analyzer library that is part of test.dart that these tests can import. 17 // url_analyzer library that is part of test.dart that these tests can import.
18 int get crossOriginPort { 18 int get crossOriginPort {
19 var searchUrl = window.location.search; 19 var searchUrl = window.location.search;
20 var crossOriginStr = 'crossOriginPort='; 20 var crossOriginStr = 'crossOriginPort=';
21 var index = searchUrl.indexOf(crossOriginStr); 21 var index = searchUrl.indexOf(crossOriginStr);
22 var nextArg = searchUrl.indexOf('&', index); 22 var nextArg = searchUrl.indexOf('&', index);
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 useHtmlIndividualConfiguration(); 28 useHtmlConfiguration();
29 29
30 group('supported', () { 30 var port = crossOriginPort;
31 test('supported', () { 31 var host = '${window.location.protocol}//${window.location.hostname}:$port';
32 expect(HttpRequest.supportsCrossOrigin, isTrue); 32
33 test('XHR Cross-domain', () {
34 var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt';
35 var xhr = new HttpRequest();
36 xhr.open('GET', url, async: true);
37 var validate = expectAsync1((data) {
38 expect(data, contains('feed'));
39 expect(data['feed'], contains('entry'));
40 expect(data, isMap);
33 }); 41 });
42 xhr.onReadyStateChange.listen((e) {
43 guardAsync(() {
44 if (xhr.readyState == HttpRequest.DONE) {
45 validate(json.parse(xhr.response));
46 }
47 });
48 });
49 xhr.send();
34 }); 50 });
35 51
36 group('functional', () { 52 test('XHR.get Cross-domain', () {
53 var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt';
54 HttpRequest.request(url).then(expectAsync1((xhr) {
55 var data = json.parse(xhr.response);
56 expect(data, contains('feed'));
57 expect(data['feed'], contains('entry'));
58 expect(data, isMap);
59 }));
60 });
37 61
38 var port = crossOriginPort; 62 test('XHR.getWithCredentials Cross-domain', () {
39 var host = '${window.location.protocol}//${window.location.hostname}:$port'; 63 var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt';
40 64 HttpRequest.request(url, withCredentials: true).then(expectAsync1((xhr) {
41 test('XHR.get Cross-domain', () { 65 var data = json.parse(xhr.response);
42 var gotError = false; 66 expect(data, contains('feed'));
43 var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt'; 67 expect(data['feed'], contains('entry'));
44 return HttpRequest.request(url).then((xhr) { 68 expect(data, isMap);
45 var data = json.parse(xhr.response); 69 }));
46 expect(data, contains('feed'));
47 expect(data['feed'], contains('entry'));
48 expect(data, isMap);
49 }).catchError((error) {}, test: (error) {
50 gotError = true;
51 // Consume errors when not supporting cross origin.
52 return !HttpRequest.supportsCrossOrigin;
53 }).whenComplete(() {
54 // Expect that we got an error when cross origin is not supported.
55 expect(gotError, !HttpRequest.supportsCrossOrigin);
56 });
57 });
58
59 // Skip the rest if not supported.
60 if (!HttpRequest.supportsCrossOrigin) {
61 return;
62 }
63
64 test('XHR Cross-domain', () {
65 var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt';
66 var xhr = new HttpRequest();
67 xhr.open('GET', url, async: true);
68 var validate = expectAsync1((data) {
69 expect(data, contains('feed'));
70 expect(data['feed'], contains('entry'));
71 expect(data, isMap);
72 });
73 xhr.onReadyStateChange.listen((e) {
74 guardAsync(() {
75 if (xhr.readyState == HttpRequest.DONE) {
76 validate(json.parse(xhr.response));
77 }
78 });
79 });
80 xhr.send();
81 });
82
83 test('XHR.getWithCredentials Cross-domain', () {
84 var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt';
85 return HttpRequest.request(url, withCredentials: true).then((xhr) {
86 var data = json.parse(xhr.response);
87 expect(data, contains('feed'));
88 expect(data['feed'], contains('entry'));
89 expect(data, isMap);
90 });
91 });
92 }); 70 });
93 } 71 }
OLDNEW
« no previous file with comments | « tests/html/html.status ('k') | tools/dom/templates/html/impl/impl_XMLHttpRequest.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698