diff options
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 6 | ||||
| -rw-r--r-- | tests/dom_tests/dom_tests.coffee | 17 | 
2 files changed, 22 insertions, 1 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index c49c27e2..abcf2b36 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -338,7 +338,11 @@ getFocusedElementIndexByRecency = do ->    installListener window, "focus", (event) ->      focusedElement = event.target if DomUtils.isEditable event.target -  (elements) -> +  # Only for tests. +  window.resetFocusInputFocusedElement = -> +    focusedElement = null + +  (elements = null) ->      Math.max 0, elements.indexOf focusedElement  extend window, diff --git a/tests/dom_tests/dom_tests.coffee b/tests/dom_tests/dom_tests.coffee index c73e0885..8cb0c41a 100644 --- a/tests/dom_tests/dom_tests.coffee +++ b/tests/dom_tests/dom_tests.coffee @@ -184,10 +184,12 @@ context "Input focus",        <input type='password' id='third' value='some value'/>"      document.getElementById("test-div").innerHTML = testContent      backupStackState() +    resetFocusInputFocusedElement()    tearDown ->      document.getElementById("test-div").innerHTML = ""      restoreStackState() +    resetFocusInputFocusedElement()    should "focus the right element", ->      focusInput 1 @@ -204,10 +206,25 @@ context "Input focus",      focusInput 1      handlerStack.bubbleEvent 'focus', { target: document.activeElement }      assert.isTrue InsertMode.permanentInstance.isActive() +    # deactivate the tabbing mode and its overlays +    handlerStack.bubbleEvent 'keydown', mockKeyboardEvent("A")      focusInput 100      handlerStack.bubbleEvent 'focus', { target: document. activeElement }      assert.isTrue InsertMode.permanentInstance.isActive() +    # deactivate the tabbing mode and its overlays +    handlerStack.bubbleEvent 'keydown', mockKeyboardEvent("A") + +  should "select the previously-focused input when count is 1", -> +    focusInput 100 +    assert.equal "third", document.activeElement.id +    # deactivate the tabbing mode and its overlays +    handlerStack.bubbleEvent 'keydown', mockKeyboardEvent("A") + +    focusInput 1 +    assert.equal "third", document.activeElement.id +    # deactivate the tabbing mode and its overlays +    handlerStack.bubbleEvent 'keydown', mockKeyboardEvent("A")  # 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  | 
