michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * Test that mozITXTToHTMLConv works properly. michael@0: */ michael@0: michael@0: var Cc = Components.classes; michael@0: var Ci = Components.interfaces; michael@0: michael@0: function run_test() { michael@0: let converter = Cc["@mozilla.org/txttohtmlconv;1"] michael@0: .getService(Ci.mozITXTToHTMLConv); michael@0: michael@0: const tests = [ michael@0: // -- RFC1738 michael@0: { michael@0: input: "RFC1738: then", michael@0: url: "http://mozilla.org" michael@0: }, michael@0: // -- RFC2396E michael@0: { michael@0: input: "RFC2396E: then", michael@0: url: "http://mozilla.org/" michael@0: }, michael@0: // -- abbreviated michael@0: { michael@0: input: "see www.mozilla.org maybe", michael@0: url: "http://www.mozilla.org" michael@0: }, michael@0: // -- freetext michael@0: { michael@0: input:"I mean http://www.mozilla.org/.", michael@0: url: "http://www.mozilla.org/" michael@0: }, michael@0: { michael@0: input:"you mean http://mozilla.org:80, right?", michael@0: url: "http://mozilla.org:80" michael@0: }, michael@0: { michael@0: input:"go to http://mozilla.org; then go home", michael@0: url: "http://mozilla.org" michael@0: }, michael@0: { michael@0: input:"http://mozilla.org! yay!", michael@0: url: "http://mozilla.org" michael@0: }, michael@0: { michael@0: input:"er, http://mozilla.com?", michael@0: url: "http://mozilla.com" michael@0: }, michael@0: { michael@0: input:"http://example.org- where things happen", michael@0: url: "http://example.org" michael@0: }, michael@0: { michael@0: input:"see http://mozilla.org: front page", michael@0: url: "http://mozilla.org" michael@0: }, michael@0: { michael@0: input:"'http://mozilla.org/': that's the url", michael@0: url: "http://mozilla.org/" michael@0: }, michael@0: { michael@0: input:"some special http://mozilla.org/?x=.,;!-:x", michael@0: url: "http://mozilla.org/?x=.,;!-:x" michael@0: }, michael@0: { michael@0: // escape & when producing html michael@0: input:"'http://example.org/?test=true&success=true': ok", michael@0: url: "http://example.org/?test=true&success=true" michael@0: }, michael@0: { michael@0: input: "bracket: http://localhost/[1] etc.", michael@0: url: "http://localhost/" michael@0: }, michael@0: { michael@0: input: "parenthesis: (http://localhost/) etc.", michael@0: url: "http://localhost/" michael@0: }, michael@0: { michael@0: input: "(thunderbird)http://mozilla.org/thunderbird", michael@0: url: "http://mozilla.org/thunderbird" michael@0: }, michael@0: { michael@0: input: "()http://mozilla.org", michael@0: url: "http://mozilla.org" michael@0: }, michael@0: { michael@0: input: "parenthesis included: http://kb.mozillazine.org/Performance_(Thunderbird) etc.", michael@0: url: "http://kb.mozillazine.org/Performance_(Thunderbird)" michael@0: }, michael@0: { michael@0: input: "parenthesis slash bracket: (http://localhost/)[1] etc.", michael@0: url: "http://localhost/" michael@0: }, michael@0: { michael@0: input: "parenthesis bracket: (http://example.org[1]) etc.", michael@0: url: "http://example.org" michael@0: }, michael@0: { michael@0: input: "ipv6 1: https://[1080::8:800:200C:417A]/foo?bar=x test", michael@0: url: "https://[1080::8:800:200C:417A]/foo?bar=x" michael@0: }, michael@0: { michael@0: input: "ipv6 2: http://[::ffff:127.0.0.1]/#yay test", michael@0: url: "http://[::ffff:127.0.0.1]/#yay" michael@0: }, michael@0: { michael@0: input: "ipv6 parenthesis port: (http://[2001:db8::1]:80/) test", michael@0: url: "http://[2001:db8::1]:80/" michael@0: } michael@0: ]; michael@0: michael@0: function hrefLink(url) { michael@0: return ' href="' + url + '"'; michael@0: } michael@0: michael@0: for (let i = 0; i < tests.length; i++) { michael@0: let output = converter.scanTXT(tests[i].input, Ci.mozITXTToHTMLConv.kURLs); michael@0: let link = hrefLink(tests[i].url); michael@0: if (output.indexOf(link) == -1) michael@0: do_throw("Unexpected conversion: input=" + tests[i].input + michael@0: ", output=" + output + ", link=" + link); michael@0: } michael@0: }