Skip to content

Commit 08b12b4

Browse files
committed
add new test case "reference_xhr_in_node_context"
1 parent b08ad4f commit 08b12b4

File tree

6 files changed

+103
-0
lines changed

6 files changed

+103
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>reference xhr in node context test</title>
6+
</head>
7+
<body>
8+
<p>reference xhr in node context test</p>
9+
10+
<script src="../res/mocha_util.js"></script>
11+
<script src="mocha_test.js"></script>
12+
13+
</body>
14+
15+
</html>
16+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf8">
5+
<title>test</title>
6+
</head>
7+
<body>
8+
<h1>it works!</h1>
9+
<script type="text/javascript">
10+
11+
var path = require('path');
12+
var fs = require('fs');
13+
var testPath = path.join(fs.realpathSync('.'), 'test.js');
14+
15+
16+
global.xhr = new XMLHttpRequest();
17+
var test = require(testPath);
18+
test.xhr();
19+
global.xhr.open('GET', 'http://127.0.0.1:8123/img.jpg', true);
20+
global.xhr.responseType = 'arraybuffer';
21+
global.xhr.send(null);
22+
23+
setTimeout(function(){
24+
var socket = require('net').connect({port: 13013});
25+
socket.setEncoding('utf8');
26+
socket.end('write');
27+
28+
},2000);
29+
</script>
30+
</body>
31+
</html>
32+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name":"nw_1404278514",
3+
"main":"index.html",
4+
"dependencies":{}
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
exports.xhr = function () {
2+
global.xhr.onreadystatechange = function() {
3+
if (global.xhr.readyState === 4 && global.xhr.status === 200) {
4+
}
5+
}
6+
global.xhr.onload = function(e) {
7+
var uInt8Array = new Uint8Array(this.response); // this.response == uInt8Array.buffer
8+
// var byte3 = uInt8Array[4]; // byte at offset 4
9+
};
10+
11+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var path = require('path');
2+
var assert = require('assert');
3+
var fs = require('fs-extra');
4+
var curDir = fs.realpathSync('.');
5+
6+
describe('reference xhr from node context',function(){
7+
8+
var server, child, crash = true;
9+
10+
before(function(done) {
11+
this.timeout(0);
12+
server = createTCPServer(13013);
13+
child = spawnChildProcess(path.join(curDir, 'internal'));
14+
server.on('connection', function(socket) {
15+
socket.setEncoding('utf8');
16+
socket.on('data', function(data) {
17+
crash = false;
18+
child.kill();
19+
done();
20+
});
21+
});
22+
23+
});
24+
25+
after(function () {
26+
server.close();
27+
});
28+
29+
it("reference xhr from node context should not crash",function(done){
30+
assert.equal(crash,false);
31+
done();
32+
});
33+
});
34+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name":"reference_xhr_in_node_context_wrapper",
3+
"main":"index.html"
4+
}
5+

0 commit comments

Comments
 (0)