Skip to content

Commit

Permalink
FileAPI FileReader interface tests added.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcxia43 committed Aug 18, 2013
1 parent 8bed17c commit b2441e0
Show file tree
Hide file tree
Showing 11 changed files with 483 additions and 0 deletions.
Empty file.
63 changes: 63 additions & 0 deletions FileAPI/FileReader-interface/filereader_abort.html
@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>FileAPI Test: filereader_abort</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="http://www.w3.org/TR/FileAPI/#abort">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>

<script>
var blob = new Blob(["TEST THE ABORT METHOD"]);
var readerNoRead = new FileReader();
var readerAbort = new FileReader();

setup({explicit_done: true});

try {
readerNoRead.abort();
} catch (e) {
test(function() {
assert_unreached("Exception thrown");
}, "Exception thrown when call abort method");
}

test(function() {
assert_equals(readerNoRead.readyState, readerNoRead.EMPTY, "The readyState is " + readerNoRead.EMPTY);
}, "Check if readyState is EMPTY when abort called and no reads called");

test(function() {
assert_equals(readerNoRead.result, null, "The result is null");
}, "Check if the result is null when abort called and no reads called");


on_event(readerAbort, "abort", function(evt) {
test(function() {
assert_equals(readerAbort.readyState, readerAbort.DONE, "The readyState is " + readerAbort.DONE);
}, "Check if abort event occurred");
});

on_event(readerAbort, "loadstart", function(evt) {
readerAbort.abort();
});

on_event(readerAbort, "loadend", function(evt) {
test(function() {
assert_equals(readerAbort.result, null, "The result is null");
}, "Check if the result is null when abort");

test(function() {
assert_equals(readerAbort.readyState, readerAbort.DONE, "The readyState is " + readerAbort.DONE);
}, "Check if the readyState is DONE when abort");

done();
});

readerAbort.readAsText(blob);
</script>
</body>
</html>
46 changes: 46 additions & 0 deletions FileAPI/FileReader-interface/filereader_error.html
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>FileAPI Test: filereader_abort</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="http://www.w3.org/TR/FileAPI/#dfn-domerror">
<link rel="help" href="http://www.w3.org/TR/FileAPI/#abort">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>

<script>
var blob = new Blob(["TEST THE ERROR ATTRIBUTE AND ERROR EVENT"]);
var reader = new FileReader();
var load = false;

setup({explicit_done: true});

test(function() {
assert_equals(reader.error, null, "The error is null when no error occurred");
}, "Check if the error attribute is null when no error occurred");

on_event(reader, "load", function(evt) {
load = true;
});

on_event(reader, "loadend", function(evt) {
test(function() {
assert_equals(reader.result, null, "The result is null");
}, "Check if the result is null when error occurred");

test(function() {
assert_false(load, "The load event not occurred");
}, "Check if the load event not occurred when reads failed");

done();
});

reader.readAsText(blob);
reader.abort();
</script>
</body>
</html>
67 changes: 67 additions & 0 deletions FileAPI/FileReader-interface/filereader_file.html
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>FileAPI Test: filereader_file</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="http://www.w3.org/TR/FileAPI/#FileReader-interface">
<link rel="help" href="http://www.w3.org/TR/FileAPI/#file">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div>
<p>Test step:</p>
<ol>
<li>Download <a href="support/blue-100x100.png">blue-100x100.png</a> to local.</li>
<li>Select the local file (blue-100x100.png) to run the test.</li>
</ol>
</div>

<form name="uploadData">
<input type="file" id="fileChooser"></input>
</form>

<div id="log"></div>
<script>
var fileInput = document.querySelector('#fileChooser');
var reader = new FileReader();

//readType: 1-> ArrayBuffer, 2-> Text, 3-> DataURL
var readType = 1;

setup({explicit_done: true});
setup({explicit_timeout: true});

on_event(fileInput, "change", function(evt) {
reader.readAsArrayBuffer(fileInput.files[0]);
});

on_event(reader, "load", function(evt) {
if (readType == 1) {
test(function() {
assert_true(reader.result instanceof ArrayBuffer, "The result is instanceof ArrayBuffer");
}, "Check if the readAsArrayBuffer works");

readType++;
reader.readAsText(fileInput.files[0]);
} else if (readType == 2) {
test(function() {
assert_equals(typeof reader.result, "string", "The result is typeof string");
}, "Check if the readAsText works");

readType++;
reader.readAsDataURL(fileInput.files[0]);
} else if (readType == 3) {
test(function() {
assert_equals(typeof reader.result, "string", "The result is typeof string");
assert_equals(reader.result.indexOf("data"), 0, "The result starts with 'data'");
assert_true(reader.result.indexOf("base64") > 0, "The result contains 'base64'");
}, "Check if the readAsDataURL works");

done();
}
});
</script>
</body>
</html>
45 changes: 45 additions & 0 deletions FileAPI/FileReader-interface/filereader_file_img.html
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>FileAPI Test: filereader_file_img</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="http://www.w3.org/TR/FileAPI/#FileReader-interface">
<link rel="help" href="http://www.w3.org/TR/FileAPI/#file">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div>
<p>Test step:</p>
<ol>
<li>Download <a href="support/blue-100x100.png">blue-100x100.png</a> to local.</li>
<li>Select the local file (blue-100x100.png) to run the test.</li>
</ol>
</div>

<form name="uploadData">
<input type="file" id="fileChooser"></input>
</form>

<div id="log"></div>
<script>
var fileInput = document.querySelector('#fileChooser');
var reader = new FileReader();

setup({explicit_done: true});
setup({explicit_timeout: true});

fileInput.addEventListener("change", function(evt) {
reader.readAsDataURL(fileInput.files[0]);
}, false);

reader.addEventListener("loadend", function(evt) {
test(function () {
assert_true(reader.result.indexOf("iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAqklEQVR42u3RsREAMAgDMe+/M4E7ZkhBoeI9gJWkWpfaeToTECACAkRAgAgIEAEB4gQgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgQJwARECACAgQ/W4AQauujc8IdAoAAAAASUVORK5CYII=") != -1, "Encoded image")
}, "Check if readAsDataURL returns correct image");
done();
}, false);
</script>
</body>
</html>
48 changes: 48 additions & 0 deletions FileAPI/FileReader-interface/filereader_readAsArrayBuffer.html
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>FileAPI Test: filereader_readAsArrayBuffer</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="http://www.w3.org/TR/FileAPI/#readAsArrayBuffer">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>

<script>
var blob = new Blob(["TEST"]);
var reader = new FileReader();

setup({explicit_done: true});

on_event(reader, "load", function() {
test(function() {
assert_equals(reader.result.byteLength, 4, "The byteLength is 4");
assert_true(reader.result instanceof ArrayBuffer, "The result is instanceof ArrayBuffer");
}, "Check if the readAsArrayBuffer method returns ArrayBuffer");

test(function() {
assert_equals(reader.readyState, reader.DONE, "The readyState");
}, "Check if the load event occurred");

done();
});

on_event(reader, "loadstart", function() {
test(function() {
assert_equals(reader.readyState, reader.LOADING, "The readyState");
}, "Check if the read processing starts");
});

on_event(reader, "progress", function() {
test(function() {
assert_equals(reader.readyState, reader.LOADING, "The readyState");
}, "Check if the read processing is working");
});

reader.readAsArrayBuffer(blob);
</script>
</body>
</html>
52 changes: 52 additions & 0 deletions FileAPI/FileReader-interface/filereader_readAsDataURL.html
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>FileAPI Test: filereader_readAsDataURL</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="http://www.w3.org/TR/FileAPI/#readAsDataURL">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>

<script>
var blob = new Blob(["TEST"]);
var reader = new FileReader();

setup({explicit_done: true});

on_event(reader, "load", function() {
test(function() {
assert_equals(typeof reader.result, "string", "The result is string");
}, "Check if the result attribute is string when readAsDataURL invoked");

test(function() {
assert_equals(reader.result.indexOf("data:"), 0, "The result attribute starts with 'data'");
assert_true(reader.result.indexOf("base64") > 0, "The result attribute contains 'base64'");
}, "Check if the readAsDataURL method returns base64 string");

test(function() {
assert_equals(reader.readyState, reader.DONE, "The readyState");
}, "Check if the load event occurred when reads succeed");

done();
});

on_event(reader, "loadstart", function() {
test(function() {
assert_equals(reader.readyState, reader.LOADING, "The readyState");
}, "Check if the readyState is LOADING when load starts");
});

on_event(reader, "progress", function() {
test(function() {
assert_equals(reader.readyState, reader.LOADING, "The readyState");
}, "Check if the the readyState is LOADING when progress");
});

reader.readAsDataURL(blob);
</script>
</body>
</html>
57 changes: 57 additions & 0 deletions FileAPI/FileReader-interface/filereader_readAsText.html
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>FileAPI Test: filereader_readAsText</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="http://www.w3.org/TR/FileAPI/#readAsDataText">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>

<script>
var blob = new Blob(["TEST"]);
var reader = new FileReader();
var reader_UTF16 = new FileReader();

setup({explicit_done: true});

on_event(reader, "load", function() {
test(function() {
assert_equals(typeof reader.result, "string", "The result is typeof string");
}, "Check if the result is typeof string");

test(function() {
assert_equals(reader.result, "TEST", "The result is TEST");
}, "Check if the readAsText method returns text");

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

on_event(reader, "loadstart", function() {
test(function() {
assert_equals(reader.readyState, reader.LOADING, "The readyState");
}, "Check if the readyState is LOADING when load will start");
});

on_event(reader, "progress", function() {
test(function() {
assert_equals(reader.readyState, reader.LOADING, "The readyState");
}, "Check if the readyState is LOADING when read progress");
});

on_event(reader_UTF16, "load", function() {
test(function() {
assert_equals(reader_UTF16.readyState, reader.DONE, "The readyState");
assert_not_equals(reader_UTF16.result, "TEST", "The result is not TEST");
}, "Check if the readAsText method returns string with encoding is UTF-16");

done();
});

reader.readAsText(blob);
</script>
</body>
</html>

0 comments on commit b2441e0

Please sign in to comment.