Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 */
6 const { Cc, Ci } = require("chrome");
7 const subprocess = require("subprocess");
8 const env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
10 // For now, only test on windows
11 if (env.get('OS') && env.get('OS').match(/Windows/)) {
13 exports.testWindows = function (test) {
14 test.waitUntilDone();
15 let envTestValue = "OK";
16 let gotStdout = false;
18 var p = subprocess.call({
19 // Retrieve windows cmd.exe path from env
20 command: env.get('ComSpec'),
21 // In order to execute a simple "echo" function
22 arguments: ['/C', 'echo %ENV_TEST%'], // ' & type CON' should display stdin, but doesn't work
23 // Printing an environnement variable set here by the parent process
24 environment: ['ENV_TEST='+envTestValue],
26 stdin: function(stdin) {
27 // Win32 command line is not really made for stdin
28 // So it doesn't seems to work as it's hard to retrieve stdin
29 stdin.write("stdin");
30 stdin.close();
31 },
32 stdout: function(data) {
33 test.assert(!gotStdout,"don't get stdout twice");
34 test.assertEqual(data,envTestValue+"\r\n","stdout contains the environment variable");
35 gotStdout = true;
36 },
37 stderr: function(data) {
38 test.fail("shouldn't get stderr");
39 },
40 done: function() {
41 test.assert(gotStdout, "got stdout before finished");
42 test.done();
43 },
44 mergeStderr: false
45 });
47 }
49 exports.testWindowsStderr = function (test) {
50 test.waitUntilDone();
51 let gotStderr = false;
53 var p = subprocess.call({
54 command: env.get('ComSpec'),
55 arguments: ['/C', 'nonexistent'],
57 stdout: function(data) {
58 test.fail("shouldn't get stdout");
59 },
60 stderr: function(data) {
61 test.assert(!gotStderr,"don't get stderr twice");
62 test.assertEqual(
63 data,
64 "'nonexistent' is not recognized as an internal or external command,\r\n" +
65 "operable program or batch file.\r\n",
66 "stderr contains the error message"
67 );
68 gotStderr = true;
69 },
70 done: function() {
71 test.assert(gotStderr, "got stderr before finished");
72 test.done();
73 },
74 mergeStderr: false
75 });
77 }
79 }
81 if (env.get('USER') && env.get('SHELL')) {
83 exports.testUnix = function (test) {
84 test.waitUntilDone();
85 let envTestValue = "OK";
86 let gotStdout = false;
88 var p = subprocess.call({
89 command: '/bin/sh',
90 // Print stdin and our env variable
91 //arguments: ['-c', 'echo $@ $ENV_TEST'],
92 environment: ['ENV_TEST='+envTestValue],
94 stdin: function(stdin) {
95 stdin.write("echo $ENV_TEST");
96 stdin.close();
97 },
98 stdout: function(data) {
99 test.assert(!gotStdout,"don't get stdout twice");
100 test.assertEqual(data,envTestValue+"\n","stdout contains the environment variable");
101 gotStdout = true;
102 },
103 stderr: function(data) {
104 test.fail("shouldn't get stderr");
105 },
106 done: function() {
107 test.assert(gotStdout, "got stdout before finished");
108 test.done();
109 },
110 mergeStderr: false
111 });
112 }
114 exports.testUnixStderr = function (test) {
115 test.waitUntilDone();
116 let gotStderr = false;
118 var p = subprocess.call({
119 // Hope that we don't have to give absolute path on linux ...
120 command: '/bin/sh',
121 arguments: ['nonexistent'],
123 stdout: function(data) {
124 test.fail("shouldn't get stdout");
125 },
126 stderr: function(data) {
127 test.assert(!gotStderr,"don't get stderr twice");
128 // There is two variant of error message
129 if (data == "/bin/sh: 0: Can't open nonexistent\n")
130 test.pass("stderr containes the expected error message");
131 else
132 test.assertEqual(data, "/bin/sh: nonexistent: No such file or directory\n",
133 "stderr contains the error message");
134 gotStderr = true;
135 },
136 done: function() {
137 test.assert(gotStderr, "got stderr before finished");
138 test.done();
139 },
140 mergeStderr: false
141 });
142 }
144 }