aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/dom_tests/dom_tests.coffee2
-rw-r--r--tests/dom_tests/vomnibar_test.coffee2
-rw-r--r--tests/unit_tests/commands_test.coffee5
-rw-r--r--tests/unit_tests/completion_test.coffee66
-rw-r--r--tests/unit_tests/exclusion_test.coffee4
-rw-r--r--tests/unit_tests/settings_test.coffee2
-rw-r--r--tests/unit_tests/test_chrome_stubs.coffee13
-rw-r--r--tests/unit_tests/utils_test.coffee23
8 files changed, 97 insertions, 20 deletions
diff --git a/tests/dom_tests/dom_tests.coffee b/tests/dom_tests/dom_tests.coffee
index ac3f9ebe..4a61877c 100644
--- a/tests/dom_tests/dom_tests.coffee
+++ b/tests/dom_tests/dom_tests.coffee
@@ -8,7 +8,7 @@ mockKeyboardEvent = (keyChar) ->
event.charCode = (if keyCodes[keyChar] isnt undefined then keyCodes[keyChar] else keyChar.charCodeAt(0))
event.keyIdentifier = "U+00" + event.charCode.toString(16)
event.keyCode = event.charCode
- event.stopPropagation = ->
+ event.stopImmediatePropagation = ->
event.preventDefault = ->
event
diff --git a/tests/dom_tests/vomnibar_test.coffee b/tests/dom_tests/vomnibar_test.coffee
index f7241552..f660f96b 100644
--- a/tests/dom_tests/vomnibar_test.coffee
+++ b/tests/dom_tests/vomnibar_test.coffee
@@ -52,7 +52,7 @@ context "Keep selection within bounds",
eventMock =
preventDefault: ->
- stopPropagation: ->
+ stopImmediatePropagation: ->
@completions = [{html:'foo',type:'tab',url:'http://example.com'}]
ui.update(true)
diff --git a/tests/unit_tests/commands_test.coffee b/tests/unit_tests/commands_test.coffee
index c10c643b..daaef016 100644
--- a/tests/unit_tests/commands_test.coffee
+++ b/tests/unit_tests/commands_test.coffee
@@ -1,8 +1,5 @@
-root.chrome =
- session:
- MAX_SESSION_RESULTS: 25
-
require "./test_helper.js"
+extend global, require "./test_chrome_stubs.js"
{Commands} = require "../../background_scripts/commands.js"
context "Key mappings",
diff --git a/tests/unit_tests/completion_test.coffee b/tests/unit_tests/completion_test.coffee
index 811436a9..e4966016 100644
--- a/tests/unit_tests/completion_test.coffee
+++ b/tests/unit_tests/completion_test.coffee
@@ -1,8 +1,8 @@
require "./test_helper.js"
extend(global, require "../../lib/utils.js")
extend(global, require "../../background_scripts/completion.js")
+extend global, require "./test_chrome_stubs.js"
-global.chrome = {}
global.document =
createElement: -> {}
@@ -163,13 +163,13 @@ context "domain completer",
should "return only a single matching domain", ->
results = filterCompleter(@completer, ["story"])
- assert.arrayEqual ["history1.com"], results.map (result) -> result.url
+ assert.arrayEqual ["http://history1.com"], results.map (result) -> result.url
should "pick domains which are more recent", ->
# These domains are the same except for their last visited time.
- assert.equal "history1.com", filterCompleter(@completer, ["story"])[0].url
+ assert.equal "http://history1.com", filterCompleter(@completer, ["story"])[0].url
@history2.lastVisitTime = hours(3)
- assert.equal "history2.com", filterCompleter(@completer, ["story"])[0].url
+ assert.equal "http://history2.com", filterCompleter(@completer, ["story"])[0].url
should "returns no results when there's more than one query term, because clearly it's not a domain", ->
assert.arrayEqual [], filterCompleter(@completer, ["his", "tory"])
@@ -194,15 +194,15 @@ context "domain completer (removing entries)",
should "remove 1 entry for domain with reference count of 1", ->
@onVisitRemovedListener { allHistory: false, urls: [@history1.url] }
- assert.equal "history2.com", filterCompleter(@completer, ["story"])[0].url
+ assert.equal "http://history2.com", filterCompleter(@completer, ["story"])[0].url
assert.equal 0, filterCompleter(@completer, ["story1"]).length
should "remove 2 entries for domain with reference count of 2", ->
@onVisitRemovedListener { allHistory: false, urls: [@history2.url] }
- assert.equal "history2.com", filterCompleter(@completer, ["story2"])[0].url
+ assert.equal "http://history2.com", filterCompleter(@completer, ["story2"])[0].url
@onVisitRemovedListener { allHistory: false, urls: [@history3.url] }
assert.equal 0, filterCompleter(@completer, ["story2"]).length
- assert.equal "history1.com", filterCompleter(@completer, ["story"])[0].url
+ assert.equal "http://history1.com", filterCompleter(@completer, ["story"])[0].url
should "remove 3 (all) matching domain entries", ->
@onVisitRemovedListener { allHistory: false, urls: [@history2.url] }
@@ -399,6 +399,58 @@ context "RegexpCache",
should "search for a string with a prefix/suffix (negative case)", ->
assert.isTrue "hound dog".search(RegexpCache.get("do", "\\b", "\\b")) == -1
+fakeTimeDeltaElapsing = ->
+
+context "TabRecency",
+ setup ->
+ @tabRecency = new TabRecency()
+
+ fakeTimeDeltaElapsing = =>
+ if @tabRecency.lastVisitedTime?
+ @tabRecency.lastVisitedTime = new Date(@tabRecency.lastVisitedTime - @tabRecency.timeDelta)
+
+ @tabRecency.register 3
+ fakeTimeDeltaElapsing()
+ @tabRecency.register 2
+ fakeTimeDeltaElapsing()
+ @tabRecency.register 9
+ fakeTimeDeltaElapsing()
+ @tabRecency.register 1
+ @tabRecency.deregister 9
+ fakeTimeDeltaElapsing()
+ @tabRecency.register 4
+ fakeTimeDeltaElapsing()
+
+ should "have entries for recently active tabs", ->
+ assert.isTrue @tabRecency.cache[1]
+ assert.isTrue @tabRecency.cache[2]
+ assert.isTrue @tabRecency.cache[3]
+
+ should "not have entries for removed tabs", ->
+ assert.isFalse @tabRecency.cache[9]
+
+ should "give a high score to the most recent tab", ->
+ assert.isTrue @tabRecency.recencyScore(4) < @tabRecency.recencyScore 1
+ assert.isTrue @tabRecency.recencyScore(3) < @tabRecency.recencyScore 1
+ assert.isTrue @tabRecency.recencyScore(2) < @tabRecency.recencyScore 1
+
+ should "give a low score to the current tab", ->
+ assert.isTrue @tabRecency.recencyScore(1) > @tabRecency.recencyScore 4
+ assert.isTrue @tabRecency.recencyScore(2) > @tabRecency.recencyScore 4
+ assert.isTrue @tabRecency.recencyScore(3) > @tabRecency.recencyScore 4
+
+ should "rank tabs by recency", ->
+ assert.isTrue @tabRecency.recencyScore(3) < @tabRecency.recencyScore 2
+ assert.isTrue @tabRecency.recencyScore(2) < @tabRecency.recencyScore 1
+ @tabRecency.register 3
+ fakeTimeDeltaElapsing()
+ @tabRecency.register 4 # Making 3 the most recent tab which isn't the current tab.
+ assert.isTrue @tabRecency.recencyScore(1) < @tabRecency.recencyScore 3
+ assert.isTrue @tabRecency.recencyScore(2) < @tabRecency.recencyScore 3
+ assert.isTrue @tabRecency.recencyScore(4) < @tabRecency.recencyScore 3
+ assert.isTrue @tabRecency.recencyScore(4) < @tabRecency.recencyScore 1
+ assert.isTrue @tabRecency.recencyScore(4) < @tabRecency.recencyScore 2
+
# A convenience wrapper around completer.filter() so it can be called synchronously in tests.
filterCompleter = (completer, queryTerms) ->
results = []
diff --git a/tests/unit_tests/exclusion_test.coffee b/tests/unit_tests/exclusion_test.coffee
index a24c3b67..25bd8125 100644
--- a/tests/unit_tests/exclusion_test.coffee
+++ b/tests/unit_tests/exclusion_test.coffee
@@ -1,13 +1,13 @@
require "./test_helper.js"
-require "./test_chrome_stubs.js"
+extend global, 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 =
+root.Marks =
create: () -> true
goto:
bind: () -> true
diff --git a/tests/unit_tests/settings_test.coffee b/tests/unit_tests/settings_test.coffee
index 1283497c..4625457b 100644
--- a/tests/unit_tests/settings_test.coffee
+++ b/tests/unit_tests/settings_test.coffee
@@ -1,5 +1,5 @@
require "./test_helper.js"
-require "./test_chrome_stubs.js"
+extend global, require "./test_chrome_stubs.js"
extend(global, require "../../lib/utils.js")
Utils.getCurrentVersion = -> '1.44'
diff --git a/tests/unit_tests/test_chrome_stubs.coffee b/tests/unit_tests/test_chrome_stubs.coffee
index 9622f85f..80750337 100644
--- a/tests/unit_tests/test_chrome_stubs.coffee
+++ b/tests/unit_tests/test_chrome_stubs.coffee
@@ -5,10 +5,10 @@
# It also provides stubs for a number of other chrome APIs.
#
-global.window = {}
-global.localStorage = {}
+exports.window = {}
+exports.localStorage = {}
-global.chrome =
+exports.chrome =
runtime:
getManifest: () ->
version: "1.2.3"
@@ -30,6 +30,10 @@ global.chrome =
addListener: () -> true
onActiveChanged:
addListener: () -> true
+ onActivated:
+ addListener: () -> true
+ onReplaced:
+ addListener: () -> true
query: () -> true
windows:
@@ -56,6 +60,9 @@ global.chrome =
items[key] = {}
@func(items,'synced storage stub')
+ session:
+ MAX_SESSION_RESULTS: 25
+
# chrome.storage.sync
sync:
store: {}
diff --git a/tests/unit_tests/utils_test.coffee b/tests/unit_tests/utils_test.coffee
index c4139dbb..556f5b7a 100644
--- a/tests/unit_tests/utils_test.coffee
+++ b/tests/unit_tests/utils_test.coffee
@@ -1,5 +1,5 @@
require "./test_helper.js"
-require "./test_chrome_stubs.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")
@@ -47,6 +47,27 @@ context "convertToUrl",
assert.equal "http://www.google.com/search?q=google", Utils.convertToUrl("google")
assert.equal "http://www.google.com/search?q=go%20ogle.com", Utils.convertToUrl("go ogle.com")
+context "hasChromePrefix",
+ should "detect chrome prefixes of URLs", ->
+ assert.isTrue Utils.hasChromePrefix "about:foobar"
+ assert.isTrue Utils.hasChromePrefix "view-source:foobar"
+ assert.isTrue Utils.hasChromePrefix "chrome-extension:foobar"
+ assert.isTrue Utils.hasChromePrefix "data:foobar"
+ assert.isTrue Utils.hasChromePrefix "data:"
+ assert.isFalse Utils.hasChromePrefix ""
+ assert.isFalse Utils.hasChromePrefix "about"
+ assert.isFalse Utils.hasChromePrefix "view-source"
+ assert.isFalse Utils.hasChromePrefix "chrome-extension"
+ assert.isFalse Utils.hasChromePrefix "data"
+ assert.isFalse Utils.hasChromePrefix "data :foobar"
+
+context "isUrl",
+ should "identify URLs as URLs", ->
+ assert.isTrue Utils.isUrl "http://www.example.com/blah"
+
+ should "identify non-URLs and non-URLs", ->
+ assert.isFalse Utils.isUrl "http://www.example.com/ blah"
+
context "Function currying",
should "Curry correctly", ->
foo = (a, b) -> "#{a},#{b}"