diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/dom_tests/dom_tests.coffee | 19 | ||||
| -rw-r--r-- | tests/unit_tests/utils_test.coffee | 22 |
2 files changed, 34 insertions, 7 deletions
diff --git a/tests/dom_tests/dom_tests.coffee b/tests/dom_tests/dom_tests.coffee index f4e63270..3d981ee5 100644 --- a/tests/dom_tests/dom_tests.coffee +++ b/tests/dom_tests/dom_tests.coffee @@ -2,7 +2,7 @@ # Dispatching keyboard events via the DOM would require async tests, # which tend to be more complicated. Here we create mock events and # invoke the handlers directly. -# +# mockKeyboardEvent = (keyChar) -> event = {} event.charCode = (if keyCodes[keyChar] isnt undefined then keyCodes[keyChar] else keyChar.charCodeAt(0)) @@ -14,14 +14,14 @@ mockKeyboardEvent = (keyChar) -> # # Retrieve the hint markers as an array object. -# +# getHintMarkers = -> Array::slice.call document.getElementsByClassName("vimiumHintMarker"), 0 # # Generate tests that are common to both default and filtered # link hinting modes. -# +# createGeneralHintTests = (isFilteredMode) -> context "Link hints", @@ -125,7 +125,8 @@ context "Filtered link hints", context "Image hints", setup -> - testContent = "<a><img alt='alt text'/></a>" + "<a><img alt='alt text' title='some title'/></a>" + "<a><img title='some title'/></a>" + "<a><img src='' width='320px' height='100px'/></a>" + testContent = "<a><img alt='alt text'/></a><a><img alt='alt text' title='some title'/></a> + <a><img title='some title'/></a>" + "<a><img src='' width='320px' height='100px'/></a>" document.getElementById("test-div").innerHTML = testContent LinkHints.activateMode() @@ -143,7 +144,10 @@ context "Filtered link hints", context "Input hints", setup -> - testContent = "<input type='text' value='some value'/>" + "<input type='password' value='some value'/>" + "<textarea>some text</textarea>" + "<label for='test-input'/>a label</label><input type='text' id='test-input' value='some value'/>" + "<label for='test-input-2'/>a label: </label><input type='text' id='test-input-2' value='some value'/>" + testContent = "<input type='text' value='some value'/><input type='password' value='some value'/> + <textarea>some text</textarea><label for='test-input'/>a label</label> + <input type='text' id='test-input' value='some value'/> + <label for='test-input-2'/>a label: </label><input type='text' id='test-input-2' value='some value'/>" document.getElementById("test-div").innerHTML = testContent LinkHints.activateMode() @@ -162,7 +166,8 @@ context "Filtered link hints", context "Input focus", setup -> - testContent = "<input type='text' id='first'/>" + "<input style='display:none;' id='second'/>" + "<input type='password' id='third' value='some value'/>" + testContent = "<input type='text' id='first'/><input style='display:none;' id='second'/> + <input type='password' id='third' value='some value'/>" document.getElementById("test-div").innerHTML = testContent tearDown -> @@ -183,7 +188,7 @@ Tests.outputMethod = (args...) -> # escape html newOutput = newOutput.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">") # highlight the source of the error - newOutput = newOutput.replace(/\/([^:/]+):([0-9]+):([0-9]+)/, "/<span class='errorPosition'>$1:$2</span>:$3") + newOutput = newOutput.replace /\/([^:/]+):([0-9]+):([0-9]+)/, "/<span class='errorPosition'>$1:$2</span>:$3" document.getElementById("output-div").innerHTML += "<div class='output-section'>" + newOutput + "</div>" console.log.apply console, args diff --git a/tests/unit_tests/utils_test.coffee b/tests/unit_tests/utils_test.coffee index 6a44b460..9da5ff65 100644 --- a/tests/unit_tests/utils_test.coffee +++ b/tests/unit_tests/utils_test.coffee @@ -1,6 +1,28 @@ require "./test_helper.js" extend(global, require "../../lib/utils.js") +context "isUrl", + should "accept valid URLs", -> + assert.isTrue Utils.isUrl "www.google.com" + assert.isTrue Utils.isUrl "www.bbc.co.uk" + assert.isTrue Utils.isUrl "yahoo.com" + assert.isTrue Utils.isUrl "nunames.nu" + assert.isTrue Utils.isUrl "user:pass@ftp.xyz.com/test" + + assert.isTrue Utils.isUrl "localhost/index.html" + assert.isTrue Utils.isUrl "127.0.0.1:8192/test.php" + + # IPv6 + assert.isTrue Utils.isUrl "[::]:9000" + + # Long TLDs + assert.isTrue Utils.isUrl "illinois.state.museum" + assert.isTrue Utils.isUrl "eqt5g4fuenphqinx.onion" + + should "reject invalid URLs", -> + assert.isFalse Utils.isUrl "a.x" + assert.isFalse Utils.isUrl "www-domain-tld" + context "convertToUrl", should "detect and clean up valid URLs", -> assert.equal "http://www.google.com/", Utils.convertToUrl("http://www.google.com/") |
