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

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

Issue 9594038: Relax strict quota limit checks when reading pre-existing DomStorage database files. The other chec… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "webkit/dom_storage/dom_storage_map.h" 7 #include "webkit/dom_storage/dom_storage_map.h"
8 8
9 namespace dom_storage { 9 namespace dom_storage {
10 10
(...skipping 19 matching lines...) Expand all
30 // Check the behavior of an empty map. 30 // Check the behavior of an empty map.
31 EXPECT_EQ(0u, map->Length()); 31 EXPECT_EQ(0u, map->Length());
32 EXPECT_TRUE(map->Key(0).is_null()); 32 EXPECT_TRUE(map->Key(0).is_null());
33 EXPECT_TRUE(map->Key(100).is_null()); 33 EXPECT_TRUE(map->Key(100).is_null());
34 EXPECT_TRUE(map->GetItem(kKey).is_null()); 34 EXPECT_TRUE(map->GetItem(kKey).is_null());
35 EXPECT_FALSE(map->RemoveItem(kKey, &old_value)); 35 EXPECT_FALSE(map->RemoveItem(kKey, &old_value));
36 EXPECT_EQ(0u, map->bytes_used()); 36 EXPECT_EQ(0u, map->bytes_used());
37 copy = map->DeepCopy(); 37 copy = map->DeepCopy();
38 EXPECT_EQ(0u, copy->Length()); 38 EXPECT_EQ(0u, copy->Length());
39 EXPECT_EQ(0u, copy->bytes_used()); 39 EXPECT_EQ(0u, copy->bytes_used());
40 EXPECT_TRUE(map->SwapValues(&swap)); 40 map->SwapValues(&swap);
41 EXPECT_TRUE(swap.empty()); 41 EXPECT_TRUE(swap.empty());
42 42
43 // Check the behavior of a map containing some values. 43 // Check the behavior of a map containing some values.
44 EXPECT_TRUE(map->SetItem(kKey, kValue, &old_nullable_value)); 44 EXPECT_TRUE(map->SetItem(kKey, kValue, &old_nullable_value));
45 EXPECT_TRUE(old_nullable_value.is_null()); 45 EXPECT_TRUE(old_nullable_value.is_null());
46 EXPECT_EQ(1u, map->Length()); 46 EXPECT_EQ(1u, map->Length());
47 EXPECT_EQ(kKey, map->Key(0).string()); 47 EXPECT_EQ(kKey, map->Key(0).string());
48 EXPECT_TRUE(map->Key(1).is_null()); 48 EXPECT_TRUE(map->Key(1).is_null());
49 EXPECT_EQ(kValue, map->GetItem(kKey).string()); 49 EXPECT_EQ(kValue, map->GetItem(kKey).string());
50 EXPECT_TRUE(map->GetItem(kKey2).is_null()); 50 EXPECT_TRUE(map->GetItem(kKey2).is_null());
(...skipping 18 matching lines...) Expand all
69 69
70 copy = map->DeepCopy(); 70 copy = map->DeepCopy();
71 EXPECT_EQ(2u, copy->Length()); 71 EXPECT_EQ(2u, copy->Length());
72 EXPECT_EQ(kValue, copy->GetItem(kKey).string()); 72 EXPECT_EQ(kValue, copy->GetItem(kKey).string());
73 EXPECT_EQ(kValue2, copy->GetItem(kKey2).string()); 73 EXPECT_EQ(kValue2, copy->GetItem(kKey2).string());
74 EXPECT_EQ(kKey, copy->Key(0).string()); 74 EXPECT_EQ(kKey, copy->Key(0).string());
75 EXPECT_EQ(kKey2, copy->Key(1).string()); 75 EXPECT_EQ(kKey2, copy->Key(1).string());
76 EXPECT_TRUE(copy->Key(2).is_null()); 76 EXPECT_TRUE(copy->Key(2).is_null());
77 EXPECT_EQ(kItemBytes + kItem2Bytes, copy->bytes_used()); 77 EXPECT_EQ(kItemBytes + kItem2Bytes, copy->bytes_used());
78 78
79 EXPECT_TRUE(map->SwapValues(&swap)); 79 map->SwapValues(&swap);
80 EXPECT_EQ(2ul, swap.size()); 80 EXPECT_EQ(2ul, swap.size());
81 EXPECT_EQ(0u, map->Length()); 81 EXPECT_EQ(0u, map->Length());
82 EXPECT_EQ(0u, map->bytes_used()); 82 EXPECT_EQ(0u, map->bytes_used());
83 } 83 }
84 84
85 TEST(DomStorageMapTest, EnforcesQuota) { 85 TEST(DomStorageMapTest, EnforcesQuota) {
86 const string16 kKey = ASCIIToUTF16("test_key"); 86 const string16 kKey = ASCIIToUTF16("test_key");
87 const string16 kValue = ASCIIToUTF16("test_value"); 87 const string16 kValue = ASCIIToUTF16("test_value");
88 const string16 kKey2 = ASCIIToUTF16("test_key_2"); 88 const string16 kKey2 = ASCIIToUTF16("test_key_2");
89 89
90 // A 50 byte quota is too small to hold both keys, so we 90 // A 50 byte quota is too small to hold both keys, so we
91 // should see the DomStorageMap enforcing it. 91 // should see the DomStorageMap enforcing it.
92 const size_t kQuota = 50; 92 const size_t kQuota = 50;
93 93
94 string16 old_value; 94 string16 old_value;
95 NullableString16 old_nullable_value; 95 NullableString16 old_nullable_value;
96 96
97 scoped_refptr<DomStorageMap> map(new DomStorageMap(kQuota)); 97 scoped_refptr<DomStorageMap> map(new DomStorageMap(kQuota));
98 EXPECT_TRUE(map->SetItem(kKey, kValue, &old_nullable_value)); 98 EXPECT_TRUE(map->SetItem(kKey, kValue, &old_nullable_value));
99 EXPECT_FALSE(map->SetItem(kKey2, kValue, &old_nullable_value)); 99 EXPECT_FALSE(map->SetItem(kKey2, kValue, &old_nullable_value));
100 EXPECT_EQ(1u, map->Length()); 100 EXPECT_EQ(1u, map->Length());
101 101
102 EXPECT_TRUE(map->RemoveItem(kKey, &old_value)); 102 EXPECT_TRUE(map->RemoveItem(kKey, &old_value));
103 EXPECT_EQ(kValue, old_value); 103 EXPECT_EQ(kValue, old_value);
104 EXPECT_EQ(0u, map->Length()); 104 EXPECT_EQ(0u, map->Length());
105 EXPECT_TRUE(map->SetItem(kKey2, kValue, &old_nullable_value)); 105 EXPECT_TRUE(map->SetItem(kKey2, kValue, &old_nullable_value));
106 EXPECT_EQ(1u, map->Length()); 106 EXPECT_EQ(1u, map->Length());
107 107
108 ValuesMap swap; 108 ValuesMap swap;
109 EXPECT_TRUE(map->SwapValues(&swap)); 109 map->SwapValues(&swap);
benm (inactive) 2012/03/06 11:31:15 What is this bit of the test verifying now? I thin
michaeln 2012/03/06 20:37:51 Done, added tests to verify the quota checking beh
110 EXPECT_EQ(0u, map->Length());
111
112 swap[kKey] = NullableString16(kValue, false);
113 swap[kKey2] = NullableString16(kValue, false);
114
115 // swap is now too big to fit in the map, the swap should fail.
116 EXPECT_FALSE(map->SwapValues(&swap));
117 EXPECT_EQ(0u, map->Length()); 110 EXPECT_EQ(0u, map->Length());
118 } 111 }
119 112
120 } // namespace dom_storage 113 } // namespace dom_storage
OLDNEW
« webkit/dom_storage/dom_storage_map.cc ('K') | « webkit/dom_storage/dom_storage_map.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698