Skip to content

Commit

Permalink
Merge pull request #55 from w3c/submission/fileapi-opera
Browse files Browse the repository at this point in the history
opera file api submissions
  • Loading branch information
jgraham committed Aug 23, 2013
2 parents 20217d7 + 73cf9bd commit e28fee2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 28 deletions.
File renamed without changes.
File renamed without changes.
Expand Up @@ -9,25 +9,17 @@
<div id="log"></div>
<iframe style=display:none></iframe><!-- used by "platform object that supports indexed properties" test -->
<script>
var isWin = navigator.platform.substr(0, 3) == 'Win';
test(function(){
var b = new Blob();
assert_true(b instanceof Blob, 'b instanceof Blob');
assert_equals(String(b), '[object Blob]', 'String(b)');
assert_equals(b.size, 0, 'b.size');
assert_equals(b.type, '', 'b.type');
}, document.title+', no args');
var t_transparent = async_test(document.title+', transparent endings');
t_transparent.step(function(){
var b1 = new Blob(['\r\r\n\n']);
assert_equals(b1.size, 4, 'omitted second arg');
var b2 = new Blob(['\r\r\n\n'], {});
assert_equals(b2.size, 4, 'empty dict');
//assert_throws(new TypeError(), function(){ var b3 = new Blob(['\r\r\n\n'], {endings:"NATIVE"}); });
var b3 = new Blob(['\r\r\n\n'], {endings:"NATIVE"});
assert_equals(b3.size, 4, 'endings:"NATIVE"');
var b4 = new Blob(['\r\r\n\n'], {ENDINGS:"native"});
assert_equals(b2.size, 4, 'ENDINGS:"native"');

async_test(function(){
var b1 = new Blob(['\r\r\n\n'], {endings:'native'});
assert_equals(b1.size, 4);
var reader = new FileReader();
reader.onload = this.step_func(function(e) {
assert_equals(reader.result, '\r\r\n\n');
Expand All @@ -37,13 +29,23 @@
assert_unreached('got error event on FileReader');
});
reader.readAsText(b1);
});
}, document.title+', non-support for obsolete "endings" thing');

test(function(){
assert_false('toNativeLineEndings' in window);
}, document.title+', non-support for obsolete "toNativeLineEndings" thing');

test(function() {
assert_throws(new TypeError(), function() { new Blob("foo"); });
// assert_throws(new TypeError(), function() { new Blob({"0": "foo", "length":1}); }); // https://www.w3.org/Bugs/Public/show_bug.cgi?id=16767
assert_throws(new TypeError(), function() { new Blob(document.createElement("div")); });
assert_throws(new TypeError(), function() { new Blob([{toString:null, valueOf:null}]); });
}, document.title+', wrong first arg');

test(function() {
var b = new Blob({"0": "foo", "length":1});
assert_equals(b.size, 3);
}, document.title+', object with properties "0" and "length"');

test(function() {
var b_window = new Blob(window);
assert_equals(b_window.size, '[object Window]'.length, 'window');
Expand All @@ -55,11 +57,13 @@
var b_select = new Blob(select);
assert_equals(b_select.size, '[object HTMLOptionElement]'.length, 'select');
}, document.title+', platform object that supports indexed properties');

test(function() {
var list = document.body.children;
Object.defineProperty(list, "length", {get: function() { throw {name:7}; }});
Object.defineProperty(list, "length", {get: function() { throw {name:7}; }});
assert_throws({name:7}, function(){ new Blob(list); });
}, document.title+', platform object that supports indexed properties, overwriting "length"');

var t_ports = async_test(document.title+', MessagePort[] (platform array object)');
t_ports.step(function() {
var channel = new MessageChannel();
Expand All @@ -71,36 +75,52 @@
var channel2 = new MessageChannel();
channel.port1.postMessage('', [channel2.port1]);
});

test(function() {
var elm = document.createElement('div');
elm.setAttribute('foo', 'bar');
var b_attrs = new Blob(elm.attributes);
assert_equals(b_attrs.size, '[object Attr]'.length);
}, document.title+', Attr[] (platform array object)');

test(function() {
var b1 = new Blob([], {type:'a'});
assert_equals(b1.type, 'a', 'b1');
var b2 = new Blob([], {type:'A'});
assert_equals(b2.type, 'A', 'b2');
var b3 = new Blob([], {type:'\u00E5'});
assert_equals(b3.type, '\u00E5', 'b3');
var b4 = new Blob([], {type:'\uD801\uDC7E'}); // U+1047E
assert_equals(b4.type, '\uD801\uDC7E', 'b4');
var b5 = new Blob([], {type:' image/gif '});
assert_equals(b5.type, ' image/gif ', 'b5');

}, document.title+', type');
var type_tests = [
// blobParts, type, expected type
[[], 'a', 'a'],
[[], 'A', 'a'],
[[], '\u00E5', ''],
[[], '\uD801\uDC7E', ''], // U+1047E
[[], ' image/gif ', ' image/gif '],
[[], '\timage/gif\t', ''],
[[], 'image/gif;\u007f', ''],
[[], '\u0130mage/gif', ''], // uppercase i with dot
[[], '\u0131mage/gif', ''], // lowercase dotless i
[[], 'image/gif\u0000', ''],
// check that type isn't changed based on sniffing
[[0x3C, 0x48, 0x54, 0x4D, 0x4C, 0x3E], 'unknown/unknown', 'unknown/unknown'], // "<HTML>"
[[0x00, 0xFF], 'text/plain', 'text/plain'],
[[0x47, 0x49, 0x46, 0x38, 0x39, 0x61], 'image/png', 'image/png'], // "GIF89a"
];

type_tests.forEach(function(t) {
test(function() {
var arr = new Uint8Array([t[0]]).buffer;
var b = new Blob([arr], {type:t[1]});
assert_equals(b.type, t[2]);
}, document.title+', type: '+t[1]);
});

test(function() {
var b1 = new Blob(['foo']);
var b2 = new Blob([b1, b1]);
assert_equals(b2.size, 6);
}, document.title+', Blob in first argument');

test(function() {
var view = new Uint8Array([0, 255, 0]);
var b1 = new Blob([view.buffer, view.buffer]);
assert_equals(b1.size, 6);
}, document.title+', ArrayBuffer in first argument');

test(function() {
var view = new Uint8Array([0, 255, 0, 4]);
var b1 = new Blob([view, view]);
Expand All @@ -109,16 +129,19 @@
var b2 = new Blob([view1, view.buffer, view1]);
assert_equals(b2.size, 2 + 4 + 2);
}, document.title+', ArrayBufferView in first argument');

test(function() {
var view = new Uint8Array([0]);
var b1 = new Blob(['fo']);
var b2 = new Blob([view.buffer, b1, "foo"]);
assert_equals(b2.size, 6);
}, document.title+', mixed types in first argument');

test(function() {
var b1 = new Blob([null, undefined]);
assert_equals(b1.size, "nullundefined".length);
}, document.title+', null/undefined in first argument');

var t_slice = async_test(document.title+', slice');
t_slice.step(function(){
var view = new Uint8Array([0, 255, 0]);
Expand Down

0 comments on commit e28fee2

Please sign in to comment.