Commit ca966cfb authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

[filesapp] Add (primitive) storage to files SWA chrome.storage fake

Add actual storage to the SWA chrome.storage fake, to allow removal of
of more "if (window.isSWA) {...}" code from CL:2500642. Implementation
code derived from

  ui/file_manager/file_manager/test/js/chrome_api_test_impl.js

Bug: 1113981
Tbr: Bo
Change-Id: I5dafeb94616ef9e051f8a3fb829f1204f039c69b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2529270
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826162}
parent d22f9bf8
......@@ -15,12 +15,64 @@ window.chrome.storage = {
addListener() {},
},
sync: {
get() {},
set() {},
/** @private {!Object} store */
store_: {},
/**
* @param {!Array<string>|string} keys
* @param {function((!Object)} callback
*/
get : (keys, callback) => {
const inKeys = Array.isArray(keys) ? keys : [keys];
const result = {};
inKeys.forEach(key => {
if (key in chrome.storage.sync.store_) {
result[key] = chrome.storage.sync.store_[key];
}
});
setTimeout(callback, 0, result);
},
/**
* @param {!Object<string>} items
* @param {function()=} opt_callback
*/
set: (items, opt_callback) => {
for (const key in items) {
chrome.storage.sync.store_[key] = items[key];
}
if (opt_callback) {
setTimeout(opt_callback);
}
},
},
local: {
get() {},
set() {},
/** @private {!Object} store */
store_: {},
/**
* @param {!Array<string>|string} keys
* @param {function((!Object)} callback
*/
get : (keys, callback) => {
const inKeys = Array.isArray(keys) ? keys : [keys];
const result = {};
inKeys.forEach(key => {
if (key in chrome.storage.local.store_) {
result[key] = chrome.storage.local.store_[key];
}
});
setTimeout(callback, 0, result);
},
/**
* @param {!Object<string>} items
* @param {function()=} opt_callback
*/
set: (items, opt_callback) => {
for (const key in items) {
chrome.storage.local.store_[key] = items[key];
}
if (opt_callback) {
setTimeout(opt_callback);
}
},
},
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment