aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--background_scripts/sync.coffee7
-rw-r--r--tests/unit_tests/settings_test.coffee9
-rw-r--r--tests/unit_tests/test_chrome_stubs.coffee9
3 files changed, 22 insertions, 3 deletions
diff --git a/background_scripts/sync.coffee b/background_scripts/sync.coffee
index 3a829722..3b34c5a6 100644
--- a/background_scripts/sync.coffee
+++ b/background_scripts/sync.coffee
@@ -56,7 +56,7 @@ root.Sync = Sync =
@log "ignoring: #{key}"
return
# Ignore, it's unchanged
- if localStorage[key] is value
+ if key of localStorage and localStorage[key] is value
@log "unchanged: #{key}"
return
@@ -64,7 +64,7 @@ root.Sync = Sync =
defaultValue = Settings.defaults[key]
defaultValueJSON = JSON.stringify(defaultValue)
- if value && value != defaultValueJSON
+ if value and value != defaultValueJSON
# Key/value has been changed to non-default value at remote instance.
@log "update: #{key}=#{value}"
localStorage[key] = value
@@ -72,7 +72,8 @@ root.Sync = Sync =
else
# Key has been reset to default value at remote instance.
@log "clear: #{key}"
- delete localStorage[key]
+ if key of localStorage
+ delete localStorage[key]
Settings.doPostUpdateHook key, defaultValue
# Only called synchronously from within vimium, never on a callback.
diff --git a/tests/unit_tests/settings_test.coffee b/tests/unit_tests/settings_test.coffee
index 07b96a30..9aec95dd 100644
--- a/tests/unit_tests/settings_test.coffee
+++ b/tests/unit_tests/settings_test.coffee
@@ -64,3 +64,12 @@ context "settings",
# Pull Sync's version of scrollStepSize, this should delete scrollStepSize in localStorage, because it's a default value.
Sync.pull()
assert.isFalse Settings.has 'scrollStepSize'
+
+ should "remote setting cleared", ->
+ # Prime localStorage.
+ Settings.set 'scrollStepSize', 20
+ assert.equal Settings.get('scrollStepSize'), 20
+ # Prime Sync with a non-default value.
+ chrome.storage.sync.set { scrollStepSize: JSON.stringify(40) }
+ chrome.storage.sync.remove 'scrollStepSize'
+ assert.isFalse Settings.has 'scrollStepSize'
diff --git a/tests/unit_tests/test_chrome_stubs.coffee b/tests/unit_tests/test_chrome_stubs.coffee
index f32de24f..dd8dccf8 100644
--- a/tests/unit_tests/test_chrome_stubs.coffee
+++ b/tests/unit_tests/test_chrome_stubs.coffee
@@ -16,6 +16,13 @@ global.chrome.storage.onChanged ||=
if @func
@func( @mkKeyValue(key,value), 'synced storage stub' )
+ callEmpty: (key) ->
+ chrome.runtime = { lastError: undefined }
+ if @func
+ items = {}
+ items[key] = {}
+ @func( items, 'synced storage stub' )
+
mkKeyValue: (key, value) ->
obj = {}
obj[key] = { newValue: value }
@@ -53,4 +60,6 @@ global.chrome.storage.sync ||=
delete @store[key]
if callback
callback()
+ # Now, generate (supposedly asynchronous) notification for listeners.
+ global.chrome.storage.onChanged.callEmpty(key)