aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPhil Crosby2012-06-04 23:25:45 -0700
committerPhil Crosby2012-06-10 01:41:45 -0700
commit9a89290cdba6739f535ee5f19e6b58228e2b6b1a (patch)
treee34b1459251a7b00bdff51b4974b4ed918777da3 /tests
parente66314769137ced25b65a248643a22af32ef1e95 (diff)
downloadvimium-9a89290cdba6739f535ee5f19e6b58228e2b6b1a.tar.bz2
Update the timestamps of cached history entries when a new site is visited.
This allows the vomnibar rankings to properly rank sites you've visited recently, after it populated its original cache.
Diffstat (limited to 'tests')
-rw-r--r--tests/completion_test.coffee53
1 files changed, 52 insertions, 1 deletions
diff --git a/tests/completion_test.coffee b/tests/completion_test.coffee
index 531d06b1..ed864151 100644
--- a/tests/completion_test.coffee
+++ b/tests/completion_test.coffee
@@ -22,9 +22,60 @@ context "bookmark completer",
@completer.filter(["mark2"], (@results) =>)
assert.arrayEqual [@bookmark2.url], @results.map (suggestion) -> suggestion.url
+context "HistoryCache",
+ context "binary search",
+ setup ->
+ @compare = (a, b) -> a - b
+
+ should "find elements to the left of the middle", ->
+ assert.equal 0, HistoryCache.binarySearch(3, [3, 5, 8], @compare)
+
+ should "find elements to the right of the middle", ->
+ assert.equal 2, HistoryCache.binarySearch(8, [3, 5, 8], @compare)
+
+ context "unfound elements",
+ should "return 0 if it should be the head of the list", ->
+ assert.equal 0, HistoryCache.binarySearch(1, [3, 5, 8], @compare)
+
+ should "return length - 1 if it should be at the end of the list", ->
+ assert.equal 0, HistoryCache.binarySearch(3, [3, 5, 8], @compare)
+
+ should "found return the position if it's between two elements", ->
+ assert.equal 1, HistoryCache.binarySearch(4, [3, 5, 8], @compare)
+ assert.equal 2, HistoryCache.binarySearch(7, [3, 5, 8], @compare)
+
+ context "fetchHistory",
+ setup ->
+ @history1 = { url: "b.com", lastVisitTime: 5 }
+ @history2 = { url: "a.com", lastVisitTime: 10 }
+ history = [@history1, @history2]
+ @onVisitedListener = null
+ global.chrome.history =
+ search: (options, callback) -> callback(history)
+ onVisited: { addListener: (@onVisitedListener) => }
+ HistoryCache.reset()
+
+ should "store visits sorted by url ascending", ->
+ HistoryCache.use (@results) =>
+ assert.arrayEqual [@history2, @history1], @results
+
+ should "add new visits to the history", ->
+ HistoryCache.use () ->
+ newSite = { url: "ab.com" }
+ @onVisitedListener(newSite)
+ HistoryCache.use (@results) =>
+ assert.arrayEqual [@history2, newSite, @history1], @results
+
+ should "replace new visits in the history", ->
+ HistoryCache.use (@results) =>
+ assert.arrayEqual [@history2, @history1], @results
+ newSite = { url: "a.com", lastVisitTime: 15 }
+ @onVisitedListener(newSite)
+ HistoryCache.use (@results) =>
+ assert.arrayEqual [newSite, @history1], @results
+
context "history completer",
setup ->
- # history2 is more recent than history1.
@history1 = { title: "history1", url: "history1.com", lastVisitTime: hours(1) }
@history2 = { title: "history2", url: "history2.com", lastVisitTime: hours(5) }