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

Unified Diff: chrome/test/data/extensions/storage_monitor/write_data/index.js

Issue 221933013: Show a notification when an ephemeral app consumes excessive disk space (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webkit_storage_monitor
Patch Set: Fix test failures Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/storage_monitor/write_data/index.js
diff --git a/chrome/test/data/extensions/storage_monitor/write_data/index.js b/chrome/test/data/extensions/storage_monitor/write_data/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..a6f4eb87e295d01d848e4440f62ca34a97a9ec64
--- /dev/null
+++ b/chrome/test/data/extensions/storage_monitor/write_data/index.js
@@ -0,0 +1,74 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var kHundredChars = '';
+var kTestFileName = 'test.txt';
+
+for (var i = 0; i < 10; i++) {
+ kHundredChars += '0123456789';
+}
+
+function FileSystemWriteError() {
+ chrome.test.fail('Filesystem write error');
+}
+
+// Appends 50 bytes of data to the file.
+function AppendDataToFile(fileEntry, numChars) {
+ fileEntry.createWriter(function(fileWriter) {
+
+ fileWriter.onwriteend = function(e) {
+ chrome.test.sendMessage('write_complete', null);
+ chrome.test.succeed();
+ chrome.app.window.current().close();
+ };
+
+ fileWriter.onerror = function(e) {
+ FileSystemWriteError();
+ };
+
+ fileWriter.seek(fileWriter.length);
+ var str = '';
+
+ // Avoid many loops for large data packets.
+ var iterations = Math.floor(numChars / 100);
+ for (var i = 0; i < iterations; ++i) {
+ str += kHundredChars;
+ }
+
+ iterations = numChars % 100;
+ for (var i = 0; i < iterations; ++i) {
+ str += 'a';
+ }
+
+ var blob = new Blob([str], {type: 'text/plain'});
+ fileWriter.write(blob);
+ });
+}
+
+function WriteData(numChars) {
+ window.webkitRequestFileSystem(
+ PERSISTENT,
+ 16384,
+ function(fs) {
+ fs.root.getFile(
+ kTestFileName,
+ {create: true},
+ function(fileEntry) {
+ AppendDataToFile(fileEntry, numChars);
+ },
+ FileSystemWriteError);
+ }, FileSystemWriteError);
+}
+
+onload = function() {
+ chrome.test.sendMessage('launched', function(reply) {
+ var numChars = parseInt(reply);
+ if (isNaN(numChars)) {
+ chrome.test.fail('Expected number of chars from browser');
+ return;
+ }
+
+ WriteData(numChars);
+ });
+};

Powered by Google App Engine
This is Rietveld 408576698