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

Side by Side Diff: chrome/browser/browsing_data_remover_unittest.cc

Issue 7129018: Time-based removal of temporary file systems via BrowsingDataRemover (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: QuotaManager. Created 9 years, 5 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) 2011 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/browsing_data_remover.h" 5 #include "chrome/browser/browsing_data_remover.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/platform_file.h" 10 #include "base/platform_file.h"
11 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h" 11 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h"
12 #include "chrome/browser/history/history.h" 12 #include "chrome/browser/history/history.h"
13 #include "chrome/test/testing_profile.h" 13 #include "chrome/test/testing_profile.h"
14 #include "content/browser/appcache/chrome_appcache_service.h" 14 #include "content/browser/appcache/chrome_appcache_service.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webkit/appcache/appcache.h" 16 #include "webkit/appcache/appcache.h"
17 #include "webkit/appcache/appcache_group.h" 17 #include "webkit/appcache/appcache_group.h"
18 #include "webkit/appcache/appcache_storage.h" 18 #include "webkit/appcache/appcache_storage.h"
19 #include "webkit/fileapi/file_system_context.h" 19 #include "webkit/fileapi/file_system_context.h"
20 #include "webkit/fileapi/file_system_operation_context.h" 20 #include "webkit/fileapi/file_system_operation_context.h"
21 #include "webkit/fileapi/file_system_file_util.h" 21 #include "webkit/fileapi/file_system_file_util.h"
22 #include "webkit/fileapi/file_system_path_manager.h" 22 #include "webkit/fileapi/file_system_path_manager.h"
23 #include "webkit/fileapi/file_system_test_helper.h"
23 #include "webkit/fileapi/sandbox_mount_point_provider.h" 24 #include "webkit/fileapi/sandbox_mount_point_provider.h"
25 #include "webkit/quota/quota_client.h"
26 #include "webkit/quota/quota_manager.h"
27 #include "webkit/quota/quota_types.h"
28
29 // Outside the anon. namespace so that it can be friends with
30 // quota::QuotaManager.
31 class BrowsingDataRemoverFileSystemTesterHelper {
32 public:
33 static void SetQuotaModified(quota::QuotaManager* manager, const GURL& origin,
34 quota::StorageType type, const base::Time& modified) {
35 manager->NotifyStorageModifiedInternal(quota::QuotaClient::kFileSystem,
36 origin, type, 0, modified);
37 }
38
39 private:
40 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverFileSystemTesterHelper);
41 };
24 42
25 namespace { 43 namespace {
26 44
27 const char kTestkOrigin1[] = "http://host1:1/"; 45 const char kTestkOrigin1[] = "http://host1:1/";
28 const char kTestkOrigin2[] = "http://host2:1/"; 46 const char kTestkOrigin2[] = "http://host2:1/";
29 const char kTestkOrigin3[] = "http://host3:1/"; 47 const char kTestkOrigin3[] = "http://host3:1/";
30 48
31 const GURL kOrigin1(kTestkOrigin1); 49 const GURL kOrigin1(kTestkOrigin1);
32 const GURL kOrigin2(kTestkOrigin2); 50 const GURL kOrigin2(kTestkOrigin2);
33 const GURL kOrigin3(kTestkOrigin3); 51 const GURL kOrigin3(kTestkOrigin3);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 sandbox_->ValidateFileSystemRootAndGetURL( 137 sandbox_->ValidateFileSystemRootAndGetURL(
120 origin, type, false, NewCallback(this, 138 origin, type, false, NewCallback(this,
121 &RemoveFileSystemTester::FindFileSystemPathCallback)); 139 &RemoveFileSystemTester::FindFileSystemPathCallback));
122 BlockUntilNotified(); 140 BlockUntilNotified();
123 return found_file_system_; 141 return found_file_system_;
124 } 142 }
125 143
126 virtual void PopulateTestFileSystemData(TestingProfile* profile) { 144 virtual void PopulateTestFileSystemData(TestingProfile* profile) {
127 // Set up kOrigin1 with a temporary file system, kOrigin2 with a persistent 145 // Set up kOrigin1 with a temporary file system, kOrigin2 with a persistent
128 // file system, and kOrigin3 with both. 146 // file system, and kOrigin3 with both.
129 sandbox_ = profile->GetFileSystemContext()->path_manager()-> 147 profile_ = profile;
148 sandbox_ = profile_->GetFileSystemContext()->path_manager()->
130 sandbox_provider(); 149 sandbox_provider();
131 150
132 CreateDirectoryForOriginAndType(kOrigin1, 151 CreateDirectoryForOriginAndType(kOrigin1,
133 fileapi::kFileSystemTypeTemporary); 152 fileapi::kFileSystemTypeTemporary);
134 CreateDirectoryForOriginAndType(kOrigin2, 153 CreateDirectoryForOriginAndType(kOrigin2,
135 fileapi::kFileSystemTypePersistent); 154 fileapi::kFileSystemTypePersistent);
136 CreateDirectoryForOriginAndType(kOrigin3, 155 CreateDirectoryForOriginAndType(kOrigin3,
137 fileapi::kFileSystemTypeTemporary); 156 fileapi::kFileSystemTypeTemporary);
138 CreateDirectoryForOriginAndType(kOrigin3, 157 CreateDirectoryForOriginAndType(kOrigin3,
139 fileapi::kFileSystemTypePersistent); 158 fileapi::kFileSystemTypePersistent);
140 159
160 FilePath temp(FILE_PATH_LITERAL("/tempfile.tmp"));
161 TouchTestFileForOriginAndType(kOrigin1, fileapi::kFileSystemTypeTemporary,
162 temp, base::Time::Now());
163 TouchTestFileForOriginAndType(kOrigin2, fileapi::kFileSystemTypePersistent,
164 temp, base::Time::Now());
165 TouchTestFileForOriginAndType(kOrigin3, fileapi::kFileSystemTypePersistent,
166 temp, base::Time::Now());
167 TouchTestFileForOriginAndType(kOrigin3, fileapi::kFileSystemTypeTemporary,
168 temp, base::Time::Now());
169
141 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin1, 170 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin1,
142 fileapi::kFileSystemTypePersistent)); 171 fileapi::kFileSystemTypePersistent));
143 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin1, 172 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin1,
144 fileapi::kFileSystemTypeTemporary)); 173 fileapi::kFileSystemTypeTemporary));
145 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin2, 174 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin2,
146 fileapi::kFileSystemTypePersistent)); 175 fileapi::kFileSystemTypePersistent));
147 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin2, 176 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin2,
148 fileapi::kFileSystemTypeTemporary)); 177 fileapi::kFileSystemTypeTemporary));
149 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, 178 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3,
150 fileapi::kFileSystemTypePersistent)); 179 fileapi::kFileSystemTypePersistent));
151 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3, 180 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3,
152 fileapi::kFileSystemTypeTemporary)); 181 fileapi::kFileSystemTypeTemporary));
153 } 182 }
154 183
155 void CreateDirectoryForOriginAndType(const GURL& origin, 184 void CreateDirectoryForOriginAndType(const GURL& origin,
156 fileapi::FileSystemType type) { 185 fileapi::FileSystemType type) {
186 fileapi::FileSystemTestOriginHelper helper(origin, type);
187 helper.SetUp(profile_->GetFileSystemContext(),
188 sandbox_->GetFileSystemFileUtil());
157 FilePath target = sandbox_->ValidateFileSystemRootAndGetPathOnFileThread( 189 FilePath target = sandbox_->ValidateFileSystemRootAndGetPathOnFileThread(
158 origin, type, FilePath(), true); 190 origin, type, FilePath(), true);
159 EXPECT_TRUE(file_util::DirectoryExists(target)); 191 EXPECT_TRUE(file_util::DirectoryExists(target));
160 } 192 }
161 193
194 void TouchTestFileForOriginAndType(const GURL& origin,
195 fileapi::FileSystemType type,
196 const FilePath& path,
197 const base::Time& modified) {
198 // We can use a raw pointer here for the same reason that `sandbox_` can be
199 // a raw pointer: everything is destroyed when the profile destroys the
200 // FileSystemContext in which they each live.
201 fileapi::FileSystemFileUtil* file_util = sandbox_->GetFileSystemFileUtil();
202
203 // The operation context, though, we'll have to destroy ourselves.
204 scoped_ptr<fileapi::FileSystemOperationContext>
205 op_context(new fileapi::FileSystemOperationContext(
206 profile_->GetFileSystemContext(), file_util));
207 op_context->set_src_origin_url(origin);
208 op_context->set_src_type(type);
209
210 bool created;
211 base::PlatformFileError status = file_util->EnsureFileExists(
212 op_context.get(), path, &created);
213 BrowsingDataRemoverFileSystemTesterHelper::SetQuotaModified(
214 profile_->GetQuotaManager(), origin,
215 type == fileapi::kFileSystemTypeTemporary ?
216 quota::kStorageTypeTemporary : quota::kStorageTypePersistent,
217 modified);
218 EXPECT_EQ(base::PLATFORM_FILE_OK, status);
219 EXPECT_TRUE(created);
220 }
221
162 private: 222 private:
223 // We own neither of these pointers; we shouldn't destroy them.
163 fileapi::SandboxMountPointProvider* sandbox_; 224 fileapi::SandboxMountPointProvider* sandbox_;
225 TestingProfile* profile_;
164 bool found_file_system_; 226 bool found_file_system_;
165 227
166 DISALLOW_COPY_AND_ASSIGN(RemoveFileSystemTester); 228 DISALLOW_COPY_AND_ASSIGN(RemoveFileSystemTester);
167 }; 229 };
168 230
169 // Helper class for injecting data into AppCacheStorage. 231 // Helper class for injecting data into AppCacheStorage.
170 class AppCacheInserter : public appcache::AppCacheStorage::Delegate { 232 class AppCacheInserter : public appcache::AppCacheStorage::Delegate {
171 public: 233 public:
172 AppCacheInserter() 234 AppCacheInserter()
173 : group_id_(0), 235 : group_id_(0),
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin2, 415 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin2,
354 fileapi::kFileSystemTypePersistent)); 416 fileapi::kFileSystemTypePersistent));
355 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin2, 417 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin2,
356 fileapi::kFileSystemTypeTemporary)); 418 fileapi::kFileSystemTypeTemporary));
357 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin3, 419 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin3,
358 fileapi::kFileSystemTypePersistent)); 420 fileapi::kFileSystemTypePersistent));
359 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin3, 421 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin3,
360 fileapi::kFileSystemTypeTemporary)); 422 fileapi::kFileSystemTypeTemporary));
361 } 423 }
362 424
425 TEST_F(BrowsingDataRemoverTest, RemoveFileSystemsForLastHour) {
426 scoped_ptr<RemoveFileSystemTester> tester(new RemoveFileSystemTester());
427
428 tester->PopulateTestFileSystemData(GetProfile());
429
430 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
431 base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get());
432
433 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin1,
434 fileapi::kFileSystemTypePersistent));
435 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin1,
436 fileapi::kFileSystemTypeTemporary));
437 EXPECT_TRUE(tester->FileSystemContainsOriginAndType(kOrigin2,
438 fileapi::kFileSystemTypePersistent));
439 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin2,
440 fileapi::kFileSystemTypeTemporary));
441 EXPECT_TRUE(tester->FileSystemContainsOriginAndType(kOrigin3,
442 fileapi::kFileSystemTypePersistent));
443 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin3,
444 fileapi::kFileSystemTypeTemporary));
445 }
446
363 TEST_F(BrowsingDataRemoverTest, RemoveAppCacheForever) { 447 TEST_F(BrowsingDataRemoverTest, RemoveAppCacheForever) {
364 // Set up ChromeAppCacheService with a single protected origin 448 // Set up ChromeAppCacheService with a single protected origin
365 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = 449 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
366 new MockExtensionSpecialStoragePolicy; 450 new MockExtensionSpecialStoragePolicy;
367 mock_policy->AddProtected(kProtectedManifest.GetOrigin()); 451 mock_policy->AddProtected(kProtectedManifest.GetOrigin());
368 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy); 452 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy);
369 scoped_refptr<ChromeAppCacheService> appcache_service = 453 scoped_refptr<ChromeAppCacheService> appcache_service =
370 GetProfile()->GetAppCacheService(); 454 GetProfile()->GetAppCacheService();
371 455
372 // AppCacheService is initialized asynchronously. It must be finished before 456 // AppCacheService is initialized asynchronously. It must be finished before
(...skipping 27 matching lines...) Expand all
400 tester->BlockUntilNotified(); 484 tester->BlockUntilNotified();
401 485
402 // Results: appcaches for the normal origin got deleted, appcaches for the 486 // Results: appcaches for the normal origin got deleted, appcaches for the
403 // protected origin didn't. 487 // protected origin didn't.
404 origins = reader.ReadAppCaches(); 488 origins = reader.ReadAppCaches();
405 EXPECT_EQ(1UL, origins->size()); 489 EXPECT_EQ(1UL, origins->size());
406 EXPECT_TRUE(origins->find(kProtectedManifest.GetOrigin()) != origins->end()); 490 EXPECT_TRUE(origins->find(kProtectedManifest.GetOrigin()) != origins->end());
407 } 491 }
408 492
409 } // namespace 493 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698