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..86fa2121bb2fae223d4059a8a06db9a918713986 |
| --- /dev/null |
| +++ b/chrome/browser/appcache/chrome_appcache_service_unittest.cc |
| @@ -0,0 +1,82 @@ |
| +// Copyright (c) 2010 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 "base/stl_util-inl.h" |
|
jochen (gone - plz use gerrit)
2011/01/05 10:55:45
why do you include this header?
pastarmovj
2011/01/05 12:15:14
Relict from the test I used as template for this f
|
| +#include "base/time.h" |
|
jochen (gone - plz use gerrit)
2011/01/05 10:55:45
and this?
pastarmovj
2011/01/05 12:15:14
This too.
|
| +#include "chrome/browser/browser_thread.h" |
| +#include "chrome/browser/appcache/chrome_appcache_service.h" |
|
jochen (gone - plz use gerrit)
2011/01/05 10:55:45
alphabetical ordering
pastarmovj
2011/01/05 12:15:14
Done.
|
| +#include "chrome/common/chrome_constants.h" |
| +#include "chrome/test/thread_test_helper.h" |
| +#include "googleurl/src/gurl.h" |
|
jochen (gone - plz use gerrit)
2011/01/05 10:55:45
isn't used either
pastarmovj
2011/01/05 12:15:14
Done.
|
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +class ChromeAppCacheServiceTest : public testing::Test { |
|
jochen (gone - plz use gerrit)
2011/01/05 10:55:45
can you move everything into an anonymous namespac
pastarmovj
2011/01/05 12:15:14
Done.
|
| + public: |
| + ChromeAppCacheServiceTest() |
| + : db_thread_(BrowserThread::DB, &message_loop_), |
| + file_thread_(BrowserThread::FILE, &message_loop_), |
| + io_thread_(BrowserThread::IO, &message_loop_) { |
| + } |
| + |
| + protected: |
| + MessageLoop message_loop_; |
| + BrowserThread db_thread_; |
| + BrowserThread file_thread_; |
| + BrowserThread io_thread_; |
| + ScopedTempDir temp_dir_; |
| +}; |
| + |
| +TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) { |
| + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| + 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( |
| + temp_dir_.path().Append(chrome::kAppCacheDirname))); |
|
jochen (gone - plz use gerrit)
2011/01/05 10:55:45
can you put this into a variable instead of recrea
pastarmovj
2011/01/05 12:15:14
Done.
|
| + ASSERT_EQ(0, file_util::WriteFile( |
| + temp_dir_.path().Append(chrome::kAppCacheDirname).AppendASCII("Index"), |
| + NULL, 0)); |
| + |
| + appcache_service = NULL; |
| + message_loop_.RunAllPending(); |
| + |
| + ASSERT_TRUE(file_util::PathExists( |
| + temp_dir_.path().Append(chrome::kAppCacheDirname))); |
| +} |
| + |
| +TEST_F(ChromeAppCacheServiceTest, RemoveOnDestruction) { |
| + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| + 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. |
| + ASSERT_TRUE(file_util::CreateDirectory( |
| + temp_dir_.path().Append(chrome::kAppCacheDirname))); |
| + ASSERT_EQ(0, file_util::WriteFile( |
| + temp_dir_.path().Append(chrome::kAppCacheDirname).AppendASCII("Index"), |
| + NULL, 0)); |
| + |
| + appcache_service = NULL; |
| + message_loop_.RunAllPending(); |
| + |
| + ASSERT_FALSE(file_util::PathExists( |
| + temp_dir_.path().Append(chrome::kAppCacheDirname))); |
| +} |