content/base/test/test_file_from_blob.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_file_from_blob.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +<!doctype html>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=819900
     1.8 +-->
     1.9 +    <head>
    1.10 +<title>Test for crash caused by unloading and reloading srcdoc iframes</title>
    1.11 +<script src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=819900">Mozilla Bug 819900</a>
    1.16 +
    1.17 +<pre id="test">
    1.18 +<script>
    1.19 +
    1.20 +  var b = new Blob(['1234567890']);
    1.21 +  ok(b, 'Blob created');
    1.22 +  is(b.size, 10, 'Blob has the right size');
    1.23 +
    1.24 +  var status = false;
    1.25 +  try {
    1.26 +    f = new File(b);
    1.27 +  } catch(e) {
    1.28 +    status = true;
    1.29 +  }
    1.30 +  ok(status, "File throws if the second argument is missing");
    1.31 +
    1.32 +  status = false;
    1.33 +  try {
    1.34 +    f = new File(42, 'foobar.txt');
    1.35 +  } catch(e) {
    1.36 +    status = true;
    1.37 +  }
    1.38 +  ok(status, "File throws if the argument is not an array");
    1.39 +
    1.40 +  status = false;
    1.41 +  try {
    1.42 +    f = new File({}, 'foobar.txt');
    1.43 +  } catch(e) {
    1.44 +    status = true;
    1.45 +  }
    1.46 +  ok(status, "File throws if the argument is not an array");
    1.47 +
    1.48 +  status = false;
    1.49 +  try {
    1.50 +    f = new File("hello world", 'foobar.txt');
    1.51 +  } catch(e) {
    1.52 +    status = true;
    1.53 +  }
    1.54 +  ok(status, "File throws if the argument is not an array");
    1.55 +
    1.56 +  f = new File(['1234567890'], '');
    1.57 +  ok(f, 'File created');
    1.58 +  is(f.size, 10, 'File has the right size');
    1.59 +  is(f.name, '');
    1.60 +  is(f.type, '');
    1.61 +
    1.62 +  f = new File(['1234567890'], 42);
    1.63 +  ok(f, 'File created');
    1.64 +  is(f.size, 10, 'File has the right size');
    1.65 +  is(f.name, '42');
    1.66 +  is(f.type, '');
    1.67 +
    1.68 +  f = new File(['1234567890'], 'text.txt');
    1.69 +  ok(f, 'File created');
    1.70 +  is(f.size, 10, 'File has the right size');
    1.71 +  is(f.name, 'text.txt');
    1.72 +  is(f.type, '');
    1.73 +
    1.74 +  f = new File(['1234567890'], 'text.txt', { type: 'plain/text' });
    1.75 +  ok(f, 'File created');
    1.76 +  is(f.size, 10, 'File has the right size');
    1.77 +  is(f.name, 'text.txt');
    1.78 +  is(f.type, 'plain/text');
    1.79 +
    1.80 +  f = new File([b], 'text.txt');
    1.81 +  ok(f, 'File created');
    1.82 +  is(f.name, 'text.txt');
    1.83 +  is(f.type, '');
    1.84 +  is(f.size, b.size);
    1.85 +
    1.86 +  f = new File([b], 'test.txt', { type: 'plain/text' });
    1.87 +  ok(f, 'File created');
    1.88 +  is(f.name, 'test.txt');
    1.89 +  is(f.type, 'plain/text');
    1.90 +  is(f.size, b.size);
    1.91 +
    1.92 +  f = new File([b, b], 'test.txt', { type: 'plain/text' });
    1.93 +  ok(f, 'File created');
    1.94 +  is(f.name, 'test.txt');
    1.95 +  is(f.type, 'plain/text');
    1.96 +  is(f.size, b.size * 2);
    1.97 +
    1.98 +  var f2 = new File([f, f], 'test.txt', { type: 'plain/text' });
    1.99 +  ok(f2, 'File created');
   1.100 +  is(f2.name, 'test.txt');
   1.101 +  is(f2.type, 'plain/text');
   1.102 +  is(f2.size, f.size * 2);
   1.103 +
   1.104 +  var f2 = new File([f, f], 'test.txt', b);
   1.105 +  ok(f2, 'File created');
   1.106 +  is(f2.name, 'test.txt');
   1.107 +  is(f2.type, b.type);
   1.108 +  is(f2.size, f.size * 2);
   1.109 +
   1.110 +</script>
   1.111 +</pre>
   1.112 +</body>
   1.113 +</html>
   1.114 +

mercurial