diff options
| author | Stephen Blott | 2014-08-24 15:24:54 +0100 |
|---|---|---|
| committer | Stephen Blott | 2014-08-24 15:34:24 +0100 |
| commit | fb25935bec26066a457468ae5402f71de4694b37 (patch) | |
| tree | abf01885a17e3f8b1ea3d9c78362c0fada66524d | |
| parent | 5cdeb4d4ac2bc3171b47043f0275d0f8331486a6 (diff) | |
| download | vimium-fb25935bec26066a457468ae5402f71de4694b37.tar.bz2 | |
PassKey tests (1)
| -rw-r--r-- | tests/unit_tests/exclusion_test.coffee | 71 | ||||
| -rw-r--r-- | tests/unit_tests/test_chrome_stubs.coffee | 43 |
2 files changed, 107 insertions, 7 deletions
diff --git a/tests/unit_tests/exclusion_test.coffee b/tests/unit_tests/exclusion_test.coffee new file mode 100644 index 00000000..33dbccd3 --- /dev/null +++ b/tests/unit_tests/exclusion_test.coffee @@ -0,0 +1,71 @@ + +require "./test_helper.js" +require "./test_chrome_stubs.js" + +# FIXME: +# Would like to do: +# extend(global, require "../../background_scripts/marks.js") +# But it looks like marks.coffee has never been included in a test before! +# Temporary fix... +root.Marks = + create: () -> true + goto: + bind: () -> true + +extend(global, require "../../lib/utils.js") +Utils.getCurrentVersion = -> '1.44' +extend(global,require "../../background_scripts/sync.js") +extend(global,require "../../background_scripts/settings.js") +Sync.init() +extend(global, require "../../background_scripts/commands.js") +extend(global, require "../../background_scripts/main.js") + +# These tests cover only the most basic aspects of excluded URLs and passKeys. +# +context "Excluded URLs and pass keys", + setup -> + Settings.set 'excludedUrls', 'http://mail.google.com/*\nhttp://www.facebook.com/* jk' + + should "be disabled for excluded sites", -> + rule = isEnabledForUrl({ url: 'http://mail.google.com/u/0/inbox' }) + assert.isFalse rule.isEnableForUrl + assert.isTrue rule.matchingUrl + + should "be enabled, but with pass keys", -> + rule = isEnabledForUrl({ url: 'http://www.facebook.com/pages' }) + assert.isTrue rule.isEnabledForUrl + assert.equal rule.passKeys, 'jk' + assert.isTrue rule.matchingUrl + + should "be enabled", -> + rule = isEnabledForUrl({ url: 'http://www.twitter.com/pages' }) + assert.isTrue rule.isEnabledForUrl + assert.isFalse rule.passKeys + + should "add a new excluded URL", -> + rule = isEnabledForUrl({ url: 'http://www.example.com/page' }) + assert.isTrue rule.isEnabledForUrl + addExcludedUrl("http://www.example.com*") + rule = isEnabledForUrl({ url: 'http://www.example.com/page' }) + assert.isFalse rule.isEnabledForUrl + assert.isFalse rule.passKeys + assert.isTrue rule.matchingUrl + + should "add a new excluded URL with passkeys", -> + rule = isEnabledForUrl({ url: 'http://www.example.com/page' }) + assert.isTrue rule.isEnabledForUrl + addExcludedUrl("http://www.example.com/* jk") + rule = isEnabledForUrl({ url: 'http://www.example.com/page' }) + assert.isTrue rule.isEnabledForUrl + assert.equal rule.passKeys, 'jk' + assert.isTrue rule.matchingUrl + + should "update an existing excluded URL with passkeys", -> + rule = isEnabledForUrl({ url: 'http://www.facebook.com/page' }) + assert.isTrue rule.isEnabledForUrl + addExcludedUrl("http://www.facebook.com/* jknp") + rule = isEnabledForUrl({ url: 'http://www.facebook.com/page' }) + assert.isTrue rule.isEnabledForUrl + assert.equal rule.passKeys, 'jknp' + assert.isTrue rule.matchingUrl + diff --git a/tests/unit_tests/test_chrome_stubs.coffee b/tests/unit_tests/test_chrome_stubs.coffee index e9c48f31..9622f85f 100644 --- a/tests/unit_tests/test_chrome_stubs.coffee +++ b/tests/unit_tests/test_chrome_stubs.coffee @@ -2,26 +2,55 @@ # # This is a stub for chrome.strorage.sync for testing. # It does what chrome.storage.sync should do (roughly), but does so synchronously. +# It also provides stubs for a number of other chrome APIs. # +global.window = {} +global.localStorage = {} + global.chrome = - runtime: {} + runtime: + getManifest: () -> + version: "1.2.3" + onConnect: + addListener: () -> true + onMessage: + addListener: () -> true - storage: + tabs: + onSelectionChanged: + addListener: () -> true + onUpdated: + addListener: () -> true + onAttached: + addListener: () -> true + onMoved: + addListener: () -> true + onRemoved: + addListener: () -> true + onActiveChanged: + addListener: () -> true + query: () -> true + windows: + onRemoved: + addListener: () -> true + getAll: () -> true + + storage: # chrome.storage.onChanged onChanged: addListener: (func) -> @func = func # Fake a callback from chrome.storage.sync. call: (key, value) -> - chrome.runtime = { lastError: undefined } + chrome.runtime.lastError = undefined key_value = {} key_value[key] = { newValue: value } @func(key_value,'synced storage stub') if @func callEmpty: (key) -> - chrome.runtime = { lastError: undefined } + chrome.runtime.lastError = undefined if @func items = {} items[key] = {} @@ -32,7 +61,7 @@ global.chrome = store: {} set: (items, callback) -> - chrome.runtime = { lastError: undefined } + chrome.runtime.lastError = undefined for own key, value of items @store[key] = value callback() if callback @@ -41,7 +70,7 @@ global.chrome = global.chrome.storage.onChanged.call(key,value) get: (keys, callback) -> - chrome.runtime = { lastError: undefined } + chrome.runtime.lastError = undefined if keys == null keys = [] for own key, value of @store @@ -53,7 +82,7 @@ global.chrome = callback items if callback remove: (key, callback) -> - chrome. runtime = { lastError: undefined } + chrome.runtime.lastError = undefined if key of @store delete @store[key] callback() if callback |
