test_overlay_sanitized.html (1449B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test DOMLocalization's DOMOverlay functionality</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 = 14 .href = https://www.hacked.com 15 16 key2 = 17 .href = https://pl.wikipedia.org 18 ` }, 19 ]; 20 const source = L10nFileSource.createMock("test", "app", ["en-US"], "/localization/{locale}", fs); 21 l10nReg.registerSources([source]); 22 23 async function test() { 24 const domLoc = new DOMLocalization( 25 ["/mock.ftl"], 26 false, 27 l10nReg, 28 ["en-US"], 29 ); 30 31 await domLoc.translateFragment(document.body); 32 33 const key1Elem = document.querySelector("[data-l10n-id=key1]"); 34 const key2Elem = document.querySelector("[data-l10n-id=key2]"); 35 36 37 is(key1Elem.hasAttribute("href"), false, "href translation should not be allowed"); 38 is(key2Elem.getAttribute("href"), "https://pl.wikipedia.org", 39 "href translation should be allowed"); 40 41 SimpleTest.finish(); 42 } 43 44 SimpleTest.waitForExplicitFinish(); 45 addLoadEvent(test); 46 </script> 47 </head> 48 <body> 49 <a data-l10n-id="key1"></a> 50 <a data-l10n-id="key2" data-l10n-attrs="href"></a> 51 </body> 52 </html>