From 7ff17b8a6f63b0f46fac2be27c2a2f7d82c8d458 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Mon, 27 Apr 2015 20:44:23 +0100 Subject: Make Settings explicitly use a cache The Settings object used by the background page now uses 1 of 3 caches, depending on the context it is available in: * localStorage - in the background page * a copy of localStorage - in non-background extension pages (options.html, popup.html, etc.) * an empty object - in all other pages (where localStorage doesn't point to the extension's localStorage object). For any extension page which is *not* the background page, a copy of localStorage is used instead of true localStorage: * Once localStorage is updated by one background page, the others can only see the updated copy. - Pages with an updated cache can't tell which changes are new, and so don't know which postUpdateHooks to run. * By copying localStorage's contents into a new object, extension pages can still access settings synchronously. - This is especially important to options.html and popup.html; they will not work without it. --- tests/unit_tests/settings_test.coffee | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/unit_tests') diff --git a/tests/unit_tests/settings_test.coffee b/tests/unit_tests/settings_test.coffee index 946a1688..ded7b5f8 100644 --- a/tests/unit_tests/settings_test.coffee +++ b/tests/unit_tests/settings_test.coffee @@ -3,6 +3,8 @@ extend global, require "./test_chrome_stubs.js" extend(global, require "../../lib/utils.js") Utils.getCurrentVersion = -> '1.44' +Utils.isBackgroundPage = -> true +Utils.isExtensionPage = -> true global.localStorage = {} extend(global,require "../../lib/settings.js") @@ -10,6 +12,7 @@ context "settings", setup -> stub global, 'localStorage', {} + Settings.cache = global.localStorage # Point the settings cache to the new localStorage object. Settings.postUpdateHooks = {} # Avoid running update hooks which include calls to outside of settings. Settings.init() -- cgit v1.2.3