1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/test/test_getTranslationNodes.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,210 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test for nsIDOMWindowUtils.getTranslationNodes</title> 1.8 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.10 +</head> 1.11 +<body onload="runTest()"> 1.12 +<script type="application/javascript"> 1.13 + var utils = SpecialPowers.wrap(window). 1.14 + QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor). 1.15 + getInterface(SpecialPowers.Ci.nsIDOMWindowUtils); 1.16 + 1.17 + 1.18 + function testTranslationRoot(rootNode) { 1.19 + var translationNodes = utils.getTranslationNodes(rootNode); 1.20 + 1.21 + var expectedResult = rootNode.getAttribute("expected"); 1.22 + var expectedLength = expectedResult.split(" ").length; 1.23 + 1.24 + is(translationNodes.length, expectedLength, 1.25 + "Correct number of translation nodes for testcase " + rootNode.id); 1.26 + 1.27 + var resultList = []; 1.28 + for (var i = 0; i < translationNodes.length; i++) { 1.29 + var node = translationNodes.item(i).localName; 1.30 + if (translationNodes.isTranslationRootAtIndex(i)) { 1.31 + node += "[root]" 1.32 + } 1.33 + resultList.push(node); 1.34 + } 1.35 + 1.36 + is(resultList.length, translationNodes.length, 1.37 + "Correct number of translation nodes for testcase " + rootNode.id); 1.38 + 1.39 + is(resultList.join(" "), expectedResult, 1.40 + "Correct list of translation nodes for testcase " + rootNode.id); 1.41 + } 1.42 + 1.43 + function runTest() { 1.44 + isnot(utils, null, "nsIDOMWindowUtils"); 1.45 + 1.46 + var testcases = document.querySelectorAll("div[expected]"); 1.47 + for (var testcase of testcases) { 1.48 + testTranslationRoot(testcase); 1.49 + } 1.50 + 1.51 + var testiframe = document.getElementById("testiframe"); 1.52 + var iframediv = testiframe.contentDocument.querySelector("div"); 1.53 + try { 1.54 + var foo = utils.getTranslationNodes(iframediv); 1.55 + ok(false, "Cannot use a node from a different document"); 1.56 + } catch (e) { 1.57 + is(e.name, "WrongDocumentError", "Cannot use a node from a different document"); 1.58 + } 1.59 + 1.60 + SimpleTest.finish(); 1.61 + } 1.62 + 1.63 + SimpleTest.waitForExplicitFinish(); 1.64 +</script> 1.65 + 1.66 +<!-- Test that an inline element inside a root is not a root --> 1.67 +<div id="testcase1" 1.68 + expected="div[root] span"> 1.69 + <div> 1.70 + lorem ipsum <span>dolor</span> sit amet 1.71 + </div> 1.72 +</div> 1.73 + 1.74 +<!-- Test that a usually inline element becomes a root if it is 1.75 + displayed as a block --> 1.76 +<div id="testcase2" 1.77 + expected="div[root] span[root]"> 1.78 + <div> 1.79 + lorem ipsum <span style="display: block;">dolor</span> sit amet 1.80 + </div> 1.81 +</div> 1.82 + 1.83 +<!-- Test that the content-less <div> is ignored and only the 1.84 + <p> with content is returned --> 1.85 +<div id="testcase3" 1.86 + expected="p[root]"> 1.87 + <div> 1.88 + <p>lorem ipsum</p> 1.89 + </div> 1.90 +</div> 1.91 + 1.92 +<!-- Test that an inline element which the parent is not a root 1.93 + becomes a root --> 1.94 +<div id="testcase4" 1.95 + expected="span[root]"> 1.96 + <div> 1.97 + <span>lorem ipsum</span> 1.98 + </div> 1.99 +</div> 1.100 + 1.101 +<!-- Test siblings --> 1.102 +<div id="testcase5" 1.103 + expected="li[root] li[root]"> 1.104 + <ul> 1.105 + <li>lorem</li> 1.106 + <li>ipsum</li> 1.107 + </ul> 1.108 +</div> 1.109 + 1.110 +<!-- Test <ul> with content outside li --> 1.111 +<div id="testcase6" 1.112 + expected="ul[root] li[root] li[root]"> 1.113 + <ul>Lorem 1.114 + <li>lorem</li> 1.115 + <li>ipsum</li> 1.116 + </ul> 1.117 +</div> 1.118 + 1.119 +<!-- Test inline siblings --> 1.120 +<div id="testcase7" 1.121 + expected="ul[root] li li"> 1.122 + <ul>Lorem 1.123 + <li style="display: inline">lorem</li> 1.124 + <li style="display: inline">ipsum</li> 1.125 + </ul> 1.126 +</div> 1.127 + 1.128 +<!-- Test inline siblings becoming roots --> 1.129 +<div id="testcase8" 1.130 + expected="li[root] li[root]"> 1.131 + <ul> 1.132 + <li style="display: inline">lorem</li> 1.133 + <li style="display: inline">ipsum</li> 1.134 + </ul> 1.135 +</div> 1.136 + 1.137 +<!-- Test that nodes with only punctuation, whitespace 1.138 + or numbers are ignored --> 1.139 +<div id="testcase9" 1.140 + expected="li[root] li[root]"> 1.141 + <ul> 1.142 + <li>lorem</li> 1.143 + <li>ipsum</li> 1.144 + <li>-.,;'/!@#$%^*()</li> 1.145 + <li>0123456789</li> 1.146 + <li> 1.147 + </li> 1.148 + </ul> 1.149 +</div> 1.150 + 1.151 +<!-- Test paragraphs --> 1.152 +<div id="testcase10" 1.153 + expected="p[root] a b p[root] a b"> 1.154 + <p>Lorem ipsum <a href="a.htm">dolor</a> sit <b>amet</b>, consetetur</p> 1.155 + <p>Lorem ipsum <a href="a.htm">dolor</a> sit <b>amet</b>, consetetur</p> 1.156 +</div> 1.157 + 1.158 +<!-- Test that a display:none element is not ignored --> 1.159 +<div id="testcase11" 1.160 + expected="p[root] a b"> 1.161 + <p>Lorem ipsum <a href="a.htm">dolor</a> sit <b style="display:none">amet</b>, consetetur</p> 1.162 +</div> 1.163 + 1.164 +<!-- Test that deep nesting does not cause useless content to be returned --> 1.165 +<div id="testcase12" 1.166 + expected="p[root]"> 1.167 + <div> 1.168 + <div> 1.169 + <div> 1.170 + <p>Lorem ipsum</p> 1.171 + </div> 1.172 + </div> 1.173 + </div> 1.174 +</div> 1.175 + 1.176 +<!-- Test that deep nesting does not cause useless content to be returned --> 1.177 +<div id="testcase13" 1.178 + expected="div[root] p[root]"> 1.179 + <div>Lorem ipsum 1.180 + <div> 1.181 + <div> 1.182 + <p>Lorem ipsum</p> 1.183 + </div> 1.184 + </div> 1.185 + </div> 1.186 +</div> 1.187 + 1.188 +<!-- Test that non-html elements and elements that usually have non-translatable 1.189 + content are ignored --> 1.190 +<div id="testcase14" 1.191 + expected="div[root]"> 1.192 + <div> 1.193 + Lorem Ipsum 1.194 + <noscript>Lorem Ipsum</noscript> 1.195 + <style>.dummyClass { color: blue; }</style> 1.196 + <script> /* script tag */ </script> 1.197 + <code> code </code> 1.198 + <iframe id="testiframe" 1.199 + src="data:text/html,<div>Lorem ipsum</div>"> 1.200 + </iframe> 1.201 + <svg>lorem</svg> 1.202 + <math>ipsum</math> 1.203 + </div> 1.204 +</div> 1.205 + 1.206 +<!-- Test that nesting of inline elements won't produce roots as long as 1.207 + the parents are in the list of translation nodes --> 1.208 +<div id="testcase15" 1.209 + expected="p[root] a b span em"> 1.210 + <p>Lorem <a>ipsum <b>dolor <span>sit</span> amet</b></a>, <em>consetetur</em></p> 1.211 +</div> 1.212 +</body> 1.213 +</html>