|
1 <?xml version="1.0"?> |
|
2 <html xmlns="http://www.w3.org/1999/xhtml" attr="value"> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=384003 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 384003</title> |
|
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
10 </head> |
|
11 <body> |
|
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=384003">Mozilla Bug 384003</a> |
|
13 <p id="display"></p> |
|
14 <div id="content" style="display: none"> |
|
15 |
|
16 </div> |
|
17 <pre id="test" xmlns:foo="http://www.foo.org"><foo:foo/> |
|
18 <script type="application/javascript"> |
|
19 <![CDATA[ |
|
20 |
|
21 /** Test for Bug 384003 **/ |
|
22 |
|
23 |
|
24 function resolverTest(expr, resolver, result, extype) { |
|
25 if (!extype) { |
|
26 extype = 0; |
|
27 } |
|
28 try { |
|
29 is(document.evaluate(expr, document, resolver, |
|
30 XPathResult.FIRST_ORDERED_NODE_TYPE, null). |
|
31 singleNodeValue, |
|
32 result, |
|
33 "Wrong XPathResult"); |
|
34 if (extype) { |
|
35 ok(false, "Should have got an exception!"); |
|
36 } |
|
37 } catch(ex) { |
|
38 is(ex.name, extype, "Wrong exception"); |
|
39 } |
|
40 } |
|
41 |
|
42 // Expression should return document element. |
|
43 // Document resolver |
|
44 resolverTest("*", document, document.documentElement); |
|
45 // Element resolver |
|
46 resolverTest("*", document.documentElement, document.documentElement); |
|
47 // Attribute resolver |
|
48 resolverTest("*", document.documentElement.getAttributeNode("attr"), |
|
49 document.documentElement); |
|
50 // Text node resolver |
|
51 resolverTest("*", document.documentElement.firstChild, |
|
52 document.documentElement); |
|
53 // Comment node resolver |
|
54 resolverTest("*", document.documentElement.firstChild.nextSibling, |
|
55 document.documentElement); |
|
56 |
|
57 // Expression should return foo element, but because of the |
|
58 // resolver it may throw an exception. |
|
59 var foo = document.getElementById("test").firstChild; |
|
60 // Document resolver |
|
61 resolverTest("//foo:foo", document, foo, "NamespaceError"); |
|
62 // Element resolver |
|
63 resolverTest("//foo:foo", document.documentElement, foo, "NamespaceError"); |
|
64 // Attribute resolver |
|
65 resolverTest("//foo:foo", document.documentElement.getAttributeNode("attr"), |
|
66 foo, "NamespaceError"); |
|
67 // Text node resolver |
|
68 resolverTest("//foo:foo", document.documentElement.firstChild, |
|
69 foo, "NamespaceError"); |
|
70 // Comment node resolver |
|
71 resolverTest("//foo:foo", document.documentElement.firstChild.nextSibling, |
|
72 foo, "NamespaceError"); |
|
73 // Function resolver |
|
74 resolverTest("//foo:foo", |
|
75 function(p) { return (p == "foo") ? "http://www.foo.org" : ""; }, |
|
76 foo); |
|
77 // Element resolver, which has definition for foo namespace |
|
78 resolverTest("//foo:foo", foo.parentNode, foo); |
|
79 |
|
80 ]]> |
|
81 </script> |
|
82 </pre> |
|
83 </body> |
|
84 </html> |