1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/uriloader/exthandler/tests/mochitest/test_unsafeBidiChars.xhtml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,139 @@ 1.4 +<html xmlns="http://www.w3.org/1999/xhtml"> 1.5 +<head> 1.6 + <title>Test for Handling of unsafe bidi chars</title> 1.7 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.8 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.9 +</head> 1.10 +<body onload="load();"> 1.11 +<p id="display"></p> 1.12 +<iframe id="test"></iframe> 1.13 +<script type="text/javascript"> 1.14 +<![CDATA[ 1.15 + 1.16 +var unsafeBidiChars = { 1.17 + LRE: "\xe2\x80\xaa", 1.18 + RLE: "\xe2\x80\xab", 1.19 + PDF: "\xe2\x80\xac", 1.20 + LRO: "\xe2\x80\xad", 1.21 + RLO: "\xe2\x80\xae" 1.22 +}; 1.23 + 1.24 +var tests = [ 1.25 + "{1}.test", 1.26 + "{1}File.test", 1.27 + "Fi{1}le.test", 1.28 + "File{1}.test", 1.29 + "File.{1}test", 1.30 + "File.te{1}st", 1.31 + "File.test{1}", 1.32 + "File.{1}", 1.33 +]; 1.34 + 1.35 +function replace(name, x) { 1.36 + return name.replace(/\{1\}/, x); 1.37 +} 1.38 + 1.39 +function sanitize(name) { 1.40 + return replace(name, '_'); 1.41 +} 1.42 + 1.43 +var gTests = []; 1.44 +function make_test(param, expected) { 1.45 + gTests.push({ 1.46 + param: param, 1.47 + expected: expected, 1.48 + }); 1.49 +} 1.50 + 1.51 +SimpleTest.waitForExplicitFinish(); 1.52 + 1.53 +function load() { 1.54 + var iframe = document.getElementById("test"); 1.55 + var gCallback = null; 1.56 + function run_test(test, cb) { 1.57 + var url = "unsafeBidiFileName.sjs?name=" + encodeURIComponent(test.param); 1.58 + gCallback = cb; 1.59 + iframe.src = url; 1.60 + } 1.61 + 1.62 + var gCounter = -1; 1.63 + function run_next_test() { 1.64 + if (++gCounter == gTests.length) 1.65 + finish_test(); 1.66 + else 1.67 + run_test(gTests[gCounter], run_next_test); 1.68 + } 1.69 + 1.70 + netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); 1.71 + 1.72 + const HELPERAPP_DIALOG_CONTRACT = "@mozilla.org/helperapplauncherdialog;1"; 1.73 + const HELPERAPP_DIALOG_CID = SpecialPowers.wrap(SpecialPowers.Components).ID(SpecialPowers.Cc[HELPERAPP_DIALOG_CONTRACT].number); 1.74 + 1.75 + const FAKE_CID = SpecialPowers.Cc["@mozilla.org/uuid-generator;1"]. 1.76 + getService(SpecialPowers.Ci.nsIUUIDGenerator).generateUUID(); 1.77 + 1.78 + function HelperAppLauncherDialog() {} 1.79 + HelperAppLauncherDialog.prototype = { 1.80 + REASON_CANTHANDLE: 0, 1.81 + REASON_SERVERREQUEST: 1, 1.82 + REASON_TYPESNIFFED: 2, 1.83 + show: function(aLauncher, aWindowContext, aReason) { 1.84 + netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); 1.85 + var test = gTests[gCounter]; 1.86 + is(aLauncher.suggestedFileName, test.expected, 1.87 + "The filename should be correctly sanitized"); 1.88 + gCallback(); 1.89 + }, 1.90 + promptForSaveToFile: function(aLauncher, aWindowContext, aDefaultFileName, aSuggestedFileExtension, aForcePrompt) { 1.91 + return null; 1.92 + }, 1.93 + QueryInterface: function(aIID) { 1.94 + netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); 1.95 + if (aIID.equals(SpecialPowers.Ci.nsISupports) || 1.96 + aIID.equals(SpecialPowers.Ci.nsIHelperAppLauncherDialog)) 1.97 + return this; 1.98 + throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE; 1.99 + } 1.100 + }; 1.101 + 1.102 + var factory = { 1.103 + createInstance: function(aOuter, aIID) { 1.104 + netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); 1.105 + if (aOuter != null) 1.106 + throw SpecialPowers.Cr.NS_ERROR_NO_AGGREGATION; 1.107 + return new HelperAppLauncherDialog().QueryInterface(aIID); 1.108 + } 1.109 + }; 1.110 + 1.111 + SpecialPowers.wrap(SpecialPowers.Components).manager 1.112 + .QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar) 1.113 + .registerFactory(FAKE_CID, "", 1.114 + HELPERAPP_DIALOG_CONTRACT, 1.115 + factory); 1.116 + 1.117 + function finish_test() { 1.118 + SpecialPowers.wrap(SpecialPowers.Components).manager 1.119 + .QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar) 1.120 + .registerFactory(HELPERAPP_DIALOG_CID, "", 1.121 + HELPERAPP_DIALOG_CONTRACT, 1.122 + null); 1.123 + SimpleTest.finish(); 1.124 + } 1.125 + 1.126 + var i,j; 1.127 + 1.128 + for (i = 0; i < tests.length; ++i) { 1.129 + for (j in unsafeBidiChars) { 1.130 + make_test(replace(tests[i], unsafeBidiChars[j]), 1.131 + sanitize(tests[i])); 1.132 + } 1.133 + } 1.134 + 1.135 + run_next_test(); 1.136 +} 1.137 + 1.138 +]]> 1.139 +</script> 1.140 +</body> 1.141 +</html> 1.142 +