OLD | NEW |
---|---|
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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 dom_namespace = context_->GetStorageNamespace(kSessionStorageNamespaceId); | 261 dom_namespace = context_->GetStorageNamespace(kSessionStorageNamespaceId); |
262 area = dom_namespace->OpenStorageArea(kOrigin); | 262 area = dom_namespace->OpenStorageArea(kOrigin); |
263 read_value = area->GetItem(kKey); | 263 read_value = area->GetItem(kKey); |
264 EXPECT_TRUE(read_value.is_null()); | 264 EXPECT_TRUE(read_value.is_null()); |
265 dom_namespace->CloseStorageArea(area); | 265 dom_namespace->CloseStorageArea(area); |
266 context_->Shutdown(); | 266 context_->Shutdown(); |
267 context_ = NULL; | 267 context_ = NULL; |
268 base::MessageLoop::current()->RunUntilIdle(); | 268 base::MessageLoop::current()->RunUntilIdle(); |
269 } | 269 } |
270 | 270 |
271 TEST_F(DOMStorageContextImplTest, PurgeMemory) { | |
michaeln
2016/05/16 21:32:42
Thanx for adding the tests!
ssid
2016/05/16 23:02:26
Acknowledged.
| |
272 auto dom_namespace = context_->GetStorageNamespace(kLocalStorageNamespaceId); | |
273 auto area1 = dom_namespace->OpenStorageArea(kOrigin); | |
274 area1->InitialImportIfNeeded(); | |
275 | |
276 // PURGE_UNOPENED does not delete the open area. | |
277 context_->PurgeMemory(DOMStorageContextImpl::PURGE_UNOPENED); | |
278 EXPECT_EQ(1u, dom_namespace->GetUsageStatistics().total_area_count); | |
279 EXPECT_EQ(0u, dom_namespace->GetUsageStatistics().inactive_area_count); | |
280 | |
281 // PURGE_UNOPENED deletes the unopened area. | |
282 dom_namespace->CloseStorageArea(area1); | |
283 EXPECT_EQ(1u, dom_namespace->GetUsageStatistics().inactive_area_count); | |
284 context_->PurgeMemory(DOMStorageContextImpl::PURGE_UNOPENED); | |
285 EXPECT_EQ(0u, dom_namespace->GetUsageStatistics().total_area_count); | |
286 | |
287 // Add an item to the database and commit changes, and keep it open. So, cache | |
288 // is kept alive. | |
289 auto area2 = dom_namespace->OpenStorageArea(kOrigin); | |
290 base::NullableString16 old_value; | |
291 area2->SetItem(kKey, kValue, &old_value); | |
292 // Call commit directly instead of posting task. | |
293 area2->CommitChanges(area2->commit_batch_.get()); | |
294 area2->commit_batch_ = nullptr; | |
295 | |
296 // PURGE_AGGRESSIVE clears the cache in the open area. | |
297 EXPECT_NE(0u, dom_namespace->GetUsageStatistics().total_cache_size); | |
298 context_->PurgeMemory(DOMStorageContextImpl::PURGE_AGGRESSIVE); | |
299 EXPECT_EQ(0u, dom_namespace->GetUsageStatistics().total_cache_size); | |
300 } | |
301 | |
271 } // namespace content | 302 } // namespace content |
OLD | NEW |