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

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

Issue 12224092: SessionStorageDatabase fix: Delete namespace keys if there are no areas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review (michaeln) Created 7 years, 10 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
« no previous file with comments | « webkit/dom_storage/session_storage_database.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 5
6 #include "webkit/dom_storage/session_storage_database.h" 6 #include "webkit/dom_storage/session_storage_database.h"
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 const NullableString16 kValue3; 76 const NullableString16 kValue3;
77 const NullableString16 kValue4; 77 const NullableString16 kValue4;
78 const NullableString16 kValueNull; 78 const NullableString16 kValueNull;
79 79
80 DISALLOW_COPY_AND_ASSIGN(SessionStorageDatabaseTest); 80 DISALLOW_COPY_AND_ASSIGN(SessionStorageDatabaseTest);
81 }; 81 };
82 82
83 SessionStorageDatabaseTest::SessionStorageDatabaseTest() 83 SessionStorageDatabaseTest::SessionStorageDatabaseTest()
84 : kOrigin1("http://www.origin1.com"), 84 : kOrigin1("http://www.origin1.com"),
85 kOrigin2("http://www.origin2.com"), 85 kOrigin2("http://www.origin2.com"),
86 kNamespace1("1"), 86 kNamespace1("namespace1"),
87 kNamespace2("namespace2"), 87 kNamespace2("namespace2"),
88 kNamespaceClone("wascloned"), 88 kNamespaceClone("wascloned"),
89 kKey1(ASCIIToUTF16("key1")), 89 kKey1(ASCIIToUTF16("key1")),
90 kKey2(ASCIIToUTF16("key2")), 90 kKey2(ASCIIToUTF16("key2")),
91 kKey3(ASCIIToUTF16("key3")), 91 kKey3(ASCIIToUTF16("key3")),
92 kValue1(NullableString16(ASCIIToUTF16("value1"), false)), 92 kValue1(NullableString16(ASCIIToUTF16("value1"), false)),
93 kValue2(NullableString16(ASCIIToUTF16("value2"), false)), 93 kValue2(NullableString16(ASCIIToUTF16("value2"), false)),
94 kValue3(NullableString16(ASCIIToUTF16("value3"), false)), 94 kValue3(NullableString16(ASCIIToUTF16("value3"), false)),
95 kValue4(NullableString16(ASCIIToUTF16("value4"), false)), 95 kValue4(NullableString16(ASCIIToUTF16("value4"), false)),
96 kValueNull(NullableString16(true)) { } 96 kValueNull(NullableString16(true)) { }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // keys. 206 // keys.
207 for (DataMap::const_iterator it = data.begin(); it != data.end(); ++it) { 207 for (DataMap::const_iterator it = data.begin(); it != data.end(); ++it) {
208 ASSERT_TRUE(it->first == next_map_id_key); 208 ASSERT_TRUE(it->first == next_map_id_key);
209 } 209 }
210 return; 210 return;
211 } 211 }
212 ++valid_keys; 212 ++valid_keys;
213 213
214 // Iterate the "namespace-" keys. 214 // Iterate the "namespace-" keys.
215 std::set<std::string> found_namespace_ids; 215 std::set<std::string> found_namespace_ids;
216 std::set<std::string> namespaces_with_areas;
216 std::map<int64, int64> expected_map_refcounts; 217 std::map<int64, int64> expected_map_refcounts;
217 int64 max_map_id = -1; 218 int64 max_map_id = -1;
218 219
219 for (DataMap::const_iterator it = data.begin(); it != data.end(); ++it) { 220 for (DataMap::const_iterator it = data.begin(); it != data.end(); ++it) {
220 std::string namespace_id; 221 std::string namespace_id;
221 std::string origin; 222 std::string origin;
222 if (IsNamespaceKey(it->first, &namespace_id)) { 223 if (IsNamespaceKey(it->first, &namespace_id)) {
223 found_namespace_ids.insert(namespace_id); 224 found_namespace_ids.insert(namespace_id);
224 ++valid_keys; 225 ++valid_keys;
225 } else if (IsNamespaceOriginKey( 226 } else if (IsNamespaceOriginKey(
226 it->first, &namespace_id)) { 227 it->first, &namespace_id)) {
227 // Check that the corresponding "namespace-<namespaceid>-" key exists. It 228 // Check that the corresponding "namespace-<namespaceid>-" key exists. It
228 // has been read by now, since the keys are stored in order. 229 // has been read by now, since the keys are stored in order.
229 ASSERT_TRUE(found_namespace_ids.find(namespace_id) != 230 ASSERT_TRUE(found_namespace_ids.find(namespace_id) !=
230 found_namespace_ids.end()); 231 found_namespace_ids.end());
232 namespaces_with_areas.insert(namespace_id);
231 int64 map_id; 233 int64 map_id;
232 bool conversion_ok = base::StringToInt64(it->second, &map_id); 234 bool conversion_ok = base::StringToInt64(it->second, &map_id);
233 ASSERT_TRUE(conversion_ok); 235 ASSERT_TRUE(conversion_ok);
234 ASSERT_GE(map_id, 0); 236 ASSERT_GE(map_id, 0);
235 ++expected_map_refcounts[map_id]; 237 ++expected_map_refcounts[map_id];
236 max_map_id = std::max(map_id, max_map_id); 238 max_map_id = std::max(map_id, max_map_id);
237 ++valid_keys; 239 ++valid_keys;
238 } 240 }
239 } 241 }
242 // Check that there are no leftover "namespace-namespaceid-" keys without
243 // associated areas.
244 ASSERT_EQ(found_namespace_ids.size(), namespaces_with_areas.size());
245
240 if (max_map_id != -1) { 246 if (max_map_id != -1) {
241 // The database contains maps. 247 // The database contains maps.
242 ASSERT_TRUE(data.find(next_map_id_key) != data.end()); 248 ASSERT_TRUE(data.find(next_map_id_key) != data.end());
243 int64 next_map_id; 249 int64 next_map_id;
244 bool conversion_ok = 250 bool conversion_ok =
245 base::StringToInt64(data[next_map_id_key], &next_map_id); 251 base::StringToInt64(data[next_map_id_key], &next_map_id);
246 ASSERT_TRUE(conversion_ok); 252 ASSERT_TRUE(conversion_ok);
247 ASSERT_GT(next_map_id, max_map_id); 253 ASSERT_GT(next_map_id, max_map_id);
248 } 254 }
249 255
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 ASSERT_TRUE(db_->CloneNamespace(kNamespace1, kNamespaceClone)); 772 ASSERT_TRUE(db_->CloneNamespace(kNamespace1, kNamespaceClone));
767 CheckOrigins(kNamespaceClone, expected_origins1); 773 CheckOrigins(kNamespaceClone, expected_origins1);
768 774
769 ASSERT_TRUE(db_->DeleteArea(kNamespace1, kOrigin2)); 775 ASSERT_TRUE(db_->DeleteArea(kNamespace1, kOrigin2));
770 expected_origins1.erase(kOrigin2); 776 expected_origins1.erase(kOrigin2);
771 CheckOrigins(kNamespace1, expected_origins1); 777 CheckOrigins(kNamespace1, expected_origins1);
772 778
773 CheckDatabaseConsistency(); 779 CheckDatabaseConsistency();
774 } 780 }
775 781
782 TEST_F(SessionStorageDatabaseTest, DeleteAllOrigins) {
783 // Write data for a namespace, for 2 origins.
784 ValuesMap data1;
785 data1[kKey1] = kValue1;
786 ASSERT_TRUE(db_->CommitAreaChanges(kNamespace1, kOrigin1, false, data1));
787 ValuesMap data2;
788 data2[kKey1] = kValue2;
789 ASSERT_TRUE(db_->CommitAreaChanges(kNamespace1, kOrigin2, false, data2));
790
791 EXPECT_TRUE(db_->DeleteArea(kNamespace1, kOrigin1));
792 EXPECT_TRUE(db_->DeleteArea(kNamespace1, kOrigin2));
793 // Check that also the namespace start key was deleted.
794 CheckDatabaseConsistency();
795 }
796
797
776 } // namespace dom_storage 798 } // namespace dom_storage
OLDNEW
« no previous file with comments | « webkit/dom_storage/session_storage_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698