test_text_children.html (1720B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test L10nOverlays Text-semantic argument elements</title> 6 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 7 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 8 <script type="application/javascript"> 9 /* global L10nOverlays */ 10 "use strict"; 11 12 function elem(name) { 13 return function(str) { 14 const element = document.createElement(name); 15 element.innerHTML = str; 16 return element; 17 }; 18 } 19 20 const { translateElement } = L10nOverlays; 21 22 { 23 // without data-l10n-name 24 const element = elem("div")` 25 <em class="bar"></em>`; 26 const translation = { 27 value: '<em title="FOO">FOO</em>', 28 attributes: null, 29 }; 30 31 translateElement(element, translation); 32 is( 33 element.innerHTML, 34 '<em title="FOO">FOO</em>' 35 ); 36 } 37 38 { 39 // mismatched types 40 const element = elem("div")` 41 <button data-l10n-name="foo"></button>`; 42 const translation = { 43 value: '<em data-l10n-name="foo" title="FOO">FOO</em>', 44 attributes: null, 45 }; 46 47 translateElement(element, translation); 48 is( 49 element.innerHTML, 50 "FOO" 51 ); 52 } 53 54 { 55 // types and names mismatch 56 const element = elem("div")` 57 <em data-l10n-name="foo" class="foo"></em>`; 58 const translation = { 59 value: '<em data-l10n-name="foo" title="FOO">FOO</em>', 60 attributes: null, 61 }; 62 63 translateElement(element, translation); 64 is( 65 element.innerHTML, 66 '<em data-l10n-name="foo" class="foo" title="FOO">FOO</em>' 67 ); 68 } 69 </script> 70 </head> 71 <body> 72 </body> 73 </html>