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

Side by Side Diff: webkit/dom_storage/dom_storage_context_unittest.cc

Issue 10413072: Teaching BrowsingDataRemover how to delete application data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Inadvertant include. Created 8 years, 7 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/file_util.h" 6 #include "base/file_util.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 context_ = new DomStorageContext(temp_dir_.path(), 44 context_ = new DomStorageContext(temp_dir_.path(),
45 FilePath(), 45 FilePath(),
46 storage_policy_, 46 storage_policy_,
47 task_runner_); 47 task_runner_);
48 } 48 }
49 49
50 virtual void TearDown() { 50 virtual void TearDown() {
51 MessageLoop::current()->RunAllPending(); 51 MessageLoop::current()->RunAllPending();
52 } 52 }
53 53
54 void RemoveDataSince(const base::Time& cutoff,
55 bool include_protected_origins) {
56 // Use a new instance to remove the contexts of temp_dir_.
57 scoped_refptr<DomStorageContext> context = new DomStorageContext(
58 temp_dir_.path(), FilePath(), storage_policy_, NULL);
59 context->DeleteDataModifiedSince(cutoff, include_protected_origins);
60 }
61
54 void VerifySingleOriginRemains(const GURL& origin) { 62 void VerifySingleOriginRemains(const GURL& origin) {
55 // Use a new instance to examine the contexts of temp_dir_. 63 // Use a new instance to examine the contexts of temp_dir_.
56 scoped_refptr<DomStorageContext> context = 64 scoped_refptr<DomStorageContext> context =
57 new DomStorageContext(temp_dir_.path(), FilePath(), NULL, NULL); 65 new DomStorageContext(temp_dir_.path(), FilePath(), NULL, NULL);
58 std::vector<DomStorageContext::UsageInfo> infos; 66 std::vector<DomStorageContext::UsageInfo> infos;
59 context->GetUsageInfo(&infos, kDontIncludeFileInfo); 67 context->GetUsageInfo(&infos, kDontIncludeFileInfo);
60 EXPECT_EQ(1u, infos.size()); 68 EXPECT_EQ(1u, infos.size());
61 EXPECT_EQ(origin, infos[0].origin); 69 if (infos.size() > 0)
70 EXPECT_EQ(origin, infos[0].origin);
62 } 71 }
63 72
64 protected: 73 protected:
65 ScopedTempDir temp_dir_; 74 ScopedTempDir temp_dir_;
66 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy_; 75 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy_;
67 scoped_refptr<MockDomStorageTaskRunner> task_runner_; 76 scoped_refptr<MockDomStorageTaskRunner> task_runner_;
68 scoped_refptr<DomStorageContext> context_; 77 scoped_refptr<DomStorageContext> context_;
69 DISALLOW_COPY_AND_ASSIGN(DomStorageContextTest); 78 DISALLOW_COPY_AND_ASSIGN(DomStorageContextTest);
70 }; 79 };
71 80
72 TEST_F(DomStorageContextTest, Basics) { 81 TEST_F(DomStorageContextTest, Basics) {
73 // This test doesn't do much, checks that the constructor 82 // This test doesn't do much, checks that the constructor
74 // initializes members properly and that invoking methods 83 // initializes members properly and that invoking methods
75 // on a newly created object w/o any data on disk do no harm. 84 // on a newly created object w/o any data on disk do no harm.
76 EXPECT_EQ(temp_dir_.path(), context_->localstorage_directory()); 85 EXPECT_EQ(temp_dir_.path(), context_->localstorage_directory());
77 EXPECT_EQ(FilePath(), context_->sessionstorage_directory()); 86 EXPECT_EQ(FilePath(), context_->sessionstorage_directory());
78 EXPECT_EQ(storage_policy_.get(), context_->special_storage_policy_.get()); 87 EXPECT_EQ(storage_policy_.get(), context_->special_storage_policy_.get());
79 context_->PurgeMemory(); 88 context_->PurgeMemory();
80 context_->DeleteOrigin(GURL("http://chromium.org/")); 89 context_->DeleteOrigin(GURL("http://chromium.org/"));
81 context_->DeleteDataModifiedSince(base::Time::Now()); 90 context_->DeleteDataModifiedSince(base::Time::Now(), false);
82 const int kFirstSessionStorageNamespaceId = 1; 91 const int kFirstSessionStorageNamespaceId = 1;
83 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)); 92 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId));
84 EXPECT_FALSE(context_->GetStorageNamespace(kFirstSessionStorageNamespaceId)); 93 EXPECT_FALSE(context_->GetStorageNamespace(kFirstSessionStorageNamespaceId));
85 EXPECT_EQ(kFirstSessionStorageNamespaceId, context_->AllocateSessionId()); 94 EXPECT_EQ(kFirstSessionStorageNamespaceId, context_->AllocateSessionId());
86 std::vector<DomStorageContext::UsageInfo> infos; 95 std::vector<DomStorageContext::UsageInfo> infos;
87 context_->GetUsageInfo(&infos, kDontIncludeFileInfo); 96 context_->GetUsageInfo(&infos, kDontIncludeFileInfo);
88 EXPECT_TRUE(infos.empty()); 97 EXPECT_TRUE(infos.empty());
89 context_->Shutdown(); 98 context_->Shutdown();
90 } 99 }
91 100
101 TEST_F(DomStorageContextTest, RemoveUnprotectedOriginData) {
102 const GURL kProtectedOrigin("http://www.protected.com/");
103 storage_policy_->AddProtected(kProtectedOrigin);
104
105 // Store data for a normal and a protected origin, then remove data since
106 // the epoch.
107 NullableString16 old_value;
108 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)->
109 OpenStorageArea(kOrigin)->SetItem(kKey, kValue, &old_value));
110 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)->
111 OpenStorageArea(kProtectedOrigin)->SetItem(kKey, kValue, &old_value));
112 context_ = NULL;
113 MessageLoop::current()->RunAllPending();
114
115 RemoveDataSince(base::Time(), false);
116 VerifySingleOriginRemains(kProtectedOrigin);
117 }
118
119 TEST_F(DomStorageContextTest, RemoveProtectedOriginData) {
120 const GURL kProtectedOrigin("http://www.protected.com/");
121 storage_policy_->AddProtected(kProtectedOrigin);
122
123 // Store data for a normal and a protected origin, then remove data since
124 // the epoch.
125 NullableString16 old_value;
126 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)->
127 OpenStorageArea(kOrigin)->SetItem(kKey, kValue, &old_value));
128 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)->
129 OpenStorageArea(kProtectedOrigin)->SetItem(kKey, kValue, &old_value));
130 context_ = NULL;
131 MessageLoop::current()->RunAllPending();
132
133 RemoveDataSince(base::Time(), true);
134
135 // Create a new context that points to the same directory, see that
136 // both origins have been removed.
137 std::vector<DomStorageContext::UsageInfo> infos;
138 context_ = new DomStorageContext(temp_dir_.path(), FilePath(), NULL, NULL);
139 context_->GetUsageInfo(&infos, kDontIncludeFileInfo);
140 EXPECT_TRUE(infos.empty());
141 }
142
92 TEST_F(DomStorageContextTest, UsageInfo) { 143 TEST_F(DomStorageContextTest, UsageInfo) {
93 // Should be empty initially 144 // Should be empty initially
94 std::vector<DomStorageContext::UsageInfo> infos; 145 std::vector<DomStorageContext::UsageInfo> infos;
95 context_->GetUsageInfo(&infos, kDontIncludeFileInfo); 146 context_->GetUsageInfo(&infos, kDontIncludeFileInfo);
96 EXPECT_TRUE(infos.empty()); 147 EXPECT_TRUE(infos.empty());
97 context_->GetUsageInfo(&infos, kDoIncludeFileInfo); 148 context_->GetUsageInfo(&infos, kDoIncludeFileInfo);
98 EXPECT_TRUE(infos.empty()); 149 EXPECT_TRUE(infos.empty());
99 150
100 // Put some data into local storage and shutdown the context 151 // Put some data into local storage and shutdown the context
101 // to ensure data is written to disk. 152 // to ensure data is written to disk.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 context_->SetClearLocalState(true); 224 context_->SetClearLocalState(true);
174 context_->SaveSessionState(); // Should override clear behavior. 225 context_->SaveSessionState(); // Should override clear behavior.
175 context_->Shutdown(); 226 context_->Shutdown();
176 context_ = NULL; 227 context_ = NULL;
177 MessageLoop::current()->RunAllPending(); 228 MessageLoop::current()->RunAllPending();
178 229
179 VerifySingleOriginRemains(kSessionOnlyOrigin); 230 VerifySingleOriginRemains(kSessionOnlyOrigin);
180 } 231 }
181 232
182 } // namespace dom_storage 233 } // namespace dom_storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698