1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
vomnibarFrame = null
SearchEngines.refresh ""
Vomnibar.init()
context "Keep selection within bounds",
setup ->
@completions = []
vomnibarFrame = Vomnibar.vomnibarUI.iframeElement.contentWindow
# The Vomnibar frame is dynamically injected, so inject our stubs here.
vomnibarFrame.Function::bind = Function::bind
vomnibarFrame.chrome = chrome
oldGetCompleter = vomnibarFrame.Vomnibar.getCompleter.bind vomnibarFrame.Vomnibar
stub vomnibarFrame.Vomnibar, 'getCompleter', (name) =>
completer = oldGetCompleter name
stub completer, 'filter', ({ callback }) => callback results: @completions
completer
# Shoulda.js doesn't support async tests, so we have to hack around.
stub Vomnibar.vomnibarUI, "postMessage", (data) ->
vomnibarFrame.UIComponentServer.handleMessage {data}
stub vomnibarFrame.UIComponentServer, "postMessage", (data) ->
UIComponent.handleMessage {data}
tearDown ->
Vomnibar.vomnibarUI.hide()
should "set selection to position -1 for omni completion by default", ->
Vomnibar.activate()
ui = vomnibarFrame.Vomnibar.vomnibarUI
@completions = []
ui.update(true)
assert.equal -1, ui.selection
@completions = [{html:'foo',type:'tab',url:'http://example.com'}]
ui.update(true)
assert.equal -1, ui.selection
@completions = []
ui.update(true)
assert.equal -1, ui.selection
should "set selection to position 0 for bookmark completion if possible", ->
Vomnibar.activateBookmarks()
ui = vomnibarFrame.Vomnibar.vomnibarUI
@completions = []
ui.update(true)
assert.equal -1, ui.selection
@completions = [{html:'foo',type:'bookmark',url:'http://example.com'}]
ui.update(true)
assert.equal 0, ui.selection
@completions = []
ui.update(true)
assert.equal -1, ui.selection
should "keep selection within bounds", ->
Vomnibar.activate()
ui = vomnibarFrame.Vomnibar.vomnibarUI
@completions = []
ui.update(true)
eventMock =
preventDefault: ->
stopImmediatePropagation: ->
@completions = [{html:'foo',type:'tab',url:'http://example.com'}]
ui.update(true)
stub ui, "actionFromKeyEvent", -> "down"
ui.onKeydown eventMock
assert.equal 0, ui.selection
@completions = []
ui.update(true)
assert.equal -1, ui.selection
|