Skip to content

Commit 1ebecda

Browse files
author
sgrekhov
committed
#932. Some HttpRequest tests fixed to work well with cross origin requests
1 parent d8301c2 commit 1ebecda

12 files changed

+60
-21
lines changed

LibTest/html/HttpRequest/abort_A01_t01.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Stop the current request.
99
* The request can only be stopped if readyState is HEADERS_RECIEVED or LOADING.
1010
* If this method is not in the process of being sent, the method has no effect.
11-
* @description Checks the state of request at variuos moments of time.
11+
* @description Checks the state of request at various moments of time.
1212
*/
1313
import "dart:html";
1414
import "../../../Utils/expect.dart";

LibTest/html/HttpRequest/dispatchEvent_A01_t01.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* @assertion bool dispatchEvent(Event event)
88
* Dispatch an event to this EventTarget.
9-
* @description Checks that an event is diapatched.
9+
* @description Checks that an event is dispatched.
1010
*/
1111
import "dart:html";
1212
import "../../../Utils/expect.dart";

LibTest/html/HttpRequest/getAllResponseHeaders_A01_t01.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77
* @assertion String getAllResponseHeaders()
88
* Retrieve all the response headers from a request.
99
* null if no headers have been received. For multipart requests,
10-
* getAllResponseHeaders will return the response headers for the current part of the request.
10+
* getAllResponseHeaders will return the response headers for the current part
11+
* of the request.
1112
* @description Checks that response headers are retrieved.
1213
*/
1314
import "dart:html";
1415
import "../../../Utils/expect.dart";
16+
import "../testcommon.dart";
1517

1618
void check(String allHeaders) {
1719
List<String> headers = allHeaders.split('\n');
1820
for (String header in headers) {
1921
List<String> entry = header.split(':');
2022
if (entry[0] == "content-type") {
21-
Expect.equals("application/dart", entry[1].trim());
23+
Expect.isTrue(entry[1].trim().startsWith("text/plain"));
2224
return;
2325
}
2426
}
@@ -27,7 +29,10 @@ void check(String allHeaders) {
2729

2830
main() {
2931
var request = new HttpRequest();
30-
request.open('GET', "http://localhost");
32+
var port = crossOriginPort;
33+
var host = '${window.location.protocol}//${window.location.hostname}:$port';
34+
var url = '$host/root_dart/tests/co19/src/LibTest/html/xhr_cross_origin_data.txt';
35+
request.open('GET', url);
3136
asyncStart();
3237
request.onLoad.listen((event) {
3338
switch (request.readyState) {

LibTest/html/HttpRequest/getResponseHeader_A01_t01.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@
1010
*/
1111
import "dart:html";
1212
import "../../../Utils/expect.dart";
13+
import "../testcommon.dart";
1314

1415
main() {
1516
var request = new HttpRequest();
16-
request.open('GET', "test.dart");
17+
var port = crossOriginPort;
18+
var host = '${window.location.protocol}//${window.location.hostname}:$port';
19+
var url = '$host/root_dart/tests/co19/src/LibTest/html/xhr_cross_origin_data.txt';
20+
request.open('GET', url);
1721
asyncStart();
1822
request.onLoad.listen((event) {
1923
switch (request.readyState) {
2024
case HttpRequest.DONE:
21-
Expect.equals(
22-
"application/dart", request.getResponseHeader("content-type"));
25+
Expect.isTrue(
26+
request.getResponseHeader("content-type")?.startsWith("text/plain"));
2327
asyncEnd();
2428
break;
2529
case HttpRequest.HEADERS_RECEIVED:

LibTest/html/HttpRequest/getString_A01_t01.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@
44
* BSD-style license that can be found in the LICENSE file.
55
*/
66
/**
7-
* @assertion Future<String> getString(String url, {bool withCredentials, void onProgress(ProgressEvent e)})
7+
* @assertion Future<String> getString(String url, {bool withCredentials, void o
8+
* nProgress(ProgressEvent e)})
89
* Creates a GET request for the specified url.
910
* The server response must be a text/ mime type for this request to succeed.
10-
* This is similar to request but specialized for HTTP GET requests which return text content.
11+
* This is similar to request but specialized for HTTP GET requests which return
12+
* text content.
1113
* @description Checks that readystatechange events are exposed.
1214
*/
1315
import "dart:html";
1416
import "../../../Utils/expect.dart";
17+
import "../testcommon.dart";
1518

1619
main() {
1720
asyncStart();
18-
var f = HttpRequest.getString("test.dart", onProgress: (event) {
21+
var port = crossOriginPort;
22+
var host = '${window.location.protocol}//${window.location.hostname}:$port';
23+
var url = '$host/root_dart/tests/co19/src/LibTest/html/xhr_cross_origin_data.txt';
24+
var f = HttpRequest.getString(url, onProgress: (event) {
1925
Expect.equals("progress", event.type, "stream.listen.onData");
2026
});
2127
f.then((content) {

LibTest/html/HttpRequest/onAbort_A01_t01.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
*/
1111
import "dart:html";
1212
import "../../../UtilsHtml/expect.dart";
13+
import "../testcommon.dart";
1314

1415
main() {
1516
var request = new HttpRequest();
16-
request.open('GET', "test.dart");
17+
var port = crossOriginPort;
18+
var host = '${window.location.protocol}//${window.location.hostname}:$port';
19+
var url = '$host/root_dart/tests/co19/src/LibTest/html/xhr_cross_origin_data.txt';
20+
request.open('GET', url);
1721
request.onAbort.listen((event) {
1822
UtilsHtml.show("request.onAbort.listen: $event");
1923
asyncEnd();

LibTest/html/HttpRequest/onError_A01_t02.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@
66
/**
77
* @assertion Stream<ProgressEvent> get onError
88
* Stream of error events handled by this HttpRequestEventTarget.
9-
* @description Checks that an error events issued when attemt to FET unexistent
10-
* resourse is made and error 404 returned.
9+
* @description Checks that an error events issued when attempt to FET unexistent
10+
* resource is made and error 404 returned.
1111
* @needsreview issue #16757
1212
*/
1313
import "dart:html";
1414
import "../../../UtilsHtml/expect.dart";
15+
import "../testcommon.dart";
1516

1617
main() {
1718
var request = new HttpRequest();
18-
request.open('GET', "IntentionallyMissingFile");
19+
var port = crossOriginPort;
20+
var host = '${window.location.protocol}//${window.location.hostname}:$port';
21+
var url = '$host/root_dart/tests/co19/src/IntentionallyMissingFile';
22+
request.open('GET', url);
1923
asyncStart();
2024
request.onError.listen((event) {
2125
UtilsHtml.show("request.onError.listen: $event");

LibTest/html/HttpRequest/onLoadEnd_A01_t01.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
/**
77
* @assertion Stream<ProgressEvent> get onLoadEnd
8-
* Stream of loadend events handled by this HttpRequestEventTarget.
8+
* Stream of loaded events handled by this HttpRequestEventTarget.
99
* @description Checks that only single event is fired.
1010
*/
1111
import "dart:html";

LibTest/html/HttpRequest/onLoad_A01_t01.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* @assertion final Stream<ProgressEvent> onLoad
88
* Stream of load events handled by this HttpRequestEventTarget.
9-
* @description Checks the state of request at variuos moments of time.
9+
* @description Checks the state of request at various moments of time.
1010
*/
1111
import "dart:html";
1212
import "../../../Utils/expect.dart";
@@ -17,6 +17,7 @@ main() {
1717
Expect.equals(HttpRequest.OPENED, request.readyState, "after open");
1818
asyncStart();
1919
request.onLoad.listen((event) {
20+
print(event);
2021
switch (request.readyState) {
2122
case HttpRequest.DONE:
2223
asyncEnd();

LibTest/html/HttpRequest/onReadyStateChange_A01_t01.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
/**
77
* @assertion Stream<ProgressEvent> get onReadyStateChange
88
* Stream of readystatechange events handled by this HttpRequest.
9-
* Event listeners to be notified every time the HttpRequest object's readyState changes values.
9+
* Event listeners to be notified every time the HttpRequest object's readyState
10+
* changes values.
1011
* @description Checks that readyState is changed every time an event is fired.
1112
*/
1213
import "dart:html";

LibTest/html/HttpRequest/overrideMimeType_A01_t01.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@
77
* @assertion void overrideMimeType(String override)
88
* Specify a particular MIME type (such as text/xml) desired for the response.
99
* This value must be set before the request has been sent.
10-
* @description Checks that MIME type is overriden.
10+
* @description Checks that MIME type is overridden.
1111
*/
1212
import "dart:html";
1313
import "../../../Utils/expect.dart";
14+
import "../testcommon.dart";
1415

15-
const desired = "text/plain";
16+
const desired = "text/plain; charset=utf-8";
1617

1718
main() {
1819
var request = new HttpRequest();
19-
request.open('GET', "test.dart");
20+
var port = crossOriginPort;
21+
var host = '${window.location.protocol}//${window.location.hostname}:$port';
22+
var url = '$host/root_dart/tests/co19/src/LibTest/html/xhr_cross_origin_data.txt';
23+
request.open('GET', url);
2024
request.overrideMimeType(desired);
2125
asyncStart();
2226
request.onLoad.listen((event) {

LibTest/html/testcommon.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,13 @@ var XlinkNamespace = "http://www.w3.org/1999/xlink";
3636
class NullTreeSanitizer implements NodeTreeSanitizer {
3737
void sanitizeTree(Node node) {}
3838
}
39+
40+
int get crossOriginPort {
41+
var searchUrl = window.location.search!;
42+
print("SearchURL=" + searchUrl);
43+
var crossOriginStr = 'crossOriginPort=';
44+
var index = searchUrl.indexOf(crossOriginStr);
45+
var nextArg = searchUrl.indexOf('&', index);
46+
return int.parse(searchUrl.substring(index + crossOriginStr.length,
47+
nextArg == -1 ? searchUrl.length : nextArg));
48+
}

0 commit comments

Comments
 (0)