@@ -175,5 +175,60 @@ describe('$httpBackend', function() {
175
175
// TODO(vojta): test whether it fires "async-start"
176
176
// TODO(vojta): test whether it fires "async-end" on both success and error
177
177
} ) ;
178
+
179
+ describe ( 'file protocol' , function ( ) {
180
+
181
+ function respond ( status , content ) {
182
+ xhr = MockXhr . $$lastInstance ;
183
+ xhr . status = status ;
184
+ xhr . responseText = content ;
185
+ xhr . readyState = 4 ;
186
+ xhr . onreadystatechange ( ) ;
187
+ }
188
+
189
+
190
+ it ( 'should convert 0 to 200 if content' , function ( ) {
191
+ $backend = createHttpBackend ( $browser , MockXhr , null , null , null , 'http' ) ;
192
+
193
+ $backend ( 'GET' , 'file:///whatever/index.html' , null , callback ) ;
194
+ respond ( 0 , 'SOME CONTENT' ) ;
195
+
196
+ expect ( callback ) . toHaveBeenCalled ( ) ;
197
+ expect ( callback . mostRecentCall . args [ 0 ] ) . toBe ( 200 ) ;
198
+ } ) ;
199
+
200
+
201
+ it ( 'should convert 0 to 200 if content - relative url' , function ( ) {
202
+ $backend = createHttpBackend ( $browser , MockXhr , null , null , null , 'file' ) ;
203
+
204
+ $backend ( 'GET' , '/whatever/index.html' , null , callback ) ;
205
+ respond ( 0 , 'SOME CONTENT' ) ;
206
+
207
+ expect ( callback ) . toHaveBeenCalled ( ) ;
208
+ expect ( callback . mostRecentCall . args [ 0 ] ) . toBe ( 200 ) ;
209
+ } ) ;
210
+
211
+
212
+ it ( 'should convert 0 to 404 if no content' , function ( ) {
213
+ $backend = createHttpBackend ( $browser , MockXhr , null , null , null , 'http' ) ;
214
+
215
+ $backend ( 'GET' , 'file:///whatever/index.html' , null , callback ) ;
216
+ respond ( 0 , '' ) ;
217
+
218
+ expect ( callback ) . toHaveBeenCalled ( ) ;
219
+ expect ( callback . mostRecentCall . args [ 0 ] ) . toBe ( 404 ) ;
220
+ } ) ;
221
+
222
+
223
+ it ( 'should convert 0 to 200 if content - relative url' , function ( ) {
224
+ $backend = createHttpBackend ( $browser , MockXhr , null , null , null , 'file' ) ;
225
+
226
+ $backend ( 'GET' , '/whatever/index.html' , null , callback ) ;
227
+ respond ( 0 , '' ) ;
228
+
229
+ expect ( callback ) . toHaveBeenCalled ( ) ;
230
+ expect ( callback . mostRecentCall . args [ 0 ] ) . toBe ( 404 ) ;
231
+ } ) ;
232
+ } ) ;
178
233
} ) ;
179
234
0 commit comments