| 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 "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
| 7 #include "base/memory/scoped_temp_dir.h" | 7 #include "base/memory/scoped_temp_dir.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "chrome/common/chrome_constants.h" | 9 #include "chrome/common/chrome_constants.h" |
| 10 #include "chrome/test/testing_browser_process.h" | 10 #include "chrome/test/testing_browser_process.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 BrowserThread file_thread_; | 36 BrowserThread file_thread_; |
| 37 BrowserThread cache_thread_; | 37 BrowserThread cache_thread_; |
| 38 BrowserThread io_thread_; | 38 BrowserThread io_thread_; |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) { | 41 TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) { |
| 42 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 42 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 43 FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname); | 43 FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname); |
| 44 scoped_refptr<ChromeAppCacheService> appcache_service = | 44 scoped_refptr<ChromeAppCacheService> appcache_service = |
| 45 new ChromeAppCacheService; | 45 new ChromeAppCacheService; |
| 46 const content::ResourceContext* resource_context = NULL; |
| 46 BrowserThread::PostTask( | 47 BrowserThread::PostTask( |
| 47 BrowserThread::IO, FROM_HERE, | 48 BrowserThread::IO, FROM_HERE, |
| 48 NewRunnableMethod(appcache_service.get(), | 49 NewRunnableMethod(appcache_service.get(), |
| 49 &ChromeAppCacheService::InitializeOnIOThread, | 50 &ChromeAppCacheService::InitializeOnIOThread, |
| 50 appcache_path, | 51 appcache_path, |
| 51 scoped_refptr<HostContentSettingsMap>(NULL), | 52 resource_context, |
| 52 scoped_refptr<quota::SpecialStoragePolicy>(NULL), | 53 scoped_refptr<quota::SpecialStoragePolicy>(NULL), |
| 53 false)); | 54 false)); |
| 54 // Make the steps needed to initialize the storage of AppCache data. | 55 // Make the steps needed to initialize the storage of AppCache data. |
| 55 message_loop_.RunAllPending(); | 56 message_loop_.RunAllPending(); |
| 56 appcache::AppCacheStorageImpl* storage = | 57 appcache::AppCacheStorageImpl* storage = |
| 57 static_cast<appcache::AppCacheStorageImpl*>(appcache_service->storage()); | 58 static_cast<appcache::AppCacheStorageImpl*>(appcache_service->storage()); |
| 58 ASSERT_TRUE(storage->database_->db_connection()); | 59 ASSERT_TRUE(storage->database_->db_connection()); |
| 59 ASSERT_EQ(1, storage->NewCacheId()); | 60 ASSERT_EQ(1, storage->NewCacheId()); |
| 60 storage->disk_cache(); | 61 storage->disk_cache(); |
| 61 message_loop_.RunAllPending(); | 62 message_loop_.RunAllPending(); |
| 62 | 63 |
| 63 ASSERT_TRUE(file_util::PathExists(appcache_path)); | 64 ASSERT_TRUE(file_util::PathExists(appcache_path)); |
| 64 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index"))); | 65 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index"))); |
| 65 | 66 |
| 66 appcache_service = NULL; | 67 appcache_service = NULL; |
| 67 message_loop_.RunAllPending(); | 68 message_loop_.RunAllPending(); |
| 68 | 69 |
| 69 ASSERT_TRUE(file_util::PathExists(appcache_path)); | 70 ASSERT_TRUE(file_util::PathExists(appcache_path)); |
| 70 } | 71 } |
| 71 | 72 |
| 72 TEST_F(ChromeAppCacheServiceTest, RemoveOnDestruction) { | 73 TEST_F(ChromeAppCacheServiceTest, RemoveOnDestruction) { |
| 73 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 74 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 74 FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname); | 75 FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname); |
| 75 scoped_refptr<ChromeAppCacheService> appcache_service = | 76 scoped_refptr<ChromeAppCacheService> appcache_service = |
| 76 new ChromeAppCacheService; | 77 new ChromeAppCacheService; |
| 78 const content::ResourceContext* resource_context = NULL; |
| 77 BrowserThread::PostTask( | 79 BrowserThread::PostTask( |
| 78 BrowserThread::IO, FROM_HERE, | 80 BrowserThread::IO, FROM_HERE, |
| 79 NewRunnableMethod(appcache_service.get(), | 81 NewRunnableMethod(appcache_service.get(), |
| 80 &ChromeAppCacheService::InitializeOnIOThread, | 82 &ChromeAppCacheService::InitializeOnIOThread, |
| 81 appcache_path, | 83 appcache_path, |
| 82 scoped_refptr<HostContentSettingsMap>(NULL), | 84 resource_context, |
| 83 scoped_refptr<quota::SpecialStoragePolicy>(NULL), | 85 scoped_refptr<quota::SpecialStoragePolicy>(NULL), |
| 84 true)); | 86 true)); |
| 85 // Make the steps needed to initialize the storage of AppCache data. | 87 // Make the steps needed to initialize the storage of AppCache data. |
| 86 message_loop_.RunAllPending(); | 88 message_loop_.RunAllPending(); |
| 87 appcache::AppCacheStorageImpl* storage = | 89 appcache::AppCacheStorageImpl* storage = |
| 88 static_cast<appcache::AppCacheStorageImpl*>(appcache_service->storage()); | 90 static_cast<appcache::AppCacheStorageImpl*>(appcache_service->storage()); |
| 89 ASSERT_TRUE(storage->database_->db_connection()); | 91 ASSERT_TRUE(storage->database_->db_connection()); |
| 90 ASSERT_EQ(1, storage->NewCacheId()); | 92 ASSERT_EQ(1, storage->NewCacheId()); |
| 91 storage->disk_cache(); | 93 storage->disk_cache(); |
| 92 message_loop_.RunAllPending(); | 94 message_loop_.RunAllPending(); |
| 93 | 95 |
| 94 ASSERT_TRUE(file_util::PathExists(appcache_path)); | 96 ASSERT_TRUE(file_util::PathExists(appcache_path)); |
| 95 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index"))); | 97 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index"))); |
| 96 | 98 |
| 97 appcache_service = NULL; | 99 appcache_service = NULL; |
| 98 message_loop_.RunAllPending(); | 100 message_loop_.RunAllPending(); |
| 99 | 101 |
| 100 ASSERT_FALSE(file_util::PathExists(appcache_path)); | 102 ASSERT_FALSE(file_util::PathExists(appcache_path)); |
| 101 } | 103 } |
| 102 | 104 |
| 103 } // namespace appcache | 105 } // namespace appcache |
| OLD | NEW |