Skip to content

Instantly share code, notes, and snippets.

@louisremi
Created May 24, 2011 12:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save louisremi/988592 to your computer and use it in GitHub Desktop.
Save louisremi/988592 to your computer and use it in GitHub Desktop.
Fake XMLHttpRequest producing slow progress events
function fakeXMLHttpRequest() {
var self = this;
this.upload = {
addEventListener: function(evt, cb) {
self.progressListener = cb;
}
}
this.open = function() {};
this.overrideMimeType = function() {};
this.loaded = 0;
this.total = 100;
this.send = function() {
var interval = setInterval(function() {
self.loaded += 10 + Math.random()*10;
self.progressListener({
loaded: Math.min(self.loaded, 100),
total: self.total
});
if ( self.loaded >= 100 ) {
self.loaded = 0;
clearInterval(interval);
}
}, 250);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment