test_docl10n_lazy.html (1378B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test Lazy 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 <script type="application/javascript"> 9 "use strict"; 10 SimpleTest.waitForExplicitFinish(); 11 12 is(document.l10n, null, "document.l10n is null."); 13 14 window.addEventListener("load", async () => { 15 is(document.l10n, null, "document.l10n is null after load."); 16 17 let desc = document.getElementById("main-desc"); 18 is(desc.textContent.length, 0, "main-desc is not translated"); 19 20 let link = document.createElement("link"); 21 link.setAttribute("rel", "localization"); 22 link.setAttribute("href", "crashreporter/aboutcrashes.ftl"); 23 document.head.appendChild(link); 24 25 // Verify now that `l10n.ready` exists and is fulfilled. 26 await document.l10n.ready; 27 28 // Lazy initialized localization should translate the document. 29 is(!!desc.textContent.length, true, "main-desc is translated"); 30 31 document.head.removeChild(link); 32 33 is(document.l10n, null, "document.l10n is null"); 34 35 SimpleTest.finish(); 36 }, { once: true}); 37 </script> 38 </head> 39 <body> 40 <h1 id="main-desc" data-l10n-id="crash-reports-title"></h1> 41 42 <p id="label1"></p> 43 </body> 44 </html>