summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/quota_file_util_unittest.cc
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-09 18:43:19 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-09 18:43:19 +0000
commit3277ef148b7c7975ec2b75b0bb18a1deef5ec85b (patch)
tree9f7e7f1fcf0d39c3697bf72cc30b1eecc3fa9ada /webkit/fileapi/quota_file_util_unittest.cc
parentcc3c7c09ea79fea70a7db1a083018fc9781b1a57 (diff)
downloadchromium_src-3277ef148b7c7975ec2b75b0bb18a1deef5ec85b.zip
chromium_src-3277ef148b7c7975ec2b75b0bb18a1deef5ec85b.tar.gz
chromium_src-3277ef148b7c7975ec2b75b0bb18a1deef5ec85b.tar.bz2
Notify the quota manager when write operation is made in FileSystem API.
BUG=74841 TEST=QuotaFileUtilTest.* Review URL: http://codereview.chromium.org/6903067 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84649 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/quota_file_util_unittest.cc')
-rw-r--r--webkit/fileapi/quota_file_util_unittest.cc69
1 files changed, 68 insertions, 1 deletions
diff --git a/webkit/fileapi/quota_file_util_unittest.cc b/webkit/fileapi/quota_file_util_unittest.cc
index bb76f65..4fad014 100644
--- a/webkit/fileapi/quota_file_util_unittest.cc
+++ b/webkit/fileapi/quota_file_util_unittest.cc
@@ -16,8 +16,14 @@
#include "webkit/fileapi/file_system_path_manager.h"
#include "webkit/fileapi/file_system_types.h"
#include "webkit/fileapi/file_system_usage_cache.h"
+#include "webkit/quota/quota_client.h"
+#include "webkit/quota/quota_manager.h"
using namespace fileapi;
+using quota::QuotaClient;
+using quota::QuotaManager;
+using quota::QuotaManagerProxy;
+using quota::StorageType;
namespace {
@@ -40,6 +46,30 @@ class MockFileSystemPathManager : public FileSystemPathManager {
FilePath test_filesystem_path_;
};
+class MockQuotaManager : public QuotaManager {
+ public:
+ MockQuotaManager(const FilePath& filesystem_path)
+ : QuotaManager(false /* is_incognito */,
+ filesystem_path,
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ base::MessageLoopProxy::CreateForCurrentThread()),
+ usage_(0) {}
+
+ int64 usage() const { return usage_; }
+
+ protected:
+ virtual void NotifyStorageModified(QuotaClient::ID client_id,
+ const GURL& origin,
+ StorageType type,
+ int64 delta) {
+ DCHECK(client_id == QuotaClient::kFileSystem);
+ usage_ += delta;
+ }
+
+ private:
+ int64 usage_;
+};
+
} // namespace (anonymous)
class QuotaFileUtilTest : public testing::Test {
@@ -55,6 +85,8 @@ class QuotaFileUtilTest : public testing::Test {
usage_file_path_ = Path(FileSystemUsageCache::kUsageFileName);
FileSystemUsageCache::UpdateUsage(usage_file_path_, 0);
+
+ quota_manager_ = new MockQuotaManager(filesystem_dir_);
}
protected:
@@ -62,7 +94,7 @@ class QuotaFileUtilTest : public testing::Test {
FileSystemOperationContext *context = new FileSystemOperationContext(
new FileSystemContext(base::MessageLoopProxy::CreateForCurrentThread(),
base::MessageLoopProxy::CreateForCurrentThread(),
- NULL, NULL, FilePath(), false,
+ NULL, quota_manager_proxy(), FilePath(), false,
true, true,
new MockFileSystemPathManager(filesystem_dir_)),
QuotaFileUtil::GetInstance());
@@ -99,11 +131,21 @@ class QuotaFileUtilTest : public testing::Test {
return FileSystemUsageCache::GetUsage(usage_file_path_);
}
+ int64 usage() const {
+ DCHECK(quota_manager_.get());
+ return quota_manager_->usage();
+ }
+ QuotaManagerProxy* quota_manager_proxy() const {
+ DCHECK(quota_manager_.get());
+ return quota_manager_->proxy();
+ }
+
private:
ScopedTempDir data_dir_;
FilePath filesystem_dir_;
FilePath usage_file_path_;
base::ScopedCallbackFactory<QuotaFileUtilTest> callback_factory_;
+ scoped_refptr<MockQuotaManager> quota_manager_;
DISALLOW_COPY_AND_ASSIGN(QuotaFileUtilTest);
};
@@ -147,6 +189,7 @@ TEST_F(QuotaFileUtilTest, Truncate) {
Path(file_name),
1020));
ASSERT_EQ(1020, GetCachedUsage());
+ ASSERT_EQ(1020, usage());
truncate_context.reset(NewContext());
truncate_context->set_allowed_bytes_growth(0);
@@ -155,6 +198,7 @@ TEST_F(QuotaFileUtilTest, Truncate) {
Path(file_name),
0));
ASSERT_EQ(0, GetCachedUsage());
+ ASSERT_EQ(0, usage());
truncate_context.reset(NewContext());
truncate_context->set_allowed_bytes_growth(1020);
@@ -163,6 +207,7 @@ TEST_F(QuotaFileUtilTest, Truncate) {
Path(file_name),
1021));
ASSERT_EQ(0, GetCachedUsage());
+ ASSERT_EQ(0, usage());
}
TEST_F(QuotaFileUtilTest, CopyFile) {
@@ -184,6 +229,7 @@ TEST_F(QuotaFileUtilTest, CopyFile) {
Path(from_file),
1020));
ASSERT_EQ(1020, GetCachedUsage());
+ ASSERT_EQ(1020, usage());
context.reset(NewContext());
context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
@@ -192,6 +238,7 @@ TEST_F(QuotaFileUtilTest, CopyFile) {
Path(obstacle_file),
1));
ASSERT_EQ(1021, GetCachedUsage());
+ ASSERT_EQ(1021, usage());
context.reset(NewContext());
context->set_allowed_bytes_growth(1020);
@@ -200,6 +247,7 @@ TEST_F(QuotaFileUtilTest, CopyFile) {
Path(from_file),
Path(to_file1)));
ASSERT_EQ(2041, GetCachedUsage());
+ ASSERT_EQ(2041, usage());
context.reset(NewContext());
context->set_allowed_bytes_growth(1019);
@@ -208,6 +256,7 @@ TEST_F(QuotaFileUtilTest, CopyFile) {
Path(from_file),
Path(to_file2)));
ASSERT_EQ(2041, GetCachedUsage());
+ ASSERT_EQ(2041, usage());
context.reset(NewContext());
context->set_allowed_bytes_growth(1019);
@@ -216,6 +265,7 @@ TEST_F(QuotaFileUtilTest, CopyFile) {
Path(from_file),
Path(obstacle_file)));
ASSERT_EQ(3060, GetCachedUsage());
+ ASSERT_EQ(3060, usage());
}
TEST_F(QuotaFileUtilTest, CopyDirectory) {
@@ -241,6 +291,7 @@ TEST_F(QuotaFileUtilTest, CopyDirectory) {
Path(from_file),
1020));
ASSERT_EQ(1020, GetCachedUsage());
+ ASSERT_EQ(1020, usage());
context.reset(NewContext());
context->set_allowed_bytes_growth(1020);
@@ -249,6 +300,7 @@ TEST_F(QuotaFileUtilTest, CopyDirectory) {
Path(from_dir),
Path(to_dir1)));
ASSERT_EQ(2040, GetCachedUsage());
+ ASSERT_EQ(2040, usage());
context.reset(NewContext());
context->set_allowed_bytes_growth(1019);
@@ -257,6 +309,7 @@ TEST_F(QuotaFileUtilTest, CopyDirectory) {
Path(from_dir),
Path(to_dir2)));
ASSERT_EQ(2040, GetCachedUsage());
+ ASSERT_EQ(2040, usage());
}
TEST_F(QuotaFileUtilTest, MoveFile) {
@@ -275,6 +328,7 @@ TEST_F(QuotaFileUtilTest, MoveFile) {
Path(from_file),
1020));
ASSERT_EQ(1020, GetCachedUsage());
+ ASSERT_EQ(1020, usage());
context.reset(NewContext());
context->set_allowed_bytes_growth(0);
@@ -283,6 +337,7 @@ TEST_F(QuotaFileUtilTest, MoveFile) {
Path(from_file),
Path(to_file)));
ASSERT_EQ(1020, GetCachedUsage());
+ ASSERT_EQ(1020, usage());
ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created));
ASSERT_TRUE(created);
@@ -296,6 +351,7 @@ TEST_F(QuotaFileUtilTest, MoveFile) {
Path(from_file),
1020));
ASSERT_EQ(2040, GetCachedUsage());
+ ASSERT_EQ(2040, usage());
context.reset(NewContext());
context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
@@ -304,6 +360,7 @@ TEST_F(QuotaFileUtilTest, MoveFile) {
Path(obstacle_file),
1));
ASSERT_EQ(2041, GetCachedUsage());
+ ASSERT_EQ(2041, usage());
context.reset(NewContext());
context->set_allowed_bytes_growth(0);
@@ -312,6 +369,7 @@ TEST_F(QuotaFileUtilTest, MoveFile) {
Path(from_file),
Path(obstacle_file)));
ASSERT_EQ(2040, GetCachedUsage());
+ ASSERT_EQ(2040, usage());
}
TEST_F(QuotaFileUtilTest, MoveDirectory) {
@@ -337,6 +395,7 @@ TEST_F(QuotaFileUtilTest, MoveDirectory) {
Path(from_file),
1020));
ASSERT_EQ(1020, GetCachedUsage());
+ ASSERT_EQ(1020, usage());
context.reset(NewContext());
context->set_allowed_bytes_growth(1020);
@@ -345,6 +404,7 @@ TEST_F(QuotaFileUtilTest, MoveDirectory) {
Path(from_dir),
Path(to_dir1)));
ASSERT_EQ(1020, GetCachedUsage());
+ ASSERT_EQ(1020, usage());
context.reset(NewContext());
ASSERT_EQ(base::PLATFORM_FILE_OK,
@@ -361,6 +421,7 @@ TEST_F(QuotaFileUtilTest, MoveDirectory) {
Path(from_file),
1020));
ASSERT_EQ(2040, GetCachedUsage());
+ ASSERT_EQ(2040, usage());
context.reset(NewContext());
context->set_allowed_bytes_growth(1019);
@@ -369,6 +430,7 @@ TEST_F(QuotaFileUtilTest, MoveDirectory) {
Path(from_dir),
Path(to_dir2)));
ASSERT_EQ(2040, GetCachedUsage());
+ ASSERT_EQ(2040, usage());
}
TEST_F(QuotaFileUtilTest, Remove) {
@@ -398,6 +460,7 @@ TEST_F(QuotaFileUtilTest, Remove) {
Path(file),
340));
ASSERT_EQ(340, GetCachedUsage());
+ ASSERT_EQ(340, usage());
context.reset(NewContext());
context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
@@ -406,6 +469,7 @@ TEST_F(QuotaFileUtilTest, Remove) {
Path(dfile1),
1020));
ASSERT_EQ(1360, GetCachedUsage());
+ ASSERT_EQ(1360, usage());
context.reset(NewContext());
context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
@@ -414,6 +478,7 @@ TEST_F(QuotaFileUtilTest, Remove) {
Path(dfile2),
120));
ASSERT_EQ(1480, GetCachedUsage());
+ ASSERT_EQ(1480, usage());
context.reset(NewContext());
context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
@@ -422,6 +487,7 @@ TEST_F(QuotaFileUtilTest, Remove) {
Path(file),
false));
ASSERT_EQ(1140, GetCachedUsage());
+ ASSERT_EQ(1140, usage());
context.reset(NewContext());
context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
@@ -430,4 +496,5 @@ TEST_F(QuotaFileUtilTest, Remove) {
Path(dir),
true));
ASSERT_EQ(0, GetCachedUsage());
+ ASSERT_EQ(0, usage());
}