| 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 "content/browser/service_worker/service_worker_cache_storage_manager.h" | 5 #include "content/browser/service_worker/service_worker_cache_storage_manager.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 protected: | 22 protected: |
| 23 ServiceWorkerCacheStorageManagerTest() | 23 ServiceWorkerCacheStorageManagerTest() |
| 24 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | 24 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), |
| 25 callback_bool_(false), | 25 callback_bool_(false), |
| 26 callback_error_( | 26 callback_error_( |
| 27 ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR), | 27 ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR), |
| 28 callback_cache_error_(ServiceWorkerCache::ErrorTypeOK), | 28 callback_cache_error_(ServiceWorkerCache::ErrorTypeOK), |
| 29 origin1_("http://example1.com"), | 29 origin1_("http://example1.com"), |
| 30 origin2_("http://example2.com") {} | 30 origin2_("http://example2.com") {} |
| 31 | 31 |
| 32 virtual void SetUp() OVERRIDE { | 32 virtual void SetUp() override { |
| 33 ChromeBlobStorageContext* blob_storage_context( | 33 ChromeBlobStorageContext* blob_storage_context( |
| 34 ChromeBlobStorageContext::GetFor(&browser_context_)); | 34 ChromeBlobStorageContext::GetFor(&browser_context_)); |
| 35 // Wait for ChromeBlobStorageContext to finish initializing. | 35 // Wait for ChromeBlobStorageContext to finish initializing. |
| 36 base::RunLoop().RunUntilIdle(); | 36 base::RunLoop().RunUntilIdle(); |
| 37 | 37 |
| 38 net::URLRequestContext* url_request_context = | 38 net::URLRequestContext* url_request_context = |
| 39 browser_context_.GetRequestContext()->GetURLRequestContext(); | 39 browser_context_.GetRequestContext()->GetURLRequestContext(); |
| 40 if (MemoryOnly()) { | 40 if (MemoryOnly()) { |
| 41 cache_manager_ = ServiceWorkerCacheStorageManager::Create( | 41 cache_manager_ = ServiceWorkerCacheStorageManager::Create( |
| 42 base::FilePath(), base::MessageLoopProxy::current()); | 42 base::FilePath(), base::MessageLoopProxy::current()); |
| 43 } else { | 43 } else { |
| 44 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 44 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 45 cache_manager_ = ServiceWorkerCacheStorageManager::Create( | 45 cache_manager_ = ServiceWorkerCacheStorageManager::Create( |
| 46 temp_dir_.path(), base::MessageLoopProxy::current()); | 46 temp_dir_.path(), base::MessageLoopProxy::current()); |
| 47 } | 47 } |
| 48 | 48 |
| 49 cache_manager_->SetBlobParametersForCache( | 49 cache_manager_->SetBlobParametersForCache( |
| 50 url_request_context, blob_storage_context->context()->AsWeakPtr()); | 50 url_request_context, blob_storage_context->context()->AsWeakPtr()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 virtual void TearDown() OVERRIDE { | 53 virtual void TearDown() override { |
| 54 base::RunLoop().RunUntilIdle(); | 54 base::RunLoop().RunUntilIdle(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 virtual bool MemoryOnly() { return false; } | 57 virtual bool MemoryOnly() { return false; } |
| 58 | 58 |
| 59 void BoolAndErrorCallback( | 59 void BoolAndErrorCallback( |
| 60 base::RunLoop* run_loop, | 60 base::RunLoop* run_loop, |
| 61 bool value, | 61 bool value, |
| 62 ServiceWorkerCacheStorage::CacheStorageError error) { | 62 ServiceWorkerCacheStorage::CacheStorageError error) { |
| 63 callback_bool_ = value; | 63 callback_bool_ = value; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 | 234 |
| 235 const GURL origin1_; | 235 const GURL origin1_; |
| 236 const GURL origin2_; | 236 const GURL origin2_; |
| 237 | 237 |
| 238 private: | 238 private: |
| 239 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorageManagerTest); | 239 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorageManagerTest); |
| 240 }; | 240 }; |
| 241 | 241 |
| 242 class ServiceWorkerCacheStorageManagerMemoryOnlyTest | 242 class ServiceWorkerCacheStorageManagerMemoryOnlyTest |
| 243 : public ServiceWorkerCacheStorageManagerTest { | 243 : public ServiceWorkerCacheStorageManagerTest { |
| 244 virtual bool MemoryOnly() OVERRIDE { return true; } | 244 virtual bool MemoryOnly() override { return true; } |
| 245 }; | 245 }; |
| 246 | 246 |
| 247 class ServiceWorkerCacheStorageManagerTestP | 247 class ServiceWorkerCacheStorageManagerTestP |
| 248 : public ServiceWorkerCacheStorageManagerTest, | 248 : public ServiceWorkerCacheStorageManagerTest, |
| 249 public testing::WithParamInterface<bool> { | 249 public testing::WithParamInterface<bool> { |
| 250 virtual bool MemoryOnly() OVERRIDE { return !GetParam(); } | 250 virtual bool MemoryOnly() override { return !GetParam(); } |
| 251 }; | 251 }; |
| 252 | 252 |
| 253 TEST_F(ServiceWorkerCacheStorageManagerTest, TestsRunOnIOThread) { | 253 TEST_F(ServiceWorkerCacheStorageManagerTest, TestsRunOnIOThread) { |
| 254 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 254 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 255 } | 255 } |
| 256 | 256 |
| 257 TEST_P(ServiceWorkerCacheStorageManagerTestP, CreateCache) { | 257 TEST_P(ServiceWorkerCacheStorageManagerTestP, CreateCache) { |
| 258 EXPECT_TRUE(CreateCache(origin1_, "foo")); | 258 EXPECT_TRUE(CreateCache(origin1_, "foo")); |
| 259 } | 259 } |
| 260 | 260 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 EXPECT_TRUE(CreateCache(origin1_, "foo")); | 454 EXPECT_TRUE(CreateCache(origin1_, "foo")); |
| 455 EXPECT_TRUE(Delete(origin1_, "foo")); | 455 EXPECT_TRUE(Delete(origin1_, "foo")); |
| 456 EXPECT_TRUE(callback_cache_->AsWeakPtr()); | 456 EXPECT_TRUE(callback_cache_->AsWeakPtr()); |
| 457 } | 457 } |
| 458 | 458 |
| 459 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheStorageManagerTests, | 459 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheStorageManagerTests, |
| 460 ServiceWorkerCacheStorageManagerTestP, | 460 ServiceWorkerCacheStorageManagerTestP, |
| 461 ::testing::Values(false, true)); | 461 ::testing::Values(false, true)); |
| 462 | 462 |
| 463 } // namespace content | 463 } // namespace content |
| OLD | NEW |