Bug 1845311 - [Part 2] Use ChromeUtils.defineLazyGetter in more places r=arai,webcomp...
[gecko.git] / netwerk / test / unit / test_blob_channelname.js
blobc1a09272da2ef5fe0eb7dd1d0dae979ec0c1e256
1 /* Any copyright is dedicated to the Public Domain.
2    http://creativecommons.org/publicdomain/zero/1.0/ */
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   });
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   );
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   });
40   inputStream.close();
41   channel.cancel(Cr.NS_ERROR_FAILURE);
42 });