Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ttwf shanghai 2013] FileAPI FileReaderSync tests added. #284

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions FileAPI/readingOnThreads/filereadersync.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>FileAPI Test: filereadersync</title>
<link rel="author" title="Intel" href="www.intel.com">
<link rel="help" href="http://www.w3.org/TR/FileAPI/#FileReaderSync">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>

<script>
var worker = new Worker("filereadersync.js");

setup({explicit_done: true});
setup({timeout: 5000});

on_event(worker, "message", function(message) {
var type = message.data.type;

if (type == "constructor") {
test(function() {
assert_true(message.data.content, "FileReaderSync has correct methods");
}, "Check if the FileReaderSync object has correct methods");
}

if (type == "arraybuffer") {
test(function() {
assert_true(message.data.content instanceof ArrayBuffer, "The object is ArrayBuffer instance");
assert_equals(message.data.content.byteLength, 19, "The byte length is 19");
}, "Check if the readasArrayBuffer works");
}

if (type == "text") {
test(function() {
assert_equals(typeof message.data.content, "string", "The type is string");
assert_equals(message.data.content, "Test FileReaderSync", "The value is 'Test FileReaderSync'");
}, "Check if the value readAsText works");
}

if (type == "text_utf16") {
test(function() {
assert_equals(typeof message.data.content, "string", "The type is string");
assert_not_equals(message.data.content, "Test FileReaderSync", "The value is not 'Test FileReaderSync'");
}, "Check if the readAsText works with encoding utf-16");
}

if (type == "dataurl") {
test(function() {
assert_equals(typeof message.data.content, "string", "The type is string");
assert_equals(message.data.content.indexOf("data"), 0, "The string starts with 'data'");
assert_true(message.data.content.indexOf("base64") > 0, "The string contains 'base64'");
}, "Check if the readAsDataURL works");

done();
}
});
</script>
</body>
</html>
16 changes: 16 additions & 0 deletions FileAPI/readingOnThreads/filereadersync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var readerSync = new FileReaderSync();
var blob = new Blob(["Test FileReaderSync"]);

//Check the constructor
postMessage({type: "constructor", content: 'readAsText' in readerSync || 'readAsArrayBuffer' in readerSync || 'readAsDataURL' in readerSync});

//Check the readAsArrayBuffer method
var arraybuffer = readerSync.readAsArrayBuffer(blob);
postMessage({type: "arraybuffer", content: arraybuffer}, [arraybuffer]);

//Check the readAstext method
postMessage({type: "text", content: readerSync.readAsText(blob)});
postMessage({type: "text_utf16", content: readerSync.readAsText(blob, "utf-16")});

//Check the readAsDataURL method
postMessage({type: "dataurl", content: readerSync.readAsDataURL(blob)});