summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/file_system_usage_cache_unittest.cc
diff options
context:
space:
mode:
authordmikurube@google.com <dmikurube@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-02 19:13:53 +0000
committerdmikurube@google.com <dmikurube@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-02 19:13:53 +0000
commitd1ca70cfc72762d6ff489f2558e6eb1333cbabf2 (patch)
tree667d1630cd6d51842b83da12b6de2e39a752882d /webkit/fileapi/file_system_usage_cache_unittest.cc
parentb05168f7a95d5a2841297e5947eccf5edcea804a (diff)
downloadchromium_src-d1ca70cfc72762d6ff489f2558e6eb1333cbabf2.zip
chromium_src-d1ca70cfc72762d6ff489f2558e6eb1333cbabf2.tar.gz
chromium_src-d1ca70cfc72762d6ff489f2558e6eb1333cbabf2.tar.bz2
Add a function for usage tracking. It's based on the bug 6426001.
BUG= TEST= Review URL: http://codereview.chromium.org/6453001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76578 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/file_system_usage_cache_unittest.cc')
-rw-r--r--webkit/fileapi/file_system_usage_cache_unittest.cc145
1 files changed, 145 insertions, 0 deletions
diff --git a/webkit/fileapi/file_system_usage_cache_unittest.cc b/webkit/fileapi/file_system_usage_cache_unittest.cc
new file mode 100644
index 0000000..f74bdbb
--- /dev/null
+++ b/webkit/fileapi/file_system_usage_cache_unittest.cc
@@ -0,0 +1,145 @@
+// Copyright (c) 2011 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.
+
+#include "webkit/fileapi/file_system_usage_cache.h"
+
+#include "base/basictypes.h"
+#include "base/file_util.h"
+#include "base/scoped_temp_dir.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using namespace fileapi;
+
+class FileSystemUsageCacheTest : public testing::Test {
+ public:
+ FileSystemUsageCacheTest() {}
+
+ void SetUp() {
+ ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
+ }
+
+protected:
+ FilePath GetUsageFilePath() {
+ return data_dir_.path().AppendASCII(FileSystemUsageCache::kUsageFileName);
+ }
+
+ private:
+ ScopedTempDir data_dir_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileSystemUsageCacheTest);
+};
+
+TEST_F(FileSystemUsageCacheTest, CreateTest) {
+ FilePath usage_file_path = GetUsageFilePath();
+ EXPECT_EQ(FileSystemUsageCache::kUsageFileSize,
+ FileSystemUsageCache::UpdateUsage(usage_file_path, 0));
+}
+
+TEST_F(FileSystemUsageCacheTest, SetSizeTest) {
+ static const int64 size = 240122;
+ FilePath usage_file_path = GetUsageFilePath();
+ ASSERT_EQ(FileSystemUsageCache::kUsageFileSize,
+ FileSystemUsageCache::UpdateUsage(usage_file_path, size));
+ EXPECT_EQ(size, FileSystemUsageCache::GetUsage(usage_file_path));
+}
+
+TEST_F(FileSystemUsageCacheTest, SetLargeSizeTest) {
+ static const int64 size = kint64max;
+ FilePath usage_file_path = GetUsageFilePath();
+ ASSERT_EQ(FileSystemUsageCache::kUsageFileSize,
+ FileSystemUsageCache::UpdateUsage(usage_file_path, size));
+ EXPECT_EQ(size, FileSystemUsageCache::GetUsage(usage_file_path));
+}
+
+TEST_F(FileSystemUsageCacheTest, IncAndGetSizeTest) {
+ FilePath usage_file_path = GetUsageFilePath();
+ ASSERT_EQ(FileSystemUsageCache::kUsageFileSize,
+ FileSystemUsageCache::UpdateUsage(usage_file_path, 98214));
+ ASSERT_EQ(true,
+ FileSystemUsageCache::IncrementDirty(usage_file_path));
+ EXPECT_EQ(-1, FileSystemUsageCache::GetUsage(usage_file_path));
+}
+
+TEST_F(FileSystemUsageCacheTest, DecAndGetSizeTest) {
+ static const int64 size = 71839;
+ FilePath usage_file_path = GetUsageFilePath();
+ ASSERT_EQ(FileSystemUsageCache::kUsageFileSize,
+ FileSystemUsageCache::UpdateUsage(usage_file_path, size));
+ // DecrementDirty for dirty = 0 is invalid. It returns false.
+ ASSERT_EQ(false,
+ FileSystemUsageCache::DecrementDirty(usage_file_path));
+ EXPECT_EQ(size, FileSystemUsageCache::GetUsage(usage_file_path));
+}
+
+TEST_F(FileSystemUsageCacheTest, IncDecAndGetSizeTest) {
+ static const int64 size = 198491;
+ FilePath usage_file_path = GetUsageFilePath();
+ ASSERT_EQ(FileSystemUsageCache::kUsageFileSize,
+ FileSystemUsageCache::UpdateUsage(usage_file_path, size));
+ ASSERT_EQ(true,
+ FileSystemUsageCache::IncrementDirty(usage_file_path));
+ ASSERT_EQ(true,
+ FileSystemUsageCache::DecrementDirty(usage_file_path));
+ EXPECT_EQ(size, FileSystemUsageCache::GetUsage(usage_file_path));
+}
+
+TEST_F(FileSystemUsageCacheTest, DecIncAndGetSizeTest) {
+ FilePath usage_file_path = GetUsageFilePath();
+ ASSERT_EQ(FileSystemUsageCache::kUsageFileSize,
+ FileSystemUsageCache::UpdateUsage(usage_file_path, 854238));
+ // DecrementDirty for dirty = 0 is invalid. It returns false.
+ ASSERT_EQ(false,
+ FileSystemUsageCache::DecrementDirty(usage_file_path));
+ ASSERT_EQ(true,
+ FileSystemUsageCache::IncrementDirty(usage_file_path));
+ // It tests DecrementDirty (which returns false) has no effect, i.e
+ // does not make dirty = -1 after DecrementDirty.
+ EXPECT_EQ(-1, FileSystemUsageCache::GetUsage(usage_file_path));
+}
+
+TEST_F(FileSystemUsageCacheTest, ManyIncsSameDecsAndGetSizeTest) {
+ static const int64 size = 82412;
+ FilePath usage_file_path = GetUsageFilePath();
+ ASSERT_EQ(FileSystemUsageCache::kUsageFileSize,
+ FileSystemUsageCache::UpdateUsage(usage_file_path, size));
+ for (int i = 0; i < 20; i++) {
+ ASSERT_EQ(true,
+ FileSystemUsageCache::IncrementDirty(usage_file_path));
+ }
+ for (int i = 0; i < 20; i++) {
+ ASSERT_EQ(true,
+ FileSystemUsageCache::DecrementDirty(usage_file_path));
+ }
+ EXPECT_EQ(size, FileSystemUsageCache::GetUsage(usage_file_path));
+}
+
+TEST_F(FileSystemUsageCacheTest, ManyIncsLessDecsAndGetSizeTest) {
+ FilePath usage_file_path = GetUsageFilePath();
+ ASSERT_EQ(FileSystemUsageCache::kUsageFileSize,
+ FileSystemUsageCache::UpdateUsage(usage_file_path, 19319));
+ for (int i = 0; i < 20; i++) {
+ ASSERT_EQ(true,
+ FileSystemUsageCache::IncrementDirty(usage_file_path));
+ }
+ for (int i = 0; i < 19; i++) {
+ ASSERT_EQ(true,
+ FileSystemUsageCache::DecrementDirty(usage_file_path));
+ }
+ EXPECT_EQ(-1, FileSystemUsageCache::GetUsage(usage_file_path));
+}
+
+TEST_F(FileSystemUsageCacheTest, GetSizeWithoutCacheFileTest) {
+ FilePath usage_file_path = GetUsageFilePath();
+ EXPECT_EQ(-1, FileSystemUsageCache::GetUsage(usage_file_path));
+}
+
+TEST_F(FileSystemUsageCacheTest, IncrementDirtyWithoutCacheFileTest) {
+ FilePath usage_file_path = GetUsageFilePath();
+ EXPECT_EQ(false, FileSystemUsageCache::IncrementDirty(usage_file_path));
+}
+
+TEST_F(FileSystemUsageCacheTest, DecrementDirtyWithoutCacheFileTest) {
+ FilePath usage_file_path = GetUsageFilePath();
+ EXPECT_EQ(false, FileSystemUsageCache::IncrementDirty(usage_file_path));
+}