electron/spec-main/fixtures/devtools-extensions/foo/panel.js

80 lines
2.2 KiB
JavaScript
Raw Normal View History

/* global chrome */
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) {
2020-03-20 20:28:31 +00:00
callback(syncItems, localItems);
});
});
});
});
}
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) {
2020-03-20 20:28:31 +00:00
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) {
2020-03-20 20:28:31 +00:00
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
2020-03-20 20:28:31 +00:00
);
});
});
});
}
testStorage(function (
syncForSet, localForSet,
syncForRemove, localForRemove,
syncForClear, localForClear
) {
setTimeout(() => {
const message = JSON.stringify({
runtimeId: chrome.runtime.id,
tabId: chrome.devtools.inspectedWindow.tabId,
i18nString: chrome.i18n.getMessage('foo', ['bar', 'baz']),
storageItems: {
local: {
set: localForSet,
remove: localForRemove,
clear: localForClear
},
sync: {
set: syncForSet,
remove: syncForRemove,
clear: syncForClear
}
}
});
const sendMessage = `require('electron').ipcRenderer.send('answer', ${message})`;
window.chrome.devtools.inspectedWindow.eval(sendMessage, function () {});
});
2020-03-20 20:28:31 +00:00
});