OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <stack> | 5 #include <stack> |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 public: | 124 public: |
125 MockQuotaManager() | 125 MockQuotaManager() |
126 : QuotaManager(true /* is_incognito */, FilePath(), | 126 : QuotaManager(true /* is_incognito */, FilePath(), |
127 io_thread->message_loop_proxy(), | 127 io_thread->message_loop_proxy(), |
128 db_thread->message_loop_proxy(), | 128 db_thread->message_loop_proxy(), |
129 NULL), | 129 NULL), |
130 async_(false) {} | 130 async_(false) {} |
131 | 131 |
132 virtual void GetUsageAndQuota( | 132 virtual void GetUsageAndQuota( |
133 const GURL& origin, quota::StorageType type, | 133 const GURL& origin, quota::StorageType type, |
134 GetUsageAndQuotaCallback* callback) { | 134 const GetUsageAndQuotaCallback& callback) OVERRIDE { |
135 EXPECT_EQ(kOrigin, origin); | 135 EXPECT_EQ(kOrigin, origin); |
136 EXPECT_EQ(quota::kStorageTypeTemporary, type); | 136 EXPECT_EQ(quota::kStorageTypeTemporary, type); |
137 if (async_) { | 137 if (async_) { |
138 MessageLoop::current()->PostTask(FROM_HERE, | 138 MessageLoop::current()->PostTask(FROM_HERE, |
139 NewRunnableMethod(this, &MockQuotaManager::CallCallbackAndDelete, | 139 NewRunnableMethod(this, &MockQuotaManager::CallCallback, |
140 callback)); | 140 callback)); |
141 return; | 141 return; |
142 } | 142 } |
143 CallCallbackAndDelete(callback); | 143 CallCallback(callback); |
144 } | 144 } |
145 | 145 |
146 void CallCallbackAndDelete(GetUsageAndQuotaCallback* callback) { | 146 void CallCallback(const GetUsageAndQuotaCallback& callback) { |
147 callback->Run(quota::kQuotaStatusOk, 0, kMockQuota); | 147 callback.Run(quota::kQuotaStatusOk, 0, kMockQuota); |
148 delete callback; | |
149 } | 148 } |
150 | 149 |
151 bool async_; | 150 bool async_; |
152 }; | 151 }; |
153 | 152 |
154 class MockQuotaManagerProxy : public quota::QuotaManagerProxy { | 153 class MockQuotaManagerProxy : public quota::QuotaManagerProxy { |
155 public: | 154 public: |
156 MockQuotaManagerProxy() | 155 MockQuotaManagerProxy() |
157 : QuotaManagerProxy(NULL, NULL), | 156 : QuotaManagerProxy(NULL, NULL), |
158 notify_storage_accessed_count_(0), | 157 notify_storage_accessed_count_(0), |
159 notify_storage_modified_count_(0), | 158 notify_storage_modified_count_(0), |
160 last_delta_(0), | 159 last_delta_(0), |
161 mock_manager_(new MockQuotaManager) { | 160 mock_manager_(new MockQuotaManager) { |
162 manager_ = mock_manager_; | 161 manager_ = mock_manager_; |
163 } | 162 } |
164 | 163 |
165 virtual void NotifyStorageAccessed(quota::QuotaClient::ID client_id, | 164 virtual void NotifyStorageAccessed(quota::QuotaClient::ID client_id, |
166 const GURL& origin, | 165 const GURL& origin, |
167 quota::StorageType type) { | 166 quota::StorageType type) OVERRIDE { |
168 EXPECT_EQ(quota::QuotaClient::kAppcache, client_id); | 167 EXPECT_EQ(quota::QuotaClient::kAppcache, client_id); |
169 EXPECT_EQ(quota::kStorageTypeTemporary, type); | 168 EXPECT_EQ(quota::kStorageTypeTemporary, type); |
170 ++notify_storage_accessed_count_; | 169 ++notify_storage_accessed_count_; |
171 last_origin_ = origin; | 170 last_origin_ = origin; |
172 } | 171 } |
173 | 172 |
174 virtual void NotifyStorageModified(quota::QuotaClient::ID client_id, | 173 virtual void NotifyStorageModified(quota::QuotaClient::ID client_id, |
175 const GURL& origin, | 174 const GURL& origin, |
176 quota::StorageType type, | 175 quota::StorageType type, |
177 int64 delta) { | 176 int64 delta) OVERRIDE { |
178 EXPECT_EQ(quota::QuotaClient::kAppcache, client_id); | 177 EXPECT_EQ(quota::QuotaClient::kAppcache, client_id); |
179 EXPECT_EQ(quota::kStorageTypeTemporary, type); | 178 EXPECT_EQ(quota::kStorageTypeTemporary, type); |
180 ++notify_storage_modified_count_; | 179 ++notify_storage_modified_count_; |
181 last_origin_ = origin; | 180 last_origin_ = origin; |
182 last_delta_ = delta; | 181 last_delta_ = delta; |
183 } | 182 } |
184 | 183 |
185 // Not needed for our tests. | 184 // Not needed for our tests. |
186 virtual void RegisterClient(quota::QuotaClient* client) {} | 185 virtual void RegisterClient(quota::QuotaClient* client) OVERRIDE {} |
187 virtual void NotifyOriginInUse(const GURL& origin) {} | 186 virtual void NotifyOriginInUse(const GURL& origin) OVERRIDE {} |
188 virtual void NotifyOriginNoLongerInUse(const GURL& origin) {} | 187 virtual void NotifyOriginNoLongerInUse(const GURL& origin) OVERRIDE {} |
189 | 188 |
190 int notify_storage_accessed_count_; | 189 int notify_storage_accessed_count_; |
191 int notify_storage_modified_count_; | 190 int notify_storage_modified_count_; |
192 GURL last_origin_; | 191 GURL last_origin_; |
193 int last_delta_; | 192 int last_delta_; |
194 scoped_refptr<MockQuotaManager> mock_manager_; | 193 scoped_refptr<MockQuotaManager> mock_manager_; |
195 }; | 194 }; |
196 | 195 |
197 // Helper class run a test on our io_thread. The io_thread | 196 // Helper class run a test on our io_thread. The io_thread |
198 // is spun up once and reused for all tests. | 197 // is spun up once and reused for all tests. |
199 template <class Method> | 198 template <class Method> |
200 class WrapperTask : public Task { | 199 class WrapperTask : public Task { |
201 public: | 200 public: |
202 WrapperTask(AppCacheStorageImplTest* test, Method method) | 201 WrapperTask(AppCacheStorageImplTest* test, Method method) |
203 : test_(test), method_(method) { | 202 : test_(test), method_(method) { |
204 } | 203 } |
205 | 204 |
206 virtual void Run() { | 205 virtual void Run() OVERRIDE { |
207 test_->SetUpTest(); | 206 test_->SetUpTest(); |
208 | 207 |
209 // Ensure InitTask execution prior to conducting a test. | 208 // Ensure InitTask execution prior to conducting a test. |
210 test_->FlushDbThreadTasks(); | 209 test_->FlushDbThreadTasks(); |
211 | 210 |
212 // We also have to wait for InitTask completion call to be performed | 211 // We also have to wait for InitTask completion call to be performed |
213 // on the IO thread prior to running the test. Its guaranteed to be | 212 // on the IO thread prior to running the test. Its guaranteed to be |
214 // queued by this time. | 213 // queued by this time. |
215 MessageLoop::current()->PostTask(FROM_HERE, | 214 MessageLoop::current()->PostTask(FROM_HERE, |
216 NewRunnableFunction(&RunMethod, test_, method_)); | 215 NewRunnableFunction(&RunMethod, test_, method_)); |
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 &AppCacheStorageImplTest::FindMainResponseExclusionsInWorkingSet); | 1314 &AppCacheStorageImplTest::FindMainResponseExclusionsInWorkingSet); |
1316 } | 1315 } |
1317 | 1316 |
1318 // That's all folks! | 1317 // That's all folks! |
1319 | 1318 |
1320 } // namespace appcache | 1319 } // namespace appcache |
1321 | 1320 |
1322 // AppCacheStorageImplTest is expected to always live longer than the | 1321 // AppCacheStorageImplTest is expected to always live longer than the |
1323 // runnable methods. This lets us call NewRunnableMethod on its instances. | 1322 // runnable methods. This lets us call NewRunnableMethod on its instances. |
1324 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheStorageImplTest); | 1323 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheStorageImplTest); |
OLD | NEW |