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

Side by Side Diff: chrome/test/data/extensions/storage_monitor/hosted_apps/common.js

Issue 2923663002: ExtensionStorageMonitor: use smaller, self-registering StorageObservers (Closed)
Patch Set: Fiddling. Created 3 years, 6 months 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 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 var kHundredChars = '';
Devlin 2017/06/12 20:15:05 do we care what these chars are? If not, maybe va
ncarter (slow) 2017/06/12 22:52:08 Removed -- this was all copypasta from ../write_da
6 for (var i = 0; i < 10; i++) {
7 kHundredChars += '0123456789';
8 }
9
10 // Opens the filesystem and returns a Promise that resolves to the opened
11 // filesystem.
12 function GetFileSystem(type, size) {
13 return new Promise(
14 (resolve, reject) =>
15 webkitRequestFileSystem(type, size, resolve, reject));
16 }
17
18 // Returns a .then()-chainable handler that accepts a fileystem, creates a file,
19 // and returns a Promise that resolves to the successfully created file.
20 function CreateFile(filename) {
21 return (filesystem) => new Promise(
22 (resolve, reject) => filesystem.root.getFile(
23 filename, {create: true}, resolve, reject));
24 }
25
26 // Returns a .then()-chainable handler that accepts a filesystem file, appends
27 // |numChars| to it, and returns a Promise that resolves to the file once the
28 // append operation is successful.
29 function AppendDataToFile(numChars) {
30 return ((fileEntry) => {
Devlin 2017/06/12 20:15:05 Hmm... where's the first paren closed? Am I missi
ncarter (slow) 2017/06/12 22:52:07 Whoops! Serves me right for trying to rejigger thi
31 return new Promise((resolve, reject) => {
32 fileEntry.createWriter((fileWriter) => {
33 // FileWriter's onwriteend resolves the promise; onerror rejects it.
34 fileWriter.onwriteend = (e) => resolve(fileEntry);
35 fileWriter.onerror = reject;
36
37 fileWriter.seek(fileWriter.length);
38 var str = '';
39
40 // Avoid many loops for large data packets.
Devlin 2017/06/12 20:15:05 or, here just: str = 'a'.repeat(numChars);
ncarter (slow) 2017/06/12 22:52:07 Much simpler! Done.
41 var iterations = Math.floor(numChars / 100);
42 for (var i = 0; i < iterations; ++i) {
43 str += kHundredChars;
44 }
45
46 iterations = numChars % 100;
47 for (var i = 0; i < iterations; ++i) {
48 str += 'a';
49 }
50
51 var blob = new Blob([str], {type: 'text/plain'});
52 fileWriter.write(blob);
53 }, reject);
54 });
55 }
56 }
57
58 // Entry point to be called via ExecuteScript in the browser test C++ code.
59 //
60 // Asynchronously opens writes |numChars| to the filesystem. Returns a Promise
61 // that resolves upon completion.
62 function HostedAppWriteData(type, numChars) {
63 return GetFileSystem(type, 16384)
64 .then(CreateFile('test.txt'))
65 .then(AppendDataToFile(numChars));
66 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698