Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Unified Diff: LayoutTests/fast/files/resources/blob-slice-common.js

Issue 57483002: Implement File constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased against master, updated patch. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/fast/files/resources/blob-slice-common.js
diff --git a/LayoutTests/fast/files/resources/blob-slice-common.js b/LayoutTests/fast/files/resources/blob-slice-common.js
new file mode 100644
index 0000000000000000000000000000000000000000..d93617ec9da181d7258ef2e8a5bfa7a44949e0a4
--- /dev/null
+++ b/LayoutTests/fast/files/resources/blob-slice-common.js
@@ -0,0 +1,58 @@
+var blob, file; // Populated by runTests() in individual tests.
+var sliceParams = []; // Populated by individual tests.
+var testIndex = 0;
+
+function testSlicing(start, end, expectedResult)
kinuko 2013/11/14 05:41:06 nit: I feel it might be cleaner to make this funct
pwnall-personal 2013/11/14 14:31:19 Done. I really like this idea, thank you very much
+{
+ var subBlob, subFile;
+ var blobReader = new FileReader();
+ var fileReader = new FileReader();
+ var message = ".slice";
+ if (start === null && end === null) {
+ message += "()";
+ subBlob = blob.slice();
+ subFile = file.slice();
+ } else if (end == undefined) {
+ message += "(" + start + ")";
+ subBlob = blob.slice(start);
+ subFile = file.slice(start);
+ } else {
+ message += "(" + start + ", " + end + ")";
+ subBlob = blob.slice(start, end);
+ subFile = file.slice(start, end);
+ }
+ blobReader.onload = function(event) {
kinuko 2013/11/14 05:41:06 nit: I know this is coming from the original code,
pwnall-personal 2013/11/14 14:31:19 Done.
+ window.blobContents = event.target.result;
+ shouldBeEqualToString("blobContents", expectedResult);
+ debug("File " + message);
+ fileReader.readAsText(subFile);
+ };
+ blobReader.onerror = function(event) {
+ testFailed("Blob read error " + message + event.target.error.message);
+ debug("File " + message);
+ fileReader.readAsText(subFile);
+ };
+ fileReader.onload = function(event) {
+ window.fileContents = event.target.result;
+ shouldBeEqualToString("fileContents", expectedResult);
+ runNextTest();
+ };
+ fileReader.onerror = function(event) {
+ testFailed("File read error " + message + event.target.error.message);
+ runNextTest();
+ }
+ debug("Blob " + message);
+ blobReader.readAsText(subBlob);
+}
+
+function runNextTest()
+{
+ if (testIndex >= sliceTestCases.length) {
+ finishJSTest();
+ return;
+ }
+
+ var testCase = sliceTestCases[testIndex];
+ testIndex++;
+ testSlicing(testCase[0], testCase[1], testCase[2]);
+}

Powered by Google App Engine
This is Rietveld 408576698