diff options
| -rw-r--r-- | Cakefile | 37 | ||||
| -rw-r--r-- | README.markdown | 8 | ||||
| -rw-r--r-- | background_scripts/main.coffee | 8 | ||||
| -rw-r--r-- | background_scripts/settings.coffee | 2 | ||||
| -rw-r--r-- | manifest.json | 2 | ||||
| -rw-r--r-- | tests/dom_tests/bind.js | 27 | ||||
| -rw-r--r-- | tests/dom_tests/chrome.coffee | 20 | ||||
| -rw-r--r-- | tests/dom_tests/dom_tests.coffee (renamed from test_harnesses/automated/automated.coffee) | 9 | ||||
| -rw-r--r-- | tests/dom_tests/dom_tests.html (renamed from test_harnesses/automated/automated.html) | 6 | ||||
| -rw-r--r-- | tests/dom_tests/phantom_runner.coffee | 32 | ||||
| -rw-r--r-- | tests/unit_tests/completion_test.coffee (renamed from tests/completion_test.coffee) | 4 | ||||
| -rw-r--r-- | tests/unit_tests/test_helper.coffee (renamed from tests/test_helper.coffee) | 4 | ||||
| -rw-r--r-- | tests/unit_tests/utils_test.coffee (renamed from tests/utils_test.coffee) | 2 | ||||
| -rw-r--r-- | vimium.css | 1 |
14 files changed, 132 insertions, 30 deletions
@@ -8,20 +8,19 @@ spawn_with_opts = (proc_name, opts) -> opt_array.push "--#{key}=#{value}" spawn proc_name, opt_array -src_directories = ["tests", "background_scripts", "content_scripts", "lib", "options", - "test_harnesses/automated"] - task "build", "compile all coffeescript files to javascript", -> - coffee = spawn "coffee", ["-c"].concat(src_directories) + coffee = spawn "coffee", ["-c", __dirname] coffee.stdout.on "data", (data) -> console.log data.toString().trim() coffee.stderr.on "data", (data) -> console.log data.toString().trim() task "clean", "removes any js files which were compiled from coffeescript", -> - src_directories.forEach (directory) -> + visit = (directory) -> fs.readdirSync(directory).forEach (filename) -> - return unless (path.extname filename) == ".js" filepath = path.join directory, filename - return unless (fs.statSync filepath).isFile() + if (fs.statSync filepath).isDirectory() + return visit filepath + + return unless (path.extname filename) == ".js" and (fs.statSync filepath).isFile() # Check if there exists a corresponding .coffee file try @@ -31,8 +30,10 @@ task "clean", "removes any js files which were compiled from coffeescript", -> fs.unlinkSync filepath if coffeeFile.isFile() + visit __dirname + task "autobuild", "continually rebuild coffeescript files using coffee --watch", -> - coffee = spawn "coffee", ["-cw"].concat(src_directories) + coffee = spawn "coffee", ["-cw", __dirname] coffee.stdout.on "data", (data) -> console.log data.toString().trim() coffee.stderr.on "data", (data) -> console.log data.toString().trim() @@ -55,10 +56,20 @@ task "package", "build .crx file", -> crxmake.stdout.on "data", (data) -> console.log data.toString().trim() crxmake.on "exit", -> fs.writeFileSync "manifest.json", orig_manifest_text -task "test", "run all unit tests", -> - test_files = fs.readdirSync("tests/").filter((filename) -> filename.indexOf("_test.js") > 0) - test_files = test_files.map((filename) -> "tests/" + filename) +task "test", "run all tests", -> + console.log "Running unit tests..." + basedir = "tests/unit_tests/" + test_files = fs.readdirSync(basedir).filter((filename) -> filename.indexOf("_test.js") > 0) + test_files = test_files.map((filename) -> basedir + filename) test_files.forEach (file) -> require "./" + file Tests.run() - if Tests.testsFailed > 0 - process.exit 1 + returnCode = if Tests.testsFailed > 0 then 1 else 0 + + console.log "Running DOM tests..." + spawn = (require "child_process").spawn + phantom = spawn "phantomjs", ["./tests/dom_tests/phantom_runner.js"] + phantom.stdout.on 'data', (data) -> process.stdout.write data + phantom.stderr.on 'data', (data) -> process.stderr.write data + phantom.on 'exit', (code) -> + returnCode += code + process.exit returnCode diff --git a/README.markdown b/README.markdown index 4e42c062..38ae93ff 100644 --- a/README.markdown +++ b/README.markdown @@ -138,6 +138,12 @@ Vimium is written in Coffeescript, which compiles to Javascript. To build Vimium 1. Install [Coffeescript](http://coffeescript.org/#installation). 2. Run `cake autobuild` from within your vimium directory. Any coffeescript files you change will now be automatically compiled to Javascript. + +Our tests use [shoulda.js](https://github.com/philc/shoulda.js) and [PhantomJS](http://phantomjs.org/). To run +the tests: + +1. `git submodule update --init --recursive` -- this pulls in shoulda.js. +2. [Install PhantomJS.](http://phantomjs.org/download.html) 3. `cake test` to run the tests. When you're done, send us a pull request on Github. Feel free to include a change to the CREDITS file with @@ -149,7 +155,7 @@ don't exceed 110 characters. Release Notes ------------- -1.38 (Unreleased) +1.38 (09/08/2012) - `O` now opens Vomnibar results in a new tab. `B` does the same for bookmarks only. - Add a browser icon to quickly add sites to Vimium's exclude list. diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 5ae80235..a3857d61 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -143,9 +143,9 @@ fetchFileContents = (extensionFileName) -> # # Returns the keys that can complete a valid command given the current key queue. # -getCompletionKeysRequest = (request) -> +getCompletionKeysRequest = (request, keysToCheck = "") -> name: "refreshCompletionKeys" - completionKeys: generateCompletionKeys() + completionKeys: generateCompletionKeys(keysToCheck) validFirstKeys: validFirstKeys # @@ -472,7 +472,7 @@ checkKeyQueue = (keysToCheck, tabId, frameId) -> # If we haven't sent the completion keys piggybacked on executePageCommand, # send them by themselves. unless refreshedCompletionKeys - chrome.tabs.sendRequest(tabId, getCompletionKeysRequest(), null) + chrome.tabs.sendRequest(tabId, getCompletionKeysRequest(null, newKeyQueue), null) newKeyQueue @@ -553,7 +553,7 @@ sendRequestHandlers = refreshCompleter: refreshCompleter # Convenience function for development use. -window.runTests = -> open(chrome.extension.getURL('test_harnesses/automated/automated.html')) +window.runTests = -> open(chrome.extension.getURL('tests/dom_tests/dom_tests.html')) # # Begin initialization. diff --git a/background_scripts/settings.coffee b/background_scripts/settings.coffee index 865ab933..ec602cc0 100644 --- a/background_scripts/settings.coffee +++ b/background_scripts/settings.coffee @@ -27,7 +27,7 @@ root.Settings = Settings = """ div > .vimiumHintMarker { /* linkhint boxes */ - background-color: yellow; + background: yellow; border: 1px solid #E3BE23; } diff --git a/manifest.json b/manifest.json index 2e8dac72..b5eb391e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Vimium", - "version": "1.37", + "version": "1.38", "description": "The Hacker's Browser. Vimium provides keyboard shortcuts for navigation and control in the spirit of Vim.", "icons": { "16": "icons/icon16.png", "48": "icons/icon48.png", diff --git a/tests/dom_tests/bind.js b/tests/dom_tests/bind.js new file mode 100644 index 00000000..833f8006 --- /dev/null +++ b/tests/dom_tests/bind.js @@ -0,0 +1,27 @@ +/* + * Polyfill taken from https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/bind + * Necessary because the current version of PhantomJS doesn't yet support bind(). + */ +if (!Function.prototype.bind) { + Function.prototype.bind = function (oThis) { + if (typeof this !== "function") { + // closest thing possible to the ECMAScript 5 internal IsCallable function + throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); + } + + var aArgs = Array.prototype.slice.call(arguments, 1), + fToBind = this, + fNOP = function () {}, + fBound = function () { + return fToBind.apply(this instanceof fNOP && oThis + ? this + : oThis, + aArgs.concat(Array.prototype.slice.call(arguments))); + }; + + fNOP.prototype = this.prototype; + fBound.prototype = new fNOP(); + + return fBound; + }; +} diff --git a/tests/dom_tests/chrome.coffee b/tests/dom_tests/chrome.coffee new file mode 100644 index 00000000..ff7a53d0 --- /dev/null +++ b/tests/dom_tests/chrome.coffee @@ -0,0 +1,20 @@ +# +# Mock the Chrome extension API. +# + +root = exports ? window + +root.chrome = { + extension: { + connect: -> { + onMessage: { + addListener: -> + } + postMessage: -> + } + onRequest: { + addListener: -> + } + sendRequest: -> + } +} diff --git a/test_harnesses/automated/automated.coffee b/tests/dom_tests/dom_tests.coffee index 283e8004..3d981ee5 100644 --- a/test_harnesses/automated/automated.coffee +++ b/tests/dom_tests/dom_tests.coffee @@ -30,6 +30,7 @@ createGeneralHintTests = (isFilteredMode) -> testContent = "<a>test</a>" + "<a>tress</a>" document.getElementById("test-div").innerHTML = testContent stub settings.values, "filterLinkHints", false + stub settings.values, "linkHintCharacters", "ab" tearDown -> document.getElementById("test-div").innerHTML = "" @@ -191,9 +192,11 @@ Tests.outputMethod = (args...) -> document.getElementById("output-div").innerHTML += "<div class='output-section'>" + newOutput + "</div>" console.log.apply console, args -# ensure the extension has time to load before commencing the tests -document.addEventListener "DOMContentLoaded", -> - setTimeout Tests.run, 200 +# PhantomJS will call the tests manually +unless navigator.userAgent == 'phantom' + # ensure the extension has time to load before commencing the tests + document.addEventListener "DOMContentLoaded", -> + setTimeout Tests.run, 200 createLinks = (n) -> for i in [0...n] by 1 diff --git a/test_harnesses/automated/automated.html b/tests/dom_tests/dom_tests.html index a0c8c7de..1dc45782 100644 --- a/test_harnesses/automated/automated.html +++ b/tests/dom_tests/dom_tests.html @@ -27,6 +27,8 @@ } </style> <link rel="stylesheet" type="text/css" href="../../vimium.css" /> + <script type="text/javascript" src="bind.js"></script> + <script type="text/javascript" src="chrome.js"></script> <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> @@ -34,8 +36,8 @@ <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/vimium_frontend.js"></script> - <script type="text/javascript" src="../../tests/shoulda.js/shoulda.js"></script> - <script type="text/javascript" src="automated.js"></script> + <script type="text/javascript" src="../shoulda.js/shoulda.js"></script> + <script type="text/javascript" src="dom_tests.js"></script> </head> <body> <!-- should always be the first element on the page --> diff --git a/tests/dom_tests/phantom_runner.coffee b/tests/dom_tests/phantom_runner.coffee new file mode 100644 index 00000000..9036b8f3 --- /dev/null +++ b/tests/dom_tests/phantom_runner.coffee @@ -0,0 +1,32 @@ +page = require('webpage').create() + +page.settings.userAgent = 'phantom' + +# ensure that the elements we test the link hints on are actually visible +page.viewportSize = + width: 900 + height: 600 + +page.onConsoleMessage = (msg) -> + console.log msg + +system = require 'system' +fs = require 'fs' + +pathParts = system.args[0].split(fs.separator) +pathParts[pathParts.length - 1] = '' +dirname = pathParts.join(fs.separator) + +page.open dirname + 'dom_tests.html', (status) -> + if status != 'success' + console.log 'Unable to load tests.' + phantom.exit 1 + + testsFailed = page.evaluate -> + Tests.run() + return Tests.testsFailed + + if testsFailed > 0 + phantom.exit 1 + else + phantom.exit 0 diff --git a/tests/completion_test.coffee b/tests/unit_tests/completion_test.coffee index 7094d720..d3369398 100644 --- a/tests/completion_test.coffee +++ b/tests/unit_tests/completion_test.coffee @@ -1,6 +1,6 @@ require "./test_helper.js" -extend(global, require "../lib/utils.js") -extend(global, require "../background_scripts/completion.js") +extend(global, require "../../lib/utils.js") +extend(global, require "../../background_scripts/completion.js") global.chrome = {} diff --git a/tests/test_helper.coffee b/tests/unit_tests/test_helper.coffee index 237f8e24..bb73bf54 100644 --- a/tests/test_helper.coffee +++ b/tests/unit_tests/test_helper.coffee @@ -1,5 +1,5 @@ -require("./shoulda.js/shoulda.js") +require("../shoulda.js/shoulda.js") global.extend = (hash1, hash2) -> for key of hash2 hash1[key] = hash2[key] - hash1
\ No newline at end of file + hash1 diff --git a/tests/utils_test.coffee b/tests/unit_tests/utils_test.coffee index f3810114..9da5ff65 100644 --- a/tests/utils_test.coffee +++ b/tests/unit_tests/utils_test.coffee @@ -1,5 +1,5 @@ require "./test_helper.js" -extend(global, require "../lib/utils.js") +extend(global, require "../../lib/utils.js") context "isUrl", should "accept valid URLs", -> @@ -115,6 +115,7 @@ div#vimiumHelpDialog { border-radius:6px; padding:8px 12px; width:640px; + max-height: 85%; left:50%; /* This needs to be 1/2 width to horizontally center the help dialog */ margin-left:-320px; |
