f6ca2c1d8f
This deletes: tests/co19 tests/corelib tests/html tests/isolate tests/language tests/lib It does not delete tests/standalone because apparently there are tests in there that are not in standalone_2. (I assume they were added after the test migration. I don't know why they were added there.) I have tried to remove references to the old tests from various scripts and tools but may have missed some. (As you can imagine, grepping for "lib" does not have the best signal-to-noise ratio.) "It was a pleasure to burn. It was a special pleasure to see things eaten, to see things blackened and changed. With the brass nozzle in his fists, with this great python spitting its venomous kerosene upon the world, the blood pounded in his head, and his hands were the hands of some amazing conductor playing all the symphonies of blazing and burning to bring down the tatters and charcoal ruins of history." - Ray Bradbury, Fahrenheit 451 Change-Id: If3db4a50e7a5ee25aff8058b1483e2ce8e68424e Reviewed-on: https://dart-review.googlesource.com/c/75420 Commit-Queue: Bob Nystrom <rnystrom@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com> Reviewed-by: William Hesse <whesse@google.com> Reviewed-by: Terry Lucas <terry@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com>
111 lines
3.7 KiB
Dart
111 lines
3.7 KiB
Dart
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
library XHRCrossOriginTest;
|
|
|
|
import 'package:unittest/unittest.dart';
|
|
import 'package:unittest/html_individual_config.dart';
|
|
import 'dart:html';
|
|
import "dart:convert";
|
|
|
|
/**
|
|
* Examine the value of "crossOriginPort" as passed in from the url from
|
|
* [window.location] to determine what the cross-origin port is for
|
|
* this test.
|
|
*/
|
|
// TODO(efortuna): If we need to use this function frequently, make a
|
|
// url_analyzer library that is part of test.dart that these tests can import.
|
|
int get crossOriginPort {
|
|
var searchUrl = window.location.search;
|
|
var crossOriginStr = 'crossOriginPort=';
|
|
var index = searchUrl.indexOf(crossOriginStr);
|
|
var nextArg = searchUrl.indexOf('&', index);
|
|
return int.parse(searchUrl.substring(index + crossOriginStr.length,
|
|
nextArg == -1 ? searchUrl.length : nextArg));
|
|
}
|
|
|
|
main() {
|
|
useHtmlIndividualConfiguration();
|
|
|
|
group('supported', () {
|
|
test('supported', () {
|
|
expect(HttpRequest.supportsCrossOrigin, isTrue);
|
|
});
|
|
});
|
|
|
|
group('functional', () {
|
|
var port = crossOriginPort;
|
|
var host = '${window.location.protocol}//${window.location.hostname}:$port';
|
|
|
|
test('XHR.get Cross-domain', () {
|
|
var gotError = false;
|
|
var url = '$host/root_dart/tests/lib_2/html/xhr_cross_origin_data.txt';
|
|
return HttpRequest.request(url).then((xhr) {
|
|
var data = json.decode(xhr.response);
|
|
expect(data, contains('feed'));
|
|
expect(data['feed'], contains('entry'));
|
|
expect(data, isMap);
|
|
}).catchError((error) {}, test: (error) {
|
|
gotError = true;
|
|
// Consume errors when not supporting cross origin.
|
|
return !HttpRequest.supportsCrossOrigin;
|
|
}).whenComplete(() {
|
|
// Expect that we got an error when cross origin is not supported.
|
|
expect(gotError, !HttpRequest.supportsCrossOrigin);
|
|
});
|
|
});
|
|
|
|
test('XHR.requestCrossOrigin', () {
|
|
var url = '$host/root_dart/tests/lib_2/html/xhr_cross_origin_data.txt';
|
|
return HttpRequest.requestCrossOrigin(url).then((response) {
|
|
expect(response, contains('feed'));
|
|
});
|
|
});
|
|
|
|
test('XHR.requestCrossOrigin errors', () {
|
|
var gotError = false;
|
|
return HttpRequest.requestCrossOrigin('does_not_exist').then((response) {
|
|
expect(true, isFalse, reason: '404s should fail request.');
|
|
}).catchError((error) {}, test: (error) {
|
|
gotError = true;
|
|
return true;
|
|
}).whenComplete(() {
|
|
expect(gotError, isTrue);
|
|
});
|
|
});
|
|
|
|
// Skip the rest if not supported.
|
|
if (!HttpRequest.supportsCrossOrigin) {
|
|
return;
|
|
}
|
|
|
|
test('XHR Cross-domain', () {
|
|
var url = '$host/root_dart/tests/lib_2/html/xhr_cross_origin_data.txt';
|
|
var xhr = new HttpRequest();
|
|
xhr.open('GET', url, async: true);
|
|
var validate = expectAsync((data) {
|
|
expect(data, contains('feed'));
|
|
expect(data['feed'], contains('entry'));
|
|
expect(data, isMap);
|
|
});
|
|
xhr.onReadyStateChange.listen((e) {
|
|
if (xhr.readyState == HttpRequest.DONE) {
|
|
validate(json.decode(xhr.response));
|
|
}
|
|
});
|
|
xhr.send();
|
|
});
|
|
|
|
test('XHR.getWithCredentials Cross-domain', () {
|
|
var url = '$host/root_dart/tests/lib_2/html/xhr_cross_origin_data.txt';
|
|
return HttpRequest.request(url, withCredentials: true).then((xhr) {
|
|
var data = json.decode(xhr.response);
|
|
expect(data, contains('feed'));
|
|
expect(data['feed'], contains('entry'));
|
|
expect(data, isMap);
|
|
});
|
|
});
|
|
});
|
|
}
|