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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 | |
9 #include "base/file_util.h" | 7 #include "base/file_util.h" |
10 #include "base/memory/scoped_callback_factory.h" | 8 #include "base/memory/scoped_callback_factory.h" |
11 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/scoped_temp_dir.h" | 10 #include "base/memory/scoped_temp_dir.h" |
13 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
14 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
15 #include "base/stl_util-inl.h" | 13 #include "base/stl_util-inl.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaError.
h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaError.
h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaType.h
" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaType.h
" |
18 #include "webkit/quota/mock_storage_client.h" | 17 #include "webkit/quota/mock_storage_client.h" |
19 #include "webkit/quota/quota_database.h" | 18 #include "webkit/quota/quota_database.h" |
20 #include "webkit/quota/quota_manager.h" | 19 #include "webkit/quota/quota_manager.h" |
21 | 20 |
22 using base::MessageLoopProxy; | 21 using base::MessageLoopProxy; |
23 using WebKit::WebStorageQuotaError; | 22 using WebKit::WebStorageQuotaError; |
24 using WebKit::WebStorageQuotaType; | 23 using WebKit::WebStorageQuotaType; |
25 | 24 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 callback_factory_.NewCallback( | 124 callback_factory_.NewCallback( |
126 &QuotaManagerTest::DidGetHostUsage)); | 125 &QuotaManagerTest::DidGetHostUsage)); |
127 } | 126 } |
128 | 127 |
129 void RunAdditionalUsageAndQuotaTask(const GURL& origin, StorageType type) { | 128 void RunAdditionalUsageAndQuotaTask(const GURL& origin, StorageType type) { |
130 quota_manager_->GetUsageAndQuota(origin, type, | 129 quota_manager_->GetUsageAndQuota(origin, type, |
131 callback_factory_.NewCallback( | 130 callback_factory_.NewCallback( |
132 &QuotaManagerTest::DidGetUsageAndQuotaAdditional)); | 131 &QuotaManagerTest::DidGetUsageAndQuotaAdditional)); |
133 } | 132 } |
134 | 133 |
| 134 void DeleteOriginData(QuotaClient* client, |
| 135 const GURL& origin, |
| 136 StorageType type) { |
| 137 quota_status_ = kQuotaStatusUnknown; |
| 138 client->DeleteOriginData(origin, type, |
| 139 callback_factory_.NewCallback( |
| 140 &QuotaManagerTest::DidDelete)); |
| 141 } |
| 142 |
135 void DidGetUsageAndQuota(QuotaStatusCode status, int64 usage, int64 quota) { | 143 void DidGetUsageAndQuota(QuotaStatusCode status, int64 usage, int64 quota) { |
136 quota_status_ = status; | 144 quota_status_ = status; |
137 usage_ = usage; | 145 usage_ = usage; |
138 quota_ = quota; | 146 quota_ = quota; |
139 } | 147 } |
140 | 148 |
141 void DidGetQuota(QuotaStatusCode status, int64 quota) { | 149 void DidGetQuota(QuotaStatusCode status, int64 quota) { |
142 quota_status_ = status; | 150 quota_status_ = status; |
143 quota_ = quota; | 151 quota_ = quota; |
144 } | 152 } |
145 | 153 |
146 void DidGetHostQuota(QuotaStatusCode status, | 154 void DidGetHostQuota(QuotaStatusCode status, |
147 const std::string& host, int64 quota) { | 155 const std::string& host, int64 quota) { |
148 quota_status_ = status; | 156 quota_status_ = status; |
149 host_ = host; | 157 host_ = host; |
150 quota_ = quota; | 158 quota_ = quota; |
151 } | 159 } |
152 | 160 |
153 void DidGetGlobalUsage(int64 usage) { | 161 void DidGetGlobalUsage(int64 usage) { |
154 usage_ = usage; | 162 usage_ = usage; |
155 } | 163 } |
156 | 164 |
157 void DidGetHostUsage(const std::string&, int64 usage) { | 165 void DidGetHostUsage(const std::string&, int64 usage) { |
158 usage_ = usage; | 166 usage_ = usage; |
159 } | 167 } |
160 | 168 |
| 169 void DidDelete(QuotaStatusCode status) { |
| 170 quota_status_ = status; |
| 171 } |
| 172 |
161 void set_additional_callback_count(int c) { additional_callback_count_ = c; } | 173 void set_additional_callback_count(int c) { additional_callback_count_ = c; } |
162 int additional_callback_count() const { return additional_callback_count_; } | 174 int additional_callback_count() const { return additional_callback_count_; } |
163 void DidGetUsageAndQuotaAdditional( | 175 void DidGetUsageAndQuotaAdditional( |
164 QuotaStatusCode status, int64 usage, int64 quota) { | 176 QuotaStatusCode status, int64 usage, int64 quota) { |
165 ++additional_callback_count_; | 177 ++additional_callback_count_; |
166 } | 178 } |
167 | 179 |
168 QuotaManager* quota_manager() const { return quota_manager_.get(); } | 180 QuotaManager* quota_manager() const { return quota_manager_.get(); } |
169 void set_quota_manager(QuotaManager* quota_manager) { | 181 void set_quota_manager(QuotaManager* quota_manager) { |
170 quota_manager_ = quota_manager; | 182 quota_manager_ = quota_manager; |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 EXPECT_EQ(usage(), 4000 + 50000); | 672 EXPECT_EQ(usage(), 4000 + 50000); |
661 | 673 |
662 client->ModifyMockOriginDataSize( | 674 client->ModifyMockOriginDataSize( |
663 GURL("http://buz.com/"), kStorageTypeTemporary, 900000000); | 675 GURL("http://buz.com/"), kStorageTypeTemporary, 900000000); |
664 | 676 |
665 GetHostUsage("buz.com", kStorageTypeTemporary); | 677 GetHostUsage("buz.com", kStorageTypeTemporary); |
666 MessageLoop::current()->RunAllPending(); | 678 MessageLoop::current()->RunAllPending(); |
667 EXPECT_EQ(usage(), 4000 + 50000 + 900000000); | 679 EXPECT_EQ(usage(), 4000 + 50000 + 900000000); |
668 } | 680 } |
669 | 681 |
| 682 TEST_F(QuotaManagerTest, GetUsage_WithDeleteOrigin) { |
| 683 static const MockOriginData kData[] = { |
| 684 { "http://foo.com/", kStorageTypeTemporary, 1 }, |
| 685 { "http://foo.com:1/", kStorageTypeTemporary, 20 }, |
| 686 { "http://foo.com/", kStorageTypePersistent, 300 }, |
| 687 { "http://bar.com/", kStorageTypeTemporary, 4000 }, |
| 688 }; |
| 689 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData)); |
| 690 RegisterClient(client); |
| 691 |
| 692 GetGlobalUsage(kStorageTypeTemporary); |
| 693 MessageLoop::current()->RunAllPending(); |
| 694 int64 predelete_global_tmp = usage(); |
| 695 |
| 696 GetHostUsage("foo.com", kStorageTypeTemporary); |
| 697 MessageLoop::current()->RunAllPending(); |
| 698 int64 predelete_host_tmp = usage(); |
| 699 |
| 700 GetHostUsage("foo.com", kStorageTypePersistent); |
| 701 MessageLoop::current()->RunAllPending(); |
| 702 int64 predelete_host_pers = usage(); |
| 703 |
| 704 DeleteOriginData(client, GURL("http://foo.com/"), kStorageTypeTemporary); |
| 705 MessageLoop::current()->RunAllPending(); |
| 706 EXPECT_EQ(kQuotaStatusOk, status()); |
| 707 |
| 708 GetGlobalUsage(kStorageTypeTemporary); |
| 709 MessageLoop::current()->RunAllPending(); |
| 710 EXPECT_EQ(predelete_global_tmp - 1, usage()); |
| 711 |
| 712 GetHostUsage("foo.com", kStorageTypeTemporary); |
| 713 MessageLoop::current()->RunAllPending(); |
| 714 EXPECT_EQ(predelete_host_tmp - 1, usage()); |
| 715 |
| 716 GetHostUsage("foo.com", kStorageTypePersistent); |
| 717 MessageLoop::current()->RunAllPending(); |
| 718 EXPECT_EQ(predelete_host_pers, usage()); |
| 719 } |
| 720 |
670 } // namespace quota | 721 } // namespace quota |
OLD | NEW |