aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormrmr19932015-04-27 17:07:16 +0100
committermrmr19932015-05-29 12:06:00 +0100
commit31873e39772c538cab418d03c244b4cac1addba0 (patch)
tree798a24aa8ba39c16aa6c90b26c01e2938cddffe4
parent960ccc627c4e55a7bdc53eead255270d9504a8bf (diff)
downloadvimium-31873e39772c538cab418d03c244b4cac1addba0.tar.bz2
Remove all direct calls to Sync, stop exporting it
This stops Sync from being referred to from anywhere except settings.coffee and settings_test.coffee.
-rw-r--r--background_scripts/main.coffee2
-rw-r--r--background_scripts/settings.coffee6
-rw-r--r--tests/unit_tests/exclusion_test.coffee2
-rw-r--r--tests/unit_tests/settings_test.coffee14
-rw-r--r--tests/unit_tests/utils_test.coffee2
5 files changed, 15 insertions, 11 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index a13d9d98..edcdf3b2 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -744,5 +744,5 @@ chrome.windows.getAll { populate: true }, (windows) ->
chrome.tabs.sendMessage(tab.id, { name: "getScrollPosition" }, createScrollPositionHandler())
# Start pulling changes from synchronized storage.
-Sync.init()
+Settings.init()
showUpgradeMessage()
diff --git a/background_scripts/settings.coffee b/background_scripts/settings.coffee
index 81bc8589..44676ad7 100644
--- a/background_scripts/settings.coffee
+++ b/background_scripts/settings.coffee
@@ -14,7 +14,7 @@
#
root = exports ? window
-root.Sync = Sync =
+Sync =
storage: chrome.storage.sync
doNotSync: ["settingsVersion", "previousVersion"]
@@ -55,6 +55,7 @@ root.Sync = Sync =
#
root.Settings = Settings =
+ init: -> Sync.init()
get: (key) ->
if (key of localStorage) then JSON.parse(localStorage[key]) else @defaults[key]
@@ -178,6 +179,9 @@ root.Settings = Settings =
settingsVersion: Utils.getCurrentVersion()
+# Export Sync via Settings for tests.
+root.Settings.Sync = Sync
+
# We use settingsVersion to coordinate any necessary schema changes.
if Utils.compareVersions("1.42", Settings.get("settingsVersion")) != -1
diff --git a/tests/unit_tests/exclusion_test.coffee b/tests/unit_tests/exclusion_test.coffee
index 217f2309..097e1f30 100644
--- a/tests/unit_tests/exclusion_test.coffee
+++ b/tests/unit_tests/exclusion_test.coffee
@@ -15,7 +15,7 @@ root.Marks =
extend(global, require "../../lib/utils.js")
Utils.getCurrentVersion = -> '1.44'
extend(global,require "../../background_scripts/settings.js")
-Sync.init()
+Settings.init()
extend(global, require "../../background_scripts/exclusions.js")
extend(global, require "../../background_scripts/commands.js")
extend(global, require "../../background_scripts/main.js")
diff --git a/tests/unit_tests/settings_test.coffee b/tests/unit_tests/settings_test.coffee
index e85c45f2..b44a904f 100644
--- a/tests/unit_tests/settings_test.coffee
+++ b/tests/unit_tests/settings_test.coffee
@@ -5,12 +5,13 @@ extend(global, require "../../lib/utils.js")
Utils.getCurrentVersion = -> '1.44'
global.localStorage = {}
extend(global,require "../../background_scripts/settings.js")
-Sync.init()
context "settings",
setup ->
stub global, 'localStorage', {}
+ 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', ""
@@ -38,24 +39,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", ->
@@ -65,9 +64,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
+ assert.equal message, receivedMessage
should "sync a key which is not a known setting (without crashing)", ->
chrome.storage.sync.set { notASetting: JSON.stringify("notAUsefullValue") }
diff --git a/tests/unit_tests/utils_test.coffee b/tests/unit_tests/utils_test.coffee
index e7febe13..283f0ca0 100644
--- a/tests/unit_tests/utils_test.coffee
+++ b/tests/unit_tests/utils_test.coffee
@@ -3,7 +3,7 @@ extend global, require "./test_chrome_stubs.js"
extend(global, require "../../lib/utils.js")
Utils.getCurrentVersion = -> '1.43'
extend(global, require "../../background_scripts/settings.js")
-Sync.init()
+Settings.init()
context "isUrl",
should "accept valid URLs", ->