From fdf592b25ead4c4ec919c1d0e6322d2dba48c1f8 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Thu, 21 Aug 2014 19:50:09 +0100 Subject: Hacks to make Vomnibar tests work again --- tests/dom_tests/dom_tests.html | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/dom_tests/dom_tests.html b/tests/dom_tests/dom_tests.html index feddafac..72f54c9d 100644 --- a/tests/dom_tests/dom_tests.html +++ b/tests/dom_tests/dom_tests.html @@ -38,6 +38,7 @@ + @@ -53,5 +54,12 @@
+
+
+ +
+ +
+ -- cgit v1.2.3 From d65f265a6ad137be0db4d8c86879e5123a10087b Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 2 Sep 2014 17:43:41 +0100 Subject: Add comments about moving the Vomnibar to an iframe --- tests/dom_tests/dom_tests.html | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/dom_tests/dom_tests.html b/tests/dom_tests/dom_tests.html index 72f54c9d..e6427e85 100644 --- a/tests/dom_tests/dom_tests.html +++ b/tests/dom_tests/dom_tests.html @@ -54,6 +54,9 @@
+
-- cgit v1.2.3 From 390a9cb85e2a97fbd9d2b1a400deee4b12394337 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 31 Oct 2014 15:02:37 +0000 Subject: Fix vomnibar/iframe tests. --- tests/dom_tests/dom_tests.html | 5 ++++- tests/dom_tests/vomnibar_test.coffee | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/dom_tests/dom_tests.html b/tests/dom_tests/dom_tests.html index e6427e85..6378807f 100644 --- a/tests/dom_tests/dom_tests.html +++ b/tests/dom_tests/dom_tests.html @@ -35,7 +35,10 @@ - + diff --git a/tests/dom_tests/vomnibar_test.coffee b/tests/dom_tests/vomnibar_test.coffee index dc2a849f..f7241552 100644 --- a/tests/dom_tests/vomnibar_test.coffee +++ b/tests/dom_tests/vomnibar_test.coffee @@ -28,7 +28,7 @@ context "Keep selection within bounds", assert.equal -1, ui.selection should "set selection to position 0 for bookmark completion if possible", -> - Vomnibar.activateBookmarks() + Vomnibar.activate "completer=bookmark&selectFirst" ui = Vomnibar.vomnibarUI @completions = [] -- cgit v1.2.3 From 1c33590eb994403ec8520c1c02bfb4fe63831745 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Mon, 8 Dec 2014 01:15:06 +0000 Subject: Detect port disconnects (ie. extension is disabled) and disable frontend --- tests/dom_tests/chrome.coffee | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/dom_tests/chrome.coffee b/tests/dom_tests/chrome.coffee index 7f99e27f..15ed4339 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: { -- cgit v1.2.3 From 833942ae06f680bc1949a7bced4719b707950568 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Wed, 17 Dec 2014 12:47:38 +0000 Subject: Stop ignoring clickable opacity: none; elements Some websites (notably Facebook) use `opacity: none;` to show an image in the place of a less-customisable element (eg. an ``). To not show link hints for such transparent elements is confusing and often the wrong thing to do. --- tests/dom_tests/dom_utils_test.coffee | 6 ------ 1 file changed, 6 deletions(-) (limited to 'tests') 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 = """ - test - """ - 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 = """ -- cgit v1.2.3 From 9c9c48598534c2a0cd8aec28a4a806d74f28e090 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Thu, 18 Dec 2014 11:56:53 +0000 Subject: Move rect functions to their own file --- tests/dom_tests/dom_tests.html | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/dom_tests/dom_tests.html b/tests/dom_tests/dom_tests.html index feddafac..d8232892 100644 --- a/tests/dom_tests/dom_tests.html +++ b/tests/dom_tests/dom_tests.html @@ -32,6 +32,7 @@ + -- cgit v1.2.3 From 91bb7d7b85df3b90882e92aeae2fa2021f61733e Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Thu, 18 Dec 2014 12:59:35 +0000 Subject: Add tests for lib/rect --- tests/unit_tests/rect_test.coffee | 232 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 tests/unit_tests/rect_test.coffee (limited to 'tests') 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 -- cgit v1.2.3 From 697b065f9adff48ad270d8ea85e90faa63190179 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Sun, 28 Dec 2014 19:51:45 +0000 Subject: Fix tests for UIComponent --- tests/dom_tests/chrome.coffee | 4 ++++ tests/dom_tests/dom_tests.html | 1 + 2 files changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/dom_tests/chrome.coffee b/tests/dom_tests/chrome.coffee index 7f99e27f..2695ef20 100644 --- a/tests/dom_tests/chrome.coffee +++ b/tests/dom_tests/chrome.coffee @@ -17,5 +17,9 @@ root.chrome = { } sendMessage: -> getManifest: -> + getURL: (url) -> "../../#{url}" } + storage: + local: + get: -> } diff --git a/tests/dom_tests/dom_tests.html b/tests/dom_tests/dom_tests.html index feddafac..750af41d 100644 --- a/tests/dom_tests/dom_tests.html +++ b/tests/dom_tests/dom_tests.html @@ -34,6 +34,7 @@ + -- cgit v1.2.3 From 0524bdc3f76279e8930bfe4b1b42d93e0e9bf6e4 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 29 Dec 2014 14:22:53 +0000 Subject: Refactor UIComponent, etc., and demo. - Simplify component API. - Iframe flashes on re-focus. - Probably some other stuff which I've forgotten. --- tests/dom_tests/chrome.coffee | 1 + tests/unit_tests/test_chrome_stubs.coffee | 4 ++++ 2 files changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/dom_tests/chrome.coffee b/tests/dom_tests/chrome.coffee index 2695ef20..a49a565a 100644 --- a/tests/dom_tests/chrome.coffee +++ b/tests/dom_tests/chrome.coffee @@ -22,4 +22,5 @@ root.chrome = { storage: local: get: -> + set: -> } 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 -- cgit v1.2.3 From c52c0ea57f86c1c5a132819fe85e763db84ce712 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 29 Dec 2014 16:33:23 +0000 Subject: Descriptions for custom search engines. --- tests/unit_tests/completion_test.coffee | 11 +++++++++-- tests/unit_tests/settings_test.coffee | 13 +++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'tests') 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/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") } -- cgit v1.2.3 From b5e9dcb5f87391c0da937517182889eb47ec8f0a Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Mon, 29 Dec 2014 19:26:26 +0000 Subject: Fix tests for UIComponent Vomnibar iframe --- tests/dom_tests/dom_tests.html | 17 +---------------- tests/dom_tests/vomnibar_test.coffee | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 22 deletions(-) (limited to 'tests') diff --git a/tests/dom_tests/dom_tests.html b/tests/dom_tests/dom_tests.html index 863c5611..7b154d24 100644 --- a/tests/dom_tests/dom_tests.html +++ b/tests/dom_tests/dom_tests.html @@ -36,13 +36,9 @@ - + - @@ -57,16 +53,5 @@

Vimium Tests

- - -
-
- -
-
    -
    - diff --git a/tests/dom_tests/vomnibar_test.coffee b/tests/dom_tests/vomnibar_test.coffee index f660f96b..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) @@ -28,8 +43,8 @@ context "Keep selection within bounds", assert.equal -1, ui.selection should "set selection to position 0 for bookmark completion if possible", -> - Vomnibar.activate "completer=bookmark&selectFirst" - ui = Vomnibar.vomnibarUI + Vomnibar.activateBookmarks() + 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) -- cgit v1.2.3