Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(522)

Side by Side Diff: content/browser/appcache/chrome_appcache_service_unittest.cc

Issue 16294003: Update content/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
147 TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) { 147 TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) {
148 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 148 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
149 base::FilePath appcache_path = 149 base::FilePath appcache_path =
150 temp_dir_.path().Append(kTestingAppCacheDirname); 150 temp_dir_.path().Append(kTestingAppCacheDirname);
151 151
152 // Create a ChromeAppCacheService and insert data into it 152 // Create a ChromeAppCacheService and insert data into it
153 scoped_refptr<ChromeAppCacheService> appcache_service = 153 scoped_refptr<ChromeAppCacheService> appcache_service =
154 CreateAppCacheService(appcache_path, true); 154 CreateAppCacheService(appcache_path, true);
155 ASSERT_TRUE(file_util::PathExists(appcache_path)); 155 ASSERT_TRUE(file_util::PathExists(appcache_path));
156 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index"))); 156 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index")));
157 InsertDataIntoAppCache(appcache_service); 157 InsertDataIntoAppCache(appcache_service.get());
158 158
159 // Test: delete the ChromeAppCacheService 159 // Test: delete the ChromeAppCacheService
160 appcache_service = NULL; 160 appcache_service = NULL;
161 message_loop_.RunUntilIdle(); 161 message_loop_.RunUntilIdle();
162 162
163 // Recreate the appcache (for reading the data back) 163 // Recreate the appcache (for reading the data back)
164 appcache_service = CreateAppCacheService(appcache_path, false); 164 appcache_service = CreateAppCacheService(appcache_path, false);
165 165
166 // The directory is still there 166 // The directory is still there
167 ASSERT_TRUE(file_util::PathExists(appcache_path)); 167 ASSERT_TRUE(file_util::PathExists(appcache_path));
168 168
169 // The appcache data is also there, except the session-only origin. 169 // The appcache data is also there, except the session-only origin.
170 AppCacheTestHelper appcache_helper; 170 AppCacheTestHelper appcache_helper;
171 std::set<GURL> origins; 171 std::set<GURL> origins;
172 appcache_helper.GetOriginsWithCaches(appcache_service, &origins); 172 appcache_helper.GetOriginsWithCaches(appcache_service.get(), &origins);
173 EXPECT_EQ(2UL, origins.size()); 173 EXPECT_EQ(2UL, origins.size());
174 EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end()); 174 EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end());
175 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); 175 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end());
176 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) == 176 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) ==
177 origins.end()); 177 origins.end());
178 178
179 // Delete and let cleanup tasks run prior to returning. 179 // Delete and let cleanup tasks run prior to returning.
180 appcache_service = NULL; 180 appcache_service = NULL;
181 message_loop_.RunUntilIdle(); 181 message_loop_.RunUntilIdle();
182 } 182 }
183 183
184 TEST_F(ChromeAppCacheServiceTest, SaveSessionState) { 184 TEST_F(ChromeAppCacheServiceTest, SaveSessionState) {
185 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 185 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
186 base::FilePath appcache_path = 186 base::FilePath appcache_path =
187 temp_dir_.path().Append(kTestingAppCacheDirname); 187 temp_dir_.path().Append(kTestingAppCacheDirname);
188 188
189 // Create a ChromeAppCacheService and insert data into it 189 // Create a ChromeAppCacheService and insert data into it
190 scoped_refptr<ChromeAppCacheService> appcache_service = 190 scoped_refptr<ChromeAppCacheService> appcache_service =
191 CreateAppCacheService(appcache_path, true); 191 CreateAppCacheService(appcache_path, true);
192 ASSERT_TRUE(file_util::PathExists(appcache_path)); 192 ASSERT_TRUE(file_util::PathExists(appcache_path));
193 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index"))); 193 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index")));
194 InsertDataIntoAppCache(appcache_service); 194 InsertDataIntoAppCache(appcache_service.get());
195 195
196 // Save session state. This should bypass the destruction-time deletion. 196 // Save session state. This should bypass the destruction-time deletion.
197 appcache_service->set_force_keep_session_state(); 197 appcache_service->set_force_keep_session_state();
198 198
199 // Test: delete the ChromeAppCacheService 199 // Test: delete the ChromeAppCacheService
200 appcache_service = NULL; 200 appcache_service = NULL;
201 message_loop_.RunUntilIdle(); 201 message_loop_.RunUntilIdle();
202 202
203 // Recreate the appcache (for reading the data back) 203 // Recreate the appcache (for reading the data back)
204 appcache_service = CreateAppCacheService(appcache_path, false); 204 appcache_service = CreateAppCacheService(appcache_path, false);
205 205
206 // The directory is still there 206 // The directory is still there
207 ASSERT_TRUE(file_util::PathExists(appcache_path)); 207 ASSERT_TRUE(file_util::PathExists(appcache_path));
208 208
209 // No appcache data was deleted. 209 // No appcache data was deleted.
210 AppCacheTestHelper appcache_helper; 210 AppCacheTestHelper appcache_helper;
211 std::set<GURL> origins; 211 std::set<GURL> origins;
212 appcache_helper.GetOriginsWithCaches(appcache_service, &origins); 212 appcache_helper.GetOriginsWithCaches(appcache_service.get(), &origins);
213 EXPECT_EQ(3UL, origins.size()); 213 EXPECT_EQ(3UL, origins.size());
214 EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end()); 214 EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end());
215 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); 215 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end());
216 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) != 216 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) !=
217 origins.end()); 217 origins.end());
218 218
219 // Delete and let cleanup tasks run prior to returning. 219 // Delete and let cleanup tasks run prior to returning.
220 appcache_service = NULL; 220 appcache_service = NULL;
221 message_loop_.RunUntilIdle(); 221 message_loop_.RunUntilIdle();
222 } 222 }
223 223
224 } // namespace content 224 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/chrome_appcache_service.cc ('k') | content/browser/browser_plugin/browser_plugin_host_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698