VulpesOS/gaia/shared/test/unit/mocks/mock_download.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

56 lines
1.4 KiB
JavaScript
Executable file

'use strict';
var DEFAULT_PARAMS = {
id: '0',
totalBytes: 1800,
currentBytes: 100,
url: 'http://firefoxos.com/archivo.mp3',
path: '//SDCARD/Downloads/archivo.mp3',
state: 'downloading',
contentType: 'audio/mpeg',
startTime: new Date(),
error: null
};
function MockDownload(params) {
params = params || {};
this.id = params.id || '0';
this.totalBytes = params.totalBytes || DEFAULT_PARAMS.totalBytes;
this.currentBytes = params.currentBytes || DEFAULT_PARAMS.currentBytes;
this.url = params.url || DEFAULT_PARAMS.url;
this.path = params.path || DEFAULT_PARAMS.path;
this.state = params.state || DEFAULT_PARAMS.state;
this.contentType = params.contentType || DEFAULT_PARAMS.contentType;
this.startTime = params.startTime || DEFAULT_PARAMS.startTime;
this.error = params.error || DEFAULT_PARAMS.error;
this.listeners = [];
}
MockDownload.prototype = {
addEventListener: function(type, listener) {
if(this.listeners.indexOf(listener) == -1) {
this.listeners.push(listener);
}
},
removeEventListener: function(type, listener) {
var index = this.listeners.indexOf(listener);
if (index > -1) {
this.listeners.splice(index, 1);
}
},
pause: function() {
return {
then: function(success, error) { setTimeout(success, 0); }
};
},
resume: function() {
return {
then: function(success, error) { setTimeout(success, 0); }
};
}
};