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

Side by Side Diff: content/browser/dom_storage/dom_storage_context_impl_unittest.cc

Issue 2403713002: Add suborigin logic to url::Origin (Closed)
Patch Set: Fix unit test Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/files/file_util.h" 6 #include "base/files/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/threading/sequenced_worker_pool.h" 12 #include "base/threading/sequenced_worker_pool.h"
13 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "content/browser/dom_storage/dom_storage_area.h" 15 #include "content/browser/dom_storage/dom_storage_area.h"
16 #include "content/browser/dom_storage/dom_storage_context_impl.h" 16 #include "content/browser/dom_storage/dom_storage_context_impl.h"
17 #include "content/browser/dom_storage/dom_storage_namespace.h" 17 #include "content/browser/dom_storage/dom_storage_namespace.h"
18 #include "content/browser/dom_storage/dom_storage_task_runner.h" 18 #include "content/browser/dom_storage/dom_storage_task_runner.h"
19 #include "content/public/browser/local_storage_usage_info.h" 19 #include "content/public/browser/local_storage_usage_info.h"
20 #include "content/public/browser/session_storage_usage_info.h" 20 #include "content/public/browser/session_storage_usage_info.h"
21 #include "content/public/test/mock_special_storage_policy.h" 21 #include "content/public/test/mock_special_storage_policy.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "url/gurl.h"
24 #include "url/origin.h"
23 25
24 using base::ASCIIToUTF16; 26 using base::ASCIIToUTF16;
25 27
26 namespace content { 28 namespace content {
27 29
28 class DOMStorageContextImplTest : public testing::Test { 30 class DOMStorageContextImplTest : public testing::Test {
29 public: 31 public:
30 DOMStorageContextImplTest() 32 DOMStorageContextImplTest()
31 : kOrigin(GURL("http://dom_storage/")), 33 : kOrigin(GURL("http://dom_storage/")),
32 kKey(ASCIIToUTF16("key")), 34 kSuborigin(GURL("http-so://foobar.dom_storage/")),
33 kValue(ASCIIToUTF16("value")), 35 kKey(ASCIIToUTF16("key")),
34 kDontIncludeFileInfo(false), 36 kValue(ASCIIToUTF16("value")),
35 kDoIncludeFileInfo(true) { 37 kDontIncludeFileInfo(false),
36 } 38 kDoIncludeFileInfo(true) {}
37 39
38 const GURL kOrigin; 40 const GURL kOrigin;
41 const GURL kSuborigin;
39 const base::string16 kKey; 42 const base::string16 kKey;
40 const base::string16 kValue; 43 const base::string16 kValue;
41 const bool kDontIncludeFileInfo; 44 const bool kDontIncludeFileInfo;
42 const bool kDoIncludeFileInfo; 45 const bool kDoIncludeFileInfo;
43 46
44 void SetUp() override { 47 void SetUp() override {
45 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 48 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
46 storage_policy_ = new MockSpecialStoragePolicy; 49 storage_policy_ = new MockSpecialStoragePolicy;
47 task_runner_ = 50 task_runner_ =
48 new MockDOMStorageTaskRunner(base::ThreadTaskRunnerHandle::Get().get()); 51 new MockDOMStorageTaskRunner(base::ThreadTaskRunnerHandle::Get().get());
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // Call commit directly instead of posting task. 293 // Call commit directly instead of posting task.
291 area2->CommitChanges(area2->commit_batch_.get()); 294 area2->CommitChanges(area2->commit_batch_.get());
292 area2->commit_batch_ = nullptr; 295 area2->commit_batch_ = nullptr;
293 296
294 // PURGE_AGGRESSIVE clears the cache in the open area. 297 // PURGE_AGGRESSIVE clears the cache in the open area.
295 EXPECT_NE(0u, dom_namespace->GetUsageStatistics().total_cache_size); 298 EXPECT_NE(0u, dom_namespace->GetUsageStatistics().total_cache_size);
296 context_->PurgeMemory(DOMStorageContextImpl::PURGE_AGGRESSIVE); 299 context_->PurgeMemory(DOMStorageContextImpl::PURGE_AGGRESSIVE);
297 EXPECT_EQ(0u, dom_namespace->GetUsageStatistics().total_cache_size); 300 EXPECT_EQ(0u, dom_namespace->GetUsageStatistics().total_cache_size);
298 } 301 }
299 302
303 // Verifies that deleting the local storage for an origin will delete any
304 // suborigins also present, and similarly, deleting a suborigin will delete the
305 // physical origin as well.
306 TEST_F(DOMStorageContextImplTest, DeleteSuboriginLocalStorage) {
307 context_->Shutdown();
308 context_ =
309 new DOMStorageContextImpl(temp_dir_.GetPath(), temp_dir_.GetPath(),
310 storage_policy_.get(), task_runner_.get());
311
312 DOMStorageNamespace* dom_namespace =
313 context_->GetStorageNamespace(kLocalStorageNamespaceId);
314 DOMStorageArea* origin_area = dom_namespace->OpenStorageArea(kOrigin);
315 DOMStorageArea* suborigin_area = dom_namespace->OpenStorageArea(kSuborigin);
316
317 const base::string16 kOriginKey(ASCIIToUTF16("foo"));
318 const base::string16 kOriginValue(ASCIIToUTF16("bar"));
319 const base::string16 kSuboriginKey(ASCIIToUTF16("foz"));
320 const base::string16 kSuboriginValue(ASCIIToUTF16("baz"));
321 base::NullableString16 old_nullable_value;
322
323 // Setup data for the first deletion (of the origin rather than the suborigin)
324 origin_area->SetItem(kOriginKey, kOriginValue, &old_nullable_value);
325 suborigin_area->SetItem(kSuboriginKey, kSuboriginValue, &old_nullable_value);
326
327 base::NullableString16 read_value;
328 read_value = origin_area->GetItem(kOriginKey);
329 EXPECT_EQ(kOriginValue, read_value.string());
330 read_value = suborigin_area->GetItem(kSuboriginKey);
331 EXPECT_EQ(kSuboriginValue, read_value.string());
332
333 // Deleting the data for the physical origin should delete the data in the
334 // suborigin as well.
335 context_->DeleteLocalStorageForPhysicalOrigin(kOrigin);
336
337 read_value = origin_area->GetItem(kOriginKey);
338 EXPECT_TRUE(read_value.is_null());
339 read_value = suborigin_area->GetItem(kSuboriginKey);
340 EXPECT_TRUE(read_value.is_null());
341
342 // Setup data again for the second deletion (of the suborigin rather than the
343 // origin)
344 origin_area->SetItem(kOriginKey, kOriginValue, &old_nullable_value);
345 suborigin_area->SetItem(kSuboriginKey, kSuboriginValue, &old_nullable_value);
346
347 read_value = origin_area->GetItem(kOriginKey);
348 EXPECT_EQ(kOriginValue, read_value.string());
349 read_value = suborigin_area->GetItem(kSuboriginKey);
350 EXPECT_EQ(kSuboriginValue, read_value.string());
351
352 // Delete the suborigin by physical origin this time. This should delete both
353 // the suborigin and physical origin.
354 context_->DeleteLocalStorageForPhysicalOrigin(kSuborigin);
355
356 read_value = origin_area->GetItem(kOriginKey);
357 EXPECT_TRUE(read_value.is_null());
358 read_value = suborigin_area->GetItem(kSuboriginKey);
359 EXPECT_TRUE(read_value.is_null());
360
361 // Setup data again for the third deletion, to test deleting the storage one
362 // at a time.
363 origin_area->SetItem(kOriginKey, kOriginValue, &old_nullable_value);
364 suborigin_area->SetItem(kSuboriginKey, kSuboriginValue, &old_nullable_value);
365
366 read_value = origin_area->GetItem(kOriginKey);
367 EXPECT_EQ(kOriginValue, read_value.string());
368 read_value = suborigin_area->GetItem(kSuboriginKey);
369 EXPECT_EQ(kSuboriginValue, read_value.string());
370
371 // Delete the origin only. This should leave the suborigin.
372 context_->DeleteLocalStorage(kOrigin);
373
374 read_value = origin_area->GetItem(kOriginKey);
375 EXPECT_TRUE(read_value.is_null());
376 read_value = suborigin_area->GetItem(kSuboriginKey);
377 EXPECT_EQ(kSuboriginValue, read_value.string());
378
379 // Put the origin value back so suborigin deletion can be tested.
380 origin_area->SetItem(kOriginKey, kOriginValue, &old_nullable_value);
381
382 read_value = origin_area->GetItem(kOriginKey);
383 EXPECT_EQ(kOriginValue, read_value.string());
384
385 // Delete the suborigin only. This should leave the origin.
386 context_->DeleteLocalStorage(kSuborigin);
387
388 read_value = origin_area->GetItem(kOriginKey);
389 EXPECT_EQ(kOriginValue, read_value.string());
390 read_value = suborigin_area->GetItem(kSuboriginKey);
391 EXPECT_TRUE(read_value.is_null());
392 }
393
300 } // namespace content 394 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/dom_storage/dom_storage_context_impl.cc ('k') | content/browser/dom_storage/dom_storage_context_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698