netwerk/test/unit/test_mozTXTToHTMLConv.js

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

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.)

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

mercurial