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
|
|
@ -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