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/completion_test.coffee11
-rw-r--r--tests/unit_tests/rect_test.coffee232
-rw-r--r--tests/unit_tests/settings_test.coffee13
-rw-r--r--tests/unit_tests/test_chrome_stubs.coffee4
8 files changed, 282 insertions, 20 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/completion_test.coffee b/tests/unit_tests/completion_test.coffee
index e4966016..b7b73cc2 100644
--- a/tests/unit_tests/completion_test.coffee
+++ b/tests/unit_tests/completion_test.coffee
@@ -233,17 +233,24 @@ context "tab completer",
context "search engines",
setup ->
- searchEngines = "foo: bar?q=%s\n# comment\nbaz: qux?q=%s"
+ searchEngines = "foo: bar?q=%s\n# comment\nbaz: qux?q=%s baz description"
Settings.set 'searchEngines', searchEngines
@completer = new SearchEngineCompleter()
# note, I couldn't just call @completer.refresh() here as I couldn't set root.Settings without errors
# workaround is below, would be good for someone that understands the testing system better than me to improve
@completer.searchEngines = Settings.getSearchEngines()
- should "return search engine suggestion", ->
+ should "return search engine suggestion without description", ->
results = filterCompleter(@completer, ["foo", "hello"])
assert.arrayEqual ["bar?q=hello"], results.map (result) -> result.url
assert.arrayEqual ["foo: hello"], results.map (result) -> result.title
+ assert.arrayEqual ["search"], results.map (result) -> result.type
+
+ should "return search engine suggestion with description", ->
+ results = filterCompleter(@completer, ["baz", "hello"])
+ assert.arrayEqual ["qux?q=hello"], results.map (result) -> result.url
+ assert.arrayEqual ["hello"], results.map (result) -> result.title
+ assert.arrayEqual ["baz description"], results.map (result) -> result.type
context "suggestions",
should "escape html in page titles", ->
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/settings_test.coffee b/tests/unit_tests/settings_test.coffee
index 4625457b..afe862a4 100644
--- a/tests/unit_tests/settings_test.coffee
+++ b/tests/unit_tests/settings_test.coffee
@@ -70,14 +70,15 @@ context "settings",
chrome.storage.sync.set { scrollStepSize: JSON.stringify(message) }
assert.equal message, Sync.message
- should "set search engines, retrieve them correctly and check that it has been parsed correctly", ->
- searchEngines = "foo: bar?q=%s\n# comment\nbaz: qux?q=%s"
- parsedSearchEngines = {"foo": "bar?q=%s", "baz": "qux?q=%s"}
+ should "set search engines, retrieve them correctly and check that they have been parsed correctly", ->
+ searchEngines = "foo: bar?q=%s\n# comment\nbaz: qux?q=%s baz description"
Settings.set 'searchEngines', searchEngines
- assert.equal(searchEngines, Settings.get('searchEngines'))
result = Settings.getSearchEngines()
- assert.isTrue(parsedSearchEngines["foo"] == result["foo"] &&
- parsedSearchEngines["baz"] == result["baz"] && Object.keys(result).length == 2)
+ assert.equal Object.keys(result).length, 2
+ assert.equal "bar?q=%s", result["foo"].url
+ assert.isFalse result["foo"].description
+ assert.equal "qux?q=%s", result["baz"].url
+ assert.equal "baz description", result["baz"].description
should "sync a key which is not a known setting (without crashing)", ->
chrome.storage.sync.set { notASetting: JSON.stringify("notAUsefullValue") }
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