From 97e61e29d59b9557fe1fb8d7ae1a34be1d47fcc1 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 19 Jan 2015 05:39:24 +0000 Subject: Rework DOM tests. - Set up modes such that they can be re-initialised. - Move initialisation of BadgeMode to general initialisation function. - Add reset() method for handlerStack. - Consistently use initializeModeState() in all tests' setup(). - Refactor focusInput tests. - Add some more tests. - Simplify some other tests. Note: Clean-up of the inputFocus overlay now happens when the exit() method is called in Mode.reset(). This eliminates most needs to artificially bubble a keyboard event to clear the overlay. --- content_scripts/mode.coffee | 12 +++++++++--- content_scripts/vimium_frontend.coffee | 21 ++++++++++++--------- 2 files changed, 21 insertions(+), 12 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index acc3978e..42ea9930 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -169,14 +169,19 @@ class Mode log: (args...) -> console.log args... if @debug - # Return the must-recently activated mode (only used in tests). + # For tests only. @top: -> @modes[@modes.length-1] + # For tests only. + @reset: -> + mode.exit() for mode in @modes + @modes = [] + # BadgeMode is a pseudo mode for triggering badge updates on focus changes and state updates. It sits at the # bottom of the handler stack, and so it receives state changes *after* all other modes, and can override the -# badge choice of the other modes. We create the the one-and-only instance here. -new class BadgeMode extends Mode +# badge choice of the other modes. +class BadgeMode extends Mode constructor: () -> super name: "badge" @@ -200,3 +205,4 @@ new class BadgeMode extends Mode root = exports ? window root.Mode = Mode +root.BadgeMode = BadgeMode diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 725d8a53..729a21bd 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -103,13 +103,8 @@ frameId = Math.floor(Math.random()*999999999) hasModifiersRegex = /^<([amc]-)+.>/ -# -# Complete initialization work that sould be done prior to DOMReady. -# -initializePreDomReady = -> - settings.addEventListener("load", LinkHints.init.bind(LinkHints)) - settings.load() - +# Only exported for tests. +window.initializeModes = -> class NormalMode extends Mode constructor: -> super @@ -122,12 +117,20 @@ initializePreDomReady = -> # Install the permanent modes. The permanently-installed insert mode tracks focus/blur events, and # activates/deactivates itself accordingly. + new BadgeMode new NormalMode new PassKeysMode new InsertMode permanent: true - checkIfEnabledForUrl() +# +# Complete initialization work that sould be done prior to DOMReady. +# +initializePreDomReady = -> + settings.addEventListener("load", LinkHints.init.bind(LinkHints)) + settings.load() + initializeModes() + checkIfEnabledForUrl() refreshCompletionKeys() # Send the key to the key handler in the background page. @@ -179,7 +182,7 @@ installListener = (element, event, callback) -> # Run this as early as possible, so the page can't register any event handlers before us. # installedListeners = false -initializeWhenEnabled = (newPassKeys) -> +window.initializeWhenEnabled = (newPassKeys) -> isEnabledForUrl = true passKeys = newPassKeys if (!installedListeners) -- cgit v1.2.3 From 661bbbd8b6c267e19f940b83da7c817c252808fd Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 20 Jan 2015 05:27:56 +0000 Subject: Rework DOM tests (clean up). --- content_scripts/mode_insert.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'content_scripts') diff --git a/content_scripts/mode_insert.coffee b/content_scripts/mode_insert.coffee index eac4a3d0..6932f419 100644 --- a/content_scripts/mode_insert.coffee +++ b/content_scripts/mode_insert.coffee @@ -48,7 +48,7 @@ class InsertMode extends Mode if @insertModeLock != event.target and DomUtils.isFocusable event.target @activateOnElement event.target - # Only for tests. This gives us a hook to test the status of the permanent instance. + # Only for tests. This gives us a hook to test the status of the permanently-installed instance. InsertMode.permanentInstance = @ if @permanent isActive: (event) -> -- cgit v1.2.3 From 7939b69ffc2880ff4590d1c8dcfd5eb7492200fd Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 20 Jan 2015 10:24:45 +0000 Subject: Rework focus input so it can be better included in tests. focusInput was getting its focus events from the handler stack. When the handler stack was reset during tests, we lost focusInput's handler. So we couldn't test the feature whereby focusInput has a memory (#1438). Instead, here focusInput adds its listener directly to the window, and we add the approriate test. --- content_scripts/vimium_frontend.coffee | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 729a21bd..5d56ad5b 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -337,11 +337,9 @@ extend window, focusInput: do -> # Track the most recently focused input element. recentlyFocusedElement = null - handlerStack.push - _name: "focus-input-tracker" - focus: (event) -> - recentlyFocusedElement = event.target if DomUtils.isEditable event.target - true + window.addEventListener "focus", + (event) -> recentlyFocusedElement = event.target if DomUtils.isEditable event.target + , true (count) -> # Focus the first input element on the page, and create overlays to highlight all the input elements, with -- cgit v1.2.3