1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 2<html> 3<head> 4<link rel="stylesheet" href="/js/resources/js-test-style.css"> 5<script src="/js/resources/js-test-pre.js"></script> 6<script src="test.js"></script> 7<script src="/xpath-test-pre.js"></script> 8</head> 9<body> 10<div id="console"></div> 11 12<script> 13 function nsResolver(prefix) { 14 if (prefix == 'x') 15 return 'http://spam.com'; 16 return null; 17 } 18 19 result = DOM.evaluate("child::*", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 20 checkSnapshot("child::*", result, CHILDREN); 21 22 result = DOM.evaluate("/child::*", CHILD1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 23 checkSnapshot("/child::*", result, [ROOT]); 24 25 result = DOM.evaluate("/*/*", CHILD1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 26 checkSnapshot("/*/*", result, CHILDREN); 27 28 result = DOM.evaluate("/child::*/*/child::GCHILD", CHILD1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 29 checkSnapshot("/child::*/*/child::GCHILD", result, GCHILDREN1.concat(GCHILDREN2)); 30 31 result = DOM.evaluate("//*", CHILD1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 32 checkSnapshot("//*", result, [ROOT, CHILD1].concat(GCHILDREN1, [CHILD2], GCHILDREN2, [CHILD3, LANG], LCHILDREN)); 33 34 result = DOM.evaluate("//GCHILD", CHILD1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 35 checkSnapshot("//GCHILD", result, GCHILDREN1.concat(GCHILDREN2)); 36 37 result = DOM.evaluate("//@attr1", CHILD1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 38 checkSnapshot("//@attr1", result, [ATTR1, ATTR2]); 39 40 result = DOM.evaluate("x:GCHILD", CHILD1, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 41 checkSnapshot("x:GCHILD", result, []); 42 43 result = DOM.evaluate(".//GCHILD", CHILD2, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 44 checkSnapshot(".//GCHILD", result, GCHILDREN2); 45 46 result = DOM.evaluate(".//GCHILD", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 47 checkSnapshot(".//GCHILD", result, GCHILDREN1.concat(GCHILDREN2)); 48 49 result = DOM.evaluate("/", text, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 50 checkSnapshot("/", result, [DOM]); 51 52 result = DOM.evaluate("//CHILD1/..", CHILD1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 53 checkSnapshot("//CHILD1/..", result, [ROOT]); 54 55 result = DOM.evaluate(".//foo:*", CHILD3, DOM.createNSResolver(CHILD3), XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 56 checkSnapshot(".//foo:*", result, []); 57 58 result = DOM.evaluate("CHILD1 | CHILD2", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 59 checkSnapshot("CHILD1 | CHILD2", result, [CHILD1, CHILD2]); 60 61 result = DOM.evaluate("descendant::GCHILD[3]", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 62 checkSnapshot("descendant::GCHILD[3]", result, [GCHILD21]); 63 64 result = DOM.evaluate("descendant::GCHILD[parent::CHILD1]", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 65 checkSnapshot("descendant::GCHILD[parent::CHILD1]", result, GCHILDREN1); 66 67 result = DOM.evaluate("descendant::GCHILD[position() > 1]", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 68 checkSnapshot("descendant::GCHILD[position() > 1]", result, [GCHILD12].concat(GCHILDREN2)); 69 70 result = DOM.evaluate("@attr1[.='val1']", CHILD1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 71 checkSnapshot("@attr1[.='val1']", result, [ATTR1]); 72 73 shouldBe('DOM.evaluate("1", ROOT, null, XPathResult.ANY_TYPE, null).numberValue', "1"); 74 shouldBe('DOM.evaluate("00200", ROOT, null, XPathResult.ANY_TYPE, null).numberValue', "200"); 75 shouldBe('DOM.evaluate("3+4*7", ROOT, null, XPathResult.ANY_TYPE, null).numberValue', "31"); 76 shouldBe('DOM.evaluate("3-4*1", ROOT, null, XPathResult.ANY_TYPE, null).numberValue', "-1"); 77 shouldBe('DOM.evaluate("string(\'1\')", ROOT, null, XPathResult.ANY_TYPE, null).stringValue', "'1'"); 78 shouldBe('DOM.evaluate("concat(\'1\', \'2\')", ROOT, null, XPathResult.ANY_TYPE, null).stringValue', "'12'"); 79 shouldBe('DOM.evaluate("true()", ROOT, null, XPathResult.ANY_TYPE, null).booleanValue', "true"); 80 shouldBe('DOM.evaluate("false()", ROOT, null, XPathResult.ANY_TYPE, null).booleanValue', "false"); 81 shouldBe('DOM.evaluate("1=3<4", ROOT, null, XPathResult.ANY_TYPE, null).booleanValue', "true"); 82 shouldBe('DOM.evaluate("1 or 2 and 3", ROOT, null, XPathResult.ANY_TYPE, null).booleanValue', "true"); 83 shouldBe('DOM.evaluate("1 and 2 = 3", ROOT, null, XPathResult.ANY_TYPE, null).booleanValue', "false"); 84 shouldBe('DOM.evaluate("-1 or 2", ROOT, null, XPathResult.ANY_TYPE, null).booleanValue', "true"); 85 shouldBe('DOM.evaluate(". or *", ROOT, null, XPathResult.ANY_TYPE, null).booleanValue', "true"); 86 87 result = DOM.evaluate("text()", CHILD3, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 88 checkSnapshot("text()", result, []); 89 90 result = DOM.evaluate("processing-instruction('f')", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 91 checkSnapshot("processing-instruction('f')", result, []); 92 93 result = DOM.evaluate("(child::*)", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 94 checkSnapshot("(child::*)", result, CHILDREN); 95 96 shouldBe('DOM.evaluate(". * 0", ROOT, null, XPathResult.NUMBER_TYPE, null).numberValue', "NaN"); 97 shouldBe('DOM.evaluate(".. * 0", ROOT, null, XPathResult.NUMBER_TYPE, null).numberValue', "NaN"); 98 shouldBe('DOM.evaluate("/.. * 0", ROOT, null, XPathResult.NUMBER_TYPE, null).numberValue', "NaN"); 99 100 result = DOM.evaluate("CHILD2/@CODE", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 101 checkSnapshot("CHILD2/@CODE", result, [IDATTR2]); 102 103 shouldBe('DOM.evaluate("CHILD2/@CODE * 0", ROOT, null, XPathResult.NUMBER_TYPE, null).numberValue', "0"); 104 105 result = DOM.evaluate("f\xf6\xf8", LANG, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 106 checkSnapshot("f\xf6\xf8", result, [NONASCIIQNAME]); 107 108 shouldThrow('DOM.evaluate("\\\\", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)'); 109 110 var successfullyParsed = true; 111 112</script> 113<script src="/js/resources/js-test-post.js"></script> 114</body> 115</html> 116