diff options
Diffstat (limited to 'tests/unit_tests/settings_test.coffee')
| -rw-r--r-- | tests/unit_tests/settings_test.coffee | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/tests/unit_tests/settings_test.coffee b/tests/unit_tests/settings_test.coffee index afe862a4..ded7b5f8 100644 --- a/tests/unit_tests/settings_test.coffee +++ b/tests/unit_tests/settings_test.coffee @@ -3,15 +3,18 @@ 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 "../../background_scripts/sync.js") -extend(global,require "../../background_scripts/settings.js") -Sync.init() +extend(global,require "../../lib/settings.js") 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() should "save settings in localStorage as JSONified strings", -> Settings.set 'dummy', "" @@ -39,24 +42,22 @@ context "settings", should "propagate non-default value via synced storage listener", -> Settings.set 'scrollStepSize', 20 assert.equal Settings.get('scrollStepSize'), 20 - Sync.handleStorageUpdate { scrollStepSize: { newValue: "40" } } + Settings.Sync.handleStorageUpdate { scrollStepSize: { newValue: "40" } } assert.equal Settings.get('scrollStepSize'), 40 should "propagate default value via synced storage listener", -> Settings.set 'scrollStepSize', 20 assert.equal Settings.get('scrollStepSize'), 20 - Sync.handleStorageUpdate { scrollStepSize: { newValue: "60" } } + Settings.Sync.handleStorageUpdate { scrollStepSize: { newValue: "60" } } assert.isFalse Settings.has 'scrollStepSize' should "propagate non-default values from synced storage", -> chrome.storage.sync.set { scrollStepSize: JSON.stringify(20) } - Sync.fetchAsync() assert.equal Settings.get('scrollStepSize'), 20 should "propagate default values from synced storage", -> Settings.set 'scrollStepSize', 20 chrome.storage.sync.set { scrollStepSize: JSON.stringify(60) } - Sync.fetchAsync() assert.isFalse Settings.has 'scrollStepSize' should "clear a setting from synced storage", -> @@ -66,19 +67,10 @@ context "settings", should "trigger a postUpdateHook", -> message = "Hello World" - Settings.postUpdateHooks['scrollStepSize'] = (value) -> Sync.message = value + receivedMessage = "" + Settings.postUpdateHooks['scrollStepSize'] = (value) -> receivedMessage = value chrome.storage.sync.set { scrollStepSize: JSON.stringify(message) } - assert.equal message, Sync.message - - should "set search engines, retrieve them correctly and check that they have been parsed correctly", -> - searchEngines = "foo: bar?q=%s\n# comment\nbaz: qux?q=%s baz description" - Settings.set 'searchEngines', searchEngines - result = Settings.getSearchEngines() - assert.equal Object.keys(result).length, 2 - assert.equal "bar?q=%s", result["foo"].url - assert.isFalse result["foo"].description - assert.equal "qux?q=%s", result["baz"].url - assert.equal "baz description", result["baz"].description + assert.equal message, receivedMessage should "sync a key which is not a known setting (without crashing)", -> chrome.storage.sync.set { notASetting: JSON.stringify("notAUsefullValue") } |
