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.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
55
gaia/tests/jsmarionette/plugins/marionette-file-manager/index.js
Executable file
55
gaia/tests/jsmarionette/plugins/marionette-file-manager/index.js
Executable file
|
|
@ -0,0 +1,55 @@
|
|||
'use strict';
|
||||
var fileManagerFactory = require('./lib/file_manager_factory'),
|
||||
deviceStorageFactory = require('./lib/device_storage_factory');
|
||||
|
||||
/**
|
||||
* A marionette plugin for managing(add, remove) files in device storage.
|
||||
* The options param is structured as { tpye: 'DesktopClient' }.
|
||||
*
|
||||
* @constructor
|
||||
* @param {Marionette.Client} client marionette client to use.
|
||||
* @param {Object} options setup the file manager.
|
||||
*/
|
||||
function MarionetteFileManager(client, options) {
|
||||
var type = '';
|
||||
|
||||
this.client = client;
|
||||
this.options = options || { type: 'DesktopClient' };
|
||||
type = this.options.type || 'DesktopClient';
|
||||
|
||||
this.deviceStorage = deviceStorageFactory.generate(client, type);
|
||||
this.fileManager = fileManagerFactory.generate(this.deviceStorage, type);
|
||||
}
|
||||
|
||||
MarionetteFileManager.prototype = {
|
||||
/**
|
||||
* Add files.
|
||||
*
|
||||
* @param {String|Array} files the path of files.
|
||||
*/
|
||||
add: function(files) {
|
||||
this.fileManager.add(files);
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove files.
|
||||
*
|
||||
* @param {String|Array} files the path of files.
|
||||
*/
|
||||
remove: function(files) {
|
||||
this.fileManager.remove(files);
|
||||
},
|
||||
|
||||
/**
|
||||
* Clean all files in device storage.
|
||||
*/
|
||||
removeAllFiles: function() {
|
||||
this.fileManager.removeAllFiles();
|
||||
}
|
||||
};
|
||||
|
||||
MarionetteFileManager.setup = function(client, options) {
|
||||
return new MarionetteFileManager(client, options);
|
||||
};
|
||||
|
||||
module.exports = MarionetteFileManager;
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
/* global Components */
|
||||
'use strict';
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
/**
|
||||
* Device storage helper.
|
||||
*
|
||||
* Currently the type includes:
|
||||
* - DesktopClient
|
||||
* TODO: We could have one for device host.
|
||||
* The type name could be called "Device".
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} client Marionette client to use.
|
||||
*/
|
||||
function DesktopClientDeviceStorage(client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
DesktopClientDeviceStorage.prototype = {
|
||||
/**
|
||||
* Get the path to the directory contain the specified type of files.
|
||||
* If the the specificed type directory is not existed yet,
|
||||
* the function will create it.
|
||||
*
|
||||
* @param {String} type the media type, like "pictures", "music", or "videos".
|
||||
* @return {String} path to the directory of the specified type files.
|
||||
*/
|
||||
getMediaFilePath: function(type) {
|
||||
var filePath = path.join(this.getDeviceStoragePath(), type);
|
||||
if (!fs.existsSync(filePath)) {
|
||||
fs.mkdirSync(filePath);
|
||||
}
|
||||
return filePath;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get device storage path.
|
||||
*
|
||||
* @return {String} path to device storage directory.
|
||||
*/
|
||||
getDeviceStoragePath: function() {
|
||||
// The device-storage-testing directory is also created by FF.
|
||||
// If it doesn't exsit before we get the its path,
|
||||
// we will create it manually.
|
||||
var filePath = path.join(this._getTemporaryPath(),
|
||||
'device-storage-testing');
|
||||
if (!fs.existsSync(filePath)) {
|
||||
fs.mkdirSync(filePath);
|
||||
}
|
||||
return filePath;
|
||||
},
|
||||
|
||||
/**
|
||||
* Determines the temporary directory that
|
||||
* is created by FF because of the prefs.
|
||||
*
|
||||
* @return {String} path to temporary directory.
|
||||
*/
|
||||
_getTemporaryPath: function() {
|
||||
var chrome = this.client.scope({ context: 'chrome' }),
|
||||
tmpDir;
|
||||
|
||||
tmpDir = chrome.executeScript(function() {
|
||||
var Cc = Components.classes;
|
||||
var Ci = Components.interfaces;
|
||||
var directoryService =
|
||||
Cc['@mozilla.org/file/directory_service;1'].
|
||||
getService(Ci.nsIProperties);
|
||||
return directoryService.get('TmpD', Ci.nsIFile).path;
|
||||
});
|
||||
|
||||
return tmpDir;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = DesktopClientDeviceStorage;
|
||||
|
|
@ -0,0 +1,151 @@
|
|||
'use strict';
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
/**
|
||||
* The file manager for desktop client.
|
||||
*
|
||||
* @constructor
|
||||
* @param {DeviceStorageFactory.DeviceStorage} deviceStorage
|
||||
* the implementation of the device storage.
|
||||
*/
|
||||
function DesktopClientFileManager(deviceStorage) {
|
||||
this.deviceStorage = deviceStorage;
|
||||
}
|
||||
|
||||
DesktopClientFileManager.prototype = {
|
||||
// TODO: Support blob param.
|
||||
/**
|
||||
* Add files by specified type.
|
||||
* The param is structured as
|
||||
* { type: 'videos', filePath: 'path/to/file', filename: 'filename' }.
|
||||
* { type: 'videos', dirPath: 'path/to/folder' }.
|
||||
*
|
||||
* @param {Array|Object} file would like to add.
|
||||
*/
|
||||
add: function(files) {
|
||||
var that = this;
|
||||
if (!Array.isArray(files)) {
|
||||
files = [files];
|
||||
}
|
||||
|
||||
files.forEach(function(file) {
|
||||
var dirPath = file.dirPath;
|
||||
var type = file.type;
|
||||
if (file.filePath) {
|
||||
that._addFile(file);
|
||||
} else {
|
||||
fs.readdirSync(dirPath).forEach(function(filename) {
|
||||
that._addFile({
|
||||
type: type,
|
||||
filePath: path.join(dirPath, filename)
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
_addFile: function(file) {
|
||||
var filename = file.filename || path.basename(file.filePath);
|
||||
var targetPath = this.deviceStorage.getMediaFilePath(file.type);
|
||||
if (!fs.existsSync(targetPath)) {
|
||||
fs.mkdirSync(targetPath);
|
||||
}
|
||||
this._copyFile(file.filePath, path.join(targetPath, filename));
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove files by specified type.
|
||||
* The param is structured as
|
||||
* { type: 'videos', filename: 'filename' }.
|
||||
*
|
||||
* @param {Array|Object} files would like to remove.
|
||||
*/
|
||||
remove: function(files) {
|
||||
var filePaths;
|
||||
if (Array.isArray(files)) {
|
||||
filePaths = files;
|
||||
} else {
|
||||
filePaths = [files];
|
||||
}
|
||||
|
||||
filePaths.forEach(function(file) {
|
||||
var filePath = this.deviceStorage.getMediaFilePath(file.type);
|
||||
fs.unlinkSync(path.join(filePath, file.filename));
|
||||
// Remove the directory if no file in it.
|
||||
if (fs.readdirSync(filePath).length === 0) {
|
||||
fs.rmdirSync(filePath);
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove all files and directories in device storage.
|
||||
*/
|
||||
removeAllFiles: function() {
|
||||
var deviceStoragePath = this.deviceStorage.getDeviceStoragePath(),
|
||||
fileList = [];
|
||||
|
||||
if (fs.existsSync(deviceStoragePath)) {
|
||||
fileList = fs.readdirSync(deviceStoragePath);
|
||||
fileList.forEach(function(item) {
|
||||
this._removeFile(path.join(deviceStoragePath, item));
|
||||
}.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove a file or a directory even inclued files.
|
||||
*
|
||||
* @param {String} filePath a file path or directory path.
|
||||
*/
|
||||
_removeFile: function(filePath) {
|
||||
var fileList = [],
|
||||
fileNumber = 0,
|
||||
dirname = '';
|
||||
|
||||
if (fs.statSync(filePath).isDirectory()) {
|
||||
fileList = fs.readdirSync(filePath);
|
||||
fileNumber = fileList.length;
|
||||
|
||||
if (fileNumber === 0) {
|
||||
fs.rmdirSync(filePath);
|
||||
}
|
||||
|
||||
fileList.forEach(function(item) {
|
||||
this._removeFile(path.join(filePath, item));
|
||||
}.bind(this));
|
||||
} else {
|
||||
fs.unlinkSync(filePath);
|
||||
dirname = path.dirname(filePath);
|
||||
if (fs.readdirSync(dirname).length === 0) {
|
||||
fs.rmdirSync(dirname);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy a single file to a specified path.
|
||||
*
|
||||
* @param {String} source the path of the source file.
|
||||
* @param {String} target the path you would like to copy to.
|
||||
*/
|
||||
_copyFile: function(source, target) {
|
||||
var BUF_LENGTH = 64 * 1024,
|
||||
buffer = new Buffer(BUF_LENGTH),
|
||||
fdr = fs.openSync(source, 'r'),
|
||||
fdw = fs.openSync(target, 'w'),
|
||||
bytesRead = 1,
|
||||
position = 0;
|
||||
|
||||
while (bytesRead > 0) {
|
||||
bytesRead = fs.readSync(fdr, buffer, 0, BUF_LENGTH, position);
|
||||
fs.writeSync(fdw, buffer, 0, bytesRead);
|
||||
position += bytesRead;
|
||||
}
|
||||
fs.closeSync(fdr);
|
||||
fs.closeSync(fdw);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = DesktopClientFileManager;
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
'use strict';
|
||||
/**
|
||||
* Generate the file manager for each type of host.
|
||||
* Currently the type includes:
|
||||
* - DesktopClient
|
||||
* TODO: We could have one for device host.
|
||||
* The type name could be called "Device".
|
||||
*/
|
||||
var DeviceStorageFactory = {
|
||||
/**
|
||||
* Generate a instance of device storage.
|
||||
*
|
||||
* @return {Object} instance of device storage.
|
||||
*/
|
||||
generate: function(client, type) {
|
||||
return DeviceStorageFactory[type](client);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate the DesktopClient instance.
|
||||
*
|
||||
* @param {Object} client the marionette client.
|
||||
* @return {Object} instance of DesktopClientDeviceStorage.
|
||||
*/
|
||||
DeviceStorageFactory.DesktopClient = function(client) {
|
||||
var DesktopClient = require('./desktop_client_device_storage');
|
||||
return new DesktopClient(client);
|
||||
};
|
||||
|
||||
module.exports = DeviceStorageFactory;
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
'use strict';
|
||||
/**
|
||||
* Generate the file manager for each type of host.
|
||||
* Currently the type includes:
|
||||
* - DesktopClient
|
||||
* TODO: We could have one for device host.
|
||||
* The type name could be called "Device".
|
||||
*/
|
||||
var FileManagerFactory = {
|
||||
/**
|
||||
* Generate a instance of file manager.
|
||||
*
|
||||
* @return {Object} instance of file manager.
|
||||
*/
|
||||
generate: function(deviceStorage, type) {
|
||||
return FileManagerFactory[type](deviceStorage);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate the DesktopClient instance.
|
||||
*
|
||||
* @param {Object} deviceStorage desktop client deviceStorage.
|
||||
* @return {Object} instance of DesktopClientFileManager.
|
||||
*/
|
||||
FileManagerFactory.DesktopClient = function(deviceStorage) {
|
||||
var DesktopClient = require('./desktop_client_file_manager');
|
||||
return new DesktopClient(deviceStorage);
|
||||
};
|
||||
|
||||
module.exports = FileManagerFactory;
|
||||
7
gaia/tests/jsmarionette/plugins/marionette-file-manager/package.json
Executable file
7
gaia/tests/jsmarionette/plugins/marionette-file-manager/package.json
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "marionette-file-manager",
|
||||
"version": "0.0.4",
|
||||
"author": "Evan Tseng <evanxd@mozilla.com>",
|
||||
"description": "A marionette plugin to manage(add, remove) files in device storage.",
|
||||
"main": "index.js"
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
'use strict';
|
||||
var assert = require('assert'),
|
||||
fs = require('fs'),
|
||||
testHelper = require('../lib/test_helper'),
|
||||
DesktopClientDeviceStorage =
|
||||
require('../../lib/desktop_client_device_storage');
|
||||
|
||||
suite('DesktopClientDeviceStorage', function() {
|
||||
var subject;
|
||||
var client = marionette.client({
|
||||
profile: {
|
||||
prefs: {
|
||||
'device.storage.enabled': true,
|
||||
'device.storage.testing': true,
|
||||
'device.storage.prompt.testing': true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
subject = new DesktopClientDeviceStorage(client);
|
||||
});
|
||||
|
||||
suite('#_getTemporaryPath', function() {
|
||||
test('should get temporary path', function() {
|
||||
var path = subject._getTemporaryPath();
|
||||
assert.ok(fs.existsSync(path));
|
||||
});
|
||||
});
|
||||
|
||||
suite('#getDeviceStoragePath', function() {
|
||||
test('should get device storage path', function() {
|
||||
var path = subject.getDeviceStoragePath();
|
||||
assert.ok(fs.existsSync(path));
|
||||
});
|
||||
});
|
||||
|
||||
suite('#getMediaFilePath', function() {
|
||||
var path;
|
||||
|
||||
teardown(function() {
|
||||
testHelper.removeFile(path);
|
||||
});
|
||||
|
||||
test('should get videos file path', function() {
|
||||
var PICTURES_TYPE = 'pictures';
|
||||
path = subject.getMediaFilePath(PICTURES_TYPE);
|
||||
assert.ok(path.indexOf(PICTURES_TYPE) !== -1);
|
||||
assert.ok(fs.existsSync(path));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
'use strict';
|
||||
var assert = require('assert'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
testHelper = require('../lib/test_helper');
|
||||
|
||||
var TEST_FILES_PATH = '../test_files',
|
||||
TEXT_FILE_NAME = 'hello_world.json',
|
||||
IMAGE_FILE_NAME = 'fxos.png',
|
||||
PICTURES_TYPE = 'pictures',
|
||||
TEXT_TYPE = 'text',
|
||||
DS_FILE_PATH = path.join(TEXT_TYPE, TEXT_FILE_NAME),
|
||||
TEST_FILE_PATH = path.join(__dirname, TEST_FILES_PATH, TEXT_FILE_NAME);
|
||||
|
||||
marionette('MarionetteFileManager', function() {
|
||||
var deviceStoragePath = '';
|
||||
|
||||
var client = marionette.client({
|
||||
profile: {
|
||||
prefs: {
|
||||
'device.storage.enabled': true,
|
||||
'device.storage.testing': true,
|
||||
'device.storage.prompt.testing': true
|
||||
}
|
||||
}
|
||||
});
|
||||
marionette.plugin('fileManager', require('../../index'));
|
||||
|
||||
setup(function() {
|
||||
deviceStoragePath =
|
||||
client.fileManager.deviceStorage.getDeviceStoragePath();
|
||||
|
||||
client.fileManager.add({
|
||||
type: PICTURES_TYPE,
|
||||
filePath: path.join(__dirname, TEST_FILES_PATH, IMAGE_FILE_NAME)
|
||||
});
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
testHelper.removeFile(deviceStoragePath);
|
||||
});
|
||||
|
||||
suite('#add', function() {
|
||||
test('should get the file from device storage', function() {
|
||||
client.fileManager.add({
|
||||
type: TEXT_TYPE,
|
||||
filePath: path.join(__dirname, TEST_FILES_PATH, TEXT_FILE_NAME)
|
||||
});
|
||||
|
||||
client.executeAsyncScript(
|
||||
getFileFromDeviceStorage,
|
||||
[DS_FILE_PATH],
|
||||
function(error, value) {
|
||||
var expectedContent = fs.readFileSync(TEST_FILE_PATH).toString();
|
||||
assert.deepEqual(value.file.toString(), expectedContent);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
suite('#remove', function() {
|
||||
test('should get the file from device storage', function() {
|
||||
client.fileManager.remove({
|
||||
type: PICTURES_TYPE,
|
||||
filename: IMAGE_FILE_NAME
|
||||
});
|
||||
|
||||
client.executeAsyncScript(
|
||||
getFilesFromDeviceStorageByType,
|
||||
['pictures'],
|
||||
function(error, value) {
|
||||
assert.ok(value.files.length === 0);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
suite('#removeAllFiles', function() {
|
||||
test('should show the "No photos or videos" message', function() {
|
||||
client.fileManager.add({
|
||||
type: PICTURES_TYPE,
|
||||
filePath: path.join(__dirname, TEST_FILES_PATH, IMAGE_FILE_NAME),
|
||||
filename: 'test_file.png'
|
||||
});
|
||||
client.fileManager.removeAllFiles();
|
||||
|
||||
client.executeAsyncScript(
|
||||
getFilesFromDeviceStorageByType,
|
||||
['pictures'],
|
||||
function(error, value) {
|
||||
assert.ok(value.files.length === 0);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test('could add file after do removeAllFiles', function() {
|
||||
client.fileManager.removeAllFiles();
|
||||
client.fileManager.add({
|
||||
type: TEXT_TYPE,
|
||||
filePath: path.join(__dirname, TEST_FILES_PATH, TEXT_FILE_NAME)
|
||||
});
|
||||
|
||||
client.executeAsyncScript(
|
||||
getFileFromDeviceStorage,
|
||||
[DS_FILE_PATH],
|
||||
function(error, value) {
|
||||
var expectedContent = fs.readFileSync(TEST_FILE_PATH).toString();
|
||||
assert.deepEqual(value.file.toString(), expectedContent);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
function getFileFromDeviceStorage(filePath) {
|
||||
var sdcard = navigator.getDeviceStorage('sdcard'),
|
||||
request = sdcard.get(filePath);
|
||||
request.onsuccess = function() {
|
||||
var fileReader = new FileReader();
|
||||
fileReader.readAsText(this.result);
|
||||
|
||||
fileReader.onloadend = function() {
|
||||
marionetteScriptFinished({ file: fileReader.result });
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function getFilesFromDeviceStorageByType(type) {
|
||||
var storage = navigator.getDeviceStorage(type),
|
||||
request = storage.enumerate(),
|
||||
files = [];
|
||||
|
||||
request.onsuccess = function() {
|
||||
var file = this.result;
|
||||
|
||||
if (file) {
|
||||
files.push(file.name);
|
||||
this.continue();
|
||||
} else {
|
||||
marionetteScriptFinished({ files: files });
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
'use strict';
|
||||
var fs = require('fs'),
|
||||
path = require('path');
|
||||
|
||||
var TestHelper = {
|
||||
/**
|
||||
* Remove a file or a directory even inclued files.
|
||||
*
|
||||
* @param {String} filePath a file path or directory path.
|
||||
*/
|
||||
removeFile: function(filePath) {
|
||||
var fileList = [],
|
||||
fileNumber = 0,
|
||||
dirname = '';
|
||||
|
||||
if (fs.statSync(filePath).isDirectory()) {
|
||||
fileList = fs.readdirSync(filePath);
|
||||
fileNumber = fileList.length;
|
||||
|
||||
if (fileNumber === 0) {
|
||||
fs.rmdirSync(filePath);
|
||||
}
|
||||
|
||||
fileList.forEach(function(item) {
|
||||
TestHelper.removeFile(filePath + '/' + item);
|
||||
});
|
||||
} else {
|
||||
fs.unlinkSync(filePath);
|
||||
dirname = path.dirname(filePath);
|
||||
if (fs.readdirSync(dirname).length === 0) {
|
||||
fs.rmdirSync(dirname);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = TestHelper;
|
||||
BIN
gaia/tests/jsmarionette/plugins/marionette-file-manager/test/test_files/fxos.png
Executable file
BIN
gaia/tests/jsmarionette/plugins/marionette-file-manager/test/test_files/fxos.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 51 KiB |
|
|
@ -0,0 +1 @@
|
|||
{ "FxOS" : "Hello world." }
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
'use strict';
|
||||
var DEVICE_STORAGE_PATH = __dirname + '/devicestorage',
|
||||
TEST_FILES_PATH = '../test_files',
|
||||
TEST_FILE_NAME = 'fxos.png',
|
||||
PICTURES_TYPE = 'pictures';
|
||||
var assert = require('assert'),
|
||||
sinon = require('sinon'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
testHelper = require('../lib/test_helper'),
|
||||
DeviceStorage =
|
||||
require('../../lib/desktop_client_device_storage'),
|
||||
FileManager =
|
||||
require('../../lib/desktop_client_file_manager'),
|
||||
subject = {};
|
||||
|
||||
suite('DesktopClientFileManager', function() {
|
||||
var deviceStorage = {};
|
||||
|
||||
setup(function() {
|
||||
// Create the device storage.
|
||||
if (!fs.existsSync(DEVICE_STORAGE_PATH)) {
|
||||
fs.mkdirSync(DEVICE_STORAGE_PATH);
|
||||
}
|
||||
|
||||
deviceStorage = new DeviceStorage({});
|
||||
sinon.stub(deviceStorage, 'getDeviceStoragePath', function() {
|
||||
return DEVICE_STORAGE_PATH;
|
||||
});
|
||||
sinon.stub(deviceStorage, 'getMediaFilePath', function(type) {
|
||||
return path.join(DEVICE_STORAGE_PATH, type);
|
||||
});
|
||||
|
||||
subject = new FileManager(deviceStorage);
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
deviceStorage.getDeviceStoragePath.restore();
|
||||
deviceStorage.getMediaFilePath.restore();
|
||||
if (fs.existsSync(DEVICE_STORAGE_PATH)) {
|
||||
fs.rmdirSync(DEVICE_STORAGE_PATH);
|
||||
}
|
||||
});
|
||||
|
||||
suite('#add', function() {
|
||||
teardown(function() {
|
||||
testHelper.removeFile(path.join(DEVICE_STORAGE_PATH, PICTURES_TYPE));
|
||||
});
|
||||
|
||||
test('should add a file in the pictures directory', function() {
|
||||
subject.add({
|
||||
type: PICTURES_TYPE,
|
||||
filePath: path.join(__dirname, TEST_FILES_PATH, TEST_FILE_NAME)
|
||||
});
|
||||
|
||||
assert.ok(
|
||||
fs.existsSync(path.join(
|
||||
DEVICE_STORAGE_PATH, PICTURES_TYPE, TEST_FILE_NAME
|
||||
))
|
||||
);
|
||||
});
|
||||
|
||||
test('should add files in the pictures directory', function() {
|
||||
var TEST_FILE_1 = 'test_file_1.png',
|
||||
TEST_FILE_2 = 'test_file_2.png';
|
||||
var fileList = [];
|
||||
|
||||
subject.add([
|
||||
{
|
||||
type: PICTURES_TYPE,
|
||||
filePath: path.join(__dirname, TEST_FILES_PATH, TEST_FILE_NAME),
|
||||
filename: TEST_FILE_1
|
||||
},
|
||||
{
|
||||
type: PICTURES_TYPE,
|
||||
filePath: path.join(__dirname, TEST_FILES_PATH, TEST_FILE_NAME),
|
||||
filename: TEST_FILE_2
|
||||
}
|
||||
]);
|
||||
|
||||
fileList = fs.readdirSync(deviceStorage.getMediaFilePath(PICTURES_TYPE));
|
||||
assert.ok(fileList.indexOf(TEST_FILE_1) !== -1);
|
||||
assert.ok(fileList.indexOf(TEST_FILE_2) !== -1);
|
||||
});
|
||||
|
||||
test('should add all files of a directory ' +
|
||||
'in the pictures directory', function() {
|
||||
var fileList = [];
|
||||
subject.add({
|
||||
type: PICTURES_TYPE,
|
||||
dirPath: path.join(__dirname, TEST_FILES_PATH)
|
||||
});
|
||||
fileList = fs.readdirSync(deviceStorage.getMediaFilePath(PICTURES_TYPE));
|
||||
assert.ok(fileList.indexOf('fxos.png') !== -1);
|
||||
assert.ok(fileList.indexOf('hello_world.json') !== -1);
|
||||
});
|
||||
});
|
||||
|
||||
suite('#remove', function() {
|
||||
setup(function() {
|
||||
subject.add({
|
||||
type: PICTURES_TYPE,
|
||||
filePath: path.join(__dirname, TEST_FILES_PATH, TEST_FILE_NAME)
|
||||
});
|
||||
});
|
||||
|
||||
test('should remove a file in the videos directory', function() {
|
||||
subject.remove({
|
||||
type: PICTURES_TYPE,
|
||||
filename: TEST_FILE_NAME
|
||||
});
|
||||
|
||||
assert.ok(!fs.existsSync(path.join(
|
||||
DEVICE_STORAGE_PATH, PICTURES_TYPE, TEST_FILE_NAME
|
||||
)));
|
||||
});
|
||||
});
|
||||
|
||||
suite('#removeAllFiles', function() {
|
||||
test('should have device storage directory', function() {
|
||||
subject.removeAllFiles();
|
||||
assert.ok(fs.existsSync(DEVICE_STORAGE_PATH));
|
||||
});
|
||||
|
||||
test('should work when no file in device storage', function() {
|
||||
subject.removeAllFiles();
|
||||
assert.ok(fs.readdirSync(DEVICE_STORAGE_PATH).length === 0);
|
||||
});
|
||||
|
||||
test('should remove all files in device storage', function() {
|
||||
subject.add({
|
||||
type: PICTURES_TYPE,
|
||||
filePath: path.join(__dirname, TEST_FILES_PATH, TEST_FILE_NAME)
|
||||
});
|
||||
|
||||
subject.removeAllFiles();
|
||||
assert.ok(fs.readdirSync(DEVICE_STORAGE_PATH).length === 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue