File tree Expand file tree Collapse file tree 6 files changed +103
-0
lines changed
tests/automation/reference_xhr_in_node_context Expand file tree Collapse file tree 6 files changed +103
-0
lines changed Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" :" nw_1404278514" ,
3
+ "main" :" index.html" ,
4
+ "dependencies" :{}
5
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" :" reference_xhr_in_node_context_wrapper" ,
3
+ "main" :" index.html"
4
+ }
5
+
You can’t perform that action at this time.
0 commit comments