test_disconnectRoot.html (1647B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test DOMLocalization.prototype.disconnectRoot</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 key2 = Value for Key 2 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 p1 = document.getElementById("p1"); 24 25 const domLoc = new DOMLocalization( 26 ["/mock.ftl"], 27 false, 28 l10nReg, 29 ["en-US"], 30 ); 31 32 await domLoc.translateRoots(); 33 is(!p1.textContent.length, true); 34 35 const body = document.body; 36 37 domLoc.connectRoot(body); 38 await domLoc.translateRoots(); 39 is(p1.textContent.includes("Key 1"), true); 40 is(p1.textContent.includes("Key 2"), false); 41 42 domLoc.disconnectRoot(body); 43 domLoc.setAttributes(p1, "key2"); 44 await domLoc.translateRoots(); 45 is(p1.textContent.includes("Key 1"), true); 46 is(p1.textContent.includes("Key 2"), false); 47 48 domLoc.connectRoot(body); 49 await domLoc.translateRoots(); 50 is(p1.textContent.includes("Key 1"), false); 51 is(p1.textContent.includes("Key 2"), true); 52 53 SimpleTest.finish(); 54 }; 55 </script> 56 </head> 57 <body> 58 <p id="p1" data-l10n-id="key1"></p> 59 </body> 60 </html>