-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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 FileReader interface tests added. #291
Closed
jcxia43
wants to merge
1
commit into
web-platform-tests:master
from
jcxia43:submission/jcxia-fileapi-filereader
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
48
FileAPI/FileReader-interface/filereader_readAsArrayBuffer.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
52
FileAPI/FileReader-interface/filereader_readAsDataURL.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://code.google.com/p/chromium/issues/detail?id=275087 for the fail on Chrome.