Skip to content

Commit

Permalink
File API: Match Firefox on readAsDataURL default MIME type.
Browse files Browse the repository at this point in the history
In Firefox, File.readAsDataURL's default MIME type is to
application/octet-stream. Chrome currently leaves the MIME type out when
it is unknown. While this meets all relevant specifications, matching
Firefox's behavior makes the platform easier to reason about.

Bug: 48368
Change-Id: If480df5cc3a1177a58c7c3dc68c57f3d6408b9eb
Reviewed-on: https://chromium-review.googlesource.com/1104183
Commit-Queue: Victor Costan <[email protected]>
Reviewed-by: Marijn Kruisselbrink <[email protected]>
Cr-Commit-Position: refs/heads/master@{#568292}
  • Loading branch information
pwnall authored and chromium-wpt-export-bot committed Jun 19, 2018
1 parent 2052baf commit 61df0b9
Showing 1 changed file with 51 additions and 39 deletions.
90 changes: 51 additions & 39 deletions FileAPI/reading-data-section/filereader_readAsDataURL.html
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
<!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://dev.w3.org/2006/webapi/FileAPI/#readAsDataURL">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>

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

reader.onload = this.step_func(function(evt) {
assert_equals(typeof reader.result, "string", "The result is string");
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'");
assert_equals(reader.readyState, reader.DONE);
this.done();
});

reader.onloadstart = this.step_func(function(evt) {
assert_equals(reader.readyState, reader.LOADING);
});

reader.onprogress = this.step_func(function(evt) {
assert_equals(reader.readyState, reader.LOADING);
});

reader.readAsDataURL(blob);
});
</script>
</body>
</html>
<!doctype html>
<meta charset="utf-8">
<title>FileAPI Test: FileReader.readAsDataURL</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://w3c.github.io/FileAPI/#readAsDataURL">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

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

reader.onload = this.step_func(function(evt) {
assert_equals(reader.readyState, reader.DONE);
testCase.done();
});
reader.onloadstart = this.step_func(function(evt) {
assert_equals(reader.readyState, reader.LOADING);
});
reader.onprogress = this.step_func(function(evt) {
assert_equals(reader.readyState, reader.LOADING);
});

reader.readAsDataURL(blob);
}, 'FileReader readyState during readAsDataURL');

async_test(function(testCase) {
var blob = new Blob(["TEST"], { type: 'text/plain' });
var reader = new FileReader();

reader.onload = this.step_func(function() {
assert_equals(reader.result, "data:text/plain;base64,VEVTVA==");
testCase.done();
});
reader.readAsDataURL(blob);
}, 'readAsDataURL result for Blob with specified MIME type');

async_test(function(testCase) {
var blob = new Blob(["TEST"]);
var reader = new FileReader();

reader.onload = this.step_func(function() {
assert_equals(reader.result,
"data:application/octet-stream;base64,VEVTVA==");
testCase.done();
});
reader.readAsDataURL(blob);
}, 'readAsDataURL result for Blob with unspecified MIME type');

</script>

0 comments on commit 61df0b9

Please sign in to comment.