diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/dom_tests/dom_tests.coffee | 11 | ||||
| -rw-r--r-- | tests/dom_tests/dom_tests.html | 1 | ||||
| -rw-r--r-- | tests/dom_tests/phantom_runner.coffee | 29 | ||||
| -rw-r--r-- | tests/dom_tests/vomnibar_test.coffee | 2 | ||||
| -rw-r--r-- | tests/unit_tests/completion_test.coffee | 52 | ||||
| -rw-r--r-- | tests/unit_tests/settings_test.coffee | 10 | ||||
| -rw-r--r-- | tests/unit_tests/utils_test.coffee | 28 |
7 files changed, 77 insertions, 56 deletions
diff --git a/tests/dom_tests/dom_tests.coffee b/tests/dom_tests/dom_tests.coffee index bb09a0a8..8c2b73c3 100644 --- a/tests/dom_tests/dom_tests.coffee +++ b/tests/dom_tests/dom_tests.coffee @@ -156,6 +156,9 @@ context "Alphabetical link hints", assert.equal "", hintMarkers[0].style.display context "Filtered link hints", + # Note. In all of these tests, the order of the elements returned by getHintMarkers() may be different from + # the order they are listed in the test HTML content. This is because LinkHints.activateMode() sorts the + # elements. setup -> stub settings.values, "filterLinkHints", true @@ -205,8 +208,8 @@ context "Filtered link hints", should "label the images", -> hintMarkers = getHintMarkers() assert.equal "1: alt text", hintMarkers[0].textContent.toLowerCase() - assert.equal "2: alt text", hintMarkers[1].textContent.toLowerCase() - assert.equal "3: some title", hintMarkers[2].textContent.toLowerCase() + assert.equal "2: some title", hintMarkers[1].textContent.toLowerCase() + assert.equal "3: alt text", hintMarkers[2].textContent.toLowerCase() assert.equal "4", hintMarkers[3].textContent.toLowerCase() context "Input hints", @@ -228,9 +231,9 @@ context "Filtered link hints", hintMarkers = getHintMarkers() assert.equal "1", hintMarkers[0].textContent.toLowerCase() assert.equal "2", hintMarkers[1].textContent.toLowerCase() - assert.equal "3", hintMarkers[2].textContent.toLowerCase() + assert.equal "3: a label", hintMarkers[2].textContent.toLowerCase() assert.equal "4: a label", hintMarkers[3].textContent.toLowerCase() - assert.equal "5: a label", hintMarkers[4].textContent.toLowerCase() + assert.equal "5", hintMarkers[4].textContent.toLowerCase() context "Input focus", diff --git a/tests/dom_tests/dom_tests.html b/tests/dom_tests/dom_tests.html index cbd91bca..5ccd39e7 100644 --- a/tests/dom_tests/dom_tests.html +++ b/tests/dom_tests/dom_tests.html @@ -44,6 +44,7 @@ <script type="text/javascript" src="../../content_scripts/mode_insert.js"></script> <script type="text/javascript" src="../../content_scripts/mode_find.js"></script> <script type="text/javascript" src="../../content_scripts/mode_visual_edit.js"></script> + <script type="text/javascript" src="../../content_scripts/hud.js"></script> <script type="text/javascript" src="../../content_scripts/vimium_frontend.js"></script> <script type="text/javascript" src="../shoulda.js/shoulda.js"></script> diff --git a/tests/dom_tests/phantom_runner.coffee b/tests/dom_tests/phantom_runner.coffee index 93218724..e0382a35 100644 --- a/tests/dom_tests/phantom_runner.coffee +++ b/tests/dom_tests/phantom_runner.coffee @@ -37,15 +37,20 @@ page.open testfile, (status) -> console.log 'Unable to load tests.' phantom.exit 1 - testsFailed = page.evaluate -> - Tests.run() - return Tests.testsFailed - - if system.args[1] == '--coverage' - data = page.evaluate -> JSON.stringify _$jscoverage - fs.write dirname + 'dom_tests_coverage.json', data, 'w' - - if testsFailed > 0 - phantom.exit 1 - else - phantom.exit 0 + runTests = -> + testsFailed = page.evaluate -> + Tests.run() + return Tests.testsFailed + + if system.args[1] == '--coverage' + data = page.evaluate -> JSON.stringify _$jscoverage + fs.write dirname + 'dom_tests_coverage.json', data, 'w' + + if testsFailed > 0 + phantom.exit 1 + else + phantom.exit 0 + + # We add a short delay to allow asynchronous initialization (that is, initialization which happens on + # "nextTick") to complete. + setTimeout runTests, 10 diff --git a/tests/dom_tests/vomnibar_test.coffee b/tests/dom_tests/vomnibar_test.coffee index 0e02bb7b..380175f3 100644 --- a/tests/dom_tests/vomnibar_test.coffee +++ b/tests/dom_tests/vomnibar_test.coffee @@ -14,7 +14,7 @@ context "Keep selection within bounds", oldGetCompleter = vomnibarFrame.Vomnibar.getCompleter.bind vomnibarFrame.Vomnibar stub vomnibarFrame.Vomnibar, 'getCompleter', (name) => completer = oldGetCompleter name - stub completer, 'filter', (query, callback) => callback(@completions) + stub completer, 'filter', ({ callback }) => callback results: @completions completer # Shoulda.js doesn't support async tests, so we have to hack around. diff --git a/tests/unit_tests/completion_test.coffee b/tests/unit_tests/completion_test.coffee index 56fcc456..88df0a43 100644 --- a/tests/unit_tests/completion_test.coffee +++ b/tests/unit_tests/completion_test.coffee @@ -1,5 +1,6 @@ require "./test_helper.js" extend(global, require "../../lib/utils.js") +extend(global, require "../../background_scripts/completion_engines.js") extend(global, require "../../background_scripts/completion.js") extend global, require "./test_chrome_stubs.js" @@ -235,44 +236,43 @@ context "tab completer", assert.arrayEqual ["tab2.com"], results.map (tab) -> tab.url assert.arrayEqual [2], results.map (tab) -> tab.tabId -context "search engines", - setup -> - 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 = SearchEngineCompleter.getSearchEngines() - - 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", -> - suggestion = new Suggestion(["queryterm"], "tab", "url", "title <span>", returns(1)) + suggestion = new Suggestion + queryTerms: ["queryterm"] + type: "tab" + url: "url" + title: "title <span>" + relevancyFunction: returns 1 assert.isTrue suggestion.generateHtml().indexOf("title <span>") >= 0 should "highlight query words", -> - suggestion = new Suggestion(["ninj", "words"], "tab", "url", "ninjawords", returns(1)) + suggestion = new Suggestion + queryTerms: ["ninj", "words"] + type: "tab" + url: "url" + title: "ninjawords" + relevancyFunction: returns 1 expected = "<span class='vomnibarMatch'>ninj</span>a<span class='vomnibarMatch'>words</span>" assert.isTrue suggestion.generateHtml().indexOf(expected) >= 0 should "highlight query words correctly when whey they overlap", -> - suggestion = new Suggestion(["ninj", "jaword"], "tab", "url", "ninjawords", returns(1)) + suggestion = new Suggestion + queryTerms: ["ninj", "jaword"] + type: "tab" + url: "url" + title: "ninjawords" + relevancyFunction: returns 1 expected = "<span class='vomnibarMatch'>ninjaword</span>s" assert.isTrue suggestion.generateHtml().indexOf(expected) >= 0 should "shorten urls", -> - suggestion = new Suggestion(["queryterm"], "tab", "http://ninjawords.com", "ninjawords", returns(1)) + suggestion = new Suggestion + queryTerms: ["queryterm"] + type: "tab" + url: "http://ninjawords.com" + title: "ninjawords" + relevancyFunction: returns 1 assert.equal -1, suggestion.generateHtml().indexOf("http://ninjawords.com") context "RankingUtils.wordRelevancy", @@ -465,7 +465,7 @@ context "TabRecency", # A convenience wrapper around completer.filter() so it can be called synchronously in tests. filterCompleter = (completer, queryTerms) -> results = [] - completer.filter(queryTerms, (completionResults) -> results = completionResults) + completer.filter({ queryTerms, query: queryTerms.join " " }, (completionResults) -> results = completionResults) results hours = (n) -> 1000 * 60 * 60 * n diff --git a/tests/unit_tests/settings_test.coffee b/tests/unit_tests/settings_test.coffee index 346c98da..4cd20211 100644 --- a/tests/unit_tests/settings_test.coffee +++ b/tests/unit_tests/settings_test.coffee @@ -70,15 +70,5 @@ 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 they have been parsed correctly", -> - searchEngines = "foo: bar?q=%s\n# comment\nbaz: qux?q=%s baz description" - Settings.set 'searchEngines', searchEngines - result = SearchEngineCompleter.getSearchEngines() - 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/utils_test.coffee b/tests/unit_tests/utils_test.coffee index 88e9a15b..bfe066c3 100644 --- a/tests/unit_tests/utils_test.coffee +++ b/tests/unit_tests/utils_test.coffee @@ -42,11 +42,22 @@ context "convertToUrl", assert.equal "http://127.0.0.1:8080", Utils.convertToUrl("127.0.0.1:8080") assert.equal "http://[::]:8080", Utils.convertToUrl("[::]:8080") assert.equal "view-source: 0.0.0.0", Utils.convertToUrl("view-source: 0.0.0.0") + assert.equal "javascript:alert('25 % 20 * 25 ');", Utils.convertToUrl "javascript:alert('25 % 20 * 25%20');" should "convert non-URL terms into search queries", -> - assert.equal "http://www.google.com/search?q=google", Utils.convertToUrl("google") - assert.equal "http://www.google.com/search?q=go+ogle.com", Utils.convertToUrl("go ogle.com") - assert.equal "http://www.google.com/search?q=%40twitter", Utils.convertToUrl("@twitter") + assert.equal "https://www.google.com/search?q=google", Utils.convertToUrl("google") + assert.equal "https://www.google.com/search?q=go+ogle.com", Utils.convertToUrl("go ogle.com") + assert.equal "https://www.google.com/search?q=%40twitter", Utils.convertToUrl("@twitter") + +context "extractQuery", + should "extract queries from search URLs", -> + assert.equal "bbc sport 1", Utils.extractQuery "https://www.google.ie/search?q=%s", "https://www.google.ie/search?q=bbc+sport+1" + assert.equal "bbc sport 2", Utils.extractQuery "http://www.google.ie/search?q=%s", "https://www.google.ie/search?q=bbc+sport+2" + assert.equal "bbc sport 3", Utils.extractQuery "https://www.google.ie/search?q=%s", "http://www.google.ie/search?q=bbc+sport+3" + assert.equal "bbc sport 4", Utils.extractQuery "https://www.google.ie/search?q=%s", "http://www.google.ie/search?q=bbc+sport+4&blah" + + should "extract not queries from incorrect search URLs", -> + assert.isFalse Utils.extractQuery "https://www.google.ie/search?q=%s&foo=bar", "https://www.google.ie/search?q=bbc+sport" context "hasChromePrefix", should "detect chrome prefixes of URLs", -> @@ -62,6 +73,17 @@ context "hasChromePrefix", assert.isFalse Utils.hasChromePrefix "data" assert.isFalse Utils.hasChromePrefix "data :foobar" +context "hasJavascriptPrefix", + should "detect javascript: URLs", -> + assert.isTrue Utils.hasJavascriptPrefix "javascript:foobar" + assert.isFalse Utils.hasJavascriptPrefix "http:foobar" + +context "decodeURIByParts", + should "decode javascript: URLs", -> + assert.equal "foobar", Utils.decodeURIByParts "foobar" + assert.equal " ", Utils.decodeURIByParts "%20" + assert.equal "25 % 20 25 ", Utils.decodeURIByParts "25 % 20 25%20" + context "isUrl", should "identify URLs as URLs", -> assert.isTrue Utils.isUrl "http://www.example.com/blah" |
