diff options
| author | Phil Crosby | 2012-11-12 22:34:08 -0800 |
|---|---|---|
| committer | Phil Crosby | 2012-11-12 22:34:08 -0800 |
| commit | 32e506dd94565d54ab4d81144eebf849a98be338 (patch) | |
| tree | a581aa23cdb43cbbd52ad8eb490224cf1344a584 /tests | |
| parent | a3eb1cbee93c4c10505f629b8bc8bc00e37adb8a (diff) | |
| parent | f0347388264b0fb437489f4f021ba8c0dbcca8e3 (diff) | |
| download | vimium-32e506dd94565d54ab4d81144eebf849a98be338.tar.bz2 | |
Merge pull request #715 from smblott-github/history--remove-entries
Remove entries from History/Domain completers when they're removed on chrome.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unit_tests/completion_test.coffee | 80 |
1 files changed, 78 insertions, 2 deletions
diff --git a/tests/unit_tests/completion_test.coffee b/tests/unit_tests/completion_test.coffee index 3de1d716..08ce46c2 100644 --- a/tests/unit_tests/completion_test.coffee +++ b/tests/unit_tests/completion_test.coffee @@ -41,6 +41,9 @@ context "HistoryCache", 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 "return one passed end of array (so: array.length) if greater than last element in array", -> + assert.equal 3, HistoryCache.binarySearch(10, [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) @@ -51,9 +54,11 @@ context "HistoryCache", @history2 = { url: "a.com", lastVisitTime: 10 } history = [@history1, @history2] @onVisitedListener = null + @onVisitRemovedListener = null global.chrome.history = search: (options, callback) -> callback(history) onVisited: { addListener: (@onVisitedListener) => } + onVisitRemoved: { addListener: (@onVisitRemovedListener) => } HistoryCache.reset() should "store visits sorted by url ascending", -> @@ -75,6 +80,30 @@ context "HistoryCache", HistoryCache.use (@results) => assert.arrayEqual [newSite, @history1], @results + should "(not) remove page from the history, when page is not in history (it should be a no-op)", -> + HistoryCache.use (@results) => + assert.arrayEqual [@history2, @history1], @results + toRemove = { urls: [ "x.com" ], allHistory: false } + @onVisitRemovedListener(toRemove) + HistoryCache.use (@results) => + assert.arrayEqual [@history2, @history1], @results + + should "remove pages from the history", -> + HistoryCache.use (@results) => + assert.arrayEqual [@history2, @history1], @results + toRemove = { urls: [ "a.com" ], allHistory: false } + @onVisitRemovedListener(toRemove) + HistoryCache.use (@results) => + assert.arrayEqual [@history1], @results + + should "remove all pages from the history", -> + HistoryCache.use (@results) => + assert.arrayEqual [@history2, @history1], @results + toRemove = { allHistory: true } + @onVisitRemovedListener(toRemove) + HistoryCache.use (@results) => + assert.arrayEqual [], @results + context "history completer", setup -> @history1 = { title: "history1", url: "history1.com", lastVisitTime: hours(1) } @@ -83,6 +112,7 @@ context "history completer", global.chrome.history = search: (options, callback) => callback([@history1, @history2]) onVisited: { addListener: -> } + onVisitRemoved: { addListener: -> } @completer = new HistoryCompleter() @@ -102,7 +132,9 @@ context "domain completer", @history2 = { title: "history2", url: "http://history2.com", lastVisitTime: hours(1) } stub(HistoryCache, "use", (onComplete) => onComplete([@history1, @history2])) - global.chrome.history = { onVisited: { addListener: -> } } + global.chrome.history = + onVisited: { addListener: -> } + onVisitRemoved: { addListener: -> } stub(Date, "now", returns(hours(24))) @completer = new DomainCompleter() @@ -112,7 +144,7 @@ context "domain completer", assert.arrayEqual ["history1.com"], results.map (result) -> result.url should "pick domains which are more recent", -> - # This domains are the same except for their last visited time. + # These domains are the same except for their last visited time. assert.equal "history1.com", filterCompleter(@completer, ["story"])[0].url @history2.lastVisitTime = hours(3) assert.equal "history2.com", filterCompleter(@completer, ["story"])[0].url @@ -120,6 +152,50 @@ context "domain completer", 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"]) +context "domain completer (removing entries)", + setup -> + @history1 = { title: "history1", url: "http://history1.com", lastVisitTime: hours(2) } + @history2 = { title: "history2", url: "http://history2.com", lastVisitTime: hours(1) } + @history3 = { title: "history2something", url: "http://history2.com/something", lastVisitTime: hours(0) } + + stub(HistoryCache, "use", (onComplete) => onComplete([@history1, @history2, @history3])) + @onVisitedListener = null + @onVisitRemovedListener = null + global.chrome.history = + onVisited: { addListener: (@onVisitedListener) => } + onVisitRemoved: { addListener: (@onVisitRemovedListener) => } + stub(Date, "now", returns(hours(24))) + + @completer = new DomainCompleter() + # Force installation of listeners. + filterCompleter(@completer, ["story"]) + + 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 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 + @onVisitRemovedListener { allHistory: false, urls: [@history3.url] } + assert.equal 0, filterCompleter(@completer, ["story2"]).length + assert.equal "history1.com", filterCompleter(@completer, ["story"])[0].url + + should "remove 3 (all) matching domain entries", -> + @onVisitRemovedListener { allHistory: false, urls: [@history2.url] } + @onVisitRemovedListener { allHistory: false, urls: [@history1.url] } + @onVisitRemovedListener { allHistory: false, urls: [@history3.url] } + assert.equal 0, filterCompleter(@completer, ["story"]).length + + should "remove 3 (all) matching domain entries, and do it all at once", -> + @onVisitRemovedListener { allHistory: false, urls: [ @history2.url, @history1.url, @history3.url ] } + assert.equal 0, filterCompleter(@completer, ["story"]).length + + should "remove *all* domain entries", -> + @onVisitRemovedListener { allHistory: true } + assert.equal 0, filterCompleter(@completer, ["story"]).length + context "tab completer", setup -> @tabs = [ |
