Chromium Code Reviews| Index: chrome/browser/appcache/chrome_appcache_service_unittest.cc |
| diff --git a/chrome/browser/appcache/chrome_appcache_service_unittest.cc b/chrome/browser/appcache/chrome_appcache_service_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f22feae35f8dda0838732cd42fc299a9f2b74134 |
| --- /dev/null |
| +++ b/chrome/browser/appcache/chrome_appcache_service_unittest.cc |
| @@ -0,0 +1,80 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/file_util.h" |
| +#include "base/message_loop.h" |
| +#include "base/ref_counted.h" |
| +#include "base/scoped_temp_dir.h" |
| +#include "chrome/browser/appcache/chrome_appcache_service.h" |
| +#include "chrome/browser/browser_thread.h" |
| +#include "chrome/common/chrome_constants.h" |
| +#include "chrome/test/thread_test_helper.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace { |
| + |
| +class ChromeAppCacheServiceTest : public testing::Test { |
| + public: |
| + ChromeAppCacheServiceTest() |
| + : db_thread_(BrowserThread::DB, &message_loop_), |
| + file_thread_(BrowserThread::FILE, &message_loop_), |
| + io_thread_(BrowserThread::IO, &message_loop_) { |
| + } |
| + |
| + protected: |
|
jochen (gone - plz use gerrit)
2011/01/05 12:29:51
why protected and not private?
pastarmovj
2011/01/05 13:47:38
At least message_loop_ and temp_dir_ are used in t
|
| + MessageLoop message_loop_; |
| + BrowserThread db_thread_; |
| + BrowserThread file_thread_; |
| + BrowserThread io_thread_; |
| + ScopedTempDir temp_dir_; |
| +}; |
| + |
| +TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) { |
| + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| + FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname); |
| + scoped_refptr<ChromeAppCacheService> appcache_service = |
| + new ChromeAppCacheService; |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + NewRunnableMethod(appcache_service.get(), |
| + &ChromeAppCacheService::InitializeOnIOThread, |
| + temp_dir_.path(), false, |
| + scoped_refptr<HostContentSettingsMap>(NULL), |
| + false)); |
| + // Create some fake cache index. |
| + ASSERT_TRUE(file_util::CreateDirectory(appcache_path)); |
| + ASSERT_EQ(0, file_util::WriteFile( |
| + appcache_path.AppendASCII("Index"), NULL, 0)); |
| + |
| + appcache_service = NULL; |
| + message_loop_.RunAllPending(); |
| + |
| + ASSERT_TRUE(file_util::PathExists(appcache_path)); |
| +} |
| + |
| +TEST_F(ChromeAppCacheServiceTest, RemoveOnDestruction) { |
| + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| + FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname); |
| + scoped_refptr<ChromeAppCacheService> appcache_service = |
| + new ChromeAppCacheService; |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + NewRunnableMethod(appcache_service.get(), |
| + &ChromeAppCacheService::InitializeOnIOThread, |
| + temp_dir_.path(), false, |
| + scoped_refptr<HostContentSettingsMap>(NULL), |
| + true)); |
| + // Create some fake cache index. |
|
jochen (gone - plz use gerrit)
2011/01/05 12:29:51
duplicate line
pastarmovj
2011/01/05 13:47:38
Done.
|
| + // Create some fake cache index. |
| + ASSERT_TRUE(file_util::CreateDirectory(appcache_path)); |
| + ASSERT_EQ(0, file_util::WriteFile( |
| + appcache_path.AppendASCII("Index"), NULL, 0)); |
| + |
| + appcache_service = NULL; |
| + message_loop_.RunAllPending(); |
| + |
| + ASSERT_FALSE(file_util::PathExists(appcache_path)); |
| +} |
| + |
| +} // namespace |