test_l10n_mutations.html (1421B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test DOMLocalization's MutationObserver</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 title = Hello World 14 title2 = Hello Another World 15 ` }, 16 ]; 17 const source = L10nFileSource.createMock("test", "app", ["en-US"], "/localization/{locale}", fs); 18 l10nReg.registerSources([source]); 19 20 window.onload = async function() { 21 SimpleTest.waitForExplicitFinish(); 22 23 const domLoc = new DOMLocalization( 24 [], 25 false, 26 l10nReg, 27 ["en-US"], 28 ); 29 30 const h1 = document.querySelectorAll("h1")[0]; 31 32 domLoc.addResourceIds(["/mock.ftl"]); 33 domLoc.connectRoot(document.body); 34 35 await domLoc.translateRoots(); 36 37 is(h1.textContent, "Hello World"); 38 39 40 const mo = new MutationObserver(function onMutations() { 41 is(h1.textContent, "Hello Another World"); 42 mo.disconnect(); 43 SimpleTest.finish(); 44 }); 45 46 mo.observe(h1, { childList: true, characterData: true }); 47 48 domLoc.setAttributes(h1, "title2"); 49 }; 50 </script> 51 </head> 52 <body> 53 <div> 54 <h1 data-l10n-id="title"></h1> 55 </div> 56 </body> 57 </html>