test_blob_channelname.js (1042B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 add_task(async function channelname() { 5 var file = new File( 6 [new Blob(["test"], { type: "text/plain" })], 7 "test-name" 8 ); 9 var url = URL.createObjectURL(file); 10 var channel = NetUtil.newChannel({ 11 uri: url, 12 loadUsingSystemPrincipal: true, 13 }); 14 15 let inputStream = channel.open(); 16 ok(inputStream, "Should be able to open channel"); 17 ok( 18 inputStream.QueryInterface(Ci.nsIAsyncInputStream), 19 "Stream should support async operations" 20 ); 21 22 await new Promise(resolve => { 23 inputStream.asyncWait( 24 () => { 25 let available = inputStream.available(); 26 ok(available, "There should be data to read"); 27 Assert.equal( 28 channel.contentDispositionFilename, 29 "test-name", 30 "filename matches" 31 ); 32 resolve(); 33 }, 34 0, 35 0, 36 Services.tm.mainThread 37 ); 38 }); 39 40 inputStream.close(); 41 channel.cancel(Cr.NS_ERROR_FAILURE); 42 });