summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit/test_bug479413.js
blob: c28f3da41255b10a09cd72a785f1a4d92515f754 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
 * Test for unassigned code points in IDNs (RFC 3454 section 7)
 */

"use strict";

var idnService;

function expected_pass(inputIDN) {
  var isASCII = {};
  var displayIDN = idnService.convertToDisplayIDN(inputIDN, isASCII);
  Assert.equal(displayIDN, inputIDN);
}

function expected_fail(inputIDN) {
  var isASCII = {};
  var displayIDN = "";

  try {
    displayIDN = idnService.convertToDisplayIDN(inputIDN, isASCII);
  } catch (e) {}

  Assert.notEqual(displayIDN, inputIDN);
}

function run_test() {
  idnService = Cc["@mozilla.org/network/idn-service;1"].getService(
    Ci.nsIIDNService
  );

  // assigned code point
  expected_pass("foo\u0101bar.com");

  // assigned code point in punycode. Should *fail* because the URL will be
  // converted to Unicode for display
  expected_fail("xn--foobar-5za.com");

  // unassigned code point
  expected_fail("foo\u3040bar.com");

  // unassigned code point in punycode. Should *pass* because the URL will not
  // be converted to Unicode
  expected_pass("xn--foobar-533e.com");

  // code point assigned since Unicode 3.0
  // XXX This test will unexpectedly pass when we update to IDNAbis
  expected_fail("foo\u0370bar.com");
}