diff options
| author | Stephen Blott | 2014-04-19 07:41:31 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2014-04-19 07:41:31 +0100 | 
| commit | 033d353b265fcd4e9963ef232c17d82d7bea43f1 (patch) | |
| tree | 87773ec1db54a25b1577647733e5533a0778fe8f | |
| parent | 654738cb4d566c5e0b2d1e229dd9055403af35f6 (diff) | |
| download | vimium-033d353b265fcd4e9963ef232c17d82d7bea43f1.tar.bz2 | |
Settings tests pass, Sync still has an error.
| -rw-r--r-- | background_scripts/settings.coffee | 4 | ||||
| -rw-r--r-- | background_scripts/sync.coffee | 6 | ||||
| -rw-r--r-- | tests/unit_tests/settings_test.coffee | 29 | ||||
| -rw-r--r-- | tests/unit_tests/test_chrome_stubs.coffee | 11 | ||||
| -rw-r--r-- | tests/unit_tests/utils_test.coffee | 3 | 
5 files changed, 35 insertions, 18 deletions
| diff --git a/background_scripts/settings.coffee b/background_scripts/settings.coffee index ad89888e..f75c1db3 100644 --- a/background_scripts/settings.coffee +++ b/background_scripts/settings.coffee @@ -14,12 +14,12 @@ root.Settings = Settings =      else        jsonValue = JSON.stringify value        localStorage[key] = jsonValue -      root.Sync.set key, jsonValue +      Sync.set key, jsonValue    clear: (key) ->      if @has key        delete localStorage[key] -    root.Sync.clear key +    Sync.clear key    has: (key) -> key of localStorage diff --git a/background_scripts/sync.coffee b/background_scripts/sync.coffee index 7cb77518..40e0c5c3 100644 --- a/background_scripts/sync.coffee +++ b/background_scripts/sync.coffee @@ -59,19 +59,19 @@ root.Sync = Sync =         return      # Ok: accept, store and propagate this update. -    defaultValue = root.Settings.defaults[key] +    defaultValue = Settings.defaults[key]      defaultValueJSON = JSON.stringify(defaultValue)      if value && value != defaultValueJSON        # Key/value has been changed to non-default value at remote instance.        @log "update: #{key}=#{value}"        localStorage[key] = value -      root.Settings.doPostUpdateHook key, JSON.parse(value) +      Settings.doPostUpdateHook key, JSON.parse(value)      else        # Key has been reset to default value at remote instance.        @log "clear: #{key}"        delete localStorage[key] -      root.Settings.doPostUpdateHook key, defaultValue +      Settings.doPostUpdateHook key, defaultValue    # Only called synchronously from within vimium, never on a callback.    # No need to propagate updates into the rest of vimium. diff --git a/tests/unit_tests/settings_test.coffee b/tests/unit_tests/settings_test.coffee index b2c5484b..040de285 100644 --- a/tests/unit_tests/settings_test.coffee +++ b/tests/unit_tests/settings_test.coffee @@ -1,30 +1,33 @@  require "./test_helper.js" +require "./test_chrome_stubs.js"  extend(global, require "../../lib/utils.js")  Utils.getCurrentVersion = -> '1.44'  global.localStorage = {} -{Settings} = require "../../background_scripts/settings.js" + +extend(global,require "../../background_scripts/sync.js") +extend(global,require "../../background_scripts/settings.js")  context "settings",    setup ->      stub global, 'localStorage', {} -  should "obtain defaults if no key is stored", -> -    assert.isFalse Settings.has 'scrollStepSize' -    assert.equal Settings.get('scrollStepSize'), 60 +should "obtain defaults if no key is stored", -> +  assert.isFalse Settings.has 'scrollStepSize' +  assert.equal Settings.get('scrollStepSize'), 60    should "store values", ->      Settings.set 'scrollStepSize', 20      assert.equal Settings.get('scrollStepSize'), 20 -  should "not store values equal to the default", -> -    Settings.set 'scrollStepSize', 20 -    assert.isTrue Settings.has 'scrollStepSize' -    Settings.set 'scrollStepSize', 60 -    assert.isFalse Settings.has 'scrollStepSize' +should "not store values equal to the default", -> +  Settings.set 'scrollStepSize', 20 +  assert.isTrue Settings.has 'scrollStepSize' +  Settings.set 'scrollStepSize', 60 +  assert.isFalse Settings.has 'scrollStepSize' -  should "revert to defaults if no key is stored", -> -    Settings.set 'scrollStepSize', 20 -    Settings.clear 'scrollStepSize' -    assert.equal Settings.get('scrollStepSize'), 60 +should "revert to defaults if no key is stored", -> +  Settings.set 'scrollStepSize', 20 +  Settings.clear 'scrollStepSize' +  assert.equal Settings.get('scrollStepSize'), 60 diff --git a/tests/unit_tests/test_chrome_stubs.coffee b/tests/unit_tests/test_chrome_stubs.coffee new file mode 100644 index 00000000..86eef1a1 --- /dev/null +++ b/tests/unit_tests/test_chrome_stubs.coffee @@ -0,0 +1,11 @@ +global.chrome ||= {} +global.chrome.storage ||= {} + +global.chrome.storage.onChanged ||= +  addListener: (changes,area) -> + +global.chrome.storage.sync ||= +  set: (key,value,callback) -> +  get: (keys,callback) -> +  remove: (key,callback) -> + diff --git a/tests/unit_tests/utils_test.coffee b/tests/unit_tests/utils_test.coffee index e1aa32c7..8e337d9e 100644 --- a/tests/unit_tests/utils_test.coffee +++ b/tests/unit_tests/utils_test.coffee @@ -1,4 +1,7 @@  require "./test_helper.js" +require "./test_chrome_stubs.js" + +extend(global, require "../../background_scripts/sync.js")  extend(global, require "../../lib/utils.js")  extend(global, require "../../background_scripts/settings.js") | 
