3
3
//https://xhr.spec.whatwg.org/
4
4
//http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/
5
5
6
- MockXMLHttpRequest . STATE_UNINITIALIZED = 0 ;
7
- MockXMLHttpRequest . STATE_OPEN = 1 ;
8
- MockXMLHttpRequest . STATE_SENT = 2 ;
9
- MockXMLHttpRequest . STATE_RECEIVING = 3 ;
10
- MockXMLHttpRequest . STATE_LOADED = 4 ;
6
+ MockXMLHttpRequest . STATE_UNSENT = 0 ;
7
+ MockXMLHttpRequest . STATE_OPENED = 1 ;
8
+ MockXMLHttpRequest . STATE_HEADERS_RECEIVED = 2 ;
9
+ MockXMLHttpRequest . STATE_LOADING = 3 ;
10
+ MockXMLHttpRequest . STATE_DONE = 4 ;
11
11
12
12
/**
13
13
* The request handlers
@@ -74,13 +74,13 @@ function MockXMLHttpRequest() {
74
74
MockXMLHttpRequest . prototype . reset = function ( ) {
75
75
76
76
this . response = null ;
77
- this . responseType = ''
77
+ this . responseType = '' ;
78
78
this . responseText = '' ;
79
79
80
80
this . status = '' ;
81
81
this . statusText = '' ;
82
82
83
- this . readyState = MockXMLHttpRequest . STATE_UNINITIALIZED ;
83
+ this . readyState = MockXMLHttpRequest . STATE_UNSENT ;
84
84
} ;
85
85
86
86
/**
@@ -94,19 +94,23 @@ MockXMLHttpRequest.prototype.trigger = function(event) {
94
94
this [ 'on' + event ] ( ) ;
95
95
}
96
96
97
+ if ( this [ 'onreadystatechange' ] ) {
98
+ this [ 'onreadystatechange' ] ( ) ;
99
+ }
100
+
97
101
//iterate over the listeners
98
102
99
103
return this ;
100
104
} ;
101
105
102
106
MockXMLHttpRequest . prototype . open = function ( method , url , async , user , password ) {
103
107
this . reset ( ) ;
104
- this . method = method ,
105
- this . url = url ,
106
- this . async = async ,
107
- this . user = user ,
108
- this . password = password ,
109
- this . data = null
108
+ this . method = method ;
109
+ this . url = url ;
110
+ this . async = async ;
111
+ this . user = user ;
112
+ this . password = password ;
113
+ this . data = null ;
110
114
} ;
111
115
112
116
MockXMLHttpRequest . prototype . setRequestHeader = function ( header , value ) {
@@ -126,13 +130,13 @@ MockXMLHttpRequest.prototype.send = function(data) {
126
130
if ( handled ) {
127
131
128
132
//trigger a success event because the request was handled
129
- self . readyState = MockXMLHttpRequest . STATE_LOADED ;
133
+ self . readyState = MockXMLHttpRequest . STATE_DONE ;
130
134
self . trigger ( 'load' ) ;
131
135
132
136
} else {
133
137
134
138
//trigger an error because the request was handled
135
- self . readyState = MockXMLHttpRequest . STATE_LOADED ;
139
+ self . readyState = MockXMLHttpRequest . STATE_DONE ;
136
140
self . trigger ( 'error' ) ;
137
141
138
142
}
@@ -144,7 +148,10 @@ MockXMLHttpRequest.prototype.send = function(data) {
144
148
MockXMLHttpRequest . prototype . abort = function ( ) {
145
149
} ;
146
150
147
- MockXMLHttpRequest . prototype . geAllResponseHeaders = function ( header ) {
151
+ MockXMLHttpRequest . prototype . getAllResponseHeaders = function ( header ) {
152
+ if ( this . readyState === MockXMLHttpRequest . STATE_UNSENT ) {
153
+ return '' ;
154
+ }
148
155
} ;
149
156
150
157
MockXMLHttpRequest . prototype . geResponseHeader = function ( header ) {
0 commit comments