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/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/run_loop.h" |
10 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
11 #include "content/browser/appcache/appcache_database.h" | 12 #include "content/browser/appcache/appcache_database.h" |
12 #include "content/browser/appcache/appcache_storage_impl.h" | 13 #include "content/browser/appcache/appcache_storage_impl.h" |
13 #include "content/browser/appcache/chrome_appcache_service.h" | 14 #include "content/browser/appcache/chrome_appcache_service.h" |
14 #include "content/browser/browser_thread_impl.h" | 15 #include "content/browser/browser_thread_impl.h" |
15 #include "content/public/browser/resource_context.h" | 16 #include "content/public/browser/resource_context.h" |
16 #include "content/public/test/mock_special_storage_policy.h" | 17 #include "content/public/test/mock_special_storage_policy.h" |
17 #include "content/public/test/test_browser_context.h" | 18 #include "content/public/test/test_browser_context.h" |
18 #include "content/test/appcache_test_helper.h" | 19 #include "content/test/appcache_test_helper.h" |
19 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 new MockURLRequestContextGetter( | 102 new MockURLRequestContextGetter( |
102 browser_context_.GetResourceContext()->GetRequestContext(), | 103 browser_context_.GetResourceContext()->GetRequestContext(), |
103 message_loop_.task_runner().get()); | 104 message_loop_.task_runner().get()); |
104 BrowserThread::PostTask( | 105 BrowserThread::PostTask( |
105 BrowserThread::IO, FROM_HERE, | 106 BrowserThread::IO, FROM_HERE, |
106 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, | 107 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, |
107 appcache_service.get(), appcache_path, | 108 appcache_service.get(), appcache_path, |
108 browser_context_.GetResourceContext(), | 109 browser_context_.GetResourceContext(), |
109 base::RetainedRef(mock_request_context_getter), mock_policy)); | 110 base::RetainedRef(mock_request_context_getter), mock_policy)); |
110 // Steps needed to initialize the storage of AppCache data. | 111 // Steps needed to initialize the storage of AppCache data. |
111 message_loop_.RunUntilIdle(); | 112 base::RunLoop().RunUntilIdle(); |
112 if (init_storage) { | 113 if (init_storage) { |
113 AppCacheStorageImpl* storage = | 114 AppCacheStorageImpl* storage = |
114 static_cast<AppCacheStorageImpl*>( | 115 static_cast<AppCacheStorageImpl*>( |
115 appcache_service->storage()); | 116 appcache_service->storage()); |
116 storage->database_->db_connection(); | 117 storage->database_->db_connection(); |
117 storage->disk_cache(); | 118 storage->disk_cache(); |
118 message_loop_.RunUntilIdle(); | 119 base::RunLoop().RunUntilIdle(); |
119 } | 120 } |
120 return appcache_service; | 121 return appcache_service; |
121 } | 122 } |
122 | 123 |
123 void ChromeAppCacheServiceTest::InsertDataIntoAppCache( | 124 void ChromeAppCacheServiceTest::InsertDataIntoAppCache( |
124 ChromeAppCacheService* appcache_service) { | 125 ChromeAppCacheService* appcache_service) { |
125 AppCacheTestHelper appcache_helper; | 126 AppCacheTestHelper appcache_helper; |
126 appcache_helper.AddGroupAndCache(appcache_service, kNormalManifestURL); | 127 appcache_helper.AddGroupAndCache(appcache_service, kNormalManifestURL); |
127 appcache_helper.AddGroupAndCache(appcache_service, kProtectedManifestURL); | 128 appcache_helper.AddGroupAndCache(appcache_service, kProtectedManifestURL); |
128 appcache_helper.AddGroupAndCache(appcache_service, kSessionOnlyManifestURL); | 129 appcache_helper.AddGroupAndCache(appcache_service, kSessionOnlyManifestURL); |
(...skipping 15 matching lines...) Expand all Loading... |
144 | 145 |
145 // Create a ChromeAppCacheService and insert data into it | 146 // Create a ChromeAppCacheService and insert data into it |
146 scoped_refptr<ChromeAppCacheService> appcache_service = | 147 scoped_refptr<ChromeAppCacheService> appcache_service = |
147 CreateAppCacheServiceImpl(appcache_path, true); | 148 CreateAppCacheServiceImpl(appcache_path, true); |
148 ASSERT_TRUE(base::PathExists(appcache_path)); | 149 ASSERT_TRUE(base::PathExists(appcache_path)); |
149 ASSERT_TRUE(base::PathExists(appcache_path.AppendASCII("Index"))); | 150 ASSERT_TRUE(base::PathExists(appcache_path.AppendASCII("Index"))); |
150 InsertDataIntoAppCache(appcache_service.get()); | 151 InsertDataIntoAppCache(appcache_service.get()); |
151 | 152 |
152 // Test: delete the ChromeAppCacheService | 153 // Test: delete the ChromeAppCacheService |
153 appcache_service = NULL; | 154 appcache_service = NULL; |
154 message_loop_.RunUntilIdle(); | 155 base::RunLoop().RunUntilIdle(); |
155 | 156 |
156 // Recreate the appcache (for reading the data back) | 157 // Recreate the appcache (for reading the data back) |
157 appcache_service = CreateAppCacheServiceImpl(appcache_path, false); | 158 appcache_service = CreateAppCacheServiceImpl(appcache_path, false); |
158 | 159 |
159 // The directory is still there | 160 // The directory is still there |
160 ASSERT_TRUE(base::PathExists(appcache_path)); | 161 ASSERT_TRUE(base::PathExists(appcache_path)); |
161 | 162 |
162 // The appcache data is also there, except the session-only origin. | 163 // The appcache data is also there, except the session-only origin. |
163 AppCacheTestHelper appcache_helper; | 164 AppCacheTestHelper appcache_helper; |
164 std::set<GURL> origins; | 165 std::set<GURL> origins; |
165 appcache_helper.GetOriginsWithCaches(appcache_service.get(), &origins); | 166 appcache_helper.GetOriginsWithCaches(appcache_service.get(), &origins); |
166 EXPECT_EQ(2UL, origins.size()); | 167 EXPECT_EQ(2UL, origins.size()); |
167 EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end()); | 168 EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end()); |
168 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); | 169 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); |
169 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) == | 170 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) == |
170 origins.end()); | 171 origins.end()); |
171 | 172 |
172 // Delete and let cleanup tasks run prior to returning. | 173 // Delete and let cleanup tasks run prior to returning. |
173 appcache_service = NULL; | 174 appcache_service = NULL; |
174 message_loop_.RunUntilIdle(); | 175 base::RunLoop().RunUntilIdle(); |
175 } | 176 } |
176 | 177 |
177 TEST_F(ChromeAppCacheServiceTest, SaveSessionState) { | 178 TEST_F(ChromeAppCacheServiceTest, SaveSessionState) { |
178 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 179 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
179 base::FilePath appcache_path = | 180 base::FilePath appcache_path = |
180 temp_dir_.path().Append(kTestingAppCacheDirname); | 181 temp_dir_.path().Append(kTestingAppCacheDirname); |
181 | 182 |
182 // Create a ChromeAppCacheService and insert data into it | 183 // Create a ChromeAppCacheService and insert data into it |
183 scoped_refptr<ChromeAppCacheService> appcache_service = | 184 scoped_refptr<ChromeAppCacheService> appcache_service = |
184 CreateAppCacheServiceImpl(appcache_path, true); | 185 CreateAppCacheServiceImpl(appcache_path, true); |
185 ASSERT_TRUE(base::PathExists(appcache_path)); | 186 ASSERT_TRUE(base::PathExists(appcache_path)); |
186 ASSERT_TRUE(base::PathExists(appcache_path.AppendASCII("Index"))); | 187 ASSERT_TRUE(base::PathExists(appcache_path.AppendASCII("Index"))); |
187 InsertDataIntoAppCache(appcache_service.get()); | 188 InsertDataIntoAppCache(appcache_service.get()); |
188 | 189 |
189 // Save session state. This should bypass the destruction-time deletion. | 190 // Save session state. This should bypass the destruction-time deletion. |
190 appcache_service->set_force_keep_session_state(); | 191 appcache_service->set_force_keep_session_state(); |
191 | 192 |
192 // Test: delete the ChromeAppCacheService | 193 // Test: delete the ChromeAppCacheService |
193 appcache_service = NULL; | 194 appcache_service = NULL; |
194 message_loop_.RunUntilIdle(); | 195 base::RunLoop().RunUntilIdle(); |
195 | 196 |
196 // Recreate the appcache (for reading the data back) | 197 // Recreate the appcache (for reading the data back) |
197 appcache_service = CreateAppCacheServiceImpl(appcache_path, false); | 198 appcache_service = CreateAppCacheServiceImpl(appcache_path, false); |
198 | 199 |
199 // The directory is still there | 200 // The directory is still there |
200 ASSERT_TRUE(base::PathExists(appcache_path)); | 201 ASSERT_TRUE(base::PathExists(appcache_path)); |
201 | 202 |
202 // No appcache data was deleted. | 203 // No appcache data was deleted. |
203 AppCacheTestHelper appcache_helper; | 204 AppCacheTestHelper appcache_helper; |
204 std::set<GURL> origins; | 205 std::set<GURL> origins; |
205 appcache_helper.GetOriginsWithCaches(appcache_service.get(), &origins); | 206 appcache_helper.GetOriginsWithCaches(appcache_service.get(), &origins); |
206 EXPECT_EQ(3UL, origins.size()); | 207 EXPECT_EQ(3UL, origins.size()); |
207 EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end()); | 208 EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end()); |
208 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); | 209 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); |
209 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) != | 210 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) != |
210 origins.end()); | 211 origins.end()); |
211 | 212 |
212 // Delete and let cleanup tasks run prior to returning. | 213 // Delete and let cleanup tasks run prior to returning. |
213 appcache_service = NULL; | 214 appcache_service = NULL; |
214 message_loop_.RunUntilIdle(); | 215 base::RunLoop().RunUntilIdle(); |
215 } | 216 } |
216 | 217 |
217 } // namespace content | 218 } // namespace content |
OLD | NEW |