B2G/gecko/netwerk/test/unit/test_filestreams.js
/**
 * We test async operations in test_NetUtil.js, and here test for simple sync
 * operations on input streams.
 *
 * @param aDeferOpen
 *        Whether to use DEFER_OPEN in the streams.
 */
We test async operations in test_NetUtil.js, and here test for simple sync
operations on input streams.

@param aDeferOpen
Whether to use DEFER_OPEN in the streams.
We test async operations in test_NetUtil . js and here test for simple sync operations on input streams . @param aDeferOpen Whether to use DEFER_OPEN in the streams .
function sync_operations(aDeferOpen)
{
  const TEST_DATA = "this is a test string";
  const LEAF_NAME = "filestreams-test-file.tmp";
  let file = Cc["@mozilla.org/file/directory_service;1"].
             getService(Ci.nsIProperties).
             get("ProfD", Ci.nsIFile);
  file.append(LEAF_NAME);
  file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
  let ostream = Cc[OUTPUT_STREAM_CONTRACT_ID].
                createInstance(Ci.nsIFileOutputStream);
  ostream.init(file, -1, -1, aDeferOpen ? Ci.nsIFileOutputStream.DEFER_OPEN : 0);
  ostream.write(TEST_DATA, TEST_DATA.length);
  ostream.close();
  let fstream = Cc["@mozilla.org/network/file-input-stream;1"].
                createInstance(Ci.nsIFileInputStream);
  fstream.init(file, -1, 0, aDeferOpen ? Ci.nsIFileInputStream.DEFER_OPEN : 0);
  let cstream = Cc["@mozilla.org/intl/converter-input-stream;1"].
                createInstance(Ci.nsIConverterInputStream);
  cstream.init(fstream, "UTF-8", 0, 0);
  let string  = {};
  cstream.readString(-1, string);
  cstream.close();
  fstream.close();
  do_check_eq(string.value, TEST_DATA);
}
function sync_operations ( aDeferOpen ) { const TEST_DATA = "this is a test string" ; const LEAF_NAME = "filestreams-test-file.tmp" ; let file = Cc [ "@mozilla.org/file/directory_service;1" ] . getService ( Ci . nsIProperties ) . get ( "ProfD" , Ci . nsIFile ) ; file . append ( LEAF_NAME ) ; file . createUnique ( Ci . nsIFile . NORMAL_FILE_TYPE , 0666 ) ; let ostream = Cc [ OUTPUT_STREAM_CONTRACT_ID ] . createInstance ( Ci . nsIFileOutputStream ) ; ostream . init ( file , - 1 , - 1 , aDeferOpen ? Ci . nsIFileOutputStream . DEFER_OPEN : 0 ) ; ostream . write ( TEST_DATA , TEST_DATA . length ) ; ostream . close ( ) ; let fstream = Cc [ "@mozilla.org/network/file-input-stream;1" ] . createInstance ( Ci . nsIFileInputStream ) ; fstream . init ( file , - 1 , 0 , aDeferOpen ? Ci . nsIFileInputStream . DEFER_OPEN : 0 ) ; let cstream = Cc [ "@mozilla.org/intl/converter-input-stream;1" ] . createInstance ( Ci . nsIConverterInputStream ) ; cstream . init ( fstream , "UTF-8" , 0 , 0 ) ; let string = { } ; cstream . readString ( - 1 , string ) ; cstream . close ( ) ; fstream . close ( ) ; do_check_eq ( string . value , TEST_DATA ) ; }
We test async operations in test_NetUtil.js, and here test for simple sync
 operations on input streams.
We test async operations in test_NetUtil . js and here test for simple sync operations on input streams .