Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <html xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 2 | <head> |
michael@0 | 3 | <title>Test for Handling of unsafe bidi chars</title> |
michael@0 | 4 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 5 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 6 | </head> |
michael@0 | 7 | <body onload="load();"> |
michael@0 | 8 | <p id="display"></p> |
michael@0 | 9 | <iframe id="test"></iframe> |
michael@0 | 10 | <script type="text/javascript"> |
michael@0 | 11 | <![CDATA[ |
michael@0 | 12 | |
michael@0 | 13 | var unsafeBidiChars = { |
michael@0 | 14 | LRE: "\xe2\x80\xaa", |
michael@0 | 15 | RLE: "\xe2\x80\xab", |
michael@0 | 16 | PDF: "\xe2\x80\xac", |
michael@0 | 17 | LRO: "\xe2\x80\xad", |
michael@0 | 18 | RLO: "\xe2\x80\xae" |
michael@0 | 19 | }; |
michael@0 | 20 | |
michael@0 | 21 | var tests = [ |
michael@0 | 22 | "{1}.test", |
michael@0 | 23 | "{1}File.test", |
michael@0 | 24 | "Fi{1}le.test", |
michael@0 | 25 | "File{1}.test", |
michael@0 | 26 | "File.{1}test", |
michael@0 | 27 | "File.te{1}st", |
michael@0 | 28 | "File.test{1}", |
michael@0 | 29 | "File.{1}", |
michael@0 | 30 | ]; |
michael@0 | 31 | |
michael@0 | 32 | function replace(name, x) { |
michael@0 | 33 | return name.replace(/\{1\}/, x); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function sanitize(name) { |
michael@0 | 37 | return replace(name, '_'); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | var gTests = []; |
michael@0 | 41 | function make_test(param, expected) { |
michael@0 | 42 | gTests.push({ |
michael@0 | 43 | param: param, |
michael@0 | 44 | expected: expected, |
michael@0 | 45 | }); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 49 | |
michael@0 | 50 | function load() { |
michael@0 | 51 | var iframe = document.getElementById("test"); |
michael@0 | 52 | var gCallback = null; |
michael@0 | 53 | function run_test(test, cb) { |
michael@0 | 54 | var url = "unsafeBidiFileName.sjs?name=" + encodeURIComponent(test.param); |
michael@0 | 55 | gCallback = cb; |
michael@0 | 56 | iframe.src = url; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | var gCounter = -1; |
michael@0 | 60 | function run_next_test() { |
michael@0 | 61 | if (++gCounter == gTests.length) |
michael@0 | 62 | finish_test(); |
michael@0 | 63 | else |
michael@0 | 64 | run_test(gTests[gCounter], run_next_test); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); |
michael@0 | 68 | |
michael@0 | 69 | const HELPERAPP_DIALOG_CONTRACT = "@mozilla.org/helperapplauncherdialog;1"; |
michael@0 | 70 | const HELPERAPP_DIALOG_CID = SpecialPowers.wrap(SpecialPowers.Components).ID(SpecialPowers.Cc[HELPERAPP_DIALOG_CONTRACT].number); |
michael@0 | 71 | |
michael@0 | 72 | const FAKE_CID = SpecialPowers.Cc["@mozilla.org/uuid-generator;1"]. |
michael@0 | 73 | getService(SpecialPowers.Ci.nsIUUIDGenerator).generateUUID(); |
michael@0 | 74 | |
michael@0 | 75 | function HelperAppLauncherDialog() {} |
michael@0 | 76 | HelperAppLauncherDialog.prototype = { |
michael@0 | 77 | REASON_CANTHANDLE: 0, |
michael@0 | 78 | REASON_SERVERREQUEST: 1, |
michael@0 | 79 | REASON_TYPESNIFFED: 2, |
michael@0 | 80 | show: function(aLauncher, aWindowContext, aReason) { |
michael@0 | 81 | netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); |
michael@0 | 82 | var test = gTests[gCounter]; |
michael@0 | 83 | is(aLauncher.suggestedFileName, test.expected, |
michael@0 | 84 | "The filename should be correctly sanitized"); |
michael@0 | 85 | gCallback(); |
michael@0 | 86 | }, |
michael@0 | 87 | promptForSaveToFile: function(aLauncher, aWindowContext, aDefaultFileName, aSuggestedFileExtension, aForcePrompt) { |
michael@0 | 88 | return null; |
michael@0 | 89 | }, |
michael@0 | 90 | QueryInterface: function(aIID) { |
michael@0 | 91 | netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); |
michael@0 | 92 | if (aIID.equals(SpecialPowers.Ci.nsISupports) || |
michael@0 | 93 | aIID.equals(SpecialPowers.Ci.nsIHelperAppLauncherDialog)) |
michael@0 | 94 | return this; |
michael@0 | 95 | throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE; |
michael@0 | 96 | } |
michael@0 | 97 | }; |
michael@0 | 98 | |
michael@0 | 99 | var factory = { |
michael@0 | 100 | createInstance: function(aOuter, aIID) { |
michael@0 | 101 | netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); |
michael@0 | 102 | if (aOuter != null) |
michael@0 | 103 | throw SpecialPowers.Cr.NS_ERROR_NO_AGGREGATION; |
michael@0 | 104 | return new HelperAppLauncherDialog().QueryInterface(aIID); |
michael@0 | 105 | } |
michael@0 | 106 | }; |
michael@0 | 107 | |
michael@0 | 108 | SpecialPowers.wrap(SpecialPowers.Components).manager |
michael@0 | 109 | .QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar) |
michael@0 | 110 | .registerFactory(FAKE_CID, "", |
michael@0 | 111 | HELPERAPP_DIALOG_CONTRACT, |
michael@0 | 112 | factory); |
michael@0 | 113 | |
michael@0 | 114 | function finish_test() { |
michael@0 | 115 | SpecialPowers.wrap(SpecialPowers.Components).manager |
michael@0 | 116 | .QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar) |
michael@0 | 117 | .registerFactory(HELPERAPP_DIALOG_CID, "", |
michael@0 | 118 | HELPERAPP_DIALOG_CONTRACT, |
michael@0 | 119 | null); |
michael@0 | 120 | SimpleTest.finish(); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | var i,j; |
michael@0 | 124 | |
michael@0 | 125 | for (i = 0; i < tests.length; ++i) { |
michael@0 | 126 | for (j in unsafeBidiChars) { |
michael@0 | 127 | make_test(replace(tests[i], unsafeBidiChars[j]), |
michael@0 | 128 | sanitize(tests[i])); |
michael@0 | 129 | } |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | run_next_test(); |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | ]]> |
michael@0 | 136 | </script> |
michael@0 | 137 | </body> |
michael@0 | 138 | </html> |
michael@0 | 139 |