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 == 'f') 15 return 'http://foo.com'; 16 return null; 17 } 18 19 shouldBe('DOM.evaluate("last()", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', '1'); 20 shouldBe('DOM.evaluate("position()", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', '1'); 21 shouldBe('DOM.evaluate("count(/ROOT | /ROOT/CHILD1)", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', '2'); 22 23 result = DOM.evaluate("id(1)", CHILD1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 24 checkSnapshot("id(1)", result, [CHILD2]); 25 26 result = DOM.evaluate("id('1 1')", CHILD1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 27 checkSnapshot("id('1 1')", result, [CHILD2]); 28 29 result = DOM.evaluate("id('0')", CHILD1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 30 checkSnapshot("id('0')", result, []); 31 32 result = DOM.evaluate("id('0 1')", CHILD1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 33 checkSnapshot("id('0 1')", result, [CHILD2]); 34 35 result = DOM.evaluate("id('0 1 1')", CHILD1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 36 checkSnapshot("id('0 1 1')", result, [CHILD2]); 37 38 result = DOM.evaluate("id('0 0 1 1')", CHILD1, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 39 checkSnapshot("id('0 0 1 1')", result, [CHILD2]); 40 41 shouldBe('DOM.evaluate("local-name(/empty)", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '""'); 42 shouldBe('DOM.evaluate("local-name(//f:CHILD3)", CHILD1, nsResolver, XPathResult.ANY_TYPE, null).stringValue', '"CHILD3"'); 43 shouldBe('DOM.evaluate("namespace-uri(/empty)", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '""'); 44 shouldBe('DOM.evaluate("namespace-uri(//f:CHILD3)", CHILD1, nsResolver, XPathResult.ANY_TYPE, null).stringValue', '"http://foo.com"'); 45 shouldBe('DOM.evaluate("name(//f:CHILD3)", CHILD1, nsResolver, XPathResult.ANY_TYPE, null).stringValue', '"foo:CHILD3"'); 46 47 strNodeset3 = " Text1 "; 48 49 shouldBe('DOM.evaluate("string(//CHILD1)", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', 'strNodeset3'); 50 shouldBe('DOM.evaluate("concat(//CHILD1, \'3.14\', \'Hi\')", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', 'strNodeset3 + "3.14Hi"'); 51 shouldBe('DOM.evaluate("starts-with(//CHILD1, \'3.14\')", CHILD1, null, XPathResult.ANY_TYPE, null).booleanValue', 'false'); 52 shouldBe('DOM.evaluate("starts-with(//CHILD1, //CHILD1)", CHILD1, null, XPathResult.ANY_TYPE, null).booleanValue', 'true'); 53 shouldBe('DOM.evaluate("starts-with(//CHILD1, \'\')", CHILD1, null, XPathResult.ANY_TYPE, null).booleanValue', 'true'); 54 shouldBe('DOM.evaluate("contains(//CHILD1, \'3.14\')", CHILD1, null, XPathResult.ANY_TYPE, null).booleanValue', 'false'); 55 shouldBe('DOM.evaluate("contains(//CHILD1, //CHILD1)", CHILD1, null, XPathResult.ANY_TYPE, null).booleanValue', 'true'); 56 shouldBe('DOM.evaluate("contains(//CHILD1, \'\')", CHILD1, null, XPathResult.ANY_TYPE, null).booleanValue', 'true'); 57 shouldBe('DOM.evaluate("substring-before(\'3.14Hi\', \'Hi\')", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"3.14"'); 58 shouldBe('DOM.evaluate("substring-before(\'3.14Hi\', \'\')", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '""'); 59 shouldBe('DOM.evaluate("substring-after(\'3.14Hi\', \'3.14\')", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"Hi"'); 60 shouldBe('DOM.evaluate("substring-after(\'3.14Hi\', \'\')", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"3.14Hi"'); 61 shouldBe('DOM.evaluate("substring(\'3.14Hi\', \'3.14\')", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"14Hi"'); 62 shouldBe('DOM.evaluate("substring(\'3.14Hi\', \'3.14\', 1)", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"1"'); 63 shouldBe('DOM.evaluate("substring(\'12345\', 2, 3)", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"234"'); 64 shouldBe('DOM.evaluate("substring(\'12345\', 2)", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"2345"'); 65 shouldBe('DOM.evaluate("substring(\'12345\', 1.5, 2.6)", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"234"'); 66 shouldBe('DOM.evaluate("substring(\'12345\', 0, 3)", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"12"'); 67 shouldBe('DOM.evaluate("substring(\'12345\', number(\'NaN\'), 3)", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '""'); 68 shouldBe('DOM.evaluate("substring(\'12345\', 1, number(\'NaN\'))", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '""'); 69 shouldBe('DOM.evaluate("substring(\'12345\', -42, 1 div 0)", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"12345"'); 70 shouldBe('DOM.evaluate("substring(\'12345\', -1 div 0, 1 div 0)", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '""'); 71 shouldBe('DOM.evaluate("string-length(\'3.14Hi\')", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', '6'); 72 shouldBe('DOM.evaluate("normalize-space(\'Ht \t There\t Mike\')", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"Ht There Mike"'); 73 shouldBe('DOM.evaluate("translate(\'Ht \t There\t Mike\', \'abcdefg\', \'ABCDEFG\')", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"Ht \t ThErE\t MikE"'); 74 shouldBe('DOM.evaluate("translate(\'hello world\', \'e\', \'a\')", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"hallo world"'); 75 shouldBe('DOM.evaluate("translate(\'hello world\', \'e\', \'abc\')", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"hallo world"'); 76 shouldBe('DOM.evaluate("translate(\'hello world\', \'el\', \'a\')", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"hao word"'); 77 shouldBe('DOM.evaluate("translate(\'hello world\', \'abcdefgabc\', \'ABCDEFG123\')", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"hEllo worlD"'); 78 shouldBe('DOM.evaluate("translate(\'hello world\', \'abcdefghhe\', \'ABCDEFGH\')", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"HEllo worlD"'); 79 shouldBe('DOM.evaluate("translate(\'hello world\', \'abcdefgh\', \'\')", CHILD1, null, XPathResult.ANY_TYPE, null).stringValue', '"llo worl"'); 80 81 shouldBe('DOM.evaluate("boolean(\'3.14\')", CHILD1, null, XPathResult.ANY_TYPE, null).booleanValue', 'true'); 82 shouldBe('DOM.evaluate("not(\'3.14Hi\')", CHILD1, null, XPathResult.ANY_TYPE, null).booleanValue', 'false'); 83 shouldBe('DOM.evaluate("true()", CHILD1, null, XPathResult.ANY_TYPE, null).booleanValue', 'true'); 84 shouldBe('DOM.evaluate("false()", CHILD1, null, XPathResult.ANY_TYPE, null).booleanValue', 'false'); 85 86 shouldBe('DOM.evaluate("number(\'NaN\')", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', 'NaN'); 87 shouldBe('DOM.evaluate("floor(3.14)", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', '3'); 88 shouldBe('DOM.evaluate("floor(number())", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', 'NaN'); 89 shouldBe('DOM.evaluate("floor(1 div 0)", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', 'Infinity'); 90 shouldBe('DOM.evaluate("floor(-1 div 0)", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', '-Infinity'); 91 shouldBe('DOM.evaluate("floor(0.5)", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', '0'); 92 shouldBe('DOM.evaluate("floor(-0.5)", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', '-1'); 93 shouldBe('DOM.evaluate("ceiling(3.14)", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', '4'); 94 shouldBe('DOM.evaluate("ceiling(number(\'NaN\'))", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', 'NaN'); 95 shouldBe('DOM.evaluate("ceiling(1 div 0)", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', 'Infinity'); 96 shouldBe('DOM.evaluate("ceiling(0.5)", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', '1'); 97 shouldBe('DOM.evaluate("ceiling(-0.5)", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', '-0'); 98 shouldBe('DOM.evaluate("round(3.14)", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', '3'); 99 shouldBe('DOM.evaluate("round(-4.5)", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', '-4'); 100 shouldBe('DOM.evaluate("round(number(\'NaN\'))", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', 'NaN'); 101 shouldBe('DOM.evaluate("round(1 div 0)", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', 'Infinity'); 102 shouldBe('DOM.evaluate("round(-1 div 0)", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', '-Infinity'); 103 shouldBe('DOM.evaluate("round(\'12345\')", CHILD1, null, XPathResult.ANY_TYPE, null).numberValue', '12345'); 104 shouldBe('DOM.evaluate("lang(\'en\')", LCHILD1, null, XPathResult.ANY_TYPE, null).booleanValue', 'false'); 105 shouldBe('DOM.evaluate("lang(\'en\')", LCHILD2, null, XPathResult.ANY_TYPE, null).booleanValue', 'true'); 106 shouldBe('DOM.evaluate("lang(\'\')", LCHILD1, null, XPathResult.ANY_TYPE, null).booleanValue', 'true'); 107 shouldBe('DOM.evaluate("lang(\'\')", LCHILD2, null, XPathResult.ANY_TYPE, null).booleanValue', 'false'); 108 shouldBe('DOM.evaluate("lang(\'foo\')", LCHILD1, null, XPathResult.ANY_TYPE, null).booleanValue', 'false'); 109 shouldBe('DOM.evaluate("lang(\'foo\')", LCHILD2, null, XPathResult.ANY_TYPE, null).booleanValue', 'false'); 110 111 var successfullyParsed = true; 112 113</script> 114<script src="/js/resources/js-test-post.js"></script> 115</body> 116</html> 117