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

Side by Side Diff: content/test/data/blob_storage/blob_creation_and_slicing.html

Issue 2516713002: [BlobStorage] Implementing disk. (Closed)
Patch Set: comments, and hopefully browsertest cleanup 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 unified diff | Download patch
OLDNEW
(Empty)
1 <html>
2 <head>
3 <title>Blob Creation & Slicing</title>
4 <script type="text/javascript" src="common.js"></script>
5 <script type="text/javascript">
6 // We create < 2000 bytes of data, as that is the max for the browsertest.
pwnall 2016/12/01 01:12:13 Instead of having a comment here, how about adding
7
8 var numRawBlobs = 100;
pwnall 2016/12/01 01:12:13 Can you please document the test parameters?
dmurph 2016/12/01 20:40:58 Done.
9 var numSlices = 100;
10 var numSandwiches = 100;
11
12 var test = function() {
13 var blobs = [];
14
15 // This should cause us to go straight to file.
16 var veryLargeDataSize = 190;
pwnall 2016/12/01 01:12:13 How about naming the buffers according to the goal
dmurph 2016/12/01 20:40:59 Done.
17 var veryLargeData = new Uint8Array(veryLargeDataSize);
18 veryLargeData.fill(2);
pwnall 2016/12/01 01:12:13 Any reason for these values? Are they set up so th
dmurph 2016/12/01 20:40:59 Done.
19 veryLargeData.fill(8, veryLargeDataSize / 2);
20
21 // This should require multiple shared memory segments.
22 var largeDataSize = 15;
pwnall 2016/12/01 01:12:13 sharedMemoryData{Size}?
dmurph 2016/12/01 20:40:59 Done.
23 var largeData = new Uint8Array(largeDataSize);
24 largeData.fill(4);
25 largeData.fill(5, largeDataSize / 2);
26
27 // This should fit in IPC.
28 var smallDataSize = 2;
pwnall 2016/12/01 01:12:13 ipcData{Size}?
dmurph 2016/12/01 20:40:59 Done.
29 var smallData = new Uint8Array(2);
30 smallData[1] = 2;
31
32 var i = 0;
pwnall 2016/12/01 01:12:13 I think you can use let i inside loops so i is blo
dmurph 2016/12/01 20:40:59 Done.
33 var blob;
34 for (i = 0; i < numRawBlobs; ++i) {
35 var data = [];
36 if (i % 5 == 0) {
37 data.push(largeData);
38 } else if (i % 13 == 0) {
39 data.push(veryLargeData);
40 } else {
41 smallData[0] = i;
42 data.push(smallData);
43 }
44 blob = new Blob(data, { content_type: "text/plain" });
45 blobs.push(blob);
46 }
47
48 for (i = 0; i < numSlices; ++i) {
49 var originalSize;
50 var rawIndex = i % numRawBlobs;
51 if (rawIndex % 5 == 0) {
52 originalSize = largeDataSize;
53 } else if (rawIndex % 13 == 0) {
54 originalSize = veryLargeDataSize;
55 } else {
56 originalSize = smallDataSize;
57 }
58 if (i % 2 == 0) {
59 blob = blobs[i].slice(originalSize / 2);
60 } else {
61 blob = blobs[i].slice(0, originalSize / 2);
62 }
63 blobs.push(blob);
64 }
65
66 for (i = 0; i < numSandwiches; ++i) {
67 var sliceIndex = numRawBlobs + (i % numSlices);
68 blobs.push(new Blob(['pre', blobs[sliceIndex], 'post'], { content_type: "tex t/plain" }));
69 }
70
71 var getBytes = function(string) {
72 var bytes = [];
73 for (var i = 0; i < string.length; ++i) {
74 bytes.push(string.charCodeAt(i));
75 }
76 return bytes;
77 }
78
79 var i = 0;
pwnall 2016/12/01 01:12:13 If you don't want to switch to let, you should at
80 var numRead = 0;
81 for (; i < blobs.length; i++) {
82 var genReader = function(index, d) {
pwnall 2016/12/01 01:12:13 This seems to be defined so you can capture i into
dmurph 2016/12/01 20:40:58 isn't that what I do?
83 var reader = new FileReader();
84 reader.onerror = function(e) {
85 fail('Error when reading blob ' + index + ': ' + reader.error);
86 }
87 reader.onloadend = function(e) {
88 if (reader.error) {
89 fail('Error when reading blob ' + index + ': ' + reader.error);
90 return;
91 }
92 numRead++;
93 debug('Finished reading blob ' + index);
94 shouldBe('event.target.result.byteLength', d.length + '');
95 shouldBe('new Uint8Array(event.target.result)',
96 '[' + d + ']');
97 if (numRead >= blobs.length) {
98 done('Done!');
99 }
100 }
101 return reader;
102 }
103 var data;
pwnall 2016/12/01 01:12:13 Can you please define these closer to where you as
dmurph 2016/12/01 20:40:58 Done.
104 var origData;
105 var originalSize;
106 var slicedData;
107 var slicedDataSize;
108 var sandwichedData;
109 var sandwichedDataSize;
110
111 var rawIndex = i % numRawBlobs;
112 var sliceIndex = i % numSlices;
113
114 if (rawIndex % 5 == 0) {
115 originalSize = largeDataSize;
116 origData = largeData;
pwnall 2016/12/01 01:12:13 Why originalSize but origData?
dmurph 2016/12/01 20:40:59 Done.
117 } else if (rawIndex % 13 == 0) {
118 originalSize = veryLargeDataSize;
119 origData = veryLargeData;
120 } else {
121 originalSize = smallDataSize;
122 origData = new Uint8Array(smallDataSize);
123 origData[0] = rawIndex;
124 origData[1] = 2;
125 }
126
127 if (sliceIndex % 2 == 0) {
128 slicedData = origData.slice(originalSize / 2);
129 } else {
130 slicedData = origData.slice(0, originalSize / 2);
131 }
132 slicedDataSize = slicedData.length;
133
134 sandwichedDataSize = 7 + slicedDataSize;
135 var sandwichedData = new Uint8Array(sandwichedDataSize);
136 sandwichedData.set(getBytes("pre"), 0);
137 sandwichedData.set(slicedData, 3);
138 sandwichedData.set(getBytes("post"), 3 + slicedDataSize);
139
140 var data;
141 if (i < numRawBlobs) {
142 data = origData;
143 } else if (i < numRawBlobs + numSlices) {
144 data = slicedData;
145 } else {
146 data = sandwichedData;
147 }
148 genReader(i, data).readAsArrayBuffer(blobs[i]);
149 }
150 };
151 </script>
152 </head>
153 <body onLoad="test()">
154 <div id="status">Starting...<br/></div>
155 </body>
156 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698