Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | /** |
michael@0 | 6 | * Test that mozITXTToHTMLConv works properly. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | var Cc = Components.classes; |
michael@0 | 10 | var Ci = Components.interfaces; |
michael@0 | 11 | |
michael@0 | 12 | function run_test() { |
michael@0 | 13 | let converter = Cc["@mozilla.org/txttohtmlconv;1"] |
michael@0 | 14 | .getService(Ci.mozITXTToHTMLConv); |
michael@0 | 15 | |
michael@0 | 16 | const tests = [ |
michael@0 | 17 | // -- RFC1738 |
michael@0 | 18 | { |
michael@0 | 19 | input: "RFC1738: <URL:http://mozilla.org> then", |
michael@0 | 20 | url: "http://mozilla.org" |
michael@0 | 21 | }, |
michael@0 | 22 | // -- RFC2396E |
michael@0 | 23 | { |
michael@0 | 24 | input: "RFC2396E: <http://mozilla.org/> then", |
michael@0 | 25 | url: "http://mozilla.org/" |
michael@0 | 26 | }, |
michael@0 | 27 | // -- abbreviated |
michael@0 | 28 | { |
michael@0 | 29 | input: "see www.mozilla.org maybe", |
michael@0 | 30 | url: "http://www.mozilla.org" |
michael@0 | 31 | }, |
michael@0 | 32 | // -- freetext |
michael@0 | 33 | { |
michael@0 | 34 | input:"I mean http://www.mozilla.org/.", |
michael@0 | 35 | url: "http://www.mozilla.org/" |
michael@0 | 36 | }, |
michael@0 | 37 | { |
michael@0 | 38 | input:"you mean http://mozilla.org:80, right?", |
michael@0 | 39 | url: "http://mozilla.org:80" |
michael@0 | 40 | }, |
michael@0 | 41 | { |
michael@0 | 42 | input:"go to http://mozilla.org; then go home", |
michael@0 | 43 | url: "http://mozilla.org" |
michael@0 | 44 | }, |
michael@0 | 45 | { |
michael@0 | 46 | input:"http://mozilla.org! yay!", |
michael@0 | 47 | url: "http://mozilla.org" |
michael@0 | 48 | }, |
michael@0 | 49 | { |
michael@0 | 50 | input:"er, http://mozilla.com?", |
michael@0 | 51 | url: "http://mozilla.com" |
michael@0 | 52 | }, |
michael@0 | 53 | { |
michael@0 | 54 | input:"http://example.org- where things happen", |
michael@0 | 55 | url: "http://example.org" |
michael@0 | 56 | }, |
michael@0 | 57 | { |
michael@0 | 58 | input:"see http://mozilla.org: front page", |
michael@0 | 59 | url: "http://mozilla.org" |
michael@0 | 60 | }, |
michael@0 | 61 | { |
michael@0 | 62 | input:"'http://mozilla.org/': that's the url", |
michael@0 | 63 | url: "http://mozilla.org/" |
michael@0 | 64 | }, |
michael@0 | 65 | { |
michael@0 | 66 | input:"some special http://mozilla.org/?x=.,;!-:x", |
michael@0 | 67 | url: "http://mozilla.org/?x=.,;!-:x" |
michael@0 | 68 | }, |
michael@0 | 69 | { |
michael@0 | 70 | // escape & when producing html |
michael@0 | 71 | input:"'http://example.org/?test=true&success=true': ok", |
michael@0 | 72 | url: "http://example.org/?test=true&success=true" |
michael@0 | 73 | }, |
michael@0 | 74 | { |
michael@0 | 75 | input: "bracket: http://localhost/[1] etc.", |
michael@0 | 76 | url: "http://localhost/" |
michael@0 | 77 | }, |
michael@0 | 78 | { |
michael@0 | 79 | input: "parenthesis: (http://localhost/) etc.", |
michael@0 | 80 | url: "http://localhost/" |
michael@0 | 81 | }, |
michael@0 | 82 | { |
michael@0 | 83 | input: "(thunderbird)http://mozilla.org/thunderbird", |
michael@0 | 84 | url: "http://mozilla.org/thunderbird" |
michael@0 | 85 | }, |
michael@0 | 86 | { |
michael@0 | 87 | input: "()http://mozilla.org", |
michael@0 | 88 | url: "http://mozilla.org" |
michael@0 | 89 | }, |
michael@0 | 90 | { |
michael@0 | 91 | input: "parenthesis included: http://kb.mozillazine.org/Performance_(Thunderbird) etc.", |
michael@0 | 92 | url: "http://kb.mozillazine.org/Performance_(Thunderbird)" |
michael@0 | 93 | }, |
michael@0 | 94 | { |
michael@0 | 95 | input: "parenthesis slash bracket: (http://localhost/)[1] etc.", |
michael@0 | 96 | url: "http://localhost/" |
michael@0 | 97 | }, |
michael@0 | 98 | { |
michael@0 | 99 | input: "parenthesis bracket: (http://example.org[1]) etc.", |
michael@0 | 100 | url: "http://example.org" |
michael@0 | 101 | }, |
michael@0 | 102 | { |
michael@0 | 103 | input: "ipv6 1: https://[1080::8:800:200C:417A]/foo?bar=x test", |
michael@0 | 104 | url: "https://[1080::8:800:200C:417A]/foo?bar=x" |
michael@0 | 105 | }, |
michael@0 | 106 | { |
michael@0 | 107 | input: "ipv6 2: http://[::ffff:127.0.0.1]/#yay test", |
michael@0 | 108 | url: "http://[::ffff:127.0.0.1]/#yay" |
michael@0 | 109 | }, |
michael@0 | 110 | { |
michael@0 | 111 | input: "ipv6 parenthesis port: (http://[2001:db8::1]:80/) test", |
michael@0 | 112 | url: "http://[2001:db8::1]:80/" |
michael@0 | 113 | } |
michael@0 | 114 | ]; |
michael@0 | 115 | |
michael@0 | 116 | function hrefLink(url) { |
michael@0 | 117 | return ' href="' + url + '"'; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | for (let i = 0; i < tests.length; i++) { |
michael@0 | 121 | let output = converter.scanTXT(tests[i].input, Ci.mozITXTToHTMLConv.kURLs); |
michael@0 | 122 | let link = hrefLink(tests[i].url); |
michael@0 | 123 | if (output.indexOf(link) == -1) |
michael@0 | 124 | do_throw("Unexpected conversion: input=" + tests[i].input + |
michael@0 | 125 | ", output=" + output + ", link=" + link); |
michael@0 | 126 | } |
michael@0 | 127 | } |