B2G/gecko/xpcom/tests/unit/test_storagestream.js
/**
 * Checks that reading any non-zero amount of data from a storage stream
 * which has had 0 bytes written to it explicitly works correctly.
 */
Checks that reading any non-zero amount of data from a storage stream
which has had 0 bytes written to it explicitly works correctly.
Checks that reading any non - zero amount of data from a storage stream which has had 0 bytes written to it explicitly works correctly .
function test3()
{
  var ss = Cc["@mozilla.org/storagestream;1"]
             .createInstance(Ci.nsIStorageStream);
  ss.init(1024, 1024, null);
  var out = ss.getOutputStream(0);
  out.write("", 0);
  try
  {
    var inp = ss.newInputStream(0);
  }
  catch (e)
  {
    do_throw("newInputStream(0) shouldn't throw if write() is called: " + e);
  }
  do_check_true(inp.isNonBlocking(), "next test expects a non-blocking stream");
  try
  {
    var threw = false;
    var bis = BIS(inp);
    var dummy = bis.readByteArray(5);
  }
  catch (e)
  {
    if (e.result != Cr.NS_BASE_STREAM_WOULD_BLOCK)
      do_throw("wrong error thrown: " + e);
    threw = true;
  }
  do_check_true(threw,
                "should have thrown (nsStorageInputStream is nonblocking)");
}
function test3 ( ) { var ss = Cc [ "@mozilla.org/storagestream;1" ] . createInstance ( Ci . nsIStorageStream ) ; ss . init ( 1024 , 1024 , null ) ; var out = ss . getOutputStream ( 0 ) ; out . write ( "" , 0 ) ; try { var inp = ss . newInputStream ( 0 ) ; } catch ( e ) { do_throw ( "newInputStream(0) shouldn't throw if write() is called: " + e ) ; } do_check_true ( inp . isNonBlocking ( ) , "next test expects a non-blocking stream" ) ; try { var threw = false ; var bis = BIS ( inp ) ; var dummy = bis . readByteArray ( 5 ) ; } catch ( e ) { if ( e . result != Cr . NS_BASE_STREAM_WOULD_BLOCK ) do_throw ( "wrong error thrown: " + e ) ; threw = true ; } do_check_true ( threw , "should have thrown (nsStorageInputStream is nonblocking)" ) ; }
Checks that reading any non-zero amount of data from a storage stream
 which has had 0 bytes written to it explicitly works correctly.
Checks that reading any non - zero amount of data from a storage stream which has had 0 bytes written to it explicitly works correctly .