Last active
November 17, 2015 13:44
-
-
Save janl/530581b17340f79fb76f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports.checkStorage = function () { | |
try { | |
global.mozSimpleStorage = require('sdk/simple-storage'); | |
} catch() { | |
global.mozSimpleStorage = false; | |
} | |
if (chrome.storage) { // We're running inside the Chrome/Web Extension context | |
return 'chromeOrWebExt'; | |
} else if (window.localStorage) { // We're running inside a normal webpage | |
return 'localStorage'; | |
} else if (mozSimpleStorage) { //We're running in a Firefox Add-On context | |
return 'firefoxAddOn'; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var storage = require('checkStorage.js'); | |
var test = require('tape'); | |
test ('checkStorage tests with chrome', function (t) { | |
global.chrome = {'storage': true}; // Mock a chrome/Web extension environment | |
t.equal(storage.checkStorage(), 'chromeOrWebExt', 'if we find the chrome API, return chromeOrWebExt'); | |
global.chrome = {'storage': false}; | |
t.end(); | |
}); | |
test ('checkStorage tests with localStorage', function (t) { | |
global.window = {'localStorage': true}; // Add localStorage API mocking. | |
t.equal(storage.checkStorage(), 'localStorage', 'if we find the localStorage API, return localStorage'); | |
global.window = {'localStorage': false}; | |
t.end(); | |
}); | |
test ('checkStorage tests with simple-storage', function (t) { | |
global.mozSimpleStorage = true; | |
t,equal(...) | |
t.end(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment