Skip to content

Commit

Permalink
Merge pull request #283 from march1993/submissions/march1993/FileAPI-…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ms2ger committed Jan 25, 2014
2 parents 0169da2 + 31f3b78 commit 82d9d65
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 0 deletions.
150 changes: 150 additions & 0 deletions FileAPI/FileReader/Determining-Encoding.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>FileAPI Test: Blob Determing Encoding</title>
<link ref="author" title="march1993" href="mailto:march511@gmail.com">
<link rel=help href="http://www.w3.org/TR/FileAPI/#enctypes">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
var t = async_test("Blob Determing Encoding with encoding argument");
t.step(function() {
// string 'hello'
var data = [0xFE,0xFF,0x00,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F];
var testStringArray = new ArrayBuffer(data.length);
var dataView = new DataView(testStringArray);
data.forEach(function(v,i){
dataView.setInt8(i, v);
});
var testString = "hello";

var blob = new Blob([testStringArray]);
var reader = new FileReader();
var strResult = "";

reader.onloadend = t.step_func_done (function(event) {
strResult = reader.result;
assert_equals(strResult, testString, "The FileReader should read the ArrayBuffer through UTF-16BE.")
t.done();
}, reader);

reader.readAsText(blob, "UTF-16BE");
});

var t = async_test("Blob Determing Encoding with type attribute");
t.step(function() {
var data = [0xFE,0xFF,0x00,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F];
var testStringArray = new ArrayBuffer(data.length);
var dataView = new DataView(testStringArray);
data.forEach(function(v,i){
dataView.setInt8(i, v);
});
var testString = "hello";

var blob = new Blob([testStringArray], {type:"text/plain;charset=UTF-16BE"});
var reader = new FileReader();
var strResult = "";

reader.onloadend = t.step_func_done (function(event) {
strResult = reader.result;
assert_equals(strResult, testString, "The FileReader should read the ArrayBuffer through UTF-16BE.")
t.done();
}, reader);

reader.readAsText(blob);
});


var t = async_test("Blob Determing Encoding with UTF-8 BOM");
t.step(function() {
var data = [0xEF,0xBB,0xBF,0x68,0x65,0x6C,0x6C,0x6F];
var testStringArray = new ArrayBuffer(data.length);
var dataView = new DataView(testStringArray);
data.forEach(function(v,i){
dataView.setInt8(i, v);
});
var testString = "hello";

var blob = new Blob([testStringArray]);
var reader = new FileReader();
var strResult = "";

reader.onloadend = t.step_func_done (function(event) {
strResult = reader.result;
assert_equals(strResult, testString, "The FileReader should read the blob with UTF-8.");
t.done();
}, reader);

reader.readAsText(blob);
});

var t = async_test("Blob Determing Encoding without anything implying charset.");
t.step(function() {
var data = [0x68,0x65,0x6C,0x6C,0x6F];
var testStringArray = new ArrayBuffer(data.length);
var dataView = new DataView(testStringArray);
data.forEach(function(v,i){
dataView.setInt8(i, v);
});
var testString = "hello";

var blob = new Blob([testStringArray]);
var reader = new FileReader();
var strResult = "";

reader.onloadend = t.step_func_done (function(event) {
strResult = reader.result;
assert_equals(strResult, testString, "The FileReader should read the blob by default with UTF-8.");
t.done();
}, reader);

reader.readAsText(blob);
});

var t = async_test("Blob Determing Encoding with UTF-16BE BOM");
t.step(function() {
var data = [0xFE,0xFF,0x00,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F];
var testStringArray = new ArrayBuffer(data.length);
var dataView = new DataView(testStringArray);
data.forEach(function(v,i){
dataView.setInt8(i, v);
});
var testString = "hello";

var blob = new Blob([testStringArray]);
var reader = new FileReader();
var strResult = "";

reader.onloadend = t.step_func_done (function(event) {
strResult = reader.result;
assert_equals(strResult, testString, "The FileReader should read the ArrayBuffer through UTF-16BE.");
t.done();
}, reader);

reader.readAsText(blob);
});

var t = async_test("Blob Determing Encoding with UTF-16LE BOM");
t.step(function() {
var data = [0xFF,0xFE,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F,0x00];
var testStringArray = new ArrayBuffer(data.length);
var dataView = new DataView(testStringArray);
data.forEach(function(v,i){
dataView.setInt8(i, v);
});
var testString = "hello";

var blob = new Blob([testStringArray]);
var reader = new FileReader();
var strResult = "";

reader.onloadend = t.step_func_done (function(event) {
strResult = reader.result;
assert_equals(strResult, testString, "The FileReader should read the ArrayBuffer through UTF-16LE.");
t.done();
}, reader);

reader.readAsText(blob);
});

</script>
1 change: 1 addition & 0 deletions FileAPI/FileReader/MANIFEST
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Determining-Encoding.html

0 comments on commit 82d9d65

Please sign in to comment.