netwerk/test/unit/test_mozTXTToHTMLConv.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/test/unit/test_mozTXTToHTMLConv.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,127 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/**
     1.9 + * Test that mozITXTToHTMLConv works properly.
    1.10 + */
    1.11 +
    1.12 +var Cc = Components.classes;
    1.13 +var Ci = Components.interfaces;
    1.14 +
    1.15 +function run_test() {
    1.16 +  let converter = Cc["@mozilla.org/txttohtmlconv;1"]
    1.17 +                     .getService(Ci.mozITXTToHTMLConv);
    1.18 +
    1.19 +  const tests = [
    1.20 +    // -- RFC1738
    1.21 +    {
    1.22 +      input: "RFC1738: <URL:http://mozilla.org> then",
    1.23 +      url: "http://mozilla.org"
    1.24 +    },
    1.25 +    // -- RFC2396E
    1.26 +    {
    1.27 +      input: "RFC2396E: <http://mozilla.org/> then",
    1.28 +      url: "http://mozilla.org/"
    1.29 +    },
    1.30 +    // -- abbreviated
    1.31 +    {
    1.32 +      input: "see www.mozilla.org maybe",
    1.33 +      url: "http://www.mozilla.org"
    1.34 +    },
    1.35 +    // -- freetext
    1.36 +    {
    1.37 +      input:"I mean http://www.mozilla.org/.",
    1.38 +      url: "http://www.mozilla.org/"
    1.39 +    },
    1.40 +    {
    1.41 +      input:"you mean http://mozilla.org:80, right?",
    1.42 +      url: "http://mozilla.org:80"
    1.43 +    },
    1.44 +    {
    1.45 +      input:"go to http://mozilla.org; then go home",
    1.46 +      url: "http://mozilla.org"
    1.47 +    },
    1.48 +    {
    1.49 +      input:"http://mozilla.org! yay!",
    1.50 +      url: "http://mozilla.org"
    1.51 +    },
    1.52 +    {
    1.53 +      input:"er, http://mozilla.com?",
    1.54 +      url: "http://mozilla.com"
    1.55 +    },
    1.56 +    {
    1.57 +      input:"http://example.org- where things happen",
    1.58 +      url: "http://example.org"
    1.59 +    },
    1.60 +    {
    1.61 +      input:"see http://mozilla.org: front page",
    1.62 +      url: "http://mozilla.org"
    1.63 +    },
    1.64 +    {
    1.65 +      input:"'http://mozilla.org/': that's the url",
    1.66 +      url: "http://mozilla.org/"
    1.67 +    },
    1.68 +    {
    1.69 +      input:"some special http://mozilla.org/?x=.,;!-:x",
    1.70 +      url: "http://mozilla.org/?x=.,;!-:x"
    1.71 +    },
    1.72 +    {
    1.73 +      // escape & when producing html
    1.74 +      input:"'http://example.org/?test=true&success=true': ok",
    1.75 +      url: "http://example.org/?test=true&amp;success=true"
    1.76 +    },
    1.77 +    {
    1.78 +      input: "bracket: http://localhost/[1] etc.",
    1.79 +      url: "http://localhost/"
    1.80 +    },
    1.81 +    {
    1.82 +      input: "parenthesis: (http://localhost/) etc.",
    1.83 +      url: "http://localhost/"
    1.84 +    },
    1.85 +    {
    1.86 +      input: "(thunderbird)http://mozilla.org/thunderbird",
    1.87 +      url: "http://mozilla.org/thunderbird"
    1.88 +    },
    1.89 +    {
    1.90 +      input: "()http://mozilla.org",
    1.91 +      url: "http://mozilla.org"
    1.92 +    },
    1.93 +    {
    1.94 +      input: "parenthesis included: http://kb.mozillazine.org/Performance_(Thunderbird) etc.",
    1.95 +      url: "http://kb.mozillazine.org/Performance_(Thunderbird)"
    1.96 +    },
    1.97 +    {
    1.98 +      input: "parenthesis slash bracket: (http://localhost/)[1] etc.",
    1.99 +      url: "http://localhost/"
   1.100 +    },
   1.101 +    {
   1.102 +      input: "parenthesis bracket: (http://example.org[1]) etc.",
   1.103 +      url: "http://example.org"
   1.104 +    },
   1.105 +    {
   1.106 +      input: "ipv6 1: https://[1080::8:800:200C:417A]/foo?bar=x test",
   1.107 +      url: "https://[1080::8:800:200C:417A]/foo?bar=x"
   1.108 +    },
   1.109 +    {
   1.110 +      input: "ipv6 2: http://[::ffff:127.0.0.1]/#yay test",
   1.111 +      url: "http://[::ffff:127.0.0.1]/#yay"
   1.112 +    },
   1.113 +    {
   1.114 +      input: "ipv6 parenthesis port: (http://[2001:db8::1]:80/) test",
   1.115 +      url: "http://[2001:db8::1]:80/"
   1.116 +    }
   1.117 +  ];
   1.118 +
   1.119 +  function hrefLink(url) {
   1.120 +    return ' href="' + url + '"';
   1.121 +  }
   1.122 +
   1.123 +  for (let i = 0; i < tests.length; i++) {
   1.124 +    let output = converter.scanTXT(tests[i].input, Ci.mozITXTToHTMLConv.kURLs);
   1.125 +    let link = hrefLink(tests[i].url);
   1.126 +    if (output.indexOf(link) == -1)
   1.127 +      do_throw("Unexpected conversion: input=" + tests[i].input +
   1.128 +               ", output=" + output + ", link=" + link);
   1.129 +  }
   1.130 +}

mercurial