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/testing_browser_process.h" | |
13 #include "chrome/test/testing_browser_process_test.h" | |
14 #include "chrome/test/thread_test_helper.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | |
16 #include "webkit/appcache/appcache_storage_impl.h" | |
17 | |
18 namespace appcache { | |
19 | |
20 class ChromeAppCacheServiceTest : public TestingBrowserProcessTest { | |
21 public: | |
22 ChromeAppCacheServiceTest() | |
23 : message_loop_(MessageLoop::TYPE_IO), | |
24 db_thread_(BrowserThread::DB, &message_loop_), | |
25 file_thread_(BrowserThread::FILE, &message_loop_), | |
26 cache_thread_(BrowserThread::CACHE, &message_loop_), | |
27 io_thread_(BrowserThread::IO, &message_loop_) { | |
28 } | |
29 | |
30 protected: | |
31 MessageLoop message_loop_; | |
32 ScopedTempDir temp_dir_; | |
33 | |
34 private: | |
35 BrowserThread db_thread_; | |
36 BrowserThread file_thread_; | |
37 BrowserThread cache_thread_; | |
38 BrowserThread io_thread_; | |
39 }; | |
40 | |
41 TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) { | |
42 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
43 FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname); | |
44 scoped_refptr<ChromeAppCacheService> appcache_service = | |
45 new ChromeAppCacheService; | |
46 BrowserThread::PostTask( | |
47 BrowserThread::IO, FROM_HERE, | |
48 NewRunnableMethod(appcache_service.get(), | |
49 &ChromeAppCacheService::InitializeOnIOThread, | |
50 temp_dir_.path(), false, | |
51 scoped_refptr<HostContentSettingsMap>(NULL), | |
52 false)); | |
53 // Make the steps needed to initialize the storage of AppCache data. | |
54 message_loop_.RunAllPending(); | |
55 appcache::AppCacheStorageImpl* storage = | |
56 static_cast<appcache::AppCacheStorageImpl*>(appcache_service->storage()); | |
57 ASSERT_TRUE(storage->database_->db_connection()); | |
58 ASSERT_EQ(1, storage->NewCacheId()); | |
59 storage->disk_cache(); | |
60 message_loop_.RunAllPending(); | |
61 | |
62 ASSERT_TRUE(file_util::PathExists(appcache_path)); | |
63 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index"))); | |
64 | |
65 appcache_service = NULL; | |
66 message_loop_.RunAllPending(); | |
67 | |
68 ASSERT_TRUE(file_util::PathExists(appcache_path)); | |
69 } | |
70 | |
71 TEST_F(ChromeAppCacheServiceTest, RemoveOnDestruction) { | |
72 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
73 FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname); | |
74 scoped_refptr<ChromeAppCacheService> appcache_service = | |
75 new ChromeAppCacheService; | |
76 BrowserThread::PostTask( | |
77 BrowserThread::IO, FROM_HERE, | |
78 NewRunnableMethod(appcache_service.get(), | |
79 &ChromeAppCacheService::InitializeOnIOThread, | |
80 temp_dir_.path(), false, | |
81 scoped_refptr<HostContentSettingsMap>(NULL), | |
82 true)); | |
83 // Make the steps needed to initialize the storage of AppCache data. | |
84 message_loop_.RunAllPending(); | |
85 appcache::AppCacheStorageImpl* storage = | |
86 static_cast<appcache::AppCacheStorageImpl*>(appcache_service->storage()); | |
87 ASSERT_TRUE(storage->database_->db_connection()); | |
88 ASSERT_EQ(1, storage->NewCacheId()); | |
89 storage->disk_cache(); | |
90 message_loop_.RunAllPending(); | |
91 | |
92 ASSERT_TRUE(file_util::PathExists(appcache_path)); | |
93 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index"))); | |
94 | |
95 appcache_service = NULL; | |
96 message_loop_.RunAllPending(); | |
97 | |
98 ASSERT_FALSE(file_util::PathExists(appcache_path)); | |
99 } | |
100 | |
101 } // namespace appcache | |
OLD | NEW |