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

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: Remove lame comment. 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 // Opens the filesystem and returns a Promise that resolves to the opened
6 // filesystem.
7 function GetFileSystem(type, size) {
8 return new Promise(
9 (resolve, reject) =>
10 webkitRequestFileSystem(type, size, resolve, reject));
11 }
12
13 // Returns a .then()-chainable handler that accepts a fileystem, creates a file,
14 // and returns a Promise that resolves to the successfully created file.
15 function CreateFile(filename) {
16 return (filesystem) => new Promise(
17 (resolve, reject) => filesystem.root.getFile(
18 filename, {create: true}, resolve, reject));
19 }
20
21 // Returns a .then()-chainable handler that accepts a filesystem file, appends
22 // |numChars| to it, and returns a Promise that resolves to the file once the
23 // append operation is successful.
24 function AppendDataToFile(numChars) {
25 return ((fileEntry) => {
26 return new Promise((resolve, reject) => {
27 fileEntry.createWriter((fileWriter) => {
28 // FileWriter's onwriteend resolves the promise; onerror rejects it.
29 fileWriter.onwriteend = (e) => resolve(fileEntry);
30 fileWriter.onerror = reject;
31 fileWriter.seek(fileWriter.length);
32
33 var str = 'a'.repeat(numChars);
34
35 var blob = new Blob([str], {type: 'text/plain'});
36 console.assert(blob.size == numChars);
37 fileWriter.write(blob);
38 }, reject);
39 });
40 });
41 }
42
43 // Entry point to be called via ExecuteScript in the browser test C++ code.
44 //
45 // Asynchronously opens writes |numChars| to the filesystem. Returns a Promise
46 // that resolves upon completion.
47 function HostedAppWriteData(type, numChars) {
48 return GetFileSystem(type, 16384)
49 .then(CreateFile('test.txt'))
50 .then(AppendDataToFile(numChars));
51 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698