diff options
| author | Stephen Blott | 2015-01-11 12:19:19 +0000 |
|---|---|---|
| committer | Stephen Blott | 2015-01-11 14:36:33 +0000 |
| commit | f76c15c6ae6565c0c08569a127974dfd3383ed88 (patch) | |
| tree | 945c8405da0ce0ddec6d47cd2e3ce60b6d2698ad /tests | |
| parent | a8096d235eae39d309c0ffd74e0d2493ff12dd22 (diff) | |
| download | vimium-f76c15c6ae6565c0c08569a127974dfd3383ed88.tar.bz2 | |
Modes; tweaks, including more tests.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/dom_tests/dom_tests.coffee | 28 | ||||
| -rw-r--r-- | tests/unit_tests/handler_stack_test.coffee | 23 |
2 files changed, 44 insertions, 7 deletions
diff --git a/tests/dom_tests/dom_tests.coffee b/tests/dom_tests/dom_tests.coffee index c84d513d..d9e7775f 100644 --- a/tests/dom_tests/dom_tests.coffee +++ b/tests/dom_tests/dom_tests.coffee @@ -8,12 +8,12 @@ mockKeyboardEvent = (keyChar) -> event.charCode = (if keyCodes[keyChar] isnt undefined then keyCodes[keyChar] else keyChar.charCodeAt(0)) event.keyIdentifier = "U+00" + event.charCode.toString(16) event.keyCode = event.charCode - event.stopImmediatePropagation = (event) -> @suppressed = true - event.preventDefault = (event) -> @suppressed = true + event.stopImmediatePropagation = -> @suppressed = true + event.preventDefault = -> @suppressed = true event # Some of these tests have side effects on the handler stack and mode. Therefore, we take backups and restore -# them later. +# them on tear down. backupStackState = -> Mode.backup = Mode.modes[..] handlerStack.backup = handlerStack.stack[..] @@ -197,6 +197,21 @@ context "Input focus", assert.equal "third", document.activeElement.id handlerStack.bubbleEvent 'keydown', mockKeyboardEvent("A") + # This is the same as above, but also verifies that focusInput activates insert mode. + should "focus the right element, and activate insert mode", -> + focusInput 1 + assert.equal "first", document.activeElement.id + # deactivate the tabbing mode and its overlays + assert.isTrue Mode.modes[Mode.modes.length-1].name != "insert" + handlerStack.bubbleEvent 'keydown', mockKeyboardEvent("A") + assert.isTrue Mode.modes[Mode.modes.length-1].name == "insert" + + focusInput 100 + assert.equal "third", document.activeElement.id + assert.isTrue Mode.modes[Mode.modes.length-1].name != "insert" + handlerStack.bubbleEvent 'keydown', mockKeyboardEvent("A") + assert.isTrue Mode.modes[Mode.modes.length-1].name == "insert" + # TODO: these find prev/next link tests could be refactored into unit tests which invoke a function which has # a tighter contract than goNext(), since they test minor aspects of goNext()'s link matching behavior, and we # don't need to construct external state many times over just to test that. @@ -262,13 +277,12 @@ createLinks = (n) -> link.textContent = "test" document.getElementById("test-div").appendChild link -# For these tests, we use "m" as a mapped key, "p" ass a pass key, and "u" as an unmapped key. +# For these tests, we use "m" as a mapped key, "p" as a pass key, and "u" as an unmapped key. context "Normal mode", setup -> backupStackState() refreshCompletionKeys - completionKeys: [ "m" ] - validFirstKeys: {} + completionKeys: "m" tearDown -> restoreStackState() @@ -616,7 +630,7 @@ context "PostFindMode", should "enter insert mode on immediate escape", -> new PostFindMode @element - assert.isTrue Mode.modes[Mode.modes.length-1].name != "insert" + assert.isTrue Mode.modes[Mode.modes.length-1].name == "post-find" handlerStack.bubbleEvent "keydown", @escape assert.isTrue Mode.modes[Mode.modes.length-1].name == "insert" diff --git a/tests/unit_tests/handler_stack_test.coffee b/tests/unit_tests/handler_stack_test.coffee index 0ed8f4c0..0ed85e63 100644 --- a/tests/unit_tests/handler_stack_test.coffee +++ b/tests/unit_tests/handler_stack_test.coffee @@ -23,6 +23,29 @@ context "handlerStack", assert.isTrue @handler2Called assert.isFalse @handler1Called + should "terminate bubbling on stopBubblingAndTrue, and be true", -> + @handlerStack.push { keydown: => @handler1Called = true } + @handlerStack.push { keydown: => @handler2Called = true; @handlerStack.stopBubblingAndTrue } + assert.isTrue @handlerStack.bubbleEvent 'keydown', {} + assert.isTrue @handler2Called + assert.isFalse @handler1Called + + should "terminate bubbling on stopBubblingAndTrue, and be false", -> + @handlerStack.push { keydown: => @handler1Called = true } + @handlerStack.push { keydown: => @handler2Called = true; @handlerStack.stopBubblingAndFalse } + assert.isFalse @handlerStack.bubbleEvent 'keydown', {} + assert.isTrue @handler2Called + assert.isFalse @handler1Called + + should "restart bubbling on restartBubbling", -> + @handler1Called = 0 + @handler2Called = 0 + id = @handlerStack.push { keydown: => @handler1Called++; @handlerStack.remove(id); @handlerStack.restartBubbling } + @handlerStack.push { keydown: => @handler2Called++; true } + assert.isTrue @handlerStack.bubbleEvent 'keydown', {} + assert.isTrue @handler1Called == 1 + assert.isTrue @handler2Called == 2 + should "remove handlers correctly", -> @handlerStack.push { keydown: => @handler1Called = true } handlerId = @handlerStack.push { keydown: => @handler2Called = true } |
