diff options
| author | Stephen Blott | 2016-03-29 15:05:52 +0100 |
|---|---|---|
| committer | Stephen Blott | 2016-03-29 15:05:52 +0100 |
| commit | 7ecc65d8215203b89248d8f313783ce48e8ba1c4 (patch) | |
| tree | b9cdb213f283961baf9e42e66649e2c83cdb841f | |
| parent | 3b72ced87f4dc6402f4ab8f8dbf2873e9a53093d (diff) | |
| download | vimium-7ecc65d8215203b89248d8f313783ce48e8ba1c4.tar.bz2 | |
Add tests for WaitForEnter.
| -rw-r--r-- | content_scripts/link_hints.coffee | 8 | ||||
| -rw-r--r-- | tests/dom_tests/dom_tests.coffee | 26 | ||||
| -rw-r--r-- | tests/dom_tests/phantom_runner.coffee | 3 |
3 files changed, 33 insertions, 4 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 7dad806f..526e3917 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -286,7 +286,7 @@ class LinkHintsMode clickEl.focus() linkActivator clickEl - installKeyBoardBlocker = (startKeyboardBlocker) -> + installKeyboardBlocker = (startKeyboardBlocker) -> if linkMatched.hintDescriptor.frameId == frameId flashEl = DomUtils.addFlashRect linkMatched.hintDescriptor.rect HintCoordinator.onExit.push -> DomUtils.removeElement flashEl @@ -297,9 +297,9 @@ class LinkHintsMode # If we're using a keyboard blocker, then the frame with the focus sends the "exit" message, otherwise the # frame containing the matched link does. if userMightOverType and Settings.get "waitForEnterForFilteredHints" - installKeyBoardBlocker (callback) -> new WaitForEnter callback + installKeyboardBlocker (callback) -> new WaitForEnter callback else if userMightOverType - installKeyBoardBlocker (callback) -> new TypingProtector 200, callback + installKeyboardBlocker (callback) -> new TypingProtector 200, callback else if linkMatched.hintDescriptor.frameId == frameId DomUtils.flashRect linkMatched.hintDescriptor.rect HintCoordinator.sendMessage "exit", isSuccess: true @@ -750,4 +750,4 @@ root = exports ? window root.LinkHints = LinkHints root.HintCoordinator = HintCoordinator # For tests: -extend root, {LinkHintsMode, LocalHints, AlphabetHints} +extend root, {LinkHintsMode, LocalHints, AlphabetHints, WaitForEnter} diff --git a/tests/dom_tests/dom_tests.coffee b/tests/dom_tests/dom_tests.coffee index c3bdb9c5..84942908 100644 --- a/tests/dom_tests/dom_tests.coffee +++ b/tests/dom_tests/dom_tests.coffee @@ -996,3 +996,29 @@ context "PostFindMode", sendKeyboardEvent "escape" assert.isTrue @postFindMode.modeIsActive +context "WaitForEnter", + setup -> + initializeModeState() + @isSuccess = null + @waitForEnter = new WaitForEnter (isSuccess) => @isSuccess = isSuccess + + should "exit with success on Enter", -> + assert.isTrue @waitForEnter.modeIsActive + assert.isFalse @isSuccess? + sendKeyboardEvent "enter" + assert.isFalse @waitForEnter.modeIsActive + assert.isTrue @isSuccess? and @isSuccess == true + + should "exit without success on Escape", -> + assert.isTrue @waitForEnter.modeIsActive + assert.isFalse @isSuccess? + sendKeyboardEvent "escape" + assert.isFalse @waitForEnter.modeIsActive + assert.isTrue @isSuccess? and @isSuccess == false + + should "not exit on other keyboard events", -> + assert.isTrue @waitForEnter.modeIsActive + assert.isFalse @isSuccess? + sendKeyboardEvents "abc" + assert.isTrue @waitForEnter.modeIsActive + assert.isFalse @isSuccess? diff --git a/tests/dom_tests/phantom_runner.coffee b/tests/dom_tests/phantom_runner.coffee index 265c994e..09d7d584 100644 --- a/tests/dom_tests/phantom_runner.coffee +++ b/tests/dom_tests/phantom_runner.coffee @@ -28,6 +28,9 @@ page.onCallback = (request) -> when "escape" page.sendEvent "keydown", page.event.key.Escape page.sendEvent "keyup", page.event.key.Escape + when "enter" + page.sendEvent "keydown", page.event.key.Enter + page.sendEvent "keyup", page.event.key.Enter when "tab" page.sendEvent "keydown", page.event.key.Tab page.sendEvent "keyup", page.event.key.Tab |
