Permalink
Browse files

More domain completer tests.

  • Loading branch information...
1 parent 7751224 commit cf757fc841c6b97a8341472bd15bdc95c527babc @smblott-github smblott-github committed Nov 11, 2012
Showing with 19 additions and 8 deletions.
  1. +19 −8 tests/unit_tests/completion_test.coffee
@@ -130,8 +130,9 @@ context "domain completer",
setup ->
@history1 = { title: "history1", url: "http://history1.com", lastVisitTime: hours(1) }
@history2 = { title: "history2", url: "http://history2.com", lastVisitTime: hours(1) }
+ @history3 = { title: "history2", url: "http://history2.com/something", lastVisitTime: hours(0) }
- stub(HistoryCache, "use", (onComplete) => onComplete([@history1, @history2]))
+ stub(HistoryCache, "use", (onComplete) => onComplete([@history1, @history2, @history3]))
@onVisitedListener = null
@onVisitRemovedListener = null
global.chrome.history =
@@ -142,7 +143,7 @@ context "domain completer",
@completer = new DomainCompleter()
should "return only a single matching domain", ->
- results = filterCompleter(@completer, ["story"])
+ results = filterCompleter(@completer, ["story1"])
assert.arrayEqual ["history1.com"], results.map (result) -> result.url
should "pick domains which are more recent", ->
@@ -156,20 +157,30 @@ context "domain completer",
should "remove 1 matching domain entry", ->
# Force installation of `@onVisitRemovedListener`
- @history2.lastVisitTime = hours(3) and filterCompleter(@completer, ["story"])
+ filterCompleter(@completer, ["story"])
@onVisitRemovedListener { allHistory: false, urls: [ @history2.url ] }
assert.equal "history1.com", filterCompleter(@completer, ["story"])[0].url
- should "remove 2 (both) matching domain entries", ->
- # Force installation of `@onVisitRemovedListener`
- @history2.lastVisitTime = hours(3) and filterCompleter(@completer, ["story"])
+ should "remove all entries from one domain", ->
+ filterCompleter(@completer, ["story"]) # Force installation of `@onVisitRemovedListener`.
+ @onVisitRemovedListener { allHistory: false, urls: [ @history2.url ] }
+ @onVisitRemovedListener { allHistory: false, urls: [ @history3.url ] }
+ assert.equal "history1.com", filterCompleter(@completer, ["story"])[0].url
+
+ should "remove 3 (all) matching domain entries", ->
+ filterCompleter(@completer, ["story"]) # Force installation of `@onVisitRemovedListener`.
@onVisitRemovedListener { allHistory: false, urls: [ @history2.url ] }
@onVisitRemovedListener { allHistory: false, urls: [ @history1.url ] }
+ @onVisitRemovedListener { allHistory: false, urls: [ @history3.url ] }
+ assert.isTrue filterCompleter(@completer, ["story"]).length == 0
+
+ should "remove 3 (all) matching domain entries, and do it all at once", ->
+ filterCompleter(@completer, ["story"]) # Force installation of `@onVisitRemovedListener`.
+ @onVisitRemovedListener { allHistory: false, urls: [ @history2.url, @history1.url, @history3.url ] }
assert.isTrue filterCompleter(@completer, ["story"]).length == 0
should "remove *all* domain entries", ->
- # Force installation of `@onVisitRemovedListener`
- @history2.lastVisitTime = hours(3) and filterCompleter(@completer, ["story"])
+ filterCompleter(@completer, ["story"]) # Force installation of `@onVisitRemovedListener`.
@onVisitRemovedListener { allHistory: true }
assert.isTrue filterCompleter(@completer, ["story"]).length == 0

0 comments on commit cf757fc

Please sign in to comment.