| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stdint.h> |
| 6 |
| 5 #include <map> | 7 #include <map> |
| 6 #include <set> | 8 #include <set> |
| 7 | 9 |
| 8 #include "base/bind.h" | 10 #include "base/bind.h" |
| 9 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 10 #include "content/browser/appcache/appcache_quota_client.h" | 12 #include "content/browser/appcache/appcache_quota_client.h" |
| 11 #include "content/browser/appcache/mock_appcache_service.h" | 13 #include "content/browser/appcache/mock_appcache_service.h" |
| 12 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 16 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 29 : kOriginA("http://host"), | 31 : kOriginA("http://host"), |
| 30 kOriginB("http://host:8000"), | 32 kOriginB("http://host:8000"), |
| 31 kOriginOther("http://other"), | 33 kOriginOther("http://other"), |
| 32 usage_(0), | 34 usage_(0), |
| 33 delete_status_(storage::kQuotaStatusUnknown), | 35 delete_status_(storage::kQuotaStatusUnknown), |
| 34 num_get_origin_usage_completions_(0), | 36 num_get_origin_usage_completions_(0), |
| 35 num_get_origins_completions_(0), | 37 num_get_origins_completions_(0), |
| 36 num_delete_origins_completions_(0), | 38 num_delete_origins_completions_(0), |
| 37 weak_factory_(this) {} | 39 weak_factory_(this) {} |
| 38 | 40 |
| 39 int64 GetOriginUsage(storage::QuotaClient* client, | 41 int64_t GetOriginUsage(storage::QuotaClient* client, |
| 40 const GURL& origin, | 42 const GURL& origin, |
| 41 storage::StorageType type) { | 43 storage::StorageType type) { |
| 42 usage_ = -1; | 44 usage_ = -1; |
| 43 AsyncGetOriginUsage(client, origin, type); | 45 AsyncGetOriginUsage(client, origin, type); |
| 44 base::RunLoop().RunUntilIdle(); | 46 base::RunLoop().RunUntilIdle(); |
| 45 return usage_; | 47 return usage_; |
| 46 } | 48 } |
| 47 | 49 |
| 48 const std::set<GURL>& GetOriginsForType(storage::QuotaClient* client, | 50 const std::set<GURL>& GetOriginsForType(storage::QuotaClient* client, |
| 49 storage::StorageType type) { | 51 storage::StorageType type) { |
| 50 origins_.clear(); | 52 origins_.clear(); |
| 51 AsyncGetOriginsForType(client, type); | 53 AsyncGetOriginsForType(client, type); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 101 |
| 100 void AsyncDeleteOriginData(storage::QuotaClient* client, | 102 void AsyncDeleteOriginData(storage::QuotaClient* client, |
| 101 storage::StorageType type, | 103 storage::StorageType type, |
| 102 const GURL& origin) { | 104 const GURL& origin) { |
| 103 client->DeleteOriginData( | 105 client->DeleteOriginData( |
| 104 origin, type, | 106 origin, type, |
| 105 base::Bind(&AppCacheQuotaClientTest::OnDeleteOriginDataComplete, | 107 base::Bind(&AppCacheQuotaClientTest::OnDeleteOriginDataComplete, |
| 106 weak_factory_.GetWeakPtr())); | 108 weak_factory_.GetWeakPtr())); |
| 107 } | 109 } |
| 108 | 110 |
| 109 void SetUsageMapEntry(const GURL& origin, int64 usage) { | 111 void SetUsageMapEntry(const GURL& origin, int64_t usage) { |
| 110 mock_service_.storage()->usage_map_[origin] = usage; | 112 mock_service_.storage()->usage_map_[origin] = usage; |
| 111 } | 113 } |
| 112 | 114 |
| 113 AppCacheQuotaClient* CreateClient() { | 115 AppCacheQuotaClient* CreateClient() { |
| 114 return new AppCacheQuotaClient(&mock_service_); | 116 return new AppCacheQuotaClient(&mock_service_); |
| 115 } | 117 } |
| 116 | 118 |
| 117 void Call_NotifyAppCacheReady(AppCacheQuotaClient* client) { | 119 void Call_NotifyAppCacheReady(AppCacheQuotaClient* client) { |
| 118 client->NotifyAppCacheReady(); | 120 client->NotifyAppCacheReady(); |
| 119 } | 121 } |
| 120 | 122 |
| 121 void Call_NotifyAppCacheDestroyed(AppCacheQuotaClient* client) { | 123 void Call_NotifyAppCacheDestroyed(AppCacheQuotaClient* client) { |
| 122 client->NotifyAppCacheDestroyed(); | 124 client->NotifyAppCacheDestroyed(); |
| 123 } | 125 } |
| 124 | 126 |
| 125 void Call_OnQuotaManagerDestroyed(AppCacheQuotaClient* client) { | 127 void Call_OnQuotaManagerDestroyed(AppCacheQuotaClient* client) { |
| 126 client->OnQuotaManagerDestroyed(); | 128 client->OnQuotaManagerDestroyed(); |
| 127 } | 129 } |
| 128 | 130 |
| 129 protected: | 131 protected: |
| 130 void OnGetOriginUsageComplete(int64 usage) { | 132 void OnGetOriginUsageComplete(int64_t usage) { |
| 131 ++num_get_origin_usage_completions_; | 133 ++num_get_origin_usage_completions_; |
| 132 usage_ = usage; | 134 usage_ = usage; |
| 133 } | 135 } |
| 134 | 136 |
| 135 void OnGetOriginsComplete(const std::set<GURL>& origins) { | 137 void OnGetOriginsComplete(const std::set<GURL>& origins) { |
| 136 ++num_get_origins_completions_; | 138 ++num_get_origins_completions_; |
| 137 origins_ = origins; | 139 origins_ = origins; |
| 138 } | 140 } |
| 139 | 141 |
| 140 void OnDeleteOriginDataComplete(storage::QuotaStatusCode status) { | 142 void OnDeleteOriginDataComplete(storage::QuotaStatusCode status) { |
| 141 ++num_delete_origins_completions_; | 143 ++num_delete_origins_completions_; |
| 142 delete_status_ = status; | 144 delete_status_ = status; |
| 143 } | 145 } |
| 144 | 146 |
| 145 base::MessageLoop message_loop_; | 147 base::MessageLoop message_loop_; |
| 146 int64 usage_; | 148 int64_t usage_; |
| 147 std::set<GURL> origins_; | 149 std::set<GURL> origins_; |
| 148 storage::QuotaStatusCode delete_status_; | 150 storage::QuotaStatusCode delete_status_; |
| 149 int num_get_origin_usage_completions_; | 151 int num_get_origin_usage_completions_; |
| 150 int num_get_origins_completions_; | 152 int num_get_origins_completions_; |
| 151 int num_delete_origins_completions_; | 153 int num_delete_origins_completions_; |
| 152 MockAppCacheService mock_service_; | 154 MockAppCacheService mock_service_; |
| 153 base::WeakPtrFactory<AppCacheQuotaClientTest> weak_factory_; | 155 base::WeakPtrFactory<AppCacheQuotaClientTest> weak_factory_; |
| 154 }; | 156 }; |
| 155 | 157 |
| 156 | 158 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 // A real completion callback from the service should | 416 // A real completion callback from the service should |
| 415 // be dropped if it comes in after NotifyAppCacheDestroyed. | 417 // be dropped if it comes in after NotifyAppCacheDestroyed. |
| 416 base::RunLoop().RunUntilIdle(); | 418 base::RunLoop().RunUntilIdle(); |
| 417 EXPECT_EQ(1, num_delete_origins_completions_); | 419 EXPECT_EQ(1, num_delete_origins_completions_); |
| 418 EXPECT_EQ(storage::kQuotaErrorAbort, delete_status_); | 420 EXPECT_EQ(storage::kQuotaErrorAbort, delete_status_); |
| 419 | 421 |
| 420 Call_OnQuotaManagerDestroyed(client); | 422 Call_OnQuotaManagerDestroyed(client); |
| 421 } | 423 } |
| 422 | 424 |
| 423 } // namespace content | 425 } // namespace content |
| OLD | NEW |