aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2016-09-26 13:44:16 +0100
committerStephen Blott2016-09-26 13:44:16 +0100
commitafeb65f5af849f04df8380212dbf50a6bf186bc4 (patch)
tree34f23beee7923bd2a3014d9c71e0da079a19e875
parent8c1957e600cff896b2a673d7ba8dbcaa132b37e5 (diff)
downloadvimium-afeb65f5af849f04df8380212dbf50a6bf186bc4.tar.bz2
Tweak jsaction detection and add tests.
This tweaks the jsaction detection, in particular excluding elements where the "actionName" is "_". I see a lot of these, and clicking them doesn't do anything. Also, added corresponding tests.
-rw-r--r--content_scripts/link_hints.coffee12
-rw-r--r--tests/dom_tests/dom_tests.coffee29
2 files changed, 38 insertions, 3 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee
index b4b63b1f..4bfd3ef2 100644
--- a/content_scripts/link_hints.coffee
+++ b/content_scripts/link_hints.coffee
@@ -670,11 +670,17 @@ LocalHints =
isClickable = true
# Check for jsaction event listeners on the element.
- if element.hasAttribute "jsaction"
+ if not isClickable and element.hasAttribute "jsaction"
jsactionRules = element.getAttribute("jsaction").split(";")
for jsactionRule in jsactionRules
- ruleSplit = jsactionRule.split ":"
- isClickable ||= ruleSplit[0] == "click" or (ruleSplit.length == 1 and ruleSplit[0] != "none")
+ ruleSplit = jsactionRule.trim().split ":"
+ if 1 <= ruleSplit.length <= 2
+ [eventType, namespace, actionName ] =
+ if ruleSplit.length == 1
+ ["click", ruleSplit[0].trim().split(".")..., "_"]
+ else
+ [ruleSplit[0], ruleSplit[1].trim().split(".")..., "_"]
+ isClickable ||= eventType == "click" and namespace != "none" and actionName != "_"
# Check for tagNames which are natively clickable.
switch tagName
diff --git a/tests/dom_tests/dom_tests.coffee b/tests/dom_tests/dom_tests.coffee
index 58fa26f9..eab47546 100644
--- a/tests/dom_tests/dom_tests.coffee
+++ b/tests/dom_tests/dom_tests.coffee
@@ -134,6 +134,35 @@ context "False positives in link-hint",
for hintMarker in hintMarkers
assert.equal "clickable", hintMarker.linkText
+context "jsaction matching",
+
+ setup ->
+ stubSettings "filterLinkHints", true
+ testContent = '<p id="test-paragraph">clickable</p>'
+ document.getElementById("test-div").innerHTML = testContent
+ @element = document.getElementById("test-paragraph")
+
+ tearDown ->
+ document.getElementById("test-div").innerHTML = ""
+
+ should "select jsaction elements", ->
+ for text in ["click:namespace.actionName", "namespace.actionName"]
+ @element.setAttribute "jsaction", text
+ linkHints = activateLinkHintsMode()
+ hintMarkers = getHintMarkers().filter (marker) -> marker.linkText != "Frame."
+ linkHints.deactivateMode()
+ assert.equal 1, hintMarkers.length
+ assert.equal "clickable", hintMarkers[0].linkText
+ assert.equal @element, hintMarkers[0].localHintDescriptor.element
+
+ should "not select inactive jsaction elements", ->
+ for text in ["mousedown:namespace.actionName", "click:namespace._", "none", "namespace:_"]
+ @element.setAttribute "jsaction", text
+ linkHints = activateLinkHintsMode()
+ hintMarkers = getHintMarkers().filter (marker) -> marker.linkText != "Frame."
+ linkHints.deactivateMode()
+ assert.equal 0, hintMarkers.length
+
inputs = []
context "Test link hints for focusing input elements correctly",