1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/unit/head_utilities.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,36 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +Components.utils.import("resource://testing-common/httpd.js"); 1.10 + 1.11 +const nsIDocumentEncoder = Components.interfaces.nsIDocumentEncoder; 1.12 +const replacementChar = Components.interfaces.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER; 1.13 + 1.14 +function loadContentFile(aFile, aCharset) { 1.15 + //if(aAsIso == undefined) aAsIso = false; 1.16 + if(aCharset == undefined) 1.17 + aCharset = 'UTF-8'; 1.18 + 1.19 + var file = do_get_file(aFile); 1.20 + var ios = Components.classes['@mozilla.org/network/io-service;1'] 1.21 + .getService(Components.interfaces.nsIIOService); 1.22 + var chann = ios.newChannelFromURI ( ios.newFileURI (file) ); 1.23 + chann.contentCharset = aCharset; 1.24 + 1.25 + /*var inputStream = Components.classes["@mozilla.org/scriptableinputstream;1"] 1.26 + .createInstance(Components.interfaces.nsIScriptableInputStream); 1.27 + inputStream.init(chann.open()); 1.28 + return inputStream.read(file.fileSize); 1.29 + */ 1.30 + 1.31 + var inputStream = Components.classes["@mozilla.org/intl/converter-input-stream;1"] 1.32 + .createInstance(Components.interfaces.nsIConverterInputStream); 1.33 + inputStream.init(chann.open(), aCharset, 1024, replacementChar); 1.34 + var str = {}, content = ''; 1.35 + while (inputStream.readString(4096, str) != 0) { 1.36 + content += str.value; 1.37 + } 1.38 + return content; 1.39 +}