test_remove_element.html (2662B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test L10n Mutations for removing element</title> 6 <script type="application/javascript" 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 // This element will be added to DOM and expected to be localized. 15 let elem = document.createElement("div"); 16 17 // This element will be added to DOM, then immediatelly removed and 18 // expected *not* to be localized. 19 let elem2 = document.createElement("div"); 20 21 // This element will be added to DOM, then immediatelly removed and 22 // and then immediatelly re-added, and expected to be localized. 23 let elem3 = document.createElement("div"); 24 25 // This element will be added to DOM, then immediatelly removed and 26 // and then re-added later, and expected to be localized. 27 let elem4 = document.createElement("div"); 28 29 document.l10n.setAttributes(elem, "crash-reports-title"); 30 document.l10n.setAttributes(elem2, "crash-reports-title"); 31 document.l10n.setAttributes(elem3, "crash-reports-title"); 32 document.l10n.setAttributes(elem4, "crash-reports-title"); 33 34 document.body.appendChild(elem); 35 document.body.appendChild(elem2); 36 document.body.appendChild(elem3); 37 document.body.appendChild(elem4); 38 39 is(elem.textContent.length, 0); 40 is(elem2.textContent.length, 0); 41 is(elem3.textContent.length, 0); 42 is(elem4.textContent.length, 0); 43 44 document.body.removeChild(elem2); 45 document.body.removeChild(elem3); 46 document.body.removeChild(elem4); 47 48 document.body.appendChild(elem3); 49 50 // 1. `elem` should be localized since it is in DOM. 51 await SimpleTest.waitForCondition(() => elem.textContent.length); 52 // 2. `elem2` was removed before l10n frame, so it should remain not localized. 53 is(elem2.textContent.length, 0); 54 // 3. `elem3` was added/removed/re-added so it should become localized. 55 await SimpleTest.waitForCondition(() => elem3.textContent.length); 56 // 4. `elem4` was not re-added, so it shouldn't be localized. 57 is(elem4.textContent.length, 0); 58 59 document.body.appendChild(elem4); 60 // 5. Now we re-added `elem4` to DOM so it should get localized. 61 await SimpleTest.waitForCondition(() => elem4.textContent.length); 62 SimpleTest.finish(); 63 }); 64 </script> 65 </head> 66 <body> 67 </body> 68 </html>