aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2016-03-25 10:37:45 +0000
committerStephen Blott2016-03-25 10:37:45 +0000
commit69333f609bcdf3724ae639d7389750cfe18f4523 (patch)
tree6336da36b7b39bcb56b48880e88507e27279f0a1
parent326d6c486db97764123fdbeb68212624b9941da2 (diff)
downloadvimium-69333f609bcdf3724ae639d7389750cfe18f4523.tar.bz2
More selective integration with the tests.
This is a better way of stubing for the tests. Previously, if anything went wrong, there would actually be a visual effect for the user (the page would scroll). This way, that cannot happen.
-rw-r--r--content_scripts/mode_visual.coffee7
-rw-r--r--tests/dom_tests/dom_tests.coffee1
2 files changed, 4 insertions, 4 deletions
diff --git a/content_scripts/mode_visual.coffee b/content_scripts/mode_visual.coffee
index cacf8aa3..cbdf6ae2 100644
--- a/content_scripts/mode_visual.coffee
+++ b/content_scripts/mode_visual.coffee
@@ -250,10 +250,9 @@ class VisualMode extends KeyHandlerMode
unless @name == "caret"
if @selection.type in [ "Caret", "Range" ]
selectionRect = @selection.getRangeAt(0).getBoundingClientRect()
- # Only for the tests. We don't have getBoundingClientRect() in the tests, so we patch in a default
- # rect here.
- # TODO(smblott) Is there a way to stub this properly?
- selectionRect ||= {top: 0, bottom: 0, left: 0, right: 0, width: 0, height: 0}
+ if window.vimiumDomTestsAreRunning
+ # We're running the DOM tests, where getBoundingClientRect() isn't available.
+ selectionRect ||= {top: 0, bottom: 0, left: 0, right: 0, width: 0, height: 0}
selectionRect = Rect.intersect selectionRect, Rect.create 0, 0, window.innerWidth, window.innerHeight
if selectionRect.height >= 0 and selectionRect.width >= 0
# The selection is visible in the current viewport.
diff --git a/tests/dom_tests/dom_tests.coffee b/tests/dom_tests/dom_tests.coffee
index d67b6c5d..517dce99 100644
--- a/tests/dom_tests/dom_tests.coffee
+++ b/tests/dom_tests/dom_tests.coffee
@@ -1,3 +1,4 @@
+window.vimiumDomTestsAreRunning = true
# Install frontend event handlers.
installListeners()