summaryrefslogtreecommitdiff
path: root/dom/base/test/browser_bug1307747.js
blob: 8d1448cc2399412aba4fe7f6e4b8ab44aa117313 (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
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */

var {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});

const BASE_URI = "http://mochi.test:8888/browser/dom/base/test/empty.html";

add_task(function* test_initialize() {
  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, BASE_URI);
  let browser = gBrowser.getBrowserForTab(tab);

  let blob = yield ContentTask.spawn(browser, null, function() {
    let blob = new Blob([new Array(1024*1024).join('123456789ABCDEF')]);
    return blob;
  });

  ok(blob, "We have a blob!");
  is(blob.size, new Array(1024*1024).join('123456789ABCDEF').length, "The size matches");

  let status = yield ContentTask.spawn(browser, blob, function(blob) {
    return new Promise(resolve => {
      let fr = new content.FileReader();
      fr.readAsText(blob);
      fr.onloadend = function() {
        resolve(fr.result == new Array(1024*1024).join('123456789ABCDEF'));
      }
    });
  });

  ok(status, "Data match!");

  yield BrowserTestUtils.removeTab(tab);
});