test_docl10n_sync.html (1606B)
1 <!DOCTYPE HTML> 2 <html data-l10n-sync> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test DocumentL10n in HTML environment</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 <link rel="localization" href="crashreporter/aboutcrashes.ftl"/> 9 <script type="application/javascript"> 10 "use strict"; 11 SimpleTest.waitForExplicitFinish(); 12 13 document.addEventListener("DOMContentLoaded", async function() { 14 await document.l10n.ready; 15 16 // Test for initial localization applied. 17 let desc = document.getElementById("main-desc"); 18 is(!!desc.textContent.length, true); 19 20 // Test for manual value formatting. 21 let msg = await document.l10n.formatValue("id-heading"); 22 is(!!msg.length, true); 23 24 // Test for mutations applied. 25 let verifyL10n = () => { 26 if (label.textContent.length) { 27 window.removeEventListener("MozAfterPaint", verifyL10n); 28 SimpleTest.finish(); 29 } 30 }; 31 window.addEventListener("MozAfterPaint", verifyL10n); 32 33 let label = document.getElementById("label1"); 34 document.l10n.setAttributes( 35 label, 36 "date-crashed-heading", 37 { 38 name: "John", 39 } 40 ); 41 42 // Test for l10n.getAttributes 43 let l10nArgs = document.l10n.getAttributes(label); 44 is(l10nArgs.id, "date-crashed-heading"); 45 is(l10nArgs.args.name, "John"); 46 }, { once: true}); 47 </script> 48 </head> 49 <body> 50 <h1 id="main-desc" data-l10n-id="crash-reports-title"></h1> 51 52 <p id="label1"></p> 53 </body> 54 </html>