test_domloc.xhtml (1987B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" 4 type="text/css"?> 5 6 7 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 8 title="Testing DOMLocalization in XUL environment"> 9 10 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> 11 <script type="application/javascript"> 12 <![CDATA[ 13 const l10nReg = new L10nRegistry(); 14 const fs = [ 15 { path: "/localization/en-US/mock.ftl", source: ` 16 file-menu = 17 .label = File 18 .accesskey = F 19 new-tab = 20 .label = New Tab 21 .accesskey = N 22 container = Some text with an <image data-l10n-name="foo"> inside it. 23 ` }, 24 ]; 25 const source = L10nFileSource.createMock("test", "app", ["en-US"], "/localization/{locale}", fs); 26 l10nReg.registerSources([source]); 27 28 SimpleTest.waitForExplicitFinish(); 29 30 31 const domLoc = new DOMLocalization( 32 [], 33 false, 34 l10nReg, 35 ["en-US"], 36 ); 37 38 async function foo() { 39 domLoc.addResourceIds(["/mock.ftl"]); 40 domLoc.connectRoot(document.documentElement); 41 await domLoc.translateRoots(); 42 43 is(document.getElementById('file-menu').getAttribute('label'), 'File'); 44 is(document.getElementById('file-menu').getAttribute('accesskey'), 'F'); 45 46 is(document.getElementById('new-tab').getAttribute('label'), 'New Tab'); 47 is(document.getElementById('new-tab').getAttribute('accesskey'), 'N'); 48 49 ok(document.querySelector("image"), 50 "Image should still be present after localization."); 51 SimpleTest.finish(); 52 } 53 54 window.onload = foo; 55 56 ]]> 57 </script> 58 <description data-l10n-id="container"><image data-l10n-name="foo"/></description> 59 60 <menubar id="main-menubar"> 61 <menu id="file-menu" data-l10n-id="file-menu"> 62 <menupopup id="menu_FilePopup"> 63 <menuitem id="new-tab" data-l10n-id="new-tab"> 64 </menuitem> 65 </menupopup> 66 </menu> 67 </menubar> 68 </window>