aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2014-11-08 06:51:44 +0000
committerStephen Blott2014-11-08 06:51:44 +0000
commita61de15c2f21e2a27f09b088dea09c1cefe699d1 (patch)
treefcf35c5baa6d1cae91ad16c58fe8f6f1d9549efd
parent7d7efb77270c6cd9527e788bdae9a862ced59d81 (diff)
downloadvimium-a61de15c2f21e2a27f09b088dea09c1cefe699d1.tar.bz2
Tabs order; add tests.
-rw-r--r--background_scripts/completion.coffee1
-rw-r--r--tests/unit_tests/completion_test.coffee20
-rw-r--r--tests/unit_tests/test_chrome_stubs.coffee4
3 files changed, 24 insertions, 1 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index 141c4ad7..af1613fc 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -573,3 +573,4 @@ root.SearchEngineCompleter = SearchEngineCompleter
root.HistoryCache = HistoryCache
root.RankingUtils = RankingUtils
root.RegexpCache = RegexpCache
+root.TabRecency = TabRecency
diff --git a/tests/unit_tests/completion_test.coffee b/tests/unit_tests/completion_test.coffee
index 811436a9..ee758dbb 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: -> {}
@@ -399,6 +399,24 @@ context "RegexpCache",
should "search for a string with a prefix/suffix (negative case)", ->
assert.isTrue "hound dog".search(RegexpCache.get("do", "\\b", "\\b")) == -1
+context "TabRecency",
+ setup ->
+ @tabRecency = new TabRecency()
+ @tabRecency.add 3
+ @tabRecency.add 2
+ @tabRecency.add 1
+ @tabRecency.add 4
+
+ 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
+
# A convenience wrapper around completer.filter() so it can be called synchronously in tests.
filterCompleter = (completer, queryTerms) ->
results = []
diff --git a/tests/unit_tests/test_chrome_stubs.coffee b/tests/unit_tests/test_chrome_stubs.coffee
index 2abd26c9..80750337 100644
--- a/tests/unit_tests/test_chrome_stubs.coffee
+++ b/tests/unit_tests/test_chrome_stubs.coffee
@@ -30,6 +30,10 @@ exports.chrome =
addListener: () -> true
onActiveChanged:
addListener: () -> true
+ onActivated:
+ addListener: () -> true
+ onReplaced:
+ addListener: () -> true
query: () -> true
windows: