summaryrefslogtreecommitdiff
path: root/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/test/test-storage.js
diff options
context:
space:
mode:
authorRuben Rodriguez <ruben@gnu.org>2015-11-28 15:24:36 -0600
committerRuben Rodriguez <ruben@gnu.org>2015-11-28 16:27:06 -0600
commite4a3586a14996bbece3b26c9e3b7704ea6af8615 (patch)
tree499bdd16b3a90c30b01e4b47a5882d13b4800f50 /data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/test/test-storage.js
parent4dbc2fae927bb02ef243c87938e638af9afee8fa (diff)
LibreJS upgraded to 6.0.10
Diffstat (limited to 'data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/test/test-storage.js')
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/test/test-storage.js134
1 files changed, 134 insertions, 0 deletions
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/test/test-storage.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/test/test-storage.js
new file mode 100644
index 0000000..14187cd
--- /dev/null
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/test/test-storage.js
@@ -0,0 +1,134 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+'use strict';
+
+const { Loader } = require('sdk/test/loader');
+const { before, after } = require('sdk/test/utils');
+
+const { get, set } = require('pathfinder/storage');
+
+exports.testGetNothing = function(assert, done) {
+ get().then(function({ data }) {
+ assert.equal(data, '', 'the data is blank!');
+ done();
+ });
+};
+
+exports.testSetThenGet = function(assert, done) {
+ const randomData = Math.random() + '';
+
+ // SET TO A RANDOM VALUE
+ set({ data: randomData }).then(function({ data }) {
+ assert.pass('setting was successful');
+ assert.equal(data, randomData, 'the data returned from set is correct [' + randomData + ']');
+ }, function(e) {
+ assert.fail('setting was unsuccessful');
+ assert.fail(e);
+ }).then(function() get()).then(function({ data }) {
+ assert.pass('getting was successful');
+ assert.equal(data, randomData, 'the data returned from get is correct [' + randomData + ']');
+ }, function(e) {
+ assert.fail('getting was unsuccessful');
+ assert.fail(e);
+ })
+ // SET AGAIN
+ .then(function() set({ data: 'test' })).then(function({ data }) {
+ assert.pass('setting was successful');
+ assert.equal(data, 'test', 'the data returned from set is correct [test]');
+ }, function(e) {
+ assert.fail('setting was unsuccessful');
+ assert.fail(e);
+ }).then(function() get()).then(function({ data }) {
+ assert.pass('getting was successful');
+ assert.equal(data, 'test', 'the data returned from get is correct [test]');
+ }, function(e) {
+ assert.fail('getting was unsuccessful');
+ assert.fail(e);
+ }).
+ // SET TO BLANK
+ then(function() set({ data: '' })).then(function({ data }) {
+ assert.pass('setting was successful');
+ assert.equal(data, '', 'the data returned from set is correct');
+ }, function(e) {
+ assert.fail('setting was unsuccessful');
+ assert.fail(e);
+ }).then(function() get()).then(function({ data }) {
+ assert.pass('getting was successful');
+ assert.equal(data, '', 'the data returned from get is correct');
+ }, function(e) {
+ assert.fail('getting was unsuccessful');
+ assert.fail(e);
+ }).
+ // SET TO BLANK AGAIN
+ then(function() set({ data: '' })).then(function({ data }) {
+ assert.pass('setting was successful');
+ assert.equal(data, '', 'the data returned from set is correct');
+ }, function(e) {
+ assert.fail('setting was unsuccessful');
+ assert.fail(e);
+ }).then(function() get()).then(function({ data }) {
+ assert.pass('getting was successful');
+ assert.equal(data, '', 'the data returned from get is correct');
+ }, function(e) {
+ assert.fail('getting was unsuccessful');
+ assert.fail(e);
+ }).then(done, assert.fail);
+};
+
+exports.testSettingJSON = function(assert, done) {
+ const json = JSON.stringify({
+ num: 1,
+ str: 'string',
+ bool: true,
+ obj: { x: 'x' },
+ ary: [ 1, 2, 3 ]
+ });
+
+ set({ data: json }).then(function({ data }) {
+ assert.pass('setting was successful');
+ assert.equal(data, json, 'the data returned from set is correct json');
+ }, function(e) {
+ assert.fail('setting was unsuccessful');
+ assert.fail(e);
+ }).then(function() get()).then(function({ data }) {
+ assert.pass('getting was successful');
+ assert.equal(data, json, 'the data returned from get is correct json');
+ }, function(e) {
+ assert.fail('getting was unsuccessful');
+ assert.fail(e);
+ }).
+ // SET TO BLANK AGAIN
+ then(function() set({ data: '' })).then(function({ data }) {
+ assert.pass('setting was successful');
+ assert.equal(data, '', 'the data returned from set is correct');
+ }, function(e) {
+ assert.fail('setting was unsuccessful');
+ assert.fail(e);
+ }).then(function() get()).then(function({ data }) {
+ assert.pass('getting was successful');
+ assert.equal(data, '', 'the data returned from get is correct');
+ }, function(e) {
+ assert.fail('getting was unsuccessful');
+ assert.fail(e);
+ }).then(done, assert.fail);
+};
+
+before(exports, function(name, assert, done) {
+ let loader = Loader(module);
+ loader.require('pathfinder/storage');
+ let file = loader.sandbox('pathfinder/storage').getStorageFile();
+ assert.pass(file.exists(), false, 'the storage file DNE');
+ loader.unload();
+ done();
+});
+after(exports, function(name, assert, done) {
+ let loader = Loader(module);
+ loader.require('pathfinder/storage');
+ let file = loader.sandbox('pathfinder/storage').getStorageFile();
+ assert.pass(file.exists(), false, 'the storage file DNE');
+ loader.unload();
+ done();
+});
+
+require('sdk/test').run(exports);