summaryrefslogtreecommitdiffstats
path: root/dom/base/test/unit/test_xml_parser.js
blob: 0d6675fdabd5a82f200da9949497203abe3dd3b0 (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
function run_test() {
  for (var i = 0; i < tests.length && tests[i][0]; ++i) {
    if (!tests[i][0].call()) {
      do_throw(tests[i][1]);
    }
  }
}

var tests = [
  [test1, "Unable to parse basic XML document"],
  [test2, "ParseXML doesn't return Document"],
  [test3, "ParseXML return value's documentElement is not Element"],
  [test4, ""],
  [test5, ""],
  [test6, ""],
  [null],
];

function test1() {
  return ParseXML("<root/>");
}

function test2() {
  return ChromeUtils.getClassName(ParseXML("<root/>")) === "XMLDocument";
}

function test3() {
  return Element.isInstance(ParseXML("<root/>").documentElement);
}

function test4() {
  var doc = ParseXML("<root/>");
  Assert.equal(doc.documentElement.namespaceURI, null);
  return true;
}

function test5() {
  var doc = ParseXML("<root xmlns=''/>");
  Assert.equal(doc.documentElement.namespaceURI, null);
  return true;
}

function test6() {
  var doc = ParseXML("<root xmlns='ns1'/>");
  Assert.notEqual(doc.documentElement.namespaceURI, null);
  Assert.equal(doc.documentElement.namespaceURI, "ns1");
  return true;
}