Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/file_util.h" | |
| 6 #include "base/message_loop.h" | |
| 7 #include "base/ref_counted.h" | |
| 8 #include "base/scoped_temp_dir.h" | |
| 9 #include "chrome/browser/appcache/chrome_appcache_service.h" | |
| 10 #include "chrome/browser/browser_thread.h" | |
| 11 #include "chrome/common/chrome_constants.h" | |
| 12 #include "chrome/test/thread_test_helper.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 #include "webkit/appcache/appcache_storage_impl.h" | |
| 15 | |
| 16 namespace appcache { | |
| 17 | |
| 18 class ChromeAppCacheServiceTest : public testing::Test { | |
| 19 public: | |
| 20 ChromeAppCacheServiceTest() | |
| 21 : message_loop_(MessageLoop::TYPE_IO), | |
| 22 db_thread_(BrowserThread::DB, &message_loop_), | |
| 23 file_thread_(BrowserThread::FILE, &message_loop_), | |
| 24 cache_thread_(BrowserThread::CACHE, &message_loop_), | |
| 25 io_thread_(BrowserThread::IO, &message_loop_) { | |
| 26 } | |
| 27 | |
| 28 protected: | |
| 29 MessageLoop message_loop_; | |
| 30 ScopedTempDir temp_dir_; | |
| 31 | |
| 32 private: | |
| 33 BrowserThread db_thread_; | |
| 34 BrowserThread file_thread_; | |
| 35 BrowserThread cache_thread_; | |
| 36 BrowserThread io_thread_; | |
| 37 }; | |
| 38 | |
| 39 TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) { | |
| 40 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
| 41 FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname); | |
| 42 scoped_refptr<ChromeAppCacheService> appcache_service = | |
| 43 new ChromeAppCacheService; | |
| 44 BrowserThread::PostTask( | |
| 45 BrowserThread::IO, FROM_HERE, | |
| 46 NewRunnableMethod(appcache_service.get(), | |
| 47 &ChromeAppCacheService::InitializeOnIOThread, | |
| 48 temp_dir_.path(), false, | |
| 49 scoped_refptr<HostContentSettingsMap>(NULL), | |
| 50 false)); | |
| 51 // Make the steps needed to initialize the storage of AppCache data. | |
| 52 message_loop_.RunAllPending(); | |
| 53 appcache::AppCacheStorageImpl* storage = | |
| 54 static_cast<appcache::AppCacheStorageImpl*>(appcache_service->storage()); | |
| 55 ASSERT_TRUE(storage->database()->db_connection()); | |
| 56 ASSERT_LE(0, storage->NewCacheId()); | |
|
michaeln
2011/01/07 19:53:05
should this be ASSERT_EQ(1, storage->NewCacheId())
pastarmovj
2011/01/10 11:02:01
I though keeping it >= 0 is more generic and still
| |
| 57 storage->disk_cache(); | |
| 58 message_loop_.RunAllPending(); | |
| 59 | |
| 60 ASSERT_TRUE(file_util::PathExists(appcache_path)); | |
| 61 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index"))); | |
| 62 | |
| 63 appcache_service = NULL; | |
| 64 message_loop_.RunAllPending(); | |
| 65 | |
| 66 ASSERT_TRUE(file_util::PathExists(appcache_path)); | |
| 67 } | |
| 68 | |
| 69 TEST_F(ChromeAppCacheServiceTest, RemoveOnDestruction) { | |
| 70 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
| 71 FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname); | |
| 72 scoped_refptr<ChromeAppCacheService> appcache_service = | |
| 73 new ChromeAppCacheService; | |
| 74 BrowserThread::PostTask( | |
| 75 BrowserThread::IO, FROM_HERE, | |
| 76 NewRunnableMethod(appcache_service.get(), | |
| 77 &ChromeAppCacheService::InitializeOnIOThread, | |
| 78 temp_dir_.path(), false, | |
| 79 scoped_refptr<HostContentSettingsMap>(NULL), | |
| 80 true)); | |
| 81 // Make the steps needed to initialize the storage of AppCache data. | |
| 82 message_loop_.RunAllPending(); | |
| 83 appcache::AppCacheStorageImpl* storage = | |
| 84 static_cast<appcache::AppCacheStorageImpl*>(appcache_service->storage()); | |
| 85 ASSERT_TRUE(storage->database()->db_connection()); | |
| 86 ASSERT_LE(0, storage->NewCacheId()); | |
| 87 storage->disk_cache(); | |
| 88 message_loop_.RunAllPending(); | |
| 89 | |
| 90 ASSERT_TRUE(file_util::PathExists(appcache_path)); | |
| 91 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index"))); | |
| 92 | |
| 93 appcache_service = NULL; | |
| 94 message_loop_.RunAllPending(); | |
| 95 | |
| 96 ASSERT_FALSE(file_util::PathExists(appcache_path)); | |
| 97 } | |
| 98 | |
| 99 } // namespace appcache | |
| OLD | NEW |