diff options
Diffstat (limited to 'tests/unit_tests/utils_test.coffee')
| -rw-r--r-- | tests/unit_tests/utils_test.coffee | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/tests/unit_tests/utils_test.coffee b/tests/unit_tests/utils_test.coffee index 88e9a15b..f9ed3636 100644 --- a/tests/unit_tests/utils_test.coffee +++ b/tests/unit_tests/utils_test.coffee @@ -2,9 +2,8 @@ require "./test_helper.js" extend global, require "./test_chrome_stubs.js" extend(global, require "../../lib/utils.js") Utils.getCurrentVersion = -> '1.43' -extend(global, require "../../background_scripts/sync.js") -extend(global, require "../../background_scripts/settings.js") -Sync.init() +extend(global, require "../../lib/settings.js") +Settings.init() context "isUrl", should "accept valid URLs", -> @@ -42,11 +41,22 @@ context "convertToUrl", assert.equal "http://127.0.0.1:8080", Utils.convertToUrl("127.0.0.1:8080") assert.equal "http://[::]:8080", Utils.convertToUrl("[::]:8080") assert.equal "view-source: 0.0.0.0", Utils.convertToUrl("view-source: 0.0.0.0") + assert.equal "javascript:alert('25 % 20 * 25 ');", Utils.convertToUrl "javascript:alert('25 % 20 * 25%20');" should "convert non-URL terms into search queries", -> - assert.equal "http://www.google.com/search?q=google", Utils.convertToUrl("google") - assert.equal "http://www.google.com/search?q=go+ogle.com", Utils.convertToUrl("go ogle.com") - assert.equal "http://www.google.com/search?q=%40twitter", Utils.convertToUrl("@twitter") + assert.equal "https://www.google.com/search?q=google", Utils.convertToUrl("google") + assert.equal "https://www.google.com/search?q=go+ogle.com", Utils.convertToUrl("go ogle.com") + assert.equal "https://www.google.com/search?q=%40twitter", Utils.convertToUrl("@twitter") + +context "extractQuery", + should "extract queries from search URLs", -> + assert.equal "bbc sport 1", Utils.extractQuery "https://www.google.ie/search?q=%s", "https://www.google.ie/search?q=bbc+sport+1" + assert.equal "bbc sport 2", Utils.extractQuery "http://www.google.ie/search?q=%s", "https://www.google.ie/search?q=bbc+sport+2" + assert.equal "bbc sport 3", Utils.extractQuery "https://www.google.ie/search?q=%s", "http://www.google.ie/search?q=bbc+sport+3" + assert.equal "bbc sport 4", Utils.extractQuery "https://www.google.ie/search?q=%s", "http://www.google.ie/search?q=bbc+sport+4&blah" + + should "extract not queries from incorrect search URLs", -> + assert.isFalse Utils.extractQuery "https://www.google.ie/search?q=%s&foo=bar", "https://www.google.ie/search?q=bbc+sport" context "hasChromePrefix", should "detect chrome prefixes of URLs", -> @@ -62,6 +72,17 @@ context "hasChromePrefix", assert.isFalse Utils.hasChromePrefix "data" assert.isFalse Utils.hasChromePrefix "data :foobar" +context "hasJavascriptPrefix", + should "detect javascript: URLs", -> + assert.isTrue Utils.hasJavascriptPrefix "javascript:foobar" + assert.isFalse Utils.hasJavascriptPrefix "http:foobar" + +context "decodeURIByParts", + should "decode javascript: URLs", -> + assert.equal "foobar", Utils.decodeURIByParts "foobar" + assert.equal " ", Utils.decodeURIByParts "%20" + assert.equal "25 % 20 25 ", Utils.decodeURIByParts "25 % 20 25%20" + context "isUrl", should "identify URLs as URLs", -> assert.isTrue Utils.isUrl "http://www.example.com/blah" |
