test_setAttributes.html (1907B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test DOMLocalization.prototype.setAttributes and DOMLocalization.prototype.setArgs</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 12 window.onload = function() { 13 SimpleTest.waitForExplicitFinish(); 14 15 const domLoc = new DOMLocalization( 16 [], 17 false, 18 l10nReg, 19 ); 20 21 const p1 = document.querySelectorAll("p")[0]; 22 23 domLoc.setAttributes(p1, "title"); 24 is( 25 p1.getAttribute("data-l10n-id"), 26 "title", 27 "The data-l10n-id can be set by setAttributes." 28 ); 29 is( 30 p1.getAttribute("data-l10n-args"), 31 null, 32 "The data-l10n-args is unset." 33 ); 34 35 36 domLoc.setAttributes(p1, "title2", {userName: "John"}); 37 is( 38 p1.getAttribute("data-l10n-id"), 39 "title2", 40 "The data-l10n-id can be set by setAttributes." 41 ); 42 is( 43 p1.getAttribute("data-l10n-args"), 44 JSON.stringify({userName: "John"}), 45 "The data-l10n-args can be set by setAttributes." 46 ); 47 48 domLoc.setArgs(p1, {userName: "Jane"}); 49 is( 50 p1.getAttribute("data-l10n-id"), 51 "title2", 52 "The data-l10n-id is unchanged by setArgs." 53 ); 54 is( 55 p1.getAttribute("data-l10n-args"), 56 JSON.stringify({userName: "Jane"}), 57 "The data-l10n-args can by set by setArgs." 58 ); 59 60 domLoc.setArgs(p1); 61 is( 62 p1.getAttribute("data-l10n-id"), 63 "title2", 64 "The data-l10n-id is unchanged by setArgs." 65 ); 66 is( 67 p1.getAttribute("data-l10n-args"), 68 null, 69 "The data-l10n-args be unset by setArgs." 70 ); 71 72 SimpleTest.finish(); 73 }; 74 </script> 75 </head> 76 <body> 77 <p /> 78 </body> 79 </html>