OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "content/browser/appcache/chrome_appcache_service.h" | 10 #include "content/browser/appcache/chrome_appcache_service.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 } | 147 } |
148 | 148 |
149 TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) { | 149 TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) { |
150 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 150 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
151 base::FilePath appcache_path = | 151 base::FilePath appcache_path = |
152 temp_dir_.path().Append(kTestingAppCacheDirname); | 152 temp_dir_.path().Append(kTestingAppCacheDirname); |
153 | 153 |
154 // Create a ChromeAppCacheService and insert data into it | 154 // Create a ChromeAppCacheService and insert data into it |
155 scoped_refptr<ChromeAppCacheService> appcache_service = | 155 scoped_refptr<ChromeAppCacheService> appcache_service = |
156 CreateAppCacheService(appcache_path, true); | 156 CreateAppCacheService(appcache_path, true); |
157 ASSERT_TRUE(file_util::PathExists(appcache_path)); | 157 ASSERT_TRUE(base::PathExists(appcache_path)); |
158 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index"))); | 158 ASSERT_TRUE(base::PathExists(appcache_path.AppendASCII("Index"))); |
159 InsertDataIntoAppCache(appcache_service.get()); | 159 InsertDataIntoAppCache(appcache_service.get()); |
160 | 160 |
161 // Test: delete the ChromeAppCacheService | 161 // Test: delete the ChromeAppCacheService |
162 appcache_service = NULL; | 162 appcache_service = NULL; |
163 message_loop_.RunUntilIdle(); | 163 message_loop_.RunUntilIdle(); |
164 | 164 |
165 // Recreate the appcache (for reading the data back) | 165 // Recreate the appcache (for reading the data back) |
166 appcache_service = CreateAppCacheService(appcache_path, false); | 166 appcache_service = CreateAppCacheService(appcache_path, false); |
167 | 167 |
168 // The directory is still there | 168 // The directory is still there |
169 ASSERT_TRUE(file_util::PathExists(appcache_path)); | 169 ASSERT_TRUE(base::PathExists(appcache_path)); |
170 | 170 |
171 // The appcache data is also there, except the session-only origin. | 171 // The appcache data is also there, except the session-only origin. |
172 AppCacheTestHelper appcache_helper; | 172 AppCacheTestHelper appcache_helper; |
173 std::set<GURL> origins; | 173 std::set<GURL> origins; |
174 appcache_helper.GetOriginsWithCaches(appcache_service.get(), &origins); | 174 appcache_helper.GetOriginsWithCaches(appcache_service.get(), &origins); |
175 EXPECT_EQ(2UL, origins.size()); | 175 EXPECT_EQ(2UL, origins.size()); |
176 EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end()); | 176 EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end()); |
177 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); | 177 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); |
178 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) == | 178 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) == |
179 origins.end()); | 179 origins.end()); |
180 | 180 |
181 // Delete and let cleanup tasks run prior to returning. | 181 // Delete and let cleanup tasks run prior to returning. |
182 appcache_service = NULL; | 182 appcache_service = NULL; |
183 message_loop_.RunUntilIdle(); | 183 message_loop_.RunUntilIdle(); |
184 } | 184 } |
185 | 185 |
186 TEST_F(ChromeAppCacheServiceTest, SaveSessionState) { | 186 TEST_F(ChromeAppCacheServiceTest, SaveSessionState) { |
187 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 187 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
188 base::FilePath appcache_path = | 188 base::FilePath appcache_path = |
189 temp_dir_.path().Append(kTestingAppCacheDirname); | 189 temp_dir_.path().Append(kTestingAppCacheDirname); |
190 | 190 |
191 // Create a ChromeAppCacheService and insert data into it | 191 // Create a ChromeAppCacheService and insert data into it |
192 scoped_refptr<ChromeAppCacheService> appcache_service = | 192 scoped_refptr<ChromeAppCacheService> appcache_service = |
193 CreateAppCacheService(appcache_path, true); | 193 CreateAppCacheService(appcache_path, true); |
194 ASSERT_TRUE(file_util::PathExists(appcache_path)); | 194 ASSERT_TRUE(base::PathExists(appcache_path)); |
195 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index"))); | 195 ASSERT_TRUE(base::PathExists(appcache_path.AppendASCII("Index"))); |
196 InsertDataIntoAppCache(appcache_service.get()); | 196 InsertDataIntoAppCache(appcache_service.get()); |
197 | 197 |
198 // Save session state. This should bypass the destruction-time deletion. | 198 // Save session state. This should bypass the destruction-time deletion. |
199 appcache_service->set_force_keep_session_state(); | 199 appcache_service->set_force_keep_session_state(); |
200 | 200 |
201 // Test: delete the ChromeAppCacheService | 201 // Test: delete the ChromeAppCacheService |
202 appcache_service = NULL; | 202 appcache_service = NULL; |
203 message_loop_.RunUntilIdle(); | 203 message_loop_.RunUntilIdle(); |
204 | 204 |
205 // Recreate the appcache (for reading the data back) | 205 // Recreate the appcache (for reading the data back) |
206 appcache_service = CreateAppCacheService(appcache_path, false); | 206 appcache_service = CreateAppCacheService(appcache_path, false); |
207 | 207 |
208 // The directory is still there | 208 // The directory is still there |
209 ASSERT_TRUE(file_util::PathExists(appcache_path)); | 209 ASSERT_TRUE(base::PathExists(appcache_path)); |
210 | 210 |
211 // No appcache data was deleted. | 211 // No appcache data was deleted. |
212 AppCacheTestHelper appcache_helper; | 212 AppCacheTestHelper appcache_helper; |
213 std::set<GURL> origins; | 213 std::set<GURL> origins; |
214 appcache_helper.GetOriginsWithCaches(appcache_service.get(), &origins); | 214 appcache_helper.GetOriginsWithCaches(appcache_service.get(), &origins); |
215 EXPECT_EQ(3UL, origins.size()); | 215 EXPECT_EQ(3UL, origins.size()); |
216 EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end()); | 216 EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end()); |
217 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); | 217 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); |
218 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) != | 218 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) != |
219 origins.end()); | 219 origins.end()); |
220 | 220 |
221 // Delete and let cleanup tasks run prior to returning. | 221 // Delete and let cleanup tasks run prior to returning. |
222 appcache_service = NULL; | 222 appcache_service = NULL; |
223 message_loop_.RunUntilIdle(); | 223 message_loop_.RunUntilIdle(); |
224 } | 224 } |
225 | 225 |
226 } // namespace content | 226 } // namespace content |
OLD | NEW |