test_idna2008.js (1664B)
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 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const kTransitionalProcessing = false; 8 9 // Four characters map differently under non-transitional processing: 10 const labels = [ 11 // U+00DF LATIN SMALL LETTER SHARP S to "ss" 12 "stra\u00dfe", 13 // U+03C2 GREEK SMALL LETTER FINAL SIGMA to U+03C3 GREEK SMALL LETTER SIGMA 14 "\u03b5\u03bb\u03bb\u03ac\u03c2", 15 // U+200C ZERO WIDTH NON-JOINER in Indic script 16 "\u0646\u0627\u0645\u0647\u200c\u0627\u06cc", 17 // U+200D ZERO WIDTH JOINER in Arabic script 18 "\u0dc1\u0dca\u200d\u0dbb\u0dd3", 19 20 // But CONTEXTJ rules prohibit ZWJ and ZWNJ in non-Arabic or Indic scripts 21 // U+200C ZERO WIDTH NON-JOINER in Latin script 22 "m\u200cn", 23 // U+200D ZERO WIDTH JOINER in Latin script 24 "p\u200dq", 25 ]; 26 27 const transitionalExpected = [ 28 "strasse", 29 "xn--hxarsa5b", 30 "xn--mgba3gch31f", 31 "xn--10cl1a0b", 32 "", 33 "", 34 ]; 35 36 const nonTransitionalExpected = [ 37 "xn--strae-oqa", 38 "xn--hxarsa0b", 39 "xn--mgba3gch31f060k", 40 "xn--10cl1a0b660p", 41 "", 42 "", 43 ]; 44 45 // Test options for converting IDN URLs under IDNA2008 46 function run_test() { 47 var idnService = Cc["@mozilla.org/network/idn-service;1"].getService( 48 Ci.nsIIDNService 49 ); 50 51 for (var i = 0; i < labels.length; ++i) { 52 var result; 53 try { 54 result = idnService.convertUTF8toACE(labels[i]); 55 } catch (e) { 56 result = ""; 57 } 58 59 if (kTransitionalProcessing) { 60 equal(result, transitionalExpected[i]); 61 } else { 62 equal(result, nonTransitionalExpected[i]); 63 } 64 } 65 }