test_attr_sanitized.html (1396B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test DOMLocalization's attr sanitization functionality</title> 6 <script 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 "use strict"; 10 const l10nReg = new L10nRegistry(); 11 const fs = [ 12 { path: "/localization/en-US/mock.ftl", source: ` 13 key1 = Value for Key 1 14 15 key2 = Value for <a>Key 2<a/>. 16 ` }, 17 ]; 18 const source = L10nFileSource.createMock("test", "app", ["en-US"], "/localization/{locale}", fs); 19 l10nReg.registerSources([source]); 20 21 SimpleTest.waitForExplicitFinish(); 22 addLoadEvent(async () => { 23 const domLoc = new DOMLocalization( 24 ["/mock.ftl"], 25 false, 26 l10nReg, 27 ["en-US"], 28 ); 29 30 await domLoc.translateFragment(document.body); 31 32 const elem1 = document.querySelector("#elem1"); 33 const elem2 = document.querySelector("#elem2"); 34 35 ok(elem1.textContent.includes("Value for")); 36 ok(!elem1.hasAttribute("title")); 37 38 ok(elem2.textContent.includes("Value for")); 39 ok(!elem2.hasAttribute("title")); 40 41 SimpleTest.finish(); 42 }); 43 </script> 44 </head> 45 <body> 46 <p id="elem1" title="Old Translation" data-l10n-id="key1"></p> 47 <p id="elem2" title="Old Translation" data-l10n-id="key2"></p> 48 </body> 49 </html>