OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 "base/stl_util-inl.h" |
| 10 #include "base/time.h" |
| 11 #include "chrome/browser/browser_thread.h" |
| 12 #include "chrome/browser/appcache/chrome_appcache_service.h" |
| 13 #include "chrome/common/chrome_constants.h" |
| 14 #include "chrome/test/thread_test_helper.h" |
| 15 #include "googleurl/src/gurl.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 |
| 18 class ChromeAppCacheServiceTest : public testing::Test { |
| 19 public: |
| 20 ChromeAppCacheServiceTest() |
| 21 : db_thread_(BrowserThread::DB, &message_loop_), |
| 22 file_thread_(BrowserThread::FILE, &message_loop_), |
| 23 io_thread_(BrowserThread::IO, &message_loop_) { |
| 24 } |
| 25 |
| 26 protected: |
| 27 MessageLoop message_loop_; |
| 28 BrowserThread db_thread_; |
| 29 BrowserThread file_thread_; |
| 30 BrowserThread io_thread_; |
| 31 ScopedTempDir temp_dir_; |
| 32 }; |
| 33 |
| 34 TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) { |
| 35 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 36 scoped_refptr<ChromeAppCacheService> appcache_service = |
| 37 new ChromeAppCacheService; |
| 38 BrowserThread::PostTask( |
| 39 BrowserThread::IO, FROM_HERE, |
| 40 NewRunnableMethod(appcache_service.get(), |
| 41 &ChromeAppCacheService::InitializeOnIOThread, |
| 42 temp_dir_.path(), false, |
| 43 scoped_refptr<HostContentSettingsMap>(NULL), |
| 44 false)); |
| 45 // Create some fake cache index. |
| 46 ASSERT_TRUE(file_util::CreateDirectory( |
| 47 temp_dir_.path().Append(chrome::kAppCacheDirname))); |
| 48 ASSERT_EQ(0, file_util::WriteFile( |
| 49 temp_dir_.path().Append(chrome::kAppCacheDirname).AppendASCII("Index"), |
| 50 NULL, 0)); |
| 51 |
| 52 appcache_service = NULL; |
| 53 message_loop_.RunAllPending(); |
| 54 |
| 55 ASSERT_TRUE(file_util::PathExists( |
| 56 temp_dir_.path().Append(chrome::kAppCacheDirname))); |
| 57 } |
| 58 |
| 59 TEST_F(ChromeAppCacheServiceTest, RemoveOnDestruction) { |
| 60 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 61 scoped_refptr<ChromeAppCacheService> appcache_service = |
| 62 new ChromeAppCacheService; |
| 63 BrowserThread::PostTask( |
| 64 BrowserThread::IO, FROM_HERE, |
| 65 NewRunnableMethod(appcache_service.get(), |
| 66 &ChromeAppCacheService::InitializeOnIOThread, |
| 67 temp_dir_.path(), false, |
| 68 scoped_refptr<HostContentSettingsMap>(NULL), |
| 69 true)); |
| 70 // Create some fake cache index. |
| 71 ASSERT_TRUE(file_util::CreateDirectory( |
| 72 temp_dir_.path().Append(chrome::kAppCacheDirname))); |
| 73 ASSERT_EQ(0, file_util::WriteFile( |
| 74 temp_dir_.path().Append(chrome::kAppCacheDirname).AppendASCII("Index"), |
| 75 NULL, 0)); |
| 76 |
| 77 appcache_service = NULL; |
| 78 message_loop_.RunAllPending(); |
| 79 |
| 80 ASSERT_FALSE(file_util::PathExists( |
| 81 temp_dir_.path().Append(chrome::kAppCacheDirname))); |
| 82 } |
OLD | NEW |