OLD | NEW |
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 Loading... |
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. |
113 } | 114 manager->AddOrigin(kOrigin1, quota::kStorageTypeTemporary, |
| 115 base::Time::Now()); |
| 116 manager->AddOrigin(kOrigin2, quota::kStorageTypePersistent, |
| 117 base::Time()); |
| 118 manager->AddOrigin(kOrigin3, quota::kStorageTypeTemporary, |
| 119 base::Time::Now() - base::TimeDelta::FromDays(1)); |
| 120 manager->AddOrigin(kOrigin3, quota::kStorageTypePersistent, |
| 121 base::Time::Now() - base::TimeDelta::FromDays(1)); |
114 | 122 |
115 bool FileSystemContainsOriginAndType(const GURL& origin, | 123 EXPECT_TRUE(manager->OriginHasData(kOrigin1, |
116 fileapi::FileSystemType type) { | 124 quota::kStorageTypeTemporary)); |
117 sandbox_->ValidateFileSystemRootAndGetURL( | 125 EXPECT_FALSE(manager->OriginHasData(kOrigin2, |
118 origin, type, false, NewCallback(this, | 126 quota::kStorageTypeTemporary)); |
119 &RemoveFileSystemTester::FindFileSystemPathCallback)); | 127 EXPECT_TRUE(manager->OriginHasData(kOrigin3, |
120 BlockUntilNotified(); | 128 quota::kStorageTypeTemporary)); |
121 return found_file_system_; | 129 EXPECT_FALSE(manager->OriginHasData(kOrigin1, |
122 } | 130 quota::kStorageTypePersistent)); |
123 | 131 EXPECT_TRUE(manager->OriginHasData(kOrigin2, |
124 virtual void PopulateTestFileSystemData(TestingProfile* profile) { | 132 quota::kStorageTypePersistent)); |
125 // Set up kOrigin1 with a temporary file system, kOrigin2 with a persistent | 133 EXPECT_TRUE(manager->OriginHasData(kOrigin3, |
126 // file system, and kOrigin3 with both. | 134 quota::kStorageTypePersistent)); |
127 sandbox_ = profile->GetFileSystemContext()->path_manager()-> | |
128 sandbox_provider(); | |
129 | |
130 CreateDirectoryForOriginAndType(kOrigin1, | |
131 fileapi::kFileSystemTypeTemporary); | |
132 CreateDirectoryForOriginAndType(kOrigin2, | |
133 fileapi::kFileSystemTypePersistent); | |
134 CreateDirectoryForOriginAndType(kOrigin3, | |
135 fileapi::kFileSystemTypeTemporary); | |
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 } | 135 } |
159 | 136 |
160 private: | 137 private: |
161 fileapi::SandboxMountPointProvider* sandbox_; | 138 DISALLOW_COPY_AND_ASSIGN(RemoveQuotaManagedDataTester); |
162 bool found_file_system_; | 139 }; |
163 | 140 |
164 DISALLOW_COPY_AND_ASSIGN(RemoveFileSystemTester); | 141 // Test Class ---------------------------------------------------------------- |
165 }; | |
166 | 142 |
167 class BrowsingDataRemoverTest : public testing::Test { | 143 class BrowsingDataRemoverTest : public testing::Test { |
168 public: | 144 public: |
169 BrowsingDataRemoverTest() | 145 BrowsingDataRemoverTest() |
170 : ui_thread_(BrowserThread::UI, &message_loop_), | 146 : ui_thread_(BrowserThread::UI, &message_loop_), |
171 db_thread_(BrowserThread::DB, &message_loop_), | 147 db_thread_(BrowserThread::DB, &message_loop_), |
172 webkit_thread_(BrowserThread::WEBKIT, &message_loop_), | 148 webkit_thread_(BrowserThread::WEBKIT, &message_loop_), |
173 file_thread_(BrowserThread::FILE, &message_loop_), | 149 file_thread_(BrowserThread::FILE, &message_loop_), |
174 io_thread_(BrowserThread::IO, &message_loop_), | 150 io_thread_(BrowserThread::IO, &message_loop_), |
175 profile_(new TestingProfile()) { | 151 profile_(new TestingProfile()) { |
(...skipping 22 matching lines...) Expand all Loading... |
198 | 174 |
199 // BrowsingDataRemover deletes itself when it completes. | 175 // BrowsingDataRemover deletes itself when it completes. |
200 remover->Remove(remove_mask); | 176 remover->Remove(remove_mask); |
201 tester->BlockUntilNotified(); | 177 tester->BlockUntilNotified(); |
202 } | 178 } |
203 | 179 |
204 TestingProfile* GetProfile() { | 180 TestingProfile* GetProfile() { |
205 return profile_.get(); | 181 return profile_.get(); |
206 } | 182 } |
207 | 183 |
| 184 quota::MockQuotaManager* GetMockManager() { |
| 185 return (quota::MockQuotaManager*) profile_->GetQuotaManager(); |
| 186 } |
| 187 |
208 private: | 188 private: |
209 // message_loop_, as well as all the threads associated with it must be | 189 // 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++. | 190 // defined before profile_ to prevent explosions. Oh how I love C++. |
211 MessageLoopForUI message_loop_; | 191 MessageLoopForUI message_loop_; |
212 BrowserThread ui_thread_; | 192 BrowserThread ui_thread_; |
213 BrowserThread db_thread_; | 193 BrowserThread db_thread_; |
214 BrowserThread webkit_thread_; | 194 BrowserThread webkit_thread_; |
215 BrowserThread file_thread_; | 195 BrowserThread file_thread_; |
216 BrowserThread io_thread_; | 196 BrowserThread io_thread_; |
217 scoped_ptr<TestingProfile> profile_; | 197 scoped_ptr<TestingProfile> profile_; |
218 | 198 |
219 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); | 199 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); |
220 }; | 200 }; |
221 | 201 |
| 202 // Tests --------------------------------------------------------------------- |
| 203 |
222 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) { | 204 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) { |
223 scoped_ptr<RemoveHistoryTester> tester( | 205 scoped_ptr<RemoveHistoryTester> tester( |
224 new RemoveHistoryTester(GetProfile())); | 206 new RemoveHistoryTester(GetProfile())); |
225 | 207 |
226 tester->AddHistory(kOrigin1, base::Time::Now()); | 208 tester->AddHistory(kOrigin1, base::Time::Now()); |
227 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); | 209 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); |
228 | 210 |
229 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 211 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
230 base::Time::Now(), BrowsingDataRemover::REMOVE_HISTORY, tester.get()); | 212 base::Time::Now(), BrowsingDataRemover::REMOVE_HISTORY, tester.get()); |
231 | 213 |
(...skipping 11 matching lines...) Expand all Loading... |
243 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); | 225 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); |
244 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2)); | 226 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2)); |
245 | 227 |
246 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, | 228 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, |
247 base::Time::Now(), BrowsingDataRemover::REMOVE_HISTORY, tester.get()); | 229 base::Time::Now(), BrowsingDataRemover::REMOVE_HISTORY, tester.get()); |
248 | 230 |
249 EXPECT_FALSE(tester->HistoryContainsURL(kOrigin1)); | 231 EXPECT_FALSE(tester->HistoryContainsURL(kOrigin1)); |
250 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2)); | 232 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2)); |
251 } | 233 } |
252 | 234 |
253 TEST_F(BrowsingDataRemoverTest, RemoveFileSystemsForever) { | 235 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForever) { |
254 scoped_ptr<RemoveFileSystemTester> tester(new RemoveFileSystemTester()); | 236 scoped_ptr<RemoveQuotaManagedDataTester> tester( |
255 | 237 new RemoveQuotaManagedDataTester()); |
256 tester->PopulateTestFileSystemData(GetProfile()); | 238 tester->PopulateTestQuotaManagedData(GetMockManager()); |
257 | 239 |
258 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 240 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
259 base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get()); | 241 base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get()); |
260 | 242 |
261 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin1, | 243 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
262 fileapi::kFileSystemTypePersistent)); | 244 quota::kStorageTypeTemporary)); |
263 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin1, | 245 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
264 fileapi::kFileSystemTypeTemporary)); | 246 quota::kStorageTypeTemporary)); |
265 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin2, | 247 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, |
266 fileapi::kFileSystemTypePersistent)); | 248 quota::kStorageTypeTemporary)); |
267 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin2, | 249 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
268 fileapi::kFileSystemTypeTemporary)); | 250 quota::kStorageTypePersistent)); |
269 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin3, | 251 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
270 fileapi::kFileSystemTypePersistent)); | 252 quota::kStorageTypePersistent)); |
271 EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin3, | 253 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, |
272 fileapi::kFileSystemTypeTemporary)); | 254 quota::kStorageTypePersistent)); |
273 } | 255 } |
274 | 256 |
275 TEST_F(BrowsingDataRemoverTest, RemoveAppCacheForever) { | 257 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) { |
276 // Set up ChromeAppCacheService. | 258 scoped_ptr<RemoveQuotaManagedDataTester> tester( |
277 scoped_refptr<ChromeAppCacheService> appcache_service = | 259 new RemoveQuotaManagedDataTester()); |
278 new ChromeAppCacheService(NULL); | 260 tester->PopulateTestQuotaManagedData(GetMockManager()); |
279 const content::ResourceContext* resource_context = NULL; | 261 |
| 262 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, |
| 263 base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get()); |
| 264 |
| 265 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
| 266 quota::kStorageTypeTemporary)); |
| 267 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
| 268 quota::kStorageTypeTemporary)); |
| 269 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, |
| 270 quota::kStorageTypeTemporary)); |
| 271 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
| 272 quota::kStorageTypePersistent)); |
| 273 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, |
| 274 quota::kStorageTypePersistent)); |
| 275 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, |
| 276 quota::kStorageTypePersistent)); |
| 277 } |
| 278 |
| 279 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastWeek) { |
| 280 scoped_ptr<RemoveQuotaManagedDataTester> tester( |
| 281 new RemoveQuotaManagedDataTester()); |
| 282 tester->PopulateTestQuotaManagedData(GetMockManager()); |
| 283 |
| 284 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK, |
| 285 base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get()); |
| 286 |
| 287 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
| 288 quota::kStorageTypeTemporary)); |
| 289 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
| 290 quota::kStorageTypeTemporary)); |
| 291 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, |
| 292 quota::kStorageTypeTemporary)); |
| 293 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
| 294 quota::kStorageTypePersistent)); |
| 295 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, |
| 296 quota::kStorageTypePersistent)); |
| 297 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, |
| 298 quota::kStorageTypePersistent)); |
| 299 } |
| 300 |
| 301 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedUnprotectedOrigins) { |
| 302 // Protect kOrigin1. |
280 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = | 303 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = |
281 new MockExtensionSpecialStoragePolicy; | 304 new MockExtensionSpecialStoragePolicy; |
282 mock_policy->AddProtected(kProtectedManifest.GetOrigin()); | 305 mock_policy->AddProtected(kOrigin1.GetOrigin()); |
283 BrowserThread::PostTask( | 306 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy); |
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 | 307 |
295 // Add data into the AppCacheStorage. | 308 scoped_ptr<RemoveQuotaManagedDataTester> tester( |
296 appcache::AppCacheTestHelper appcache_helper; | 309 new RemoveQuotaManagedDataTester()); |
297 appcache_helper.AddGroupAndCache(appcache_service, kNormalManifest); | 310 tester->PopulateTestQuotaManagedData(GetMockManager()); |
298 appcache_helper.AddGroupAndCache(appcache_service, kProtectedManifest); | |
299 | 311 |
300 // Verify that adding the data succeeded. | 312 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
301 std::set<GURL> origins; | 313 base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get()); |
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 | 314 |
307 // Set up the object to be tested. | 315 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1, |
308 scoped_ptr<BrowsingDataRemoverTester> tester(new BrowsingDataRemoverTester()); | 316 quota::kStorageTypeTemporary)); |
309 BrowsingDataRemover* remover = new BrowsingDataRemover( | 317 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
310 profile, BrowsingDataRemover::EVERYTHING, base::Time::Now()); | 318 quota::kStorageTypeTemporary)); |
311 remover->AddObserver(tester.get()); | 319 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, |
312 | 320 quota::kStorageTypeTemporary)); |
313 // Remove the appcaches and wait for it to complete. BrowsingDataRemover | 321 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
314 // deletes itself when it completes. | 322 quota::kStorageTypePersistent)); |
315 remover->Remove(BrowsingDataRemover::REMOVE_COOKIES); | 323 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
316 tester->BlockUntilNotified(); | 324 quota::kStorageTypePersistent)); |
317 | 325 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, |
318 // Results: appcaches for the normal origin got deleted, appcaches for the | 326 quota::kStorageTypePersistent)); |
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 } | 327 } |
324 | 328 |
325 } // namespace | 329 } // namespace |
OLD | NEW |