1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
let blobTypes = [
{
type: "memory",
factory: async content => {
return new Blob([content]);
},
blobImplType: "MultipartBlobImpl[StringBlobImpl]",
},
{
type: "ipcBlob",
factory: async content => {
return new Promise(resolve => {
let bc1 = new BroadcastChannel("blob tests");
bc1.onmessage = e => {
resolve(e.data);
};
let bc2 = new BroadcastChannel("blob tests");
bc2.postMessage(new Blob([content]));
});
},
blobImplType:
"StreamBlobImpl[StreamBlobImpl[MultipartBlobImpl[StringBlobImpl]]]",
},
{
type: "memoryBlob",
factory: async content => {
return new Promise(resolve => {
var xhr = new XMLHttpRequest();
xhr.open(
"POST",
"http://mochi.test:8888/browser/dom/xhr/tests/temporaryFileBlob.sjs"
);
xhr.responseType = "blob";
xhr.send(content);
xhr.onloadend = _ => {
resolve(xhr.response);
};
});
},
blobImplType: "MemoryBlobImpl",
},
{
type: "temporaryBlob",
factory: async content => {
await SpecialPowers.pushPrefEnv({
set: [["dom.blob.memoryToTemporaryFile", 1]],
});
return new Promise(resolve => {
var xhr = new XMLHttpRequest();
xhr.open(
"POST",
"http://mochi.test:8888/browser/dom/xhr/tests/temporaryFileBlob.sjs"
);
xhr.responseType = "blob";
xhr.send(content);
xhr.onloadend = _ => {
resolve(xhr.response);
};
});
},
blobImplType: "StreamBlobImpl[TemporaryFileBlobImpl]",
},
];
async function forEachBlobType(content, cb) {
for (let i = 0; i < blobTypes.length; ++i) {
info("Running tests for " + blobTypes[i].type);
let blob = await blobTypes[i].factory(content);
is(
SpecialPowers.wrap(blob).blobImplType,
blobTypes[i].blobImplType,
"Correct blobImplType"
);
ok(blob instanceof Blob, "Blob created");
await cb(blob, content);
}
}
|