~ubuntu-branches/ubuntu/trusty/enigmail/trusty-updates

« back to all changes in this revision

Viewing changes to extensions/enigmail/ipc/tests/unit/test_subprocess.js

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2011-06-07 14:35:53 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: package-import@ubuntu.com-20110607143553-fbgqhhvh8g8h6j1y
Tags: 2:1.2~a2~cvs20110606t2200-0ubuntu1
* Update to latest trunk snapshot for Thunderbird beta compat

* Remove build/pgo/profileserver.py from debian/clean. The new build
  system has a target depending on this
  - update debian/clean
* Drop debian/patches/autoconf.diff, just generate this at build time
* Refresh debian/patches/build_system_dont_link_libxul.diff
* libipc seems to be renamed to libipc-pipe. Fix genxpi and chrome.manifest
  to fix this 
  - add debian/patches/ipc-pipe_rename.diff
  - update debian/patches/series
* The makefiles in extensions/enigmail/ipc have an incorrect DEPTH
  attribute. Fix this so that they can find the rest of the build system
  - add debian/patches/makefile_depth.diff
  - update debian/patches/series
* Drop debian/patches/makefile-in-empty-xpcom-fix.diff - fixed in the
  current version
* Don't register a class ID multiple times, as this breaks enigmail entirely
  - add debian/patches/dont_register_cids_multiple_times.diff
  - update debian/patches/series
* Look for the Thunderbird 5 SDK
  - update debian/rules
  - update debian/control
* Run autoconf2.13 at build time
  - update debian/rules
  - update debian/control
* Add useless mesa-common-dev build-dep, just to satisfy the build system.
  We should just patch this out entirely really, but that's for another upload
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ***** BEGIN LICENSE BLOCK *****
 
2
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
3
 *
 
4
 * The contents of this file are subject to the Mozilla Public
 
5
 * License Version 1.1 (the "MPL"); you may not use this file
 
6
 * except in compliance with the MPL. You may obtain a copy of
 
7
 * the MPL at http://www.mozilla.org/MPL/
 
8
 *
 
9
 * Software distributed under the MPL is distributed on an "AS
 
10
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
11
 * implied. See the MPL for the specific language governing
 
12
 * rights and limitations under the MPL.
 
13
 *
 
14
 * The Original Code is ipc-pipe.
 
15
 *
 
16
 * The Initial Developer of the Original Code is Patrick Brunschwig.
 
17
 * Portions created by Patrick Brunschwig <patrick@mozilla-enigmail.org> are
 
18
 * Copyright (C) 2010 Patrick Brunschwig. All Rights Reserved.
 
19
 *
 
20
 * Contributor(s):
 
21
 *
 
22
 * Alternatively, the contents of this file may be used under the terms of
 
23
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
24
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
25
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
26
 * of those above. If you wish to allow use of your version of this file only
 
27
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
28
 * use your version of this file under the terms of the MPL, indicate your
 
29
 * decision by deleting the provisions above and replace them with the notice
 
30
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
31
 * the provisions above, a recipient may use your version of this file under
 
32
 * the terms of any one of the MPL, the GPL or the LGPL.
 
33
 * ***** END LICENSE BLOCK ***** */
 
34
 
 
35
/**
 
36
 * This file tests the implementation of subprocess.jsm
 
37
 */
 
38
 
 
39
Components.utils.import("resource://gre/modules/subprocess.jsm");
 
40
 
 
41
const Cc = Components.classes;
 
42
const Ci = Components.interfaces;
 
43
 
 
44
var gTestLines;
 
45
var gResultData;
 
46
 
 
47
function run_test()
 
48
{
 
49
  var isWindows = ("@mozilla.org/windows-registry-key;1" in Components.classes);
 
50
  var dataFile = do_get_file("ipc-data.txt" , true);
 
51
 
 
52
  var processDir = do_get_cwd();
 
53
  var cmd = processDir.clone();
 
54
  cmd.append("IpcCat" + (isWindows ? ".exe" : ""));
 
55
 
 
56
  if (!cmd.exists())
 
57
    do_throw("Could not locate the IpcCat helper executable\n");
 
58
 
 
59
  var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
 
60
                      getService(Ci.nsIProperties).
 
61
                      QueryInterface(Ci.nsIDirectoryService);
 
62
  var greDir = dirSvc.get("GreD", Ci.nsIFile);
 
63
 
 
64
 
 
65
  var envList = [
 
66
    "DYLD_LIBRARY_PATH="+greDir.path, // for Mac
 
67
    "LD_LIBRARY_PATH="+greDir.path    // for Linux
 
68
  ];
 
69
 
 
70
  var eol = isWindows ? "\r\n" : "\n";
 
71
  gTestLines = [ "Writing example data"+eol,
 
72
                  "Writing something more"+eol,
 
73
                  "And yet some more text"+eol ];
 
74
 
 
75
  /////////////////////////////////////////////////////////////////
 
76
  // Test standard scenario
 
77
  /////////////////////////////////////////////////////////////////
 
78
 
 
79
  gResultData = "";
 
80
  var p = subprocess.call({
 
81
    command:     cmd,
 
82
    arguments:   [ 'dump' ],
 
83
    environment: envList,
 
84
    stdin: subprocess.WritablePipe(function() {
 
85
        for (var i=0; i < gTestLines.length; i++) {
 
86
          this.write(gTestLines[i]);
 
87
        }
 
88
        this.close();
 
89
    }),
 
90
    stdout: subprocess.ReadablePipe(function (data) {
 
91
      gResultData += data;
 
92
    }),
 
93
    stderr: subprocess.ReadablePipe(function(data) {
 
94
    let len = gTestLines.join("").length;
 
95
    if (isWindows) len -= gTestLines.length;
 
96
      do_check_eq("Starting dump\nDumped "+len+" bytes\n",
 
97
    data.replace(/\r\n/g, "\n"));
 
98
    }),
 
99
    onFinished: subprocess.Terminate(function() {
 
100
      do_check_eq(0, this.exitCode);
 
101
    }),
 
102
    mergeStderr: false
 
103
  });
 
104
 
 
105
  p.wait();
 
106
  do_check_eq(gTestLines.join(""), gResultData);
 
107
 
 
108
 
 
109
  /////////////////////////////////////////////////////////////////
 
110
  // Test mergeStderr=true & stdin as string
 
111
  /////////////////////////////////////////////////////////////////
 
112
 
 
113
  gResultData = "";
 
114
  p = subprocess.call({
 
115
    command:     cmd,
 
116
    arguments:   [ 'dump' ],
 
117
    environment: envList,
 
118
    stdin: gTestLines.join(""),
 
119
    stdout: subprocess.ReadablePipe(function (data) {
 
120
      gResultData += data;
 
121
    }),
 
122
    stderr: subprocess.ReadablePipe(function(data) {
 
123
      do_throw("Got unexpected data '"+data+"' on stderr\n");
 
124
    }),
 
125
    onFinished: subprocess.Terminate(function() {
 
126
      do_check_eq(0, this.exitCode);
 
127
    }),
 
128
    mergeStderr: true
 
129
  });
 
130
 
 
131
  p.wait();
 
132
  do_check_eq(gTestLines.join("").length + (isWindows ? 32 : 30), gResultData.length);
 
133
 
 
134
 
 
135
  /////////////////////////////////////////////////////////////////
 
136
  // Test with cwd & no stderr
 
137
  /////////////////////////////////////////////////////////////////
 
138
 
 
139
  gResultData = "";
 
140
  var p = subprocess.call({
 
141
    command:     cmd,
 
142
    arguments:   [ 'dump' ],
 
143
    environment: envList,
 
144
    cwd: do_get_file(".", true),
 
145
    stdin: subprocess.WritablePipe(function() {
 
146
        for (var i=0; i < gTestLines.length; i++) {
 
147
          this.write(gTestLines[i]);
 
148
        }
 
149
    }),
 
150
    onFinished: subprocess.Terminate(function() {
 
151
      gResultData = this.stdoutData;
 
152
      do_check_eq(0, this.exitCode);
 
153
    }),
 
154
    mergeStderr: false
 
155
  });
 
156
 
 
157
  p.wait();
 
158
  do_check_eq(gTestLines.join(""), gResultData);
 
159
 
 
160
  /////////////////////////////////////////////////////////////////
 
161
  // Test exit code != 0
 
162
  /////////////////////////////////////////////////////////////////
 
163
 
 
164
  gResultData = "";
 
165
  var p = subprocess.call({
 
166
    command:     cmd,
 
167
    arguments:   [ 'wrong', 'arguments' ],
 
168
    environment: envList,
 
169
    stdin: "Dummy text",
 
170
    stdout: subprocess.ReadablePipe(function (data) {
 
171
      gResultData += data;
 
172
    }),
 
173
    stderr: subprocess.ReadablePipe(function(data) {
 
174
      do_check_eq(0, data.length);
 
175
    }),
 
176
    onFinished: subprocess.Terminate(function() {
 
177
      do_check_eq(4, this.exitCode);
 
178
    }),
 
179
    mergeStderr: false
 
180
  });
 
181
 
 
182
  p.wait();
 
183
  do_check_eq("", gResultData);
 
184
 
 
185
 
 
186
  /////////////////////////////////////////////////////////////////
 
187
  // Test minimal scenario with stdout only
 
188
  /////////////////////////////////////////////////////////////////
 
189
 
 
190
  gResultData = "";
 
191
  var p = subprocess.call({
 
192
    command:     cmd,
 
193
    arguments:   [ 'write', dataFile.path ],
 
194
    stdin: gTestLines.join("")
 
195
  });
 
196
 
 
197
  p.wait();
 
198
 
 
199
  var p = subprocess.call({
 
200
    command:     cmd,
 
201
    arguments:   [ 'read', dataFile.path ],
 
202
    environment: envList,
 
203
    stdout: subprocess.ReadablePipe(function (data) {
 
204
      gResultData += data;
 
205
    })
 
206
  });
 
207
 
 
208
  p.wait();
 
209
  do_check_eq(gTestLines.join(""), gResultData);
 
210
 
 
211
  /////////////////////////////////////////////////////////////////
 
212
  // Test minimal scenario with onFinished only
 
213
  /////////////////////////////////////////////////////////////////
 
214
 
 
215
  var p = subprocess.call({
 
216
    command:     cmd,
 
217
    arguments:   [ 'read', dataFile.path ],
 
218
    environment: envList,
 
219
    onFinished: subprocess.Terminate(function() {
 
220
      gResultData = this.stdoutData;
 
221
      do_check_eq(0, this.exitCode);
 
222
    })
 
223
  });
 
224
 
 
225
  p.wait();
 
226
  do_check_eq(gTestLines.join(""), gResultData);
 
227
 
 
228
 
 
229
  /////////////////////////////////////////////////////////////////
 
230
  // Test environment variables
 
231
  /////////////////////////////////////////////////////////////////
 
232
 
 
233
  gTestLines= [ "This is test variable" ];
 
234
  envList.push("TESTVAR="+gTestLines[0]);
 
235
 
 
236
  gResultData = "";
 
237
  var p = subprocess.call({
 
238
    command:     cmd.path,
 
239
    arguments:   [ 'getenv', 'TESTVAR' ],
 
240
    cwd: do_get_file(".", true),
 
241
    environment: envList,
 
242
    onFinished: subprocess.Terminate(function() {
 
243
      gResultData = this.stdoutData;
 
244
      do_check_eq(0, this.exitCode);
 
245
    }),
 
246
    mergeStderr: false
 
247
  });
 
248
 
 
249
  p.wait();
 
250
  do_check_eq(gTestLines.join(""), gResultData);
 
251
}