From a1103158551ace4232b613d290f5d193a7c5185f Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 26 Mar 2016 12:53:40 +0000 Subject: Multiple minor tweaks. Some of this code is showing its age, so these are just a number of minor tweaks (to keep things clear, consistent and concise). Also, add a couple of tests (while we're at it). --- tests/unit_tests/exclusion_test.coffee | 16 +++++++++++++++- tests/unit_tests/utils_test.coffee | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/unit_tests/exclusion_test.coffee b/tests/unit_tests/exclusion_test.coffee index 649dfd1f..54cb4ed3 100644 --- a/tests/unit_tests/exclusion_test.coffee +++ b/tests/unit_tests/exclusion_test.coffee @@ -15,12 +15,13 @@ root.Marks = extend(global, require "../../lib/utils.js") Utils.getCurrentVersion = -> '1.44' extend(global,require "../../lib/settings.js") +extend(global,require "../../lib/clipboard.js") extend(global, require "../../background_scripts/exclusions.js") extend(global, require "../../background_scripts/commands.js") extend(global, require "../../background_scripts/main.js") isEnabledForUrl = (request) -> - Frames.isEnabledForUrl {request, tabId: 0, port: postMessage: (request) -> request} + Exclusions.isEnabledForUrl request.url # These tests cover only the most basic aspects of excluded URLs and passKeys. # @@ -34,6 +35,9 @@ context "Excluded URLs and pass keys", { pattern: "http*://www.facebook.com/*", passKeys: "cdcd" } { pattern: "http*://www.bbc.com/*", passKeys: "" } { pattern: "http*://www.bbc.com/*", passKeys: "ab" } + { pattern: "http*://www.example.com/*", passKeys: "a bb c bba a" } + { pattern: "http*://www.duplicate.com/*", passKeys: "ace" } + { pattern: "http*://www.duplicate.com/*", passKeys: "bdf" } ]) should "be disabled for excluded sites", -> @@ -56,3 +60,13 @@ context "Excluded URLs and pass keys", assert.isTrue rule.isEnabledForUrl assert.isFalse rule.passKeys + should "handle spaces and duplicates in passkeys", -> + rule = isEnabledForUrl({ url: 'http://www.example.com/pages' }) + assert.isTrue rule.isEnabledForUrl + assert.equal "abc", rule.passKeys + + should "handle multiple passkeys rules", -> + rule = isEnabledForUrl({ url: 'http://www.duplicate.com/pages' }) + assert.isTrue rule.isEnabledForUrl + assert.equal "abcdef", rule.passKeys + diff --git a/tests/unit_tests/utils_test.coffee b/tests/unit_tests/utils_test.coffee index 9b71ca72..93849349 100644 --- a/tests/unit_tests/utils_test.coffee +++ b/tests/unit_tests/utils_test.coffee @@ -125,3 +125,7 @@ context "makeIdempotent", assert.equal 1, @count @func() assert.equal 1, @count + +context "distinctCharacters", + should "eliminate duplicate characters", -> + assert.equal "abc", Utils.distinctCharacters "bbabaabbacabbbab" -- cgit v1.2.3