Merge pull request #7923 from jhen0409/patch-1
Add support remove / clear for chrome.storage
This commit is contained in:
commit
eeffa42513
3 changed files with 88 additions and 9 deletions
|
@ -56,6 +56,27 @@ const getStorageManager = (storageType) => {
|
|||
|
||||
setStorage(storageType, storage)
|
||||
|
||||
setTimeout(callback)
|
||||
},
|
||||
|
||||
remove (keys, callback) {
|
||||
const storage = getStorage(storageType)
|
||||
|
||||
if (!Array.isArray(keys)) {
|
||||
keys = [keys]
|
||||
}
|
||||
keys.forEach(function (key) {
|
||||
delete storage[key]
|
||||
})
|
||||
|
||||
setStorage(storageType, storage)
|
||||
|
||||
setTimeout(callback)
|
||||
},
|
||||
|
||||
clear (callback) {
|
||||
setStorage(storageType, {})
|
||||
|
||||
setTimeout(callback)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1475,8 +1475,16 @@ describe('browser-window module', function () {
|
|||
assert.equal(message.tabId, w.webContents.id)
|
||||
assert.equal(message.i18nString, 'foo - bar (baz)')
|
||||
assert.deepEqual(message.storageItems, {
|
||||
local: {hello: 'world'},
|
||||
sync: {foo: 'bar'}
|
||||
local: {
|
||||
set: {hello: 'world', world: 'hello'},
|
||||
remove: {world: 'hello'},
|
||||
clear: {}
|
||||
},
|
||||
sync: {
|
||||
set: {foo: 'bar', bar: 'foo'},
|
||||
remove: {foo: 'bar'},
|
||||
clear: {}
|
||||
}
|
||||
})
|
||||
done()
|
||||
})
|
||||
|
|
64
spec/fixtures/devtools-extensions/foo/index.html
vendored
64
spec/fixtures/devtools-extensions/foo/index.html
vendored
|
@ -4,10 +4,10 @@
|
|||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<script>
|
||||
function testStorage (callback) {
|
||||
chrome.storage.sync.set({foo: 'bar'}, function () {
|
||||
chrome.storage.sync.get({foo: 'baz'}, function (syncItems) {
|
||||
chrome.storage.local.set({hello: 'world'}, function () {
|
||||
function testStorageClear (callback) {
|
||||
chrome.storage.sync.clear(function () {
|
||||
chrome.storage.sync.get(null, function (syncItems) {
|
||||
chrome.storage.local.clear(function () {
|
||||
chrome.storage.local.get(null, function(localItems) {
|
||||
callback(syncItems, localItems)
|
||||
})
|
||||
|
@ -16,6 +16,44 @@
|
|||
})
|
||||
}
|
||||
|
||||
function testStorageRemove (callback) {
|
||||
chrome.storage.sync.remove('bar', function () {
|
||||
chrome.storage.sync.get({foo: 'baz'}, function (syncItems) {
|
||||
chrome.storage.local.remove(['hello'], function () {
|
||||
chrome.storage.local.get(null, function(localItems) {
|
||||
callback(syncItems, localItems)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function testStorageSet (callback) {
|
||||
chrome.storage.sync.set({foo: 'bar', bar: 'foo'}, function () {
|
||||
chrome.storage.sync.get({foo: 'baz', bar: 'fooo'}, function (syncItems) {
|
||||
chrome.storage.local.set({hello: 'world', world: 'hello'}, function () {
|
||||
chrome.storage.local.get(null, function(localItems) {
|
||||
callback(syncItems, localItems)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function testStorage (callback) {
|
||||
testStorageSet(function (syncForSet, localForSet) {
|
||||
testStorageRemove(function (syncForRemove, localForRemove) {
|
||||
testStorageClear(function (syncForClear, localForClear) {
|
||||
callback(
|
||||
syncForSet, localForSet,
|
||||
syncForRemove, localForRemove,
|
||||
syncForClear, localForClear
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function reportCoverage () {
|
||||
var message = JSON.stringify({
|
||||
pid: chrome.runtime.id,
|
||||
|
@ -25,14 +63,26 @@
|
|||
window.chrome.devtools.inspectedWindow.eval(coverageMessage, function () {})
|
||||
}
|
||||
|
||||
testStorage(function (syncItems, localItems) {
|
||||
testStorage(function (
|
||||
syncForSet, localForSet,
|
||||
syncForRemove, localForRemove,
|
||||
syncForClear, localForClear
|
||||
) {
|
||||
var message = JSON.stringify({
|
||||
runtimeId: chrome.runtime.id,
|
||||
tabId: chrome.devtools.inspectedWindow.tabId,
|
||||
i18nString: chrome.i18n.getMessage('foo', ['bar', 'baz']),
|
||||
storageItems: {
|
||||
local: localItems,
|
||||
sync: syncItems
|
||||
local: {
|
||||
set: localForSet,
|
||||
remove: localForRemove,
|
||||
clear: localForClear
|
||||
},
|
||||
sync: {
|
||||
set: syncForSet,
|
||||
remove: syncForRemove,
|
||||
clear: syncForClear
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue