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

Unified Diff: content/test/data/blob_storage/blob_creation_and_slicing.html

Issue 2516713002: [BlobStorage] Implementing disk. (Closed)
Patch Set: file flushing, stack track on reader error Created 4 years 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: content/test/data/blob_storage/blob_creation_and_slicing.html
diff --git a/content/test/data/blob_storage/blob_creation_and_slicing.html b/content/test/data/blob_storage/blob_creation_and_slicing.html
new file mode 100644
index 0000000000000000000000000000000000000000..c979b6be8a55feb0bfc0f16bdad2183bd9a98c2a
--- /dev/null
+++ b/content/test/data/blob_storage/blob_creation_and_slicing.html
@@ -0,0 +1,159 @@
+<html>
+ <head>
+ <title>Blob Creation & Slicing</title>
+ <script type="text/javascript" src="common.js"></script>
+ <script type="text/javascript">
+// We create < 2000 bytes of data, as that is the max for the browsertest.
pwnall 2016/12/01 23:28:49 2000 or 3000?
dmurph 2016/12/02 01:11:33 Done.
+var maxBytes = 3000;
+
+// Number of blobs constructed with raw data.
+var numRawBlobs = 100;
+// Number of blobs we create by slicing the raw data blobs.
+var numSlices = 100;
+// Number of blobs we create by sandwiching sliced blobs in between new data.
+var numSandwiches = 100;
+var totalSize = 0;
+
+var fillPsueodoRandom = function(array) {
+ for (let i = 0; i < array.length; ++i) {
+ array[i] = (17 + 23 * i) & 0xFF;
+ }
+}
+
+var test = function() {
+ var blobs = [];
+
+ // This should cause us to go straight to file.
+ var savedToDiskDataSize = 190;
+ var savedToDiskData = new Uint8Array(savedToDiskDataSize);
pwnall 2016/12/01 23:28:49 How about moving the array allocation into the hel
dmurph 2016/12/02 01:11:34 Done.
+ fillPsueodoRandom(savedToDiskData);
+
+ // This should require multiple shared memory segments.
+ var sharedMemoryDataSize = 15;
+ var sharedMemoryData = new Uint8Array(sharedMemoryDataSize);
+ fillPsueodoRandom(sharedMemoryData);
+
+ var sandwichDataSize = 7;
+
+ // This should fit in IPC.
+ var ipcDataSize = 2;
+ var ipcData = new Uint8Array(2);
+ fillPsueodoRandom(ipcData);
+
+ for (let i = 0; i < numRawBlobs; ++i) {
+ var data = [];
+ if (i % 5 == 0) {
+ data.push(sharedMemoryData);
+ } else if (i % 13 == 0) {
+ data.push(savedToDiskData);
+ } else {
+ data.push(ipcData);
+ }
+ let blob = new Blob(data, { content_type: "text/plain" });
+ blobs.push(blob);
+ totalSize += blob.size;
+ }
+
+ for (let i = 0; i < numSlices; ++i) {
+ var origSize;
+ var rawIndex = i % numRawBlobs;
+ if (rawIndex % 5 == 0) {
+ origSize = sharedMemoryDataSize;
+ } else if (rawIndex % 13 == 0) {
+ origSize = savedToDiskDataSize;
+ } else {
+ origSize = ipcDataSize;
+ }
+ let blob;
+ if (i % 2 == 0) {
+ blob = blobs[i].slice(origSize / 2);
+ } else {
+ blob = blobs[i].slice(0, origSize / 2);
+ }
+ blobs.push(blob);
+ }
+
+ for (let i = 0; i < numSandwiches; ++i) {
+ var sliceIndex = numRawBlobs + (i % numSlices);
+ blobs.push(new Blob(['pre', blobs[sliceIndex], 'post'], { content_type: "text/plain" }));
+ totalSize += sandwichDataSize;
+ }
+ shouldBeTrue("totalSize <= maxBytes");
+
+ var getBytes = function(string) {
+ var bytes = [];
+ for (let i = 0; i < string.length; ++i) {
+ bytes.push(string.charCodeAt(i));
+ }
+ return bytes;
+ }
+
+ var numRead = 0;
+ for (let i = 0; i < blobs.length; i++) {
+ var genReader = function(index, d) {
+ var reader = new FileReader();
+ reader.onloadend = function(e) {
+ if (reader.error) {
+ fail('Error when reading blob ' + index + ': ' + reader.error);
+ return;
+ }
+ numRead++;
+ debug('Finished reading blob ' + index);
+ shouldBe('event.target.result.byteLength', d.length + '');
+ shouldBe('new Uint8Array(event.target.result)',
+ '[' + d + ']');
+ if (numRead >= blobs.length) {
+ done('Done!');
+ }
+ }
+ return reader;
+ }
+
+ var rawIndex = i % numRawBlobs;
+ var sliceIndex = i % numSlices;
+
+ var origData;
pwnall 2016/12/01 23:28:49 The logic here seems to duplicate some of the logi
dmurph 2016/12/02 01:11:34 Done.
+ var origSize;
+ if (rawIndex % 5 == 0) {
+ origSize = sharedMemoryDataSize;
+ origData = sharedMemoryData;
+ } else if (rawIndex % 13 == 0) {
+ origSize = savedToDiskDataSize;
+ origData = savedToDiskData;
+ } else {
+ origSize = ipcDataSize;
+ origData = ipcData;
+ }
+
+ var slicedData;
+ var slicedDataSize;
+ if (sliceIndex % 2 == 0) {
+ slicedData = origData.slice(origSize / 2);
+ } else {
+ slicedData = origData.slice(0, origSize / 2);
+ }
+ slicedDataSize = slicedData.length;
+
+ var sandwichedDataSize = sandwichDataSize + slicedDataSize;
+ var sandwichedData = new Uint8Array(sandwichedDataSize);
+ sandwichedData.set(getBytes("pre"), 0);
+ sandwichedData.set(slicedData, 3);
+ sandwichedData.set(getBytes("post"), 3 + slicedDataSize);
+
+ var data;
+ if (i < numRawBlobs) {
pwnall 2016/12/01 23:28:49 If you follow my suggestion above, this whole bloc
dmurph 2016/12/02 01:11:34 Done.
+ data = origData;
+ } else if (i < numRawBlobs + numSlices) {
+ data = slicedData;
+ } else {
+ data = sandwichedData;
+ }
+ genReader(i, data).readAsArrayBuffer(blobs[i]);
+ }
+};
+ </script>
+ </head>
+ <body onLoad="test()">
+ <div id="status">Starting...<br/></div>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698