forked from rase-/node-XMLHttpRequest
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtest-url-origin.js
47 lines (43 loc) · 1.29 KB
/
test-url-origin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var assert = require("assert")
, XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
, spawn = require('child_process').spawn;
// Test server
var serverProcess = spawn(process.argv[0], [__dirname + "/server.js"], { stdio: 'inherit' });
var runTest = function () {
try {
let xhr = new XMLHttpRequest({ origin: "http://localhost:8888" });
xhr.open("GET", "text", false);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
assert.equal(xhr.getResponseHeader('Content-Type'), 'text/plain');
assert.equal(xhr.responseText, "Hello world!");
console.log("origin test 1: done");
}
};
xhr.send();
} catch(e) {
console.log("ERROR: Exception raised", e);
}
try {
let xhr = new XMLHttpRequest({ origin: "http://localhost:8888/text" });
xhr.open("GET", "", false);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
assert.equal(xhr.getResponseHeader('Content-Type'), 'text/plain');
assert.equal(xhr.responseText, "Hello world!");
console.log("origin test 2: done");
}
};
xhr.send();
} catch(e) {
console.log("ERROR: Exception raised", e);
throw e;
}
}
setTimeout(function () {
try {
runTest();
} finally {
serverProcess.kill('SIGINT');
}
}, 100);