[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
thestig | b7aad54f | 2014-09-05 18:25:39 | [diff] [blame] | 5 | #include "base/files/file_util.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 6 | #include "base/location.h" |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 7 | #include "base/run_loop.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 8 | #include "base/single_thread_task_runner.h" |
| 9 | #include "base/thread_task_runner_handle.h" |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 10 | #include "base/threading/thread.h" |
| 11 | #include "content/browser/browser_thread_impl.h" |
| 12 | #include "content/browser/gpu/shader_disk_cache.h" |
[email protected] | 4cc6b45 | 2014-04-09 00:21:41 | [diff] [blame] | 13 | #include "content/browser/quota/mock_quota_manager.h" |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 14 | #include "content/browser/storage_partition_impl.h" |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 15 | #include "content/public/browser/local_storage_usage_info.h" |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 16 | #include "content/public/browser/storage_partition.h" |
[email protected] | 523e5c59 | 2014-04-30 21:46:25 | [diff] [blame] | 17 | #include "content/public/test/mock_special_storage_policy.h" |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 18 | #include "content/public/test/test_browser_context.h" |
| 19 | #include "content/public/test/test_browser_thread.h" |
[email protected] | ec04d3f | 2013-06-06 21:31:39 | [diff] [blame] | 20 | #include "content/public/test/test_browser_thread_bundle.h" |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 21 | #include "net/base/test_completion_callback.h" |
davidben | f7c94cd4 | 2015-10-09 21:23:18 | [diff] [blame] | 22 | #include "net/cookies/cookie_store.h" |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 23 | #include "net/url_request/url_request_context.h" |
| 24 | #include "net/url_request/url_request_context_getter.h" |
pilgrim | e92c5fcd | 2014-09-10 23:31:23 | [diff] [blame] | 25 | #include "storage/browser/quota/quota_manager.h" |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 26 | #include "testing/gtest/include/gtest/gtest.h" |
| 27 | |
| 28 | namespace content { |
| 29 | namespace { |
| 30 | |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 31 | const int kDefaultClientId = 42; |
| 32 | const char kCacheKey[] = "key"; |
| 33 | const char kCacheValue[] = "cached value"; |
| 34 | |
| 35 | const char kTestOrigin1[] = "http://host1:1/"; |
| 36 | const char kTestOrigin2[] = "http://host2:1/"; |
| 37 | const char kTestOrigin3[] = "http://host3:1/"; |
| 38 | const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; |
| 39 | |
| 40 | const GURL kOrigin1(kTestOrigin1); |
| 41 | const GURL kOrigin2(kTestOrigin2); |
| 42 | const GURL kOrigin3(kTestOrigin3); |
| 43 | const GURL kOriginDevTools(kTestOriginDevTools); |
| 44 | |
| 45 | const base::FilePath::CharType kDomStorageOrigin1[] = |
| 46 | FILE_PATH_LITERAL("http_host1_1.localstorage"); |
| 47 | |
| 48 | const base::FilePath::CharType kDomStorageOrigin2[] = |
| 49 | FILE_PATH_LITERAL("http_host2_1.localstorage"); |
| 50 | |
| 51 | const base::FilePath::CharType kDomStorageOrigin3[] = |
| 52 | FILE_PATH_LITERAL("http_host3_1.localstorage"); |
| 53 | |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 54 | const storage::StorageType kTemporary = storage::kStorageTypeTemporary; |
| 55 | const storage::StorageType kPersistent = storage::kStorageTypePersistent; |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 56 | |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 57 | const storage::QuotaClient::ID kClientFile = storage::QuotaClient::kFileSystem; |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 58 | |
| 59 | const uint32 kAllQuotaRemoveMask = |
[email protected] | 93ea188 | 2014-07-10 20:30:12 | [diff] [blame] | 60 | StoragePartition::REMOVE_DATA_MASK_APPCACHE | |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 61 | StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | |
[email protected] | 93ea188 | 2014-07-10 20:30:12 | [diff] [blame] | 62 | StoragePartition::REMOVE_DATA_MASK_INDEXEDDB | |
| 63 | StoragePartition::REMOVE_DATA_MASK_WEBSQL; |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 64 | |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 65 | class AwaitCompletionHelper { |
| 66 | public: |
| 67 | AwaitCompletionHelper() : start_(false), already_quit_(false) {} |
| 68 | virtual ~AwaitCompletionHelper() {} |
| 69 | |
| 70 | void BlockUntilNotified() { |
| 71 | if (!already_quit_) { |
| 72 | DCHECK(!start_); |
| 73 | start_ = true; |
| 74 | base::MessageLoop::current()->Run(); |
| 75 | } else { |
| 76 | DCHECK(!start_); |
| 77 | already_quit_ = false; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | void Notify() { |
| 82 | if (start_) { |
| 83 | DCHECK(!already_quit_); |
ki.stfu | 80077924 | 2015-10-12 22:46:26 | [diff] [blame] | 84 | base::MessageLoop::current()->QuitWhenIdle(); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 85 | start_ = false; |
| 86 | } else { |
| 87 | DCHECK(!already_quit_); |
| 88 | already_quit_ = true; |
| 89 | } |
| 90 | } |
| 91 | |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 92 | private: |
| 93 | // Helps prevent from running message_loop, if the callback invoked |
| 94 | // immediately. |
| 95 | bool start_; |
| 96 | bool already_quit_; |
| 97 | |
| 98 | DISALLOW_COPY_AND_ASSIGN(AwaitCompletionHelper); |
| 99 | }; |
| 100 | |
| 101 | class RemoveCookieTester { |
| 102 | public: |
| 103 | explicit RemoveCookieTester(TestBrowserContext* context) |
davidben | f7c94cd4 | 2015-10-09 21:23:18 | [diff] [blame] | 104 | : get_cookie_success_(false), |
| 105 | cookie_store_(context->GetRequestContext() |
| 106 | ->GetURLRequestContext() |
| 107 | ->cookie_store()) {} |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 108 | |
| 109 | // Returns true, if the given cookie exists in the cookie store. |
| 110 | bool ContainsCookie() { |
| 111 | get_cookie_success_ = false; |
davidben | f7c94cd4 | 2015-10-09 21:23:18 | [diff] [blame] | 112 | cookie_store_->GetCookiesWithOptionsAsync( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 113 | kOrigin1, net::CookieOptions(), |
| 114 | base::Bind(&RemoveCookieTester::GetCookieCallback, |
| 115 | base::Unretained(this))); |
| 116 | await_completion_.BlockUntilNotified(); |
| 117 | return get_cookie_success_; |
| 118 | } |
| 119 | |
| 120 | void AddCookie() { |
davidben | f7c94cd4 | 2015-10-09 21:23:18 | [diff] [blame] | 121 | cookie_store_->SetCookieWithOptionsAsync( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 122 | kOrigin1, "A=1", net::CookieOptions(), |
| 123 | base::Bind(&RemoveCookieTester::SetCookieCallback, |
| 124 | base::Unretained(this))); |
| 125 | await_completion_.BlockUntilNotified(); |
| 126 | } |
| 127 | |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 128 | private: |
| 129 | void GetCookieCallback(const std::string& cookies) { |
| 130 | if (cookies == "A=1") { |
| 131 | get_cookie_success_ = true; |
| 132 | } else { |
| 133 | EXPECT_EQ("", cookies); |
| 134 | get_cookie_success_ = false; |
| 135 | } |
| 136 | await_completion_.Notify(); |
| 137 | } |
| 138 | |
| 139 | void SetCookieCallback(bool result) { |
| 140 | ASSERT_TRUE(result); |
| 141 | await_completion_.Notify(); |
| 142 | } |
| 143 | |
| 144 | bool get_cookie_success_; |
| 145 | AwaitCompletionHelper await_completion_; |
davidben | f7c94cd4 | 2015-10-09 21:23:18 | [diff] [blame] | 146 | net::CookieStore* cookie_store_; |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 147 | |
| 148 | DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester); |
| 149 | }; |
| 150 | |
| 151 | class RemoveLocalStorageTester { |
| 152 | public: |
| 153 | explicit RemoveLocalStorageTester(TestBrowserContext* profile) |
| 154 | : profile_(profile), dom_storage_context_(NULL) { |
| 155 | dom_storage_context_ = |
| 156 | content::BrowserContext::GetDefaultStoragePartition(profile)-> |
| 157 | GetDOMStorageContext(); |
| 158 | } |
| 159 | |
| 160 | // Returns true, if the given origin URL exists. |
| 161 | bool DOMStorageExistsForOrigin(const GURL& origin) { |
| 162 | GetLocalStorageUsage(); |
| 163 | await_completion_.BlockUntilNotified(); |
| 164 | for (size_t i = 0; i < infos_.size(); ++i) { |
| 165 | if (origin == infos_[i].origin) |
| 166 | return true; |
| 167 | } |
| 168 | return false; |
| 169 | } |
| 170 | |
| 171 | void AddDOMStorageTestData() { |
| 172 | // Note: This test depends on details of how the dom_storage library |
| 173 | // stores data in the host file system. |
| 174 | base::FilePath storage_path = |
| 175 | profile_->GetPath().AppendASCII("Local Storage"); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 176 | base::CreateDirectory(storage_path); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 177 | |
| 178 | // Write some files. |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 179 | base::WriteFile(storage_path.Append(kDomStorageOrigin1), NULL, 0); |
| 180 | base::WriteFile(storage_path.Append(kDomStorageOrigin2), NULL, 0); |
| 181 | base::WriteFile(storage_path.Append(kDomStorageOrigin3), NULL, 0); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 182 | |
| 183 | // Tweak their dates. |
[email protected] | c0d50816 | 2013-12-04 22:49:00 | [diff] [blame] | 184 | base::Time now = base::Time::Now(); |
| 185 | base::TouchFile(storage_path.Append(kDomStorageOrigin1), now, now); |
| 186 | |
| 187 | base::Time one_day_ago = now - base::TimeDelta::FromDays(1); |
| 188 | base::TouchFile(storage_path.Append(kDomStorageOrigin2), |
| 189 | one_day_ago, one_day_ago); |
| 190 | |
| 191 | base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60); |
| 192 | base::TouchFile(storage_path.Append(kDomStorageOrigin3), |
| 193 | sixty_days_ago, sixty_days_ago); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | private: |
| 197 | void GetLocalStorageUsage() { |
| 198 | dom_storage_context_->GetLocalStorageUsage( |
| 199 | base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage, |
| 200 | base::Unretained(this))); |
| 201 | } |
| 202 | void OnGotLocalStorageUsage( |
| 203 | const std::vector<content::LocalStorageUsageInfo>& infos) { |
| 204 | infos_ = infos; |
| 205 | await_completion_.Notify(); |
| 206 | } |
| 207 | |
| 208 | // We don't own these pointers. |
| 209 | TestBrowserContext* profile_; |
| 210 | content::DOMStorageContext* dom_storage_context_; |
| 211 | |
| 212 | std::vector<content::LocalStorageUsageInfo> infos_; |
| 213 | |
| 214 | AwaitCompletionHelper await_completion_; |
| 215 | |
| 216 | DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester); |
| 217 | }; |
| 218 | |
| 219 | bool IsWebSafeSchemeForTest(const std::string& scheme) { |
| 220 | return scheme == "http"; |
| 221 | } |
| 222 | |
| 223 | bool DoesOriginMatchForUnprotectedWeb( |
| 224 | const GURL& origin, |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 225 | storage::SpecialStoragePolicy* special_storage_policy) { |
[email protected] | 8c63cd2 | 2013-11-08 11:31:21 | [diff] [blame] | 226 | if (IsWebSafeSchemeForTest(origin.scheme())) |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 227 | return !special_storage_policy->IsStorageProtected(origin.GetOrigin()); |
| 228 | |
[email protected] | 8c63cd2 | 2013-11-08 11:31:21 | [diff] [blame] | 229 | return false; |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | bool DoesOriginMatchForBothProtectedAndUnprotectedWeb( |
| 233 | const GURL& origin, |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 234 | storage::SpecialStoragePolicy* special_storage_policy) { |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 235 | return true; |
| 236 | } |
| 237 | |
| 238 | bool DoesOriginMatchUnprotected( |
| 239 | const GURL& origin, |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 240 | storage::SpecialStoragePolicy* special_storage_policy) { |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 241 | return origin.GetOrigin().scheme() != kOriginDevTools.scheme(); |
| 242 | } |
| 243 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 244 | void ClearQuotaData(content::StoragePartition* partition, |
| 245 | base::RunLoop* loop_to_quit) { |
[email protected] | 93ea188 | 2014-07-10 20:30:12 | [diff] [blame] | 246 | partition->ClearData(kAllQuotaRemoveMask, |
| 247 | StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, GURL(), |
| 248 | StoragePartition::OriginMatcherFunction(), base::Time(), |
| 249 | base::Time::Max(), loop_to_quit->QuitClosure()); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | void ClearQuotaDataWithOriginMatcher( |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 253 | content::StoragePartition* partition, |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 254 | const GURL& remove_origin, |
| 255 | const StoragePartition::OriginMatcherFunction& origin_matcher, |
| 256 | const base::Time delete_begin, |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 257 | base::RunLoop* loop_to_quit) { |
| 258 | partition->ClearData(kAllQuotaRemoveMask, |
| 259 | StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
| 260 | remove_origin, origin_matcher, delete_begin, |
| 261 | base::Time::Max(), loop_to_quit->QuitClosure()); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | void ClearQuotaDataForOrigin( |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 265 | content::StoragePartition* partition, |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 266 | const GURL& remove_origin, |
| 267 | const base::Time delete_begin, |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 268 | base::RunLoop* loop_to_quit) { |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 269 | ClearQuotaDataWithOriginMatcher( |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 270 | partition, remove_origin, |
| 271 | StoragePartition::OriginMatcherFunction(), delete_begin, |
| 272 | loop_to_quit); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | void ClearQuotaDataForNonPersistent( |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 276 | content::StoragePartition* partition, |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 277 | const base::Time delete_begin, |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 278 | base::RunLoop* loop_to_quit) { |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 279 | partition->ClearData( |
[email protected] | 93ea188 | 2014-07-10 20:30:12 | [diff] [blame] | 280 | kAllQuotaRemoveMask, |
| 281 | ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT, |
| 282 | GURL(), StoragePartition::OriginMatcherFunction(), delete_begin, |
| 283 | base::Time::Max(), loop_to_quit->QuitClosure()); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 284 | } |
| 285 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 286 | void ClearCookies(content::StoragePartition* partition, |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 287 | const base::Time delete_begin, |
| 288 | const base::Time delete_end, |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 289 | base::RunLoop* run_loop) { |
| 290 | partition->ClearData( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 291 | StoragePartition::REMOVE_DATA_MASK_COOKIES, |
| 292 | StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 293 | GURL(), StoragePartition::OriginMatcherFunction(), |
| 294 | delete_begin, delete_end, run_loop->QuitClosure()); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | void ClearStuff(uint32 remove_mask, |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 298 | content::StoragePartition* partition, |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 299 | const base::Time delete_begin, |
| 300 | const base::Time delete_end, |
| 301 | const StoragePartition::OriginMatcherFunction& origin_matcher, |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 302 | base::RunLoop* run_loop) { |
| 303 | partition->ClearData( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 304 | remove_mask, StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 305 | GURL(), origin_matcher, delete_begin, delete_end, |
| 306 | run_loop->QuitClosure()); |
| 307 | } |
| 308 | |
| 309 | void ClearData(content::StoragePartition* partition, |
| 310 | base::RunLoop* run_loop) { |
| 311 | base::Time time; |
| 312 | partition->ClearData( |
| 313 | StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE, |
| 314 | StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
| 315 | GURL(), StoragePartition::OriginMatcherFunction(), |
| 316 | time, time, run_loop->QuitClosure()); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 317 | } |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 318 | |
| 319 | } // namespace |
| 320 | |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 321 | class StoragePartitionImplTest : public testing::Test { |
| 322 | public: |
| 323 | StoragePartitionImplTest() |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 324 | : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 325 | browser_context_(new TestBrowserContext()) { |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 326 | } |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 327 | |
[email protected] | 4cc6b45 | 2014-04-09 00:21:41 | [diff] [blame] | 328 | MockQuotaManager* GetMockManager() { |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 329 | if (!quota_manager_.get()) { |
[email protected] | 4cc6b45 | 2014-04-09 00:21:41 | [diff] [blame] | 330 | quota_manager_ = new MockQuotaManager( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 331 | browser_context_->IsOffTheRecord(), |
| 332 | browser_context_->GetPath(), |
| 333 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(), |
| 334 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB).get(), |
| 335 | browser_context_->GetSpecialStoragePolicy()); |
| 336 | } |
| 337 | return quota_manager_.get(); |
| 338 | } |
| 339 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 340 | TestBrowserContext* browser_context() { |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 341 | return browser_context_.get(); |
| 342 | } |
| 343 | |
| 344 | private: |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 345 | content::TestBrowserThreadBundle thread_bundle_; |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 346 | scoped_ptr<TestBrowserContext> browser_context_; |
[email protected] | 4cc6b45 | 2014-04-09 00:21:41 | [diff] [blame] | 347 | scoped_refptr<MockQuotaManager> quota_manager_; |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 348 | |
| 349 | DISALLOW_COPY_AND_ASSIGN(StoragePartitionImplTest); |
| 350 | }; |
| 351 | |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 352 | class StoragePartitionShaderClearTest : public testing::Test { |
| 353 | public: |
[email protected] | ec04d3f | 2013-06-06 21:31:39 | [diff] [blame] | 354 | StoragePartitionShaderClearTest() |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 355 | : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 356 | browser_context_(new TestBrowserContext()) { |
| 357 | ShaderCacheFactory::GetInstance()->SetCacheInfo( |
| 358 | kDefaultClientId, |
| 359 | BrowserContext::GetDefaultStoragePartition( |
| 360 | browser_context())->GetPath()); |
| 361 | cache_ = ShaderCacheFactory::GetInstance()->Get(kDefaultClientId); |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 362 | } |
| 363 | |
dcheng | fa85b15 | 2014-10-28 01:13:42 | [diff] [blame] | 364 | ~StoragePartitionShaderClearTest() override { |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 365 | cache_ = NULL; |
| 366 | ShaderCacheFactory::GetInstance()->RemoveCacheInfo(kDefaultClientId); |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | void InitCache() { |
| 370 | net::TestCompletionCallback available_cb; |
| 371 | int rv = cache_->SetAvailableCallback(available_cb.callback()); |
| 372 | ASSERT_EQ(net::OK, available_cb.GetResult(rv)); |
| 373 | EXPECT_EQ(0, cache_->Size()); |
| 374 | |
| 375 | cache_->Cache(kCacheKey, kCacheValue); |
| 376 | |
| 377 | net::TestCompletionCallback complete_cb; |
| 378 | |
| 379 | rv = cache_->SetCacheCompleteCallback(complete_cb.callback()); |
| 380 | ASSERT_EQ(net::OK, complete_cb.GetResult(rv)); |
| 381 | } |
| 382 | |
| 383 | size_t Size() { return cache_->Size(); } |
| 384 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 385 | TestBrowserContext* browser_context() { |
| 386 | return browser_context_.get(); |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 387 | } |
| 388 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 389 | private: |
[email protected] | ec04d3f | 2013-06-06 21:31:39 | [diff] [blame] | 390 | content::TestBrowserThreadBundle thread_bundle_; |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 391 | scoped_ptr<TestBrowserContext> browser_context_; |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 392 | |
| 393 | scoped_refptr<ShaderDiskCache> cache_; |
| 394 | }; |
| 395 | |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 396 | // Tests --------------------------------------------------------------------- |
| 397 | |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 398 | TEST_F(StoragePartitionShaderClearTest, ClearShaderCache) { |
| 399 | InitCache(); |
| 400 | EXPECT_EQ(1u, Size()); |
| 401 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 402 | base::RunLoop run_loop; |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 403 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 404 | FROM_HERE, |
| 405 | base::Bind(&ClearData, |
| 406 | BrowserContext::GetDefaultStoragePartition(browser_context()), |
| 407 | &run_loop)); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 408 | run_loop.Run(); |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 409 | EXPECT_EQ(0u, Size()); |
| 410 | } |
| 411 | |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 412 | TEST_F(StoragePartitionImplTest, QuotaClientMaskGeneration) { |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 413 | EXPECT_EQ(storage::QuotaClient::kFileSystem, |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 414 | StoragePartitionImpl::GenerateQuotaClientMask( |
| 415 | StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS)); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 416 | EXPECT_EQ(storage::QuotaClient::kDatabase, |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 417 | StoragePartitionImpl::GenerateQuotaClientMask( |
| 418 | StoragePartition::REMOVE_DATA_MASK_WEBSQL)); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 419 | EXPECT_EQ(storage::QuotaClient::kAppcache, |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 420 | StoragePartitionImpl::GenerateQuotaClientMask( |
| 421 | StoragePartition::REMOVE_DATA_MASK_APPCACHE)); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 422 | EXPECT_EQ(storage::QuotaClient::kIndexedDatabase, |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 423 | StoragePartitionImpl::GenerateQuotaClientMask( |
| 424 | StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 425 | EXPECT_EQ(storage::QuotaClient::kFileSystem | |
| 426 | storage::QuotaClient::kDatabase | |
| 427 | storage::QuotaClient::kAppcache | |
| 428 | storage::QuotaClient::kIndexedDatabase, |
[email protected] | 93ea188 | 2014-07-10 20:30:12 | [diff] [blame] | 429 | StoragePartitionImpl::GenerateQuotaClientMask(kAllQuotaRemoveMask)); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 430 | } |
| 431 | |
[email protected] | 4cc6b45 | 2014-04-09 00:21:41 | [diff] [blame] | 432 | void PopulateTestQuotaManagedPersistentData(MockQuotaManager* manager) { |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 433 | manager->AddOrigin(kOrigin2, kPersistent, kClientFile, base::Time()); |
| 434 | manager->AddOrigin(kOrigin3, kPersistent, kClientFile, |
| 435 | base::Time::Now() - base::TimeDelta::FromDays(1)); |
| 436 | |
| 437 | EXPECT_FALSE(manager->OriginHasData(kOrigin1, kPersistent, kClientFile)); |
| 438 | EXPECT_TRUE(manager->OriginHasData(kOrigin2, kPersistent, kClientFile)); |
| 439 | EXPECT_TRUE(manager->OriginHasData(kOrigin3, kPersistent, kClientFile)); |
| 440 | } |
| 441 | |
[email protected] | 4cc6b45 | 2014-04-09 00:21:41 | [diff] [blame] | 442 | void PopulateTestQuotaManagedTemporaryData(MockQuotaManager* manager) { |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 443 | manager->AddOrigin(kOrigin1, kTemporary, kClientFile, base::Time::Now()); |
| 444 | manager->AddOrigin(kOrigin3, kTemporary, kClientFile, |
| 445 | base::Time::Now() - base::TimeDelta::FromDays(1)); |
| 446 | |
| 447 | EXPECT_TRUE(manager->OriginHasData(kOrigin1, kTemporary, kClientFile)); |
| 448 | EXPECT_FALSE(manager->OriginHasData(kOrigin2, kTemporary, kClientFile)); |
| 449 | EXPECT_TRUE(manager->OriginHasData(kOrigin3, kTemporary, kClientFile)); |
| 450 | } |
| 451 | |
[email protected] | 4cc6b45 | 2014-04-09 00:21:41 | [diff] [blame] | 452 | void PopulateTestQuotaManagedData(MockQuotaManager* manager) { |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 453 | // Set up kOrigin1 with a temporary quota, kOrigin2 with a persistent |
| 454 | // quota, and kOrigin3 with both. kOrigin1 is modified now, kOrigin2 |
| 455 | // is modified at the beginning of time, and kOrigin3 is modified one day |
| 456 | // ago. |
| 457 | PopulateTestQuotaManagedPersistentData(manager); |
| 458 | PopulateTestQuotaManagedTemporaryData(manager); |
| 459 | } |
| 460 | |
[email protected] | 4cc6b45 | 2014-04-09 00:21:41 | [diff] [blame] | 461 | void PopulateTestQuotaManagedNonBrowsingData(MockQuotaManager* manager) { |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 462 | manager->AddOrigin(kOriginDevTools, kTemporary, kClientFile, base::Time()); |
| 463 | manager->AddOrigin(kOriginDevTools, kPersistent, kClientFile, base::Time()); |
| 464 | } |
| 465 | |
| 466 | TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverBoth) { |
| 467 | PopulateTestQuotaManagedData(GetMockManager()); |
| 468 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 469 | StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 470 | BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 471 | partition->OverrideQuotaManagerForTesting( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 472 | GetMockManager()); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 473 | |
| 474 | base::RunLoop run_loop; |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 475 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 476 | FROM_HERE, base::Bind(&ClearQuotaData, partition, &run_loop)); |
| 477 | run_loop.Run(); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 478 | |
| 479 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 480 | kClientFile)); |
| 481 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 482 | kClientFile)); |
| 483 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 484 | kClientFile)); |
| 485 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 486 | kClientFile)); |
| 487 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 488 | kClientFile)); |
| 489 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 490 | kClientFile)); |
| 491 | } |
| 492 | |
| 493 | TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlyTemporary) { |
| 494 | PopulateTestQuotaManagedTemporaryData(GetMockManager()); |
| 495 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 496 | StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 497 | BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 498 | partition->OverrideQuotaManagerForTesting( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 499 | GetMockManager()); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 500 | |
| 501 | base::RunLoop run_loop; |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 502 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 503 | FROM_HERE, base::Bind(&ClearQuotaData, partition, &run_loop)); |
| 504 | run_loop.Run(); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 505 | |
| 506 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 507 | kClientFile)); |
| 508 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 509 | kClientFile)); |
| 510 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 511 | kClientFile)); |
| 512 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 513 | kClientFile)); |
| 514 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 515 | kClientFile)); |
| 516 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 517 | kClientFile)); |
| 518 | } |
| 519 | |
| 520 | TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlyPersistent) { |
| 521 | PopulateTestQuotaManagedPersistentData(GetMockManager()); |
| 522 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 523 | StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 524 | BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 525 | partition->OverrideQuotaManagerForTesting( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 526 | GetMockManager()); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 527 | |
| 528 | base::RunLoop run_loop; |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 529 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 530 | FROM_HERE, base::Bind(&ClearQuotaData, partition, &run_loop)); |
| 531 | run_loop.Run(); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 532 | |
| 533 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 534 | kClientFile)); |
| 535 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 536 | kClientFile)); |
| 537 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 538 | kClientFile)); |
| 539 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 540 | kClientFile)); |
| 541 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 542 | kClientFile)); |
| 543 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 544 | kClientFile)); |
| 545 | } |
| 546 | |
| 547 | TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverNeither) { |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 548 | StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 549 | BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 550 | partition->OverrideQuotaManagerForTesting( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 551 | GetMockManager()); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 552 | |
| 553 | base::RunLoop run_loop; |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 554 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 555 | FROM_HERE, base::Bind(&ClearQuotaData, partition, &run_loop)); |
| 556 | run_loop.Run(); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 557 | |
| 558 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 559 | kClientFile)); |
| 560 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 561 | kClientFile)); |
| 562 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 563 | kClientFile)); |
| 564 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 565 | kClientFile)); |
| 566 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 567 | kClientFile)); |
| 568 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 569 | kClientFile)); |
| 570 | } |
| 571 | |
| 572 | TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverSpecificOrigin) { |
| 573 | PopulateTestQuotaManagedData(GetMockManager()); |
| 574 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 575 | StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 576 | BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 577 | partition->OverrideQuotaManagerForTesting( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 578 | GetMockManager()); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 579 | |
| 580 | base::RunLoop run_loop; |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 581 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 582 | FROM_HERE, base::Bind(&ClearQuotaDataForOrigin, partition, kOrigin1, |
| 583 | base::Time(), &run_loop)); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 584 | run_loop.Run(); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 585 | |
| 586 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 587 | kClientFile)); |
| 588 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 589 | kClientFile)); |
| 590 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 591 | kClientFile)); |
| 592 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 593 | kClientFile)); |
| 594 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 595 | kClientFile)); |
| 596 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 597 | kClientFile)); |
| 598 | } |
| 599 | |
| 600 | TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForLastHour) { |
| 601 | PopulateTestQuotaManagedData(GetMockManager()); |
| 602 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 603 | StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 604 | BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 605 | partition->OverrideQuotaManagerForTesting( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 606 | GetMockManager()); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 607 | |
| 608 | base::RunLoop run_loop; |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 609 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 610 | FROM_HERE, |
| 611 | base::Bind(&ClearQuotaDataForOrigin, partition, GURL(), |
| 612 | base::Time::Now() - base::TimeDelta::FromHours(1), &run_loop)); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 613 | run_loop.Run(); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 614 | |
| 615 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 616 | kClientFile)); |
| 617 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 618 | kClientFile)); |
| 619 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 620 | kClientFile)); |
| 621 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 622 | kClientFile)); |
| 623 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 624 | kClientFile)); |
| 625 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 626 | kClientFile)); |
| 627 | } |
| 628 | |
| 629 | TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForLastWeek) { |
| 630 | PopulateTestQuotaManagedData(GetMockManager()); |
| 631 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 632 | base::RunLoop run_loop; |
| 633 | StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 634 | BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 635 | partition->OverrideQuotaManagerForTesting( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 636 | GetMockManager()); |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 637 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 638 | FROM_HERE, |
| 639 | base::Bind(&ClearQuotaDataForNonPersistent, partition, |
| 640 | base::Time::Now() - base::TimeDelta::FromDays(7), &run_loop)); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 641 | run_loop.Run(); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 642 | |
| 643 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 644 | kClientFile)); |
| 645 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 646 | kClientFile)); |
| 647 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 648 | kClientFile)); |
| 649 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 650 | kClientFile)); |
| 651 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 652 | kClientFile)); |
| 653 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 654 | kClientFile)); |
| 655 | } |
| 656 | |
| 657 | TEST_F(StoragePartitionImplTest, RemoveQuotaManagedUnprotectedOrigins) { |
| 658 | // Protect kOrigin1. |
[email protected] | 523e5c59 | 2014-04-30 21:46:25 | [diff] [blame] | 659 | scoped_refptr<MockSpecialStoragePolicy> mock_policy = |
| 660 | new MockSpecialStoragePolicy; |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 661 | mock_policy->AddProtected(kOrigin1.GetOrigin()); |
| 662 | |
| 663 | PopulateTestQuotaManagedData(GetMockManager()); |
| 664 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 665 | StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 666 | BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 667 | partition->OverrideQuotaManagerForTesting( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 668 | GetMockManager()); |
dcheng | 54c3719d | 2014-08-26 21:52:56 | [diff] [blame] | 669 | partition->OverrideSpecialStoragePolicyForTesting(mock_policy.get()); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 670 | |
| 671 | base::RunLoop run_loop; |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 672 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 673 | FROM_HERE, base::Bind(&ClearQuotaDataWithOriginMatcher, partition, GURL(), |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 674 | base::Bind(&DoesOriginMatchForUnprotectedWeb), |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 675 | base::Time(), &run_loop)); |
| 676 | run_loop.Run(); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 677 | |
| 678 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 679 | kClientFile)); |
| 680 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 681 | kClientFile)); |
| 682 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 683 | kClientFile)); |
| 684 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 685 | kClientFile)); |
| 686 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 687 | kClientFile)); |
| 688 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 689 | kClientFile)); |
| 690 | } |
| 691 | |
| 692 | TEST_F(StoragePartitionImplTest, RemoveQuotaManagedProtectedSpecificOrigin) { |
| 693 | // Protect kOrigin1. |
[email protected] | 523e5c59 | 2014-04-30 21:46:25 | [diff] [blame] | 694 | scoped_refptr<MockSpecialStoragePolicy> mock_policy = |
| 695 | new MockSpecialStoragePolicy; |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 696 | mock_policy->AddProtected(kOrigin1.GetOrigin()); |
| 697 | |
| 698 | PopulateTestQuotaManagedData(GetMockManager()); |
| 699 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 700 | StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 701 | BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 702 | partition->OverrideQuotaManagerForTesting( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 703 | GetMockManager()); |
dcheng | 54c3719d | 2014-08-26 21:52:56 | [diff] [blame] | 704 | partition->OverrideSpecialStoragePolicyForTesting(mock_policy.get()); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 705 | |
| 706 | // Try to remove kOrigin1. Expect failure. |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 707 | base::RunLoop run_loop; |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 708 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 709 | FROM_HERE, |
| 710 | base::Bind(&ClearQuotaDataWithOriginMatcher, partition, kOrigin1, |
| 711 | base::Bind(&DoesOriginMatchForUnprotectedWeb), base::Time(), |
| 712 | &run_loop)); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 713 | run_loop.Run(); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 714 | |
| 715 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 716 | kClientFile)); |
| 717 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 718 | kClientFile)); |
| 719 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 720 | kClientFile)); |
| 721 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 722 | kClientFile)); |
| 723 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 724 | kClientFile)); |
| 725 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 726 | kClientFile)); |
| 727 | } |
| 728 | |
| 729 | TEST_F(StoragePartitionImplTest, RemoveQuotaManagedProtectedOrigins) { |
| 730 | // Protect kOrigin1. |
[email protected] | 523e5c59 | 2014-04-30 21:46:25 | [diff] [blame] | 731 | scoped_refptr<MockSpecialStoragePolicy> mock_policy = |
| 732 | new MockSpecialStoragePolicy; |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 733 | mock_policy->AddProtected(kOrigin1.GetOrigin()); |
| 734 | |
| 735 | PopulateTestQuotaManagedData(GetMockManager()); |
| 736 | |
| 737 | // Try to remove kOrigin1. Expect success. |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 738 | base::RunLoop run_loop; |
| 739 | StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 740 | BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 741 | partition->OverrideQuotaManagerForTesting( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 742 | GetMockManager()); |
dcheng | 54c3719d | 2014-08-26 21:52:56 | [diff] [blame] | 743 | partition->OverrideSpecialStoragePolicyForTesting(mock_policy.get()); |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 744 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 745 | FROM_HERE, |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 746 | base::Bind(&ClearQuotaDataWithOriginMatcher, partition, GURL(), |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 747 | base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb), |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 748 | base::Time(), &run_loop)); |
| 749 | run_loop.Run(); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 750 | |
| 751 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 752 | kClientFile)); |
| 753 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 754 | kClientFile)); |
| 755 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 756 | kClientFile)); |
| 757 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 758 | kClientFile)); |
| 759 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 760 | kClientFile)); |
| 761 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 762 | kClientFile)); |
| 763 | } |
| 764 | |
| 765 | TEST_F(StoragePartitionImplTest, RemoveQuotaManagedIgnoreDevTools) { |
| 766 | PopulateTestQuotaManagedNonBrowsingData(GetMockManager()); |
| 767 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 768 | base::RunLoop run_loop; |
| 769 | StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 770 | BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 771 | partition->OverrideQuotaManagerForTesting( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 772 | GetMockManager()); |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 773 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 774 | FROM_HERE, base::Bind(&ClearQuotaDataWithOriginMatcher, partition, GURL(), |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 775 | base::Bind(&DoesOriginMatchUnprotected), |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 776 | base::Time(), &run_loop)); |
| 777 | run_loop.Run(); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 778 | |
| 779 | // Check that devtools data isn't removed. |
| 780 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kTemporary, |
| 781 | kClientFile)); |
| 782 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kPersistent, |
| 783 | kClientFile)); |
| 784 | } |
| 785 | |
| 786 | TEST_F(StoragePartitionImplTest, RemoveCookieForever) { |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 787 | RemoveCookieTester tester(browser_context()); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 788 | |
| 789 | tester.AddCookie(); |
| 790 | ASSERT_TRUE(tester.ContainsCookie()); |
| 791 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 792 | StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 793 | BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 794 | partition->SetURLRequestContext(browser_context()->GetRequestContext()); |
| 795 | |
| 796 | base::RunLoop run_loop; |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 797 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 798 | FROM_HERE, base::Bind(&ClearCookies, partition, base::Time(), |
| 799 | base::Time::Max(), &run_loop)); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 800 | run_loop.Run(); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 801 | |
| 802 | EXPECT_FALSE(tester.ContainsCookie()); |
| 803 | } |
| 804 | |
| 805 | TEST_F(StoragePartitionImplTest, RemoveCookieLastHour) { |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 806 | RemoveCookieTester tester(browser_context()); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 807 | |
| 808 | tester.AddCookie(); |
| 809 | ASSERT_TRUE(tester.ContainsCookie()); |
| 810 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 811 | StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 812 | BrowserContext::GetDefaultStoragePartition(browser_context())); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 813 | base::Time an_hour_ago = base::Time::Now() - base::TimeDelta::FromHours(1); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 814 | partition->SetURLRequestContext(browser_context()->GetRequestContext()); |
| 815 | |
| 816 | base::RunLoop run_loop; |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 817 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 818 | FROM_HERE, base::Bind(&ClearCookies, partition, an_hour_ago, |
| 819 | base::Time::Max(), &run_loop)); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 820 | run_loop.Run(); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 821 | |
| 822 | EXPECT_FALSE(tester.ContainsCookie()); |
| 823 | } |
| 824 | |
| 825 | TEST_F(StoragePartitionImplTest, RemoveUnprotectedLocalStorageForever) { |
| 826 | // Protect kOrigin1. |
[email protected] | 523e5c59 | 2014-04-30 21:46:25 | [diff] [blame] | 827 | scoped_refptr<MockSpecialStoragePolicy> mock_policy = |
| 828 | new MockSpecialStoragePolicy; |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 829 | mock_policy->AddProtected(kOrigin1.GetOrigin()); |
| 830 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 831 | RemoveLocalStorageTester tester(browser_context()); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 832 | |
| 833 | tester.AddDOMStorageTestData(); |
| 834 | EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin1)); |
| 835 | EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin2)); |
| 836 | EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); |
| 837 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 838 | StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 839 | BrowserContext::GetDefaultStoragePartition(browser_context())); |
dcheng | 54c3719d | 2014-08-26 21:52:56 | [diff] [blame] | 840 | partition->OverrideSpecialStoragePolicyForTesting(mock_policy.get()); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 841 | |
| 842 | base::RunLoop run_loop; |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 843 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 844 | FROM_HERE, |
| 845 | base::Bind(&ClearStuff, |
| 846 | StoragePartitionImpl::REMOVE_DATA_MASK_LOCAL_STORAGE, |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 847 | partition, base::Time(), base::Time::Max(), |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 848 | base::Bind(&DoesOriginMatchForUnprotectedWeb), &run_loop)); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 849 | run_loop.Run(); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 850 | |
| 851 | EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin1)); |
| 852 | EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); |
| 853 | EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin3)); |
| 854 | } |
| 855 | |
| 856 | TEST_F(StoragePartitionImplTest, RemoveProtectedLocalStorageForever) { |
| 857 | // Protect kOrigin1. |
[email protected] | 523e5c59 | 2014-04-30 21:46:25 | [diff] [blame] | 858 | scoped_refptr<MockSpecialStoragePolicy> mock_policy = |
| 859 | new MockSpecialStoragePolicy; |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 860 | mock_policy->AddProtected(kOrigin1.GetOrigin()); |
| 861 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 862 | RemoveLocalStorageTester tester(browser_context()); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 863 | |
| 864 | tester.AddDOMStorageTestData(); |
| 865 | EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin1)); |
| 866 | EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin2)); |
| 867 | EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); |
| 868 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 869 | StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 870 | BrowserContext::GetDefaultStoragePartition(browser_context())); |
dcheng | 54c3719d | 2014-08-26 21:52:56 | [diff] [blame] | 871 | partition->OverrideSpecialStoragePolicyForTesting(mock_policy.get()); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 872 | |
| 873 | base::RunLoop run_loop; |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 874 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 875 | FROM_HERE, |
| 876 | base::Bind(&ClearStuff, |
| 877 | StoragePartitionImpl::REMOVE_DATA_MASK_LOCAL_STORAGE, |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 878 | partition, base::Time(), base::Time::Max(), |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 879 | base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb), |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 880 | &run_loop)); |
| 881 | run_loop.Run(); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 882 | |
| 883 | // Even if kOrigin1 is protected, it will be deleted since we specify |
| 884 | // ClearData to delete protected data. |
| 885 | EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); |
| 886 | EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); |
| 887 | EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin3)); |
| 888 | } |
| 889 | |
| 890 | TEST_F(StoragePartitionImplTest, RemoveLocalStorageForLastWeek) { |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 891 | RemoveLocalStorageTester tester(browser_context()); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 892 | |
| 893 | tester.AddDOMStorageTestData(); |
| 894 | EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin1)); |
| 895 | EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin2)); |
| 896 | EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); |
| 897 | |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 898 | StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 899 | BrowserContext::GetDefaultStoragePartition(browser_context())); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 900 | base::Time a_week_ago = base::Time::Now() - base::TimeDelta::FromDays(7); |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 901 | |
| 902 | base::RunLoop run_loop; |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 903 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 904 | FROM_HERE, |
| 905 | base::Bind(&ClearStuff, |
| 906 | StoragePartitionImpl::REMOVE_DATA_MASK_LOCAL_STORAGE, |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 907 | partition, a_week_ago, base::Time::Max(), |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 908 | base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb), |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 909 | &run_loop)); |
| 910 | run_loop.Run(); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 911 | |
| 912 | // kOrigin1 and kOrigin2 do not have age more than a week. |
| 913 | EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); |
| 914 | EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); |
| 915 | EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); |
| 916 | } |
| 917 | |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 918 | } // namespace content |