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

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: michaeln's feedback. 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"
15 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webkit/appcache/appcache_test_helper.h"
17 #include "webkit/fileapi/file_system_context.h" 15 #include "webkit/fileapi/file_system_context.h"
16 #include "webkit/fileapi/file_system_file_util.h"
18 #include "webkit/fileapi/file_system_operation_context.h" 17 #include "webkit/fileapi/file_system_operation_context.h"
19 #include "webkit/fileapi/file_system_file_util.h"
20 #include "webkit/fileapi/file_system_path_manager.h" 18 #include "webkit/fileapi/file_system_path_manager.h"
21 #include "webkit/fileapi/sandbox_mount_point_provider.h" 19 #include "webkit/fileapi/sandbox_mount_point_provider.h"
20 #include "webkit/quota/mock_quota_manager.h"
21 #include "webkit/quota/quota_manager.h"
22 #include "webkit/quota/quota_types.h"
22 23
23 namespace { 24 namespace {
24 25
25 const char kTestkOrigin1[] = "http://host1:1/"; 26 const char kTestkOrigin1[] = "http://host1:1/";
26 const char kTestkOrigin2[] = "http://host2:1/"; 27 const char kTestkOrigin2[] = "http://host2:1/";
27 const char kTestkOrigin3[] = "http://host3:1/"; 28 const char kTestkOrigin3[] = "http://host3:1/";
28 29
29 const GURL kOrigin1(kTestkOrigin1); 30 const GURL kOrigin1(kTestkOrigin1);
30 const GURL kOrigin2(kTestkOrigin2); 31 const GURL kOrigin2(kTestkOrigin2);
31 const GURL kOrigin3(kTestkOrigin3); 32 const GURL kOrigin3(kTestkOrigin3);
32 33
33 const GURL kProtectedManifest("http://www.protected.com/cache.manifest");
34 const GURL kNormalManifest("http://www.normal.com/cache.manifest");
35
36 class BrowsingDataRemoverTester : public BrowsingDataRemover::Observer { 34 class BrowsingDataRemoverTester : public BrowsingDataRemover::Observer {
37 public: 35 public:
38 BrowsingDataRemoverTester() {} 36 BrowsingDataRemoverTester() {}
39 virtual ~BrowsingDataRemoverTester() {} 37 virtual ~BrowsingDataRemoverTester() {}
40 38
41 void BlockUntilNotified() { 39 void BlockUntilNotified() {
42 MessageLoop::current()->Run(); 40 MessageLoop::current()->Run();
43 } 41 }
44 42
45 protected: 43 protected:
46 // BrowsingDataRemover::Observer implementation. 44 // BrowsingDataRemover::Observer implementation.
47 virtual void OnBrowsingDataRemoverDone() { 45 virtual void OnBrowsingDataRemoverDone() {
48 Notify(); 46 Notify();
49 } 47 }
50 48
51 void Notify() { 49 void Notify() {
52 MessageLoop::current()->Quit(); 50 MessageLoop::current()->Quit();
53 } 51 }
54 52
55 private: 53 private:
56 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTester); 54 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTester);
57 }; 55 };
58 56
57 // Testers -------------------------------------------------------------------
58
59 class RemoveHistoryTester : public BrowsingDataRemoverTester { 59 class RemoveHistoryTester : public BrowsingDataRemoverTester {
60 public: 60 public:
61 explicit RemoveHistoryTester(TestingProfile* profile) 61 explicit RemoveHistoryTester(TestingProfile* profile)
62 : query_url_success_(false) { 62 : query_url_success_(false) {
63 profile->CreateHistoryService(true, false); 63 profile->CreateHistoryService(true, false);
64 history_service_ = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); 64 history_service_ = profile->GetHistoryService(Profile::EXPLICIT_ACCESS);
65 } 65 }
66 66
67 // Returns true, if the given URL exists in the history service. 67 // Returns true, if the given URL exists in the history service.
68 bool HistoryContainsURL(const GURL& url) { 68 bool HistoryContainsURL(const GURL& url) {
(...skipping 25 matching lines...) Expand all
94 // For History requests. 94 // For History requests.
95 CancelableRequestConsumer consumer_; 95 CancelableRequestConsumer consumer_;
96 bool query_url_success_; 96 bool query_url_success_;
97 97
98 // TestingProfile owns the history service; we shouldn't delete it. 98 // TestingProfile owns the history service; we shouldn't delete it.
99 HistoryService* history_service_; 99 HistoryService* history_service_;
100 100
101 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester); 101 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester);
102 }; 102 };
103 103
104 class RemoveFileSystemTester : public BrowsingDataRemoverTester { 104 class RemoveQuotaManagedDataTester : public BrowsingDataRemoverTester {
105 public: 105 public:
106 explicit RemoveFileSystemTester() {} 106 RemoveQuotaManagedDataTester() {}
107 virtual ~RemoveQuotaManagedDataTester() {}
107 108
108 void FindFileSystemPathCallback(bool success, 109 void PopulateTestQuotaManagedData(quota::MockQuotaManager* manager) {
109 const FilePath& path, 110 // Set up kOrigin1 with a temporary quota, kOrigin2 with a persistent
110 const std::string& name) { 111 // quota, and kOrigin3 with both. kOrigin1 is modified now, kOrigin2
111 found_file_system_ = success; 112 // is modified at the beginning of time, and kOrigin3 is modified one day
112 Notify(); 113 // ago.
114 PopulateTestQuotaManagedPersistentData(manager);
115 PopulateTestQuotaManagedTemporaryData(manager);
113 } 116 }
114 117
115 bool FileSystemContainsOriginAndType(const GURL& origin, 118 void PopulateTestQuotaManagedPersistentData(
116 fileapi::FileSystemType type) { 119 quota::MockQuotaManager* manager) {
117 sandbox_->ValidateFileSystemRootAndGetURL( 120 manager->AddOrigin(kOrigin2, quota::kStorageTypePersistent,
118 origin, type, false, NewCallback(this, 121 base::Time());
119 &RemoveFileSystemTester::FindFileSystemPathCallback)); 122 manager->AddOrigin(kOrigin3, quota::kStorageTypePersistent,
120 BlockUntilNotified(); 123 base::Time::Now() - base::TimeDelta::FromDays(1));
121 return found_file_system_; 124
125 EXPECT_FALSE(manager->OriginHasData(kOrigin1,
126 quota::kStorageTypePersistent));
127 EXPECT_TRUE(manager->OriginHasData(kOrigin2,
128 quota::kStorageTypePersistent));
129 EXPECT_TRUE(manager->OriginHasData(kOrigin3,
130 quota::kStorageTypePersistent));
122 } 131 }
123 132
124 virtual void PopulateTestFileSystemData(TestingProfile* profile) { 133 void PopulateTestQuotaManagedTemporaryData(quota::MockQuotaManager* manager) {
125 // Set up kOrigin1 with a temporary file system, kOrigin2 with a persistent 134 manager->AddOrigin(kOrigin1, quota::kStorageTypeTemporary,
126 // file system, and kOrigin3 with both. 135 base::Time::Now());
127 sandbox_ = profile->GetFileSystemContext()->path_manager()-> 136 manager->AddOrigin(kOrigin3, quota::kStorageTypeTemporary,
128 sandbox_provider(); 137 base::Time::Now() - base::TimeDelta::FromDays(1));
129 138
130 CreateDirectoryForOriginAndType(kOrigin1, 139 EXPECT_TRUE(manager->OriginHasData(kOrigin1,
131 fileapi::kFileSystemTypeTemporary); 140 quota::kStorageTypeTemporary));
132 CreateDirectoryForOriginAndType(kOrigin2, 141 EXPECT_FALSE(manager->OriginHasData(kOrigin2,
133 fileapi::kFileSystemTypePersistent); 142 quota::kStorageTypeTemporary));
134 CreateDirectoryForOriginAndType(kOrigin3, 143 EXPECT_TRUE(manager->OriginHasData(kOrigin3,
135 fileapi::kFileSystemTypeTemporary); 144 quota::kStorageTypeTemporary));
136 CreateDirectoryForOriginAndType(kOrigin3,
137 fileapi::kFileSystemTypePersistent);
138
139 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin1,
140 fileapi::kFileSystemTypePersistent));
141 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin1,
142 fileapi::kFileSystemTypeTemporary));
143 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin2,
144 fileapi::kFileSystemTypePersistent));
145 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin2,
146 fileapi::kFileSystemTypeTemporary));
147 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3,
148 fileapi::kFileSystemTypePersistent));
149 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin3,
150 fileapi::kFileSystemTypeTemporary));
151 }
152
153 void CreateDirectoryForOriginAndType(const GURL& origin,
154 fileapi::FileSystemType type) {
155 FilePath target = sandbox_->ValidateFileSystemRootAndGetPathOnFileThread(
156 origin, type, FilePath(), true);
157 EXPECT_TRUE(file_util::DirectoryExists(target));
158 } 145 }
159 146
160 private: 147 private:
161 fileapi::SandboxMountPointProvider* sandbox_; 148 DISALLOW_COPY_AND_ASSIGN(RemoveQuotaManagedDataTester);
162 bool found_file_system_; 149 };
163 150
164 DISALLOW_COPY_AND_ASSIGN(RemoveFileSystemTester); 151 // Test Class ----------------------------------------------------------------
165 };
166 152
167 class BrowsingDataRemoverTest : public testing::Test { 153 class BrowsingDataRemoverTest : public testing::Test {
168 public: 154 public:
169 BrowsingDataRemoverTest() 155 BrowsingDataRemoverTest()
170 : ui_thread_(BrowserThread::UI, &message_loop_), 156 : ui_thread_(BrowserThread::UI, &message_loop_),
171 db_thread_(BrowserThread::DB, &message_loop_), 157 db_thread_(BrowserThread::DB, &message_loop_),
172 webkit_thread_(BrowserThread::WEBKIT, &message_loop_), 158 webkit_thread_(BrowserThread::WEBKIT, &message_loop_),
173 file_thread_(BrowserThread::FILE, &message_loop_), 159 file_thread_(BrowserThread::FILE, &message_loop_),
174 io_thread_(BrowserThread::IO, &message_loop_), 160 io_thread_(BrowserThread::IO, &message_loop_),
175 profile_(new TestingProfile()) { 161 profile_(new TestingProfile()) {
(...skipping 22 matching lines...) Expand all
198 184
199 // BrowsingDataRemover deletes itself when it completes. 185 // BrowsingDataRemover deletes itself when it completes.
200 remover->Remove(remove_mask); 186 remover->Remove(remove_mask);
201 tester->BlockUntilNotified(); 187 tester->BlockUntilNotified();
202 } 188 }
203 189
204 TestingProfile* GetProfile() { 190 TestingProfile* GetProfile() {
205 return profile_.get(); 191 return profile_.get();
206 } 192 }
207 193
194 quota::MockQuotaManager* GetMockManager() {
195 if (profile_->GetQuotaManager() == NULL) {
196 profile_->SetQuotaManager(new quota::MockQuotaManager(
197 profile_->IsOffTheRecord(),
198 profile_->GetPath(),
199 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
200 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
201 profile_->GetExtensionSpecialStoragePolicy()));
202 }
203 return (quota::MockQuotaManager*) profile_->GetQuotaManager();
204 }
205
208 private: 206 private:
209 // message_loop_, as well as all the threads associated with it must be 207 // message_loop_, as well as all the threads associated with it must be
210 // defined before profile_ to prevent explosions. Oh how I love C++. 208 // defined before profile_ to prevent explosions. Oh how I love C++.
211 MessageLoopForUI message_loop_; 209 MessageLoopForUI message_loop_;
212 BrowserThread ui_thread_; 210 BrowserThread ui_thread_;
213 BrowserThread db_thread_; 211 BrowserThread db_thread_;
214 BrowserThread webkit_thread_; 212 BrowserThread webkit_thread_;
215 BrowserThread file_thread_; 213 BrowserThread file_thread_;
216 BrowserThread io_thread_; 214 BrowserThread io_thread_;
217 scoped_ptr<TestingProfile> profile_; 215 scoped_ptr<TestingProfile> profile_;
218 216
219 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); 217 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest);
220 }; 218 };
221 219
220 // Tests ---------------------------------------------------------------------
221
222 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) { 222 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) {
223 scoped_ptr<RemoveHistoryTester> tester( 223 scoped_ptr<RemoveHistoryTester> tester(
224 new RemoveHistoryTester(GetProfile())); 224 new RemoveHistoryTester(GetProfile()));
225 225
226 tester->AddHistory(kOrigin1, base::Time::Now()); 226 tester->AddHistory(kOrigin1, base::Time::Now());
227 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); 227 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1));
228 228
229 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 229 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
230 base::Time::Now(), BrowsingDataRemover::REMOVE_HISTORY, tester.get()); 230 base::Time::Now(), BrowsingDataRemover::REMOVE_HISTORY, tester.get());
231 231
(...skipping 11 matching lines...) Expand all
243 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); 243 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1));
244 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2)); 244 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2));
245 245
246 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, 246 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
247 base::Time::Now(), BrowsingDataRemover::REMOVE_HISTORY, tester.get()); 247 base::Time::Now(), BrowsingDataRemover::REMOVE_HISTORY, tester.get());
248 248
249 EXPECT_FALSE(tester->HistoryContainsURL(kOrigin1)); 249 EXPECT_FALSE(tester->HistoryContainsURL(kOrigin1));
250 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2)); 250 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2));
251 } 251 }
252 252
253 TEST_F(BrowsingDataRemoverTest, RemoveFileSystemsForever) { 253 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) {
254 scoped_ptr<RemoveFileSystemTester> tester(new RemoveFileSystemTester()); 254 scoped_ptr<RemoveQuotaManagedDataTester> tester(
255 new RemoveQuotaManagedDataTester());
255 256
256 tester->PopulateTestFileSystemData(GetProfile()); 257 tester->PopulateTestQuotaManagedData(GetMockManager());
258 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
259 base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get());
260
261 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
262 quota::kStorageTypeTemporary));
263 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
264 quota::kStorageTypeTemporary));
265 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
266 quota::kStorageTypeTemporary));
267 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
268 quota::kStorageTypePersistent));
269 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
270 quota::kStorageTypePersistent));
271 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
272 quota::kStorageTypePersistent));
273 }
274
275 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyTemporary) {
276 scoped_ptr<RemoveQuotaManagedDataTester> tester(
277 new RemoveQuotaManagedDataTester());
278
279 tester->PopulateTestQuotaManagedTemporaryData(GetMockManager());
280 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
281 base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get());
282
283 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
284 quota::kStorageTypeTemporary));
285 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
286 quota::kStorageTypeTemporary));
287 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
288 quota::kStorageTypeTemporary));
289 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
290 quota::kStorageTypePersistent));
291 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
292 quota::kStorageTypePersistent));
293 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
294 quota::kStorageTypePersistent));
295 }
296
297 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyPersistent) {
298 scoped_ptr<RemoveQuotaManagedDataTester> tester(
299 new RemoveQuotaManagedDataTester());
300
301 tester->PopulateTestQuotaManagedPersistentData(GetMockManager());
302 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
303 base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get());
304
305 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
306 quota::kStorageTypeTemporary));
307 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
308 quota::kStorageTypeTemporary));
309 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
310 quota::kStorageTypeTemporary));
311 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
312 quota::kStorageTypePersistent));
313 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
314 quota::kStorageTypePersistent));
315 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
316 quota::kStorageTypePersistent));
317 }
318
319 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverNeither) {
320 scoped_ptr<RemoveQuotaManagedDataTester> tester(
321 new RemoveQuotaManagedDataTester());
322
323 GetMockManager(); // Creates the QuotaManager instance.
324 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
325 base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get());
326
327 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
328 quota::kStorageTypeTemporary));
329 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
330 quota::kStorageTypeTemporary));
331 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
332 quota::kStorageTypeTemporary));
333 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
334 quota::kStorageTypePersistent));
335 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
336 quota::kStorageTypePersistent));
337 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
338 quota::kStorageTypePersistent));
339 }
340
341 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) {
342 scoped_ptr<RemoveQuotaManagedDataTester> tester(
343 new RemoveQuotaManagedDataTester());
344 tester->PopulateTestQuotaManagedData(GetMockManager());
345
346 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
347 base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get());
348
349 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
350 quota::kStorageTypeTemporary));
351 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
352 quota::kStorageTypeTemporary));
353 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3,
354 quota::kStorageTypeTemporary));
355 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
356 quota::kStorageTypePersistent));
357 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2,
358 quota::kStorageTypePersistent));
359 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3,
360 quota::kStorageTypePersistent));
361 }
362
363 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastWeek) {
364 scoped_ptr<RemoveQuotaManagedDataTester> tester(
365 new RemoveQuotaManagedDataTester());
366 tester->PopulateTestQuotaManagedData(GetMockManager());
367
368 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK,
369 base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get());
370
371 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
372 quota::kStorageTypeTemporary));
373 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
374 quota::kStorageTypeTemporary));
375 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
376 quota::kStorageTypeTemporary));
377 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
378 quota::kStorageTypePersistent));
379 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2,
380 quota::kStorageTypePersistent));
381 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3,
382 quota::kStorageTypePersistent));
383 }
384
385 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedUnprotectedOrigins) {
386 // Protect kOrigin1.
387 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
388 new MockExtensionSpecialStoragePolicy;
389 mock_policy->AddProtected(kOrigin1.GetOrigin());
390 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy);
391
392 scoped_ptr<RemoveQuotaManagedDataTester> tester(
393 new RemoveQuotaManagedDataTester());
394 tester->PopulateTestQuotaManagedData(GetMockManager());
257 395
258 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 396 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
259 base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get()); 397 base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get());
260 398
261 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin1, 399 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1,
262 fileapi::kFileSystemTypePersistent)); 400 quota::kStorageTypeTemporary));
263 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin1, 401 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
264 fileapi::kFileSystemTypeTemporary)); 402 quota::kStorageTypeTemporary));
265 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin2, 403 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
266 fileapi::kFileSystemTypePersistent)); 404 quota::kStorageTypeTemporary));
267 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin2, 405 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
268 fileapi::kFileSystemTypeTemporary)); 406 quota::kStorageTypePersistent));
269 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin3, 407 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
270 fileapi::kFileSystemTypePersistent)); 408 quota::kStorageTypePersistent));
271 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin3, 409 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
272 fileapi::kFileSystemTypeTemporary)); 410 quota::kStorageTypePersistent));
273 }
274
275 TEST_F(BrowsingDataRemoverTest, RemoveAppCacheForever) {
276 // Set up ChromeAppCacheService.
277 scoped_refptr<ChromeAppCacheService> appcache_service =
278 new ChromeAppCacheService(NULL);
279 const content::ResourceContext* resource_context = NULL;
280 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
281 new MockExtensionSpecialStoragePolicy;
282 mock_policy->AddProtected(kProtectedManifest.GetOrigin());
283 BrowserThread::PostTask(
284 BrowserThread::IO, FROM_HERE,
285 NewRunnableMethod(appcache_service.get(),
286 &ChromeAppCacheService::InitializeOnIOThread,
287 FilePath(),
288 resource_context,
289 mock_policy));
290 MessageLoop::current()->RunAllPending();
291 TestingProfile* profile = GetProfile();
292 profile->SetAppCacheService(appcache_service);
293 profile->SetExtensionSpecialStoragePolicy(mock_policy);
294
295 // Add data into the AppCacheStorage.
296 appcache::AppCacheTestHelper appcache_helper;
297 appcache_helper.AddGroupAndCache(appcache_service, kNormalManifest);
298 appcache_helper.AddGroupAndCache(appcache_service, kProtectedManifest);
299
300 // Verify that adding the data succeeded.
301 std::set<GURL> origins;
302 appcache_helper.GetOriginsWithCaches(appcache_service, &origins);
303 EXPECT_EQ(2UL, origins.size());
304 EXPECT_TRUE(origins.find(kProtectedManifest.GetOrigin()) != origins.end());
305 EXPECT_TRUE(origins.find(kNormalManifest.GetOrigin()) != origins.end());
306
307 // Set up the object to be tested.
308 scoped_ptr<BrowsingDataRemoverTester> tester(new BrowsingDataRemoverTester());
309 BrowsingDataRemover* remover = new BrowsingDataRemover(
310 profile, BrowsingDataRemover::EVERYTHING, base::Time::Now());
311 remover->AddObserver(tester.get());
312
313 // Remove the appcaches and wait for it to complete. BrowsingDataRemover
314 // deletes itself when it completes.
315 remover->Remove(BrowsingDataRemover::REMOVE_COOKIES);
316 tester->BlockUntilNotified();
317
318 // Results: appcaches for the normal origin got deleted, appcaches for the
319 // protected origin didn't.
320 appcache_helper.GetOriginsWithCaches(appcache_service, &origins);
321 EXPECT_EQ(1UL, origins.size());
322 EXPECT_TRUE(origins.find(kProtectedManifest.GetOrigin()) != origins.end());
323 } 411 }
324 412
325 } // namespace 413 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698