content/base/test/unit/head_utilities.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:661a284d1d7e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 Components.utils.import("resource://testing-common/httpd.js");
7
8 const nsIDocumentEncoder = Components.interfaces.nsIDocumentEncoder;
9 const replacementChar = Components.interfaces.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER;
10
11 function loadContentFile(aFile, aCharset) {
12 //if(aAsIso == undefined) aAsIso = false;
13 if(aCharset == undefined)
14 aCharset = 'UTF-8';
15
16 var file = do_get_file(aFile);
17 var ios = Components.classes['@mozilla.org/network/io-service;1']
18 .getService(Components.interfaces.nsIIOService);
19 var chann = ios.newChannelFromURI ( ios.newFileURI (file) );
20 chann.contentCharset = aCharset;
21
22 /*var inputStream = Components.classes["@mozilla.org/scriptableinputstream;1"]
23 .createInstance(Components.interfaces.nsIScriptableInputStream);
24 inputStream.init(chann.open());
25 return inputStream.read(file.fileSize);
26 */
27
28 var inputStream = Components.classes["@mozilla.org/intl/converter-input-stream;1"]
29 .createInstance(Components.interfaces.nsIConverterInputStream);
30 inputStream.init(chann.open(), aCharset, 1024, replacementChar);
31 var str = {}, content = '';
32 while (inputStream.readString(4096, str) != 0) {
33 content += str.value;
34 }
35 return content;
36 }

mercurial