aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/dom_tests/chrome.coffee8
-rw-r--r--tests/dom_tests/dom_tests.html3
-rw-r--r--tests/dom_tests/dom_utils_test.coffee6
-rw-r--r--tests/dom_tests/vomnibar_test.coffee25
-rw-r--r--tests/unit_tests/exclusion_test.coffee50
-rw-r--r--tests/unit_tests/rect_test.coffee232
-rw-r--r--tests/unit_tests/test_chrome_stubs.coffee4
7 files changed, 283 insertions, 45 deletions
diff --git a/tests/dom_tests/chrome.coffee b/tests/dom_tests/chrome.coffee
index 7f99e27f..ad4ae74b 100644
--- a/tests/dom_tests/chrome.coffee
+++ b/tests/dom_tests/chrome.coffee
@@ -10,6 +10,9 @@ root.chrome = {
onMessage: {
addListener: ->
}
+ onDisconnect: {
+ addListener: ->
+ }
postMessage: ->
}
onMessage: {
@@ -17,5 +20,10 @@ root.chrome = {
}
sendMessage: ->
getManifest: ->
+ getURL: (url) -> "../../#{url}"
}
+ storage:
+ local:
+ get: ->
+ set: ->
}
diff --git a/tests/dom_tests/dom_tests.html b/tests/dom_tests/dom_tests.html
index feddafac..a764b42d 100644
--- a/tests/dom_tests/dom_tests.html
+++ b/tests/dom_tests/dom_tests.html
@@ -32,8 +32,10 @@
<script type="text/javascript" src="../../lib/utils.js"></script>
<script type="text/javascript" src="../../lib/keyboard_utils.js"></script>
<script type="text/javascript" src="../../lib/dom_utils.js"></script>
+ <script type="text/javascript" src="../../lib/rect.js"></script>
<script type="text/javascript" src="../../lib/handler_stack.js"></script>
<script type="text/javascript" src="../../lib/clipboard.js"></script>
+ <script type="text/javascript" src="../../content_scripts/ui_component.js"></script>
<script type="text/javascript" src="../../content_scripts/link_hints.js"></script>
<script type="text/javascript" src="../../content_scripts/vomnibar.js"></script>
<script type="text/javascript" src="../../content_scripts/scroller.js"></script>
@@ -52,6 +54,5 @@
<h1>Vimium Tests</h1>
<div id="output-div"></div>
-
</body>
</html>
diff --git a/tests/dom_tests/dom_utils_test.coffee b/tests/dom_tests/dom_utils_test.coffee
index 130a3014..ad8bde3c 100644
--- a/tests/dom_tests/dom_utils_test.coffee
+++ b/tests/dom_tests/dom_utils_test.coffee
@@ -50,12 +50,6 @@ context "Check visibility",
assert.isTrue (DomUtils.getVisibleClientRect document.getElementById 'foo') != null
assert.isTrue (DomUtils.getVisibleClientRect document.getElementById 'bar') != null
- should "detect opacity:0 links as hidden", ->
- document.getElementById("test-div").innerHTML = """
- <a id='foo' style='opacity:0'>test</a>
- """
- assert.equal null, DomUtils.getVisibleClientRect document.getElementById 'foo'
-
should "detect links that contain only floated / absolutely-positioned divs as visible", ->
document.getElementById("test-div").innerHTML = """
<a id='foo'>
diff --git a/tests/dom_tests/vomnibar_test.coffee b/tests/dom_tests/vomnibar_test.coffee
index b414fdfb..0e02bb7b 100644
--- a/tests/dom_tests/vomnibar_test.coffee
+++ b/tests/dom_tests/vomnibar_test.coffee
@@ -1,19 +1,34 @@
+vomnibarFrame = null
+
context "Keep selection within bounds",
setup ->
@completions = []
- oldGetCompleter = Vomnibar.getCompleter.bind Vomnibar
- stub Vomnibar, 'getCompleter', (name) =>
+
+ vomnibarFrame = Vomnibar.vomnibarUI.iframeElement.contentWindow
+
+ # The Vomnibar frame is dynamically injected, so inject our stubs here.
+ vomnibarFrame.Function::bind = Function::bind
+ vomnibarFrame.chrome = chrome
+
+ oldGetCompleter = vomnibarFrame.Vomnibar.getCompleter.bind vomnibarFrame.Vomnibar
+ stub vomnibarFrame.Vomnibar, 'getCompleter', (name) =>
completer = oldGetCompleter name
stub completer, 'filter', (query, callback) => callback(@completions)
completer
+ # Shoulda.js doesn't support async tests, so we have to hack around.
+ stub Vomnibar.vomnibarUI, "postMessage", (data) ->
+ vomnibarFrame.UIComponentServer.handleMessage {data}
+ stub vomnibarFrame.UIComponentServer, "postMessage", (data) ->
+ UIComponent.handleMessage {data}
+
tearDown ->
Vomnibar.vomnibarUI.hide()
should "set selection to position -1 for omni completion by default", ->
Vomnibar.activate()
- ui = Vomnibar.vomnibarUI
+ ui = vomnibarFrame.Vomnibar.vomnibarUI
@completions = []
ui.update(true)
@@ -29,7 +44,7 @@ context "Keep selection within bounds",
should "set selection to position 0 for bookmark completion if possible", ->
Vomnibar.activateBookmarks()
- ui = Vomnibar.vomnibarUI
+ ui = vomnibarFrame.Vomnibar.vomnibarUI
@completions = []
ui.update(true)
@@ -45,7 +60,7 @@ context "Keep selection within bounds",
should "keep selection within bounds", ->
Vomnibar.activate()
- ui = Vomnibar.vomnibarUI
+ ui = vomnibarFrame.Vomnibar.vomnibarUI
@completions = []
ui.update(true)
diff --git a/tests/unit_tests/exclusion_test.coffee b/tests/unit_tests/exclusion_test.coffee
index 25bd8125..b3ed7194 100644
--- a/tests/unit_tests/exclusion_test.coffee
+++ b/tests/unit_tests/exclusion_test.coffee
@@ -25,49 +25,33 @@ extend(global, require "../../background_scripts/main.js")
#
context "Excluded URLs and pass keys",
- # These tests have no setup, they use the default values from settings.coffee.
+ setup ->
+ Exclusions.postUpdateHook(
+ [
+ { pattern: "http*://mail.google.com/*", passKeys: "" }
+ { pattern: "http*://www.facebook.com/*", passKeys: "abab" }
+ { pattern: "http*://www.facebook.com/*", passKeys: "cdcd" }
+ { pattern: "http*://www.bbc.com/*", passKeys: "" }
+ { pattern: "http*://www.bbc.com/*", passKeys: "ab" }
+ ])
should "be disabled for excluded sites", ->
- rule = isEnabledForUrl({ url: 'http://www.google.com/calendar/page' })
- assert.isFalse rule.isEnableForUrl
+ rule = isEnabledForUrl({ url: 'http://mail.google.com/calendar/page' })
+ assert.isFalse rule.isEnabledForUrl
assert.isFalse rule.passKeys
- should "be enabled, but with pass keys", ->
- rule = isEnabledForUrl({ url: 'https://www.facebook.com/something' })
- assert.isTrue rule.isEnabledForUrl
+ should "be disabled for excluded sites, one exclusion", ->
+ rule = isEnabledForUrl({ url: 'http://www.bbc.com/calendar/page' })
+ assert.isFalse rule.isEnabledForUrl
assert.isFalse rule.passKeys
- addExclusionRule("http*://www.facebook.com/*","oO")
+
+ should "be enabled, but with pass keys", ->
rule = isEnabledForUrl({ url: 'https://www.facebook.com/something' })
assert.isTrue rule.isEnabledForUrl
- assert.equal rule.passKeys, 'oO'
+ assert.equal rule.passKeys, 'abcd'
should "be enabled", ->
rule = isEnabledForUrl({ url: 'http://www.twitter.com/pages' })
assert.isTrue rule.isEnabledForUrl
assert.isFalse rule.passKeys
- should "add a new excluded URL", ->
- rule = isEnabledForUrl({ url: 'http://www.example.com/page' })
- assert.isTrue rule.isEnabledForUrl
- addExclusionRule("http://www.example.com*")
- rule = isEnabledForUrl({ url: 'http://www.example.com/page' })
- assert.isFalse rule.isEnabledForUrl
- assert.isFalse rule.passKeys
-
- should "add a new excluded URL with passkeys", ->
- rule = isEnabledForUrl({ url: 'http://www.anotherexample.com/page' })
- assert.isTrue rule.isEnabledForUrl
- addExclusionRule("http://www.anotherexample.com/*","jk")
- rule = isEnabledForUrl({ url: 'http://www.anotherexample.com/page' })
- assert.isTrue rule.isEnabledForUrl
- assert.equal rule.passKeys, 'jk'
-
- should "update an existing excluded URL with passkeys", ->
- rule = isEnabledForUrl({ url: 'http://mail.google.com/page' })
- assert.isFalse rule.isEnabledForUrl
- assert.isFalse rule.passKeys
- addExclusionRule("http*://mail.google.com/*","jknp")
- rule = isEnabledForUrl({ url: 'http://mail.google.com/page' })
- assert.isTrue rule.isEnabledForUrl
- assert.equal rule.passKeys, 'jknp'
-
diff --git a/tests/unit_tests/rect_test.coffee b/tests/unit_tests/rect_test.coffee
new file mode 100644
index 00000000..cfb26b05
--- /dev/null
+++ b/tests/unit_tests/rect_test.coffee
@@ -0,0 +1,232 @@
+require "./test_helper.js"
+extend(global, require "../../lib/rect.js")
+
+context "Rect",
+ should "set rect properties correctly", ->
+ [x1, y1, x2, y2] = [1, 2, 3, 4]
+ rect = Rect.create x1, y1, x2, y2
+ assert.equal rect.left, x1
+ assert.equal rect.top, y1
+ assert.equal rect.right, x2
+ assert.equal rect.bottom, y2
+ assert.equal rect.width, x2 - x1
+ assert.equal rect.height, y2 - y1
+
+ should "translate rect horizontally", ->
+ [x1, y1, x2, y2] = [1, 2, 3, 4]
+ x = 5
+ rect1 = Rect.create x1, y1, x2, y2
+ rect2 = Rect.translate rect1, x
+
+ assert.equal rect1.left + x, rect2.left
+ assert.equal rect1.right + x, rect2.right
+
+ assert.equal rect1.width, rect2.width
+ assert.equal rect1.height, rect2.height
+ assert.equal rect1.top, rect2.top
+ assert.equal rect1.bottom, rect2.bottom
+
+ should "translate rect vertically", ->
+ [x1, y1, x2, y2] = [1, 2, 3, 4]
+ y = 5
+ rect1 = Rect.create x1, y1, x2, y2
+ rect2 = Rect.translate rect1, undefined, y
+
+ assert.equal rect1.top + y, rect2.top
+ assert.equal rect1.bottom + y, rect2.bottom
+
+ assert.equal rect1.width, rect2.width
+ assert.equal rect1.height, rect2.height
+ assert.equal rect1.left, rect2.left
+ assert.equal rect1.right, rect2.right
+
+context "Rect subtraction",
+ context "unchanged by rects outside",
+ should "left, above", ->
+ rect1 = Rect.create 0, 0, 1, 1
+ rect2 = Rect.create -2, -2, -1, -1
+
+ rects = Rect.subtract rect1, rect2
+ assert.equal rects.length, 1
+ rect = rects[0]
+ assert.isTrue Rect.equals rect1, rect
+
+ should "left", ->
+ rect1 = Rect.create 0, 0, 1, 1
+ rect2 = Rect.create -2, 0, -1, 1
+
+ rects = Rect.subtract rect1, rect2
+ assert.equal rects.length, 1
+ rect = rects[0]
+ assert.isTrue Rect.equals rect1, rect
+
+ should "left, below", ->
+ rect1 = Rect.create 0, 0, 1, 1
+ rect2 = Rect.create -2, 2, -1, 3
+
+ rects = Rect.subtract rect1, rect2
+ assert.equal rects.length, 1
+ rect = rects[0]
+ assert.isTrue Rect.equals rect1, rect
+
+ should "right, above", ->
+ rect1 = Rect.create 0, 0, 1, 1
+ rect2 = Rect.create 2, -2, 3, -1
+
+ rects = Rect.subtract rect1, rect2
+ assert.equal rects.length, 1
+ rect = rects[0]
+ assert.isTrue Rect.equals rect1, rect
+
+ should "right", ->
+ rect1 = Rect.create 0, 0, 1, 1
+ rect2 = Rect.create 2, 0, 3, 1
+
+ rects = Rect.subtract rect1, rect2
+ assert.equal rects.length, 1
+ rect = rects[0]
+ assert.isTrue Rect.equals rect1, rect
+
+ should "right, below", ->
+ rect1 = Rect.create 0, 0, 1, 1
+ rect2 = Rect.create 2, 2, 3, 3
+
+ rects = Rect.subtract rect1, rect2
+ assert.equal rects.length, 1
+ rect = rects[0]
+ assert.isTrue Rect.equals rect1, rect
+
+ should "above", ->
+ rect1 = Rect.create 0, 0, 1, 1
+ rect2 = Rect.create 0, -2, 1, -1
+
+ rects = Rect.subtract rect1, rect2
+ assert.equal rects.length, 1
+ rect = rects[0]
+ assert.isTrue Rect.equals rect1, rect
+
+ should "below", ->
+ rect1 = Rect.create 0, 0, 1, 1
+ rect2 = Rect.create 0, 2, 1, 3
+
+ rects = Rect.subtract rect1, rect2
+ assert.equal rects.length, 1
+ rect = rects[0]
+ assert.isTrue Rect.equals rect1, rect
+
+ context "unchanged by rects touching",
+ should "left, above", ->
+ rect1 = Rect.create 0, 0, 1, 1
+ rect2 = Rect.create -1, -1, 0, 0
+
+ rects = Rect.subtract rect1, rect2
+ assert.equal rects.length, 1
+ rect = rects[0]
+ assert.isTrue Rect.equals rect1, rect
+
+ should "left", ->
+ rect1 = Rect.create 0, 0, 1, 1
+ rect2 = Rect.create -1, 0, 0, 1
+
+ rects = Rect.subtract rect1, rect2
+ assert.equal rects.length, 1
+ rect = rects[0]
+ assert.isTrue Rect.equals rect1, rect
+
+ should "left, below", ->
+ rect1 = Rect.create 0, 0, 1, 1
+ rect2 = Rect.create -1, 1, 0, 2
+
+ rects = Rect.subtract rect1, rect2
+ assert.equal rects.length, 1
+ rect = rects[0]
+ assert.isTrue Rect.equals rect1, rect
+
+ should "right, above", ->
+ rect1 = Rect.create 0, 0, 1, 1
+ rect2 = Rect.create 1, -1, 2, 0
+
+ rects = Rect.subtract rect1, rect2
+ assert.equal rects.length, 1
+ rect = rects[0]
+ assert.isTrue Rect.equals rect1, rect
+
+ should "right", ->
+ rect1 = Rect.create 0, 0, 1, 1
+ rect2 = Rect.create 1, 0, 2, 1
+
+ rects = Rect.subtract rect1, rect2
+ assert.equal rects.length, 1
+ rect = rects[0]
+ assert.isTrue Rect.equals rect1, rect
+
+ should "right, below", ->
+ rect1 = Rect.create 0, 0, 1, 1
+ rect2 = Rect.create 1, 1, 2, 2
+
+ rects = Rect.subtract rect1, rect2
+ assert.equal rects.length, 1
+ rect = rects[0]
+ assert.isTrue Rect.equals rect1, rect
+
+ should "above", ->
+ rect1 = Rect.create 0, 0, 1, 1
+ rect2 = Rect.create 0, -1, 1, 0
+
+ rects = Rect.subtract rect1, rect2
+ assert.equal rects.length, 1
+ rect = rects[0]
+ assert.isTrue Rect.equals rect1, rect
+
+ should "below", ->
+ rect1 = Rect.create 0, 0, 1, 1
+ rect2 = Rect.create 0, 1, 1, 2
+
+ rects = Rect.subtract rect1, rect2
+ assert.equal rects.length, 1
+ rect = rects[0]
+ assert.isTrue Rect.equals rect1, rect
+
+ should "have nothing when subtracting itself", ->
+ rect = Rect.create 0, 0, 1, 1
+ rects = Rect.subtract rect, rect
+ assert.equal rects.length, 0
+
+ should "not overlap subtracted rect", ->
+ rect = Rect.create 0, 0, 3, 3
+ for x in [-2..2]
+ for y in [-2..2]
+ for width in [1..3]
+ for height in [1..3]
+ subtractRect = Rect.create x, y, (x + width), (y + height)
+ resultRects = Rect.subtract rect, subtractRect
+ for resultRect in resultRects
+ assert.isFalse Rect.contains subtractRect, resultRect
+
+ should "be contained in original rect", ->
+ rect = Rect.create 0, 0, 3, 3
+ for x in [-2..2]
+ for y in [-2..2]
+ for width in [1..3]
+ for height in [1..3]
+ subtractRect = Rect.create x, y, (x + width), (y + height)
+ resultRects = Rect.subtract rect, subtractRect
+ for resultRect in resultRects
+ assert.isTrue Rect.contains rect, resultRect
+
+ should "contain the subtracted rect in the original minus the results", ->
+ rect = Rect.create 0, 0, 3, 3
+ for x in [-2..2]
+ for y in [-2..2]
+ for width in [1..3]
+ for height in [1..3]
+ subtractRect = Rect.create x, y, (x + width), (y + height)
+ resultRects = Rect.subtract rect, subtractRect
+ resultComplement = [Rect.copy rect]
+ for resultRect in resultRects
+ resultComplement = Array::concat.apply [],
+ (resultComplement.map (rect) -> Rect.subtract rect, resultRect)
+ assert.isTrue (resultComplement.length == 0 or resultComplement.length == 1)
+ if resultComplement.length == 1
+ complementRect = resultComplement[0]
+ assert.isTrue Rect.contains subtractRect, complementRect
diff --git a/tests/unit_tests/test_chrome_stubs.coffee b/tests/unit_tests/test_chrome_stubs.coffee
index 80750337..3258bcd6 100644
--- a/tests/unit_tests/test_chrome_stubs.coffee
+++ b/tests/unit_tests/test_chrome_stubs.coffee
@@ -42,6 +42,10 @@ exports.chrome =
getAll: () -> true
storage:
+ # chrome.storage.local
+ local:
+ set: ->
+
# chrome.storage.onChanged
onChanged:
addListener: (func) -> @func = func