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> | 5 #include <stdint.h> |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 data_size_ = 0; | 76 data_size_ = 0; |
77 } | 77 } |
78 | 78 |
79 private: | 79 private: |
80 void ScheduleUserCallback(int result) { | 80 void ScheduleUserCallback(int result) { |
81 base::ThreadTaskRunnerHandle::Get()->PostTask( | 81 base::ThreadTaskRunnerHandle::Get()->PostTask( |
82 FROM_HERE, base::Bind(&MockResponseReader::InvokeUserCompletionCallback, | 82 FROM_HERE, base::Bind(&MockResponseReader::InvokeUserCompletionCallback, |
83 weak_factory_.GetWeakPtr(), result)); | 83 weak_factory_.GetWeakPtr(), result)); |
84 } | 84 } |
85 | 85 |
86 scoped_ptr<net::HttpResponseInfo> info_; | 86 std::unique_ptr<net::HttpResponseInfo> info_; |
87 int info_size_; | 87 int info_size_; |
88 const char* data_; | 88 const char* data_; |
89 int data_size_; | 89 int data_size_; |
90 }; | 90 }; |
91 | 91 |
92 } // namespace | 92 } // namespace |
93 | 93 |
94 | 94 |
95 class AppCacheServiceImplTest : public testing::Test { | 95 class AppCacheServiceImplTest : public testing::Test { |
96 public: | 96 public: |
(...skipping 24 matching lines...) Expand all Loading... |
121 | 121 |
122 bool IsGroupStored(const GURL& manifest_url) { | 122 bool IsGroupStored(const GURL& manifest_url) { |
123 return mock_storage()->IsGroupForManifestStored(manifest_url); | 123 return mock_storage()->IsGroupForManifestStored(manifest_url); |
124 } | 124 } |
125 | 125 |
126 int CountPendingHelpers() { | 126 int CountPendingHelpers() { |
127 return service_->pending_helpers_.size(); | 127 return service_->pending_helpers_.size(); |
128 } | 128 } |
129 | 129 |
130 void SetupMockGroup() { | 130 void SetupMockGroup() { |
131 scoped_ptr<net::HttpResponseInfo> info(MakeMockResponseInfo()); | 131 std::unique_ptr<net::HttpResponseInfo> info(MakeMockResponseInfo()); |
132 const int kMockInfoSize = GetResponseInfoSize(info.get()); | 132 const int kMockInfoSize = GetResponseInfoSize(info.get()); |
133 | 133 |
134 // Create a mock group, cache, and entry and stuff them into mock storage. | 134 // Create a mock group, cache, and entry and stuff them into mock storage. |
135 scoped_refptr<AppCacheGroup> group( | 135 scoped_refptr<AppCacheGroup> group( |
136 new AppCacheGroup(service_->storage(), kManifestUrl, kMockGroupId)); | 136 new AppCacheGroup(service_->storage(), kManifestUrl, kMockGroupId)); |
137 scoped_refptr<AppCache> cache( | 137 scoped_refptr<AppCache> cache( |
138 new AppCache(service_->storage(), kMockCacheId)); | 138 new AppCache(service_->storage(), kMockCacheId)); |
139 cache->AddEntry( | 139 cache->AddEntry( |
140 kManifestUrl, | 140 kManifestUrl, |
141 AppCacheEntry(AppCacheEntry::MANIFEST, kMockResponseId, | 141 AppCacheEntry(AppCacheEntry::MANIFEST, kMockResponseId, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 const net::HttpResponseInfo* info) { | 176 const net::HttpResponseInfo* info) { |
177 const bool kSkipTransientHeaders = true; | 177 const bool kSkipTransientHeaders = true; |
178 const bool kTruncated = false; | 178 const bool kTruncated = false; |
179 info->Persist(pickle, kSkipTransientHeaders, kTruncated); | 179 info->Persist(pickle, kSkipTransientHeaders, kTruncated); |
180 return pickle->size(); | 180 return pickle->size(); |
181 } | 181 } |
182 | 182 |
183 const GURL kOrigin; | 183 const GURL kOrigin; |
184 const GURL kManifestUrl; | 184 const GURL kManifestUrl; |
185 | 185 |
186 scoped_ptr<AppCacheServiceImpl> service_; | 186 std::unique_ptr<AppCacheServiceImpl> service_; |
187 int delete_result_; | 187 int delete_result_; |
188 int delete_completion_count_; | 188 int delete_completion_count_; |
189 net::CompletionCallback deletion_callback_; | 189 net::CompletionCallback deletion_callback_; |
190 | 190 |
191 private: | 191 private: |
192 base::MessageLoop message_loop_; | 192 base::MessageLoop message_loop_; |
193 }; | 193 }; |
194 | 194 |
195 TEST_F(AppCacheServiceImplTest, DeleteAppCachesForOrigin) { | 195 TEST_F(AppCacheServiceImplTest, DeleteAppCachesForOrigin) { |
196 // Without giving mock storage simiulated info, should fail. | 196 // Without giving mock storage simiulated info, should fail. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 } | 330 } |
331 | 331 |
332 // Just tests the backoff scheduling function, not the actual reinit function. | 332 // Just tests the backoff scheduling function, not the actual reinit function. |
333 TEST_F(AppCacheServiceImplTest, ScheduleReinitialize) { | 333 TEST_F(AppCacheServiceImplTest, ScheduleReinitialize) { |
334 const base::TimeDelta kNoDelay; | 334 const base::TimeDelta kNoDelay; |
335 const base::TimeDelta kOneSecond(base::TimeDelta::FromSeconds(1)); | 335 const base::TimeDelta kOneSecond(base::TimeDelta::FromSeconds(1)); |
336 const base::TimeDelta k30Seconds(base::TimeDelta::FromSeconds(30)); | 336 const base::TimeDelta k30Seconds(base::TimeDelta::FromSeconds(30)); |
337 const base::TimeDelta kOneHour(base::TimeDelta::FromHours(1)); | 337 const base::TimeDelta kOneHour(base::TimeDelta::FromHours(1)); |
338 | 338 |
339 // Do things get initialized as expected? | 339 // Do things get initialized as expected? |
340 scoped_ptr<AppCacheServiceImpl> service(new AppCacheServiceImpl(NULL)); | 340 std::unique_ptr<AppCacheServiceImpl> service(new AppCacheServiceImpl(NULL)); |
341 EXPECT_TRUE(service->last_reinit_time_.is_null()); | 341 EXPECT_TRUE(service->last_reinit_time_.is_null()); |
342 EXPECT_FALSE(service->reinit_timer_.IsRunning()); | 342 EXPECT_FALSE(service->reinit_timer_.IsRunning()); |
343 EXPECT_EQ(kNoDelay, service->next_reinit_delay_); | 343 EXPECT_EQ(kNoDelay, service->next_reinit_delay_); |
344 | 344 |
345 // Do we see artifacts of the timer pending and such? | 345 // Do we see artifacts of the timer pending and such? |
346 service->ScheduleReinitialize(); | 346 service->ScheduleReinitialize(); |
347 EXPECT_TRUE(service->reinit_timer_.IsRunning()); | 347 EXPECT_TRUE(service->reinit_timer_.IsRunning()); |
348 EXPECT_EQ(kNoDelay, service->reinit_timer_.GetCurrentDelay()); | 348 EXPECT_EQ(kNoDelay, service->reinit_timer_.GetCurrentDelay()); |
349 EXPECT_EQ(k30Seconds, service->next_reinit_delay_); | 349 EXPECT_EQ(k30Seconds, service->next_reinit_delay_); |
350 | 350 |
(...skipping 29 matching lines...) Expand all Loading... |
380 EXPECT_EQ(kOneHour, service->reinit_timer_.GetCurrentDelay()); | 380 EXPECT_EQ(kOneHour, service->reinit_timer_.GetCurrentDelay()); |
381 EXPECT_EQ(kOneHour, service->next_reinit_delay_); | 381 EXPECT_EQ(kOneHour, service->next_reinit_delay_); |
382 | 382 |
383 // Fine to delete while pending. | 383 // Fine to delete while pending. |
384 service.reset(NULL); | 384 service.reset(NULL); |
385 } | 385 } |
386 | 386 |
387 | 387 |
388 | 388 |
389 } // namespace content | 389 } // namespace content |
OLD | NEW |