summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/fetch/common_temporaryFileBlob.js
blob: 47f5695b1c1a16d22f2e04a65a697e1da1d2818f (plain)
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
var data = new Array(256).join("1234567890ABCDEF");

function test_basic() {
  info("Simple test");

  fetch("/tests/dom/xhr/tests/temporaryFileBlob.sjs",
        { method: "POST", body: data })
  .then(response => {
    return response.blob();
  }).then(blob => {
    ok(blob instanceof Blob, "We have a blob!");
    is(blob.size, data.length, "Data length matches");

    var fr = new FileReader();
    fr.readAsText(blob);
    fr.onload = function() {
      is(fr.result, data, "Data content matches");
      next();
    }
  });
}

function test_worker() {
  info("XHR in workers");
  var w = new Worker('worker_temporaryFileBlob.js');
  w.onmessage = function(e) {
    if (e.data.type == 'info') {
      info(e.data.msg);
    } else if (e.data.type == 'check') {
      ok(e.data.what, e.data.msg);
    } else if (e.data.type == 'finish') {
      next();
    } else {
      ok(false, 'Something wrong happened');
    }
  }

  w.postMessage(42);
}