/
xhr.js
60 lines (52 loc) · 1.31 KB
/
xhr.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
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or http://ckeditor.com/license
*/
'use strict';
// Mock the real XMLHttpRequest so the upload test may work locally.
window.XMLHttpRequest = function() {
var basePath = bender.config.tests[ bender.testData.group ].basePath;
return {
open: function() {},
send: function() {
var total = 10259,
loaded = 0,
step = Math.round( total / 10 ),
xhr = this,
onprogress = this.onprogress,
onload = this.onload,
interval;
// Wait 400 ms for every step.
interval = setInterval( function() {
// Add data to 'loaded' counter.
loaded += step;
if ( loaded > total ) {
loaded = total;
}
// If file is not loaded call onprogress.
if ( loaded < total ) {
onprogress( { loaded: loaded } );
}
// If file is loaded call onload.
else {
clearInterval( interval );
xhr.status = 200;
xhr.responseText = JSON.stringify( {
fileName: 'smallmoon (another copy)(20).JPG',
uploaded: 1,
url: '\/' + basePath + '_assets\/lena.jpg',
error: {
number: 201,
message: ''
}
} );
onload();
}
}, 400 );
},
// Abort should call onabort.
abort: function() {
this.onabort();
}
};
};