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

Side by Side Diff: trunk/src/webkit/browser/fileapi/quota/quota_reservation_manager_unittest.cc

Issue 64883003: Revert 233815 "Quota: Implement QuotaBackendImpl" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/browser/fileapi/quota/quota_reservation_manager.h" 5 #include "webkit/browser/fileapi/quota/quota_reservation_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webkit/browser/fileapi/quota/open_file_handle.h" 14 #include "webkit/browser/fileapi/quota/open_file_handle.h"
15 #include "webkit/browser/fileapi/quota/quota_reservation.h" 15 #include "webkit/browser/fileapi/quota/quota_reservation.h"
16 16
17 namespace fileapi { 17 namespace fileapi {
18 18
19 namespace { 19 namespace {
20 20
21 const char kOrigin[] = "http://example.com"; 21 const char kOrigin[] = "http://example.com";
22 const FileSystemType kType = kFileSystemTypeTemporary; 22 const FileSystemType kType = kFileSystemTypeTemporary;
23 const int64 kInitialFileSize = 30; 23 const int64 kInitialFileSize = 30;
24 24
25 typedef QuotaReservationManager::ReserveQuotaCallback ReserveQuotaCallback; 25 typedef QuotaReservationManager::ReserveQuotaCallback ReserveQuotaCallback;
26 typedef QuotaReservationManager::StatusCallback StatusCallback;
26 27
27 class FakeBackend : public QuotaReservationManager::QuotaBackend { 28 class FakeBackend : public QuotaReservationManager::QuotaBackend {
28 public: 29 public:
29 FakeBackend() 30 FakeBackend()
30 : on_memory_usage_(0), 31 : on_memory_usage_(0),
31 on_disk_usage_(0) {} 32 on_disk_usage_(0) {}
32 virtual ~FakeBackend() {} 33 virtual ~FakeBackend() {}
33 34
34 virtual void ReserveQuota(const GURL& origin, 35 virtual void ReserveQuota(const GURL& origin,
35 FileSystemType type, 36 FileSystemType type,
(...skipping 11 matching lines...) Expand all
47 FileSystemType type, 48 FileSystemType type,
48 int64 size) OVERRIDE { 49 int64 size) OVERRIDE {
49 EXPECT_LE(0, size); 50 EXPECT_LE(0, size);
50 EXPECT_EQ(GURL(kOrigin), origin); 51 EXPECT_EQ(GURL(kOrigin), origin);
51 EXPECT_EQ(kType, type); 52 EXPECT_EQ(kType, type);
52 on_memory_usage_ -= size; 53 on_memory_usage_ -= size;
53 } 54 }
54 55
55 virtual void CommitQuotaUsage(const GURL& origin, 56 virtual void CommitQuotaUsage(const GURL& origin,
56 FileSystemType type, 57 FileSystemType type,
57 int64 delta) OVERRIDE { 58 int64 delta,
59 const StatusCallback& callback) OVERRIDE {
58 EXPECT_EQ(GURL(kOrigin), origin); 60 EXPECT_EQ(GURL(kOrigin), origin);
59 EXPECT_EQ(kType, type); 61 EXPECT_EQ(kType, type);
60 on_disk_usage_ += delta; 62 on_disk_usage_ += delta;
63 base::MessageLoopProxy::current()->PostTask(
64 FROM_HERE, base::Bind(callback, base::PLATFORM_FILE_OK));
61 } 65 }
62 66
63 virtual void IncrementDirtyCount(const GURL& origin, 67 virtual void IncreaseDirtyCount(const GURL& origin,
64 FileSystemType type) OVERRIDE {} 68 FileSystemType type) OVERRIDE {}
65 virtual void DecrementDirtyCount(const GURL& origin, 69 virtual void DecreaseDirtyCount(const GURL& origin,
66 FileSystemType type) OVERRIDE {} 70 FileSystemType type) OVERRIDE {}
67 71
68 int64 on_memory_usage() { return on_memory_usage_; } 72 int64 on_memory_usage() { return on_memory_usage_; }
69 int64 on_disk_usage() { return on_disk_usage_; } 73 int64 on_disk_usage() { return on_disk_usage_; }
70 74
71 private: 75 private:
72 int64 on_memory_usage_; 76 int64 on_memory_usage_;
73 int64 on_disk_usage_; 77 int64 on_disk_usage_;
74 78
75 DISALLOW_COPY_AND_ASSIGN(FakeBackend); 79 DISALLOW_COPY_AND_ASSIGN(FakeBackend);
76 }; 80 };
(...skipping 18 matching lines...) Expand all
95 class QuotaReservationManagerTest : public testing::Test { 99 class QuotaReservationManagerTest : public testing::Test {
96 public: 100 public:
97 QuotaReservationManagerTest() {} 101 QuotaReservationManagerTest() {}
98 virtual ~QuotaReservationManagerTest() {} 102 virtual ~QuotaReservationManagerTest() {}
99 103
100 virtual void SetUp() OVERRIDE { 104 virtual void SetUp() OVERRIDE {
101 ASSERT_TRUE(work_dir_.CreateUniqueTempDir()); 105 ASSERT_TRUE(work_dir_.CreateUniqueTempDir());
102 file_path_ = work_dir_.path().Append(FILE_PATH_LITERAL("hoge")); 106 file_path_ = work_dir_.path().Append(FILE_PATH_LITERAL("hoge"));
103 SetFileSize(kInitialFileSize); 107 SetFileSize(kInitialFileSize);
104 108
105 scoped_ptr<QuotaReservationManager::QuotaBackend> backend(new FakeBackend); 109 fake_backend_.reset(new FakeBackend);
106 reservation_manager_.reset(new QuotaReservationManager(backend.Pass())); 110 reservation_manager_.reset(new QuotaReservationManager(
111 fake_backend_.get()));
107 } 112 }
108 113
109 virtual void TearDown() OVERRIDE { 114 virtual void TearDown() OVERRIDE {
110 reservation_manager_.reset(); 115 reservation_manager_.reset();
116 fake_backend_.reset();
111 } 117 }
112 118
113 int64 GetFileSize() { 119 int64 GetFileSize() {
114 int64 size = 0; 120 int64 size = 0;
115 file_util::GetFileSize(file_path_, &size); 121 file_util::GetFileSize(file_path_, &size);
116 return size; 122 return size;
117 } 123 }
118 124
119 void SetFileSize(int64 size) { 125 void SetFileSize(int64 size) {
120 bool created = false; 126 bool created = false;
121 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 127 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED;
122 base::PlatformFile file = CreatePlatformFile( 128 base::PlatformFile file = CreatePlatformFile(
123 file_path_, 129 file_path_,
124 base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE, 130 base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE,
125 &created, &error); 131 &created, &error);
126 ASSERT_EQ(base::PLATFORM_FILE_OK, error); 132 ASSERT_EQ(base::PLATFORM_FILE_OK, error);
127 ASSERT_TRUE(base::TruncatePlatformFile(file, size)); 133 ASSERT_TRUE(base::TruncatePlatformFile(file, size));
128 ASSERT_TRUE(base::ClosePlatformFile(file)); 134 ASSERT_TRUE(base::ClosePlatformFile(file));
129 } 135 }
130 136
131 void ExtendFileTo(int64 size) { 137 void ExtendFileTo(int64 size) {
132 if (GetFileSize() < size) 138 if (GetFileSize() < size)
133 SetFileSize(size); 139 SetFileSize(size);
134 } 140 }
135 141
136 FakeBackend* fake_backend() { 142 FakeBackend* fake_backend() {
137 return static_cast<FakeBackend*>(reservation_manager_->backend_.get()); 143 return fake_backend_.get();
138 } 144 }
139 145
140 QuotaReservationManager* reservation_manager() { 146 QuotaReservationManager* reservation_manager() {
141 return reservation_manager_.get(); 147 return reservation_manager_.get();
142 } 148 }
143 149
144 const base::FilePath& file_path() const { 150 const base::FilePath& file_path() const {
145 return file_path_; 151 return file_path_;
146 } 152 }
147 153
148 private: 154 private:
149 base::MessageLoop message_loop_; 155 base::MessageLoop message_loop_;
150 base::ScopedTempDir work_dir_; 156 base::ScopedTempDir work_dir_;
151 base::FilePath file_path_; 157 base::FilePath file_path_;
158 scoped_ptr<FakeBackend> fake_backend_;
152 scoped_ptr<QuotaReservationManager> reservation_manager_; 159 scoped_ptr<QuotaReservationManager> reservation_manager_;
153 160
154 DISALLOW_COPY_AND_ASSIGN(QuotaReservationManagerTest); 161 DISALLOW_COPY_AND_ASSIGN(QuotaReservationManagerTest);
155 }; 162 };
156 163
157 TEST_F(QuotaReservationManagerTest, BasicTest) { 164 TEST_F(QuotaReservationManagerTest, BasicTest) {
158 GURL origin(kOrigin); 165 GURL origin(kOrigin);
159 FileSystemType type = kType; 166 FileSystemType type = kType;
160 167
161 // Create Reservation channel for the origin and type. 168 // Create Reservation channel for the origin and type.
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 356
350 EXPECT_EQ(400, GetFileSize()); 357 EXPECT_EQ(400, GetFileSize());
351 EXPECT_EQ(0, fake_backend()->on_memory_usage()); 358 EXPECT_EQ(0, fake_backend()->on_memory_usage());
352 EXPECT_EQ(400 - kInitialFileSize, fake_backend()->on_disk_usage()); 359 EXPECT_EQ(400 - kInitialFileSize, fake_backend()->on_disk_usage());
353 } 360 }
354 361
355 // TODO(tzik): Add Truncate test. 362 // TODO(tzik): Add Truncate test.
356 // TODO(tzik): Add PluginCrash test and DropReservationManager test. 363 // TODO(tzik): Add PluginCrash test and DropReservationManager test.
357 364
358 } // namespace fileapi 365 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698