OLD | NEW |
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 <list> | 5 #include <list> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "webkit/renderer/dom_storage/dom_storage_cached_area.h" | 10 #include "webkit/renderer/dom_storage/dom_storage_cached_area.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 scoped_refptr<MockProxy> mock_proxy_; | 149 scoped_refptr<MockProxy> mock_proxy_; |
150 }; | 150 }; |
151 | 151 |
152 TEST_F(DomStorageCachedAreaTest, Basics) { | 152 TEST_F(DomStorageCachedAreaTest, Basics) { |
153 EXPECT_TRUE(mock_proxy_->HasOneRef()); | 153 EXPECT_TRUE(mock_proxy_->HasOneRef()); |
154 scoped_refptr<DomStorageCachedArea> cached_area = | 154 scoped_refptr<DomStorageCachedArea> cached_area = |
155 new DomStorageCachedArea(kNamespaceId, kOrigin, mock_proxy_.get()); | 155 new DomStorageCachedArea(kNamespaceId, kOrigin, mock_proxy_.get()); |
156 EXPECT_EQ(kNamespaceId, cached_area->namespace_id()); | 156 EXPECT_EQ(kNamespaceId, cached_area->namespace_id()); |
157 EXPECT_EQ(kOrigin, cached_area->origin()); | 157 EXPECT_EQ(kOrigin, cached_area->origin()); |
158 EXPECT_FALSE(mock_proxy_->HasOneRef()); | 158 EXPECT_FALSE(mock_proxy_->HasOneRef()); |
159 cached_area->ApplyMutation(NullableString16(kKey, false), | 159 cached_area->ApplyMutation(base::NullableString16(kKey, false), |
160 NullableString16(kValue, false)); | 160 base::NullableString16(kValue, false)); |
161 EXPECT_FALSE(IsPrimed(cached_area.get())); | 161 EXPECT_FALSE(IsPrimed(cached_area.get())); |
162 | 162 |
163 ResetAll(cached_area.get()); | 163 ResetAll(cached_area.get()); |
164 EXPECT_EQ(kNamespaceId, cached_area->namespace_id()); | 164 EXPECT_EQ(kNamespaceId, cached_area->namespace_id()); |
165 EXPECT_EQ(kOrigin, cached_area->origin()); | 165 EXPECT_EQ(kOrigin, cached_area->origin()); |
166 | 166 |
167 const int kConnectionId = 1; | 167 const int kConnectionId = 1; |
168 EXPECT_EQ(0u, cached_area->GetLength(kConnectionId)); | 168 EXPECT_EQ(0u, cached_area->GetLength(kConnectionId)); |
169 EXPECT_TRUE(cached_area->SetItem(kConnectionId, kKey, kValue, kPageUrl)); | 169 EXPECT_TRUE(cached_area->SetItem(kConnectionId, kKey, kValue, kPageUrl)); |
170 EXPECT_EQ(1u, cached_area->GetLength(kConnectionId)); | 170 EXPECT_EQ(1u, cached_area->GetLength(kConnectionId)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 cached_area->RemoveItem(kConnectionId, kKey, kPageUrl); | 244 cached_area->RemoveItem(kConnectionId, kKey, kPageUrl); |
245 EXPECT_TRUE(IsPrimed(cached_area.get())); | 245 EXPECT_TRUE(IsPrimed(cached_area.get())); |
246 EXPECT_TRUE(mock_proxy_->observed_load_area_); | 246 EXPECT_TRUE(mock_proxy_->observed_load_area_); |
247 EXPECT_FALSE(mock_proxy_->observed_remove_item_); | 247 EXPECT_FALSE(mock_proxy_->observed_remove_item_); |
248 EXPECT_EQ(kConnectionId, mock_proxy_->observed_connection_id_); | 248 EXPECT_EQ(kConnectionId, mock_proxy_->observed_connection_id_); |
249 EXPECT_EQ(1u, mock_proxy_->pending_callbacks_.size()); | 249 EXPECT_EQ(1u, mock_proxy_->pending_callbacks_.size()); |
250 | 250 |
251 // RemoveItem with something to remove, expect a call to load followed | 251 // RemoveItem with something to remove, expect a call to load followed |
252 // by a call to remove. | 252 // by a call to remove. |
253 ResetAll(cached_area.get()); | 253 ResetAll(cached_area.get()); |
254 mock_proxy_->load_area_return_values_[kKey] = NullableString16(kValue, false); | 254 mock_proxy_->load_area_return_values_[kKey] = |
| 255 base::NullableString16(kValue, false); |
255 EXPECT_FALSE(IsPrimed(cached_area.get())); | 256 EXPECT_FALSE(IsPrimed(cached_area.get())); |
256 cached_area->RemoveItem(kConnectionId, kKey, kPageUrl); | 257 cached_area->RemoveItem(kConnectionId, kKey, kPageUrl); |
257 EXPECT_TRUE(IsPrimed(cached_area.get())); | 258 EXPECT_TRUE(IsPrimed(cached_area.get())); |
258 EXPECT_TRUE(mock_proxy_->observed_load_area_); | 259 EXPECT_TRUE(mock_proxy_->observed_load_area_); |
259 EXPECT_TRUE(mock_proxy_->observed_remove_item_); | 260 EXPECT_TRUE(mock_proxy_->observed_remove_item_); |
260 EXPECT_EQ(kConnectionId, mock_proxy_->observed_connection_id_); | 261 EXPECT_EQ(kConnectionId, mock_proxy_->observed_connection_id_); |
261 EXPECT_EQ(kPageUrl, mock_proxy_->observed_page_url_); | 262 EXPECT_EQ(kPageUrl, mock_proxy_->observed_page_url_); |
262 EXPECT_EQ(kKey, mock_proxy_->observed_key_); | 263 EXPECT_EQ(kKey, mock_proxy_->observed_key_); |
263 EXPECT_EQ(2u, mock_proxy_->pending_callbacks_.size()); | 264 EXPECT_EQ(2u, mock_proxy_->pending_callbacks_.size()); |
264 } | 265 } |
265 | 266 |
266 TEST_F(DomStorageCachedAreaTest, MutationsAreIgnoredUntilLoadCompletion) { | 267 TEST_F(DomStorageCachedAreaTest, MutationsAreIgnoredUntilLoadCompletion) { |
267 const int kConnectionId = 7; | 268 const int kConnectionId = 7; |
268 scoped_refptr<DomStorageCachedArea> cached_area = | 269 scoped_refptr<DomStorageCachedArea> cached_area = |
269 new DomStorageCachedArea(kNamespaceId, kOrigin, mock_proxy_.get()); | 270 new DomStorageCachedArea(kNamespaceId, kOrigin, mock_proxy_.get()); |
270 EXPECT_TRUE(cached_area->GetItem(kConnectionId, kKey).is_null()); | 271 EXPECT_TRUE(cached_area->GetItem(kConnectionId, kKey).is_null()); |
271 EXPECT_TRUE(IsPrimed(cached_area.get())); | 272 EXPECT_TRUE(IsPrimed(cached_area.get())); |
272 EXPECT_TRUE(IsIgnoringAllMutations(cached_area.get())); | 273 EXPECT_TRUE(IsIgnoringAllMutations(cached_area.get())); |
273 | 274 |
274 // Before load completion, the mutation should be ignored. | 275 // Before load completion, the mutation should be ignored. |
275 cached_area->ApplyMutation(NullableString16(kKey, false), | 276 cached_area->ApplyMutation(base::NullableString16(kKey, false), |
276 NullableString16(kValue, false)); | 277 base::NullableString16(kValue, false)); |
277 EXPECT_TRUE(cached_area->GetItem(kConnectionId, kKey).is_null()); | 278 EXPECT_TRUE(cached_area->GetItem(kConnectionId, kKey).is_null()); |
278 | 279 |
279 // Call the load completion callback. | 280 // Call the load completion callback. |
280 mock_proxy_->CompleteOnePendingCallback(true); | 281 mock_proxy_->CompleteOnePendingCallback(true); |
281 EXPECT_FALSE(IsIgnoringAllMutations(cached_area.get())); | 282 EXPECT_FALSE(IsIgnoringAllMutations(cached_area.get())); |
282 | 283 |
283 // Verify that mutations are now applied. | 284 // Verify that mutations are now applied. |
284 cached_area->ApplyMutation(NullableString16(kKey, false), | 285 cached_area->ApplyMutation(base::NullableString16(kKey, false), |
285 NullableString16(kValue, false)); | 286 base::NullableString16(kValue, false)); |
286 EXPECT_EQ(kValue, cached_area->GetItem(kConnectionId, kKey).string()); | 287 EXPECT_EQ(kValue, cached_area->GetItem(kConnectionId, kKey).string()); |
287 } | 288 } |
288 | 289 |
289 TEST_F(DomStorageCachedAreaTest, MutationsAreIgnoredUntilClearCompletion) { | 290 TEST_F(DomStorageCachedAreaTest, MutationsAreIgnoredUntilClearCompletion) { |
290 const int kConnectionId = 4; | 291 const int kConnectionId = 4; |
291 scoped_refptr<DomStorageCachedArea> cached_area = | 292 scoped_refptr<DomStorageCachedArea> cached_area = |
292 new DomStorageCachedArea(kNamespaceId, kOrigin, mock_proxy_.get()); | 293 new DomStorageCachedArea(kNamespaceId, kOrigin, mock_proxy_.get()); |
293 cached_area->Clear(kConnectionId, kPageUrl); | 294 cached_area->Clear(kConnectionId, kPageUrl); |
294 EXPECT_TRUE(IsIgnoringAllMutations(cached_area.get())); | 295 EXPECT_TRUE(IsIgnoringAllMutations(cached_area.get())); |
295 mock_proxy_->CompleteOnePendingCallback(true); | 296 mock_proxy_->CompleteOnePendingCallback(true); |
(...skipping 15 matching lines...) Expand all Loading... |
311 TEST_F(DomStorageCachedAreaTest, KeyMutationsAreIgnoredUntilCompletion) { | 312 TEST_F(DomStorageCachedAreaTest, KeyMutationsAreIgnoredUntilCompletion) { |
312 const int kConnectionId = 8; | 313 const int kConnectionId = 8; |
313 scoped_refptr<DomStorageCachedArea> cached_area = | 314 scoped_refptr<DomStorageCachedArea> cached_area = |
314 new DomStorageCachedArea(kNamespaceId, kOrigin, mock_proxy_.get()); | 315 new DomStorageCachedArea(kNamespaceId, kOrigin, mock_proxy_.get()); |
315 | 316 |
316 // SetItem | 317 // SetItem |
317 EXPECT_TRUE(cached_area->SetItem(kConnectionId, kKey, kValue, kPageUrl)); | 318 EXPECT_TRUE(cached_area->SetItem(kConnectionId, kKey, kValue, kPageUrl)); |
318 mock_proxy_->CompleteOnePendingCallback(true); // load completion | 319 mock_proxy_->CompleteOnePendingCallback(true); // load completion |
319 EXPECT_FALSE(IsIgnoringAllMutations(cached_area.get())); | 320 EXPECT_FALSE(IsIgnoringAllMutations(cached_area.get())); |
320 EXPECT_TRUE(IsIgnoringKeyMutations(cached_area.get(), kKey)); | 321 EXPECT_TRUE(IsIgnoringKeyMutations(cached_area.get(), kKey)); |
321 cached_area->ApplyMutation(NullableString16(kKey, false), | 322 cached_area->ApplyMutation(base::NullableString16(kKey, false), |
322 NullableString16(true)); | 323 base::NullableString16(true)); |
323 EXPECT_EQ(kValue, cached_area->GetItem(kConnectionId, kKey).string()); | 324 EXPECT_EQ(kValue, cached_area->GetItem(kConnectionId, kKey).string()); |
324 mock_proxy_->CompleteOnePendingCallback(true); // set completion | 325 mock_proxy_->CompleteOnePendingCallback(true); // set completion |
325 EXPECT_FALSE(IsIgnoringKeyMutations(cached_area.get(), kKey)); | 326 EXPECT_FALSE(IsIgnoringKeyMutations(cached_area.get(), kKey)); |
326 | 327 |
327 // RemoveItem | 328 // RemoveItem |
328 cached_area->RemoveItem(kConnectionId, kKey, kPageUrl); | 329 cached_area->RemoveItem(kConnectionId, kKey, kPageUrl); |
329 EXPECT_TRUE(IsIgnoringKeyMutations(cached_area.get(), kKey)); | 330 EXPECT_TRUE(IsIgnoringKeyMutations(cached_area.get(), kKey)); |
330 mock_proxy_->CompleteOnePendingCallback(true); // remove completion | 331 mock_proxy_->CompleteOnePendingCallback(true); // remove completion |
331 EXPECT_FALSE(IsIgnoringKeyMutations(cached_area.get(), kKey)); | 332 EXPECT_FALSE(IsIgnoringKeyMutations(cached_area.get(), kKey)); |
332 | 333 |
333 // Multiple mutations to the same key. | 334 // Multiple mutations to the same key. |
334 EXPECT_TRUE(cached_area->SetItem(kConnectionId, kKey, kValue, kPageUrl)); | 335 EXPECT_TRUE(cached_area->SetItem(kConnectionId, kKey, kValue, kPageUrl)); |
335 cached_area->RemoveItem(kConnectionId, kKey, kPageUrl); | 336 cached_area->RemoveItem(kConnectionId, kKey, kPageUrl); |
336 EXPECT_TRUE(IsIgnoringKeyMutations(cached_area.get(), kKey)); | 337 EXPECT_TRUE(IsIgnoringKeyMutations(cached_area.get(), kKey)); |
337 mock_proxy_->CompleteOnePendingCallback(true); // set completion | 338 mock_proxy_->CompleteOnePendingCallback(true); // set completion |
338 EXPECT_TRUE(IsIgnoringKeyMutations(cached_area.get(), kKey)); | 339 EXPECT_TRUE(IsIgnoringKeyMutations(cached_area.get(), kKey)); |
339 mock_proxy_->CompleteOnePendingCallback(true); // remove completion | 340 mock_proxy_->CompleteOnePendingCallback(true); // remove completion |
340 EXPECT_FALSE(IsIgnoringKeyMutations(cached_area.get(), kKey)); | 341 EXPECT_FALSE(IsIgnoringKeyMutations(cached_area.get(), kKey)); |
341 | 342 |
342 // A failed set item operation should Reset the cache. | 343 // A failed set item operation should Reset the cache. |
343 EXPECT_TRUE(cached_area->SetItem(kConnectionId, kKey, kValue, kPageUrl)); | 344 EXPECT_TRUE(cached_area->SetItem(kConnectionId, kKey, kValue, kPageUrl)); |
344 EXPECT_TRUE(IsIgnoringKeyMutations(cached_area.get(), kKey)); | 345 EXPECT_TRUE(IsIgnoringKeyMutations(cached_area.get(), kKey)); |
345 mock_proxy_->CompleteOnePendingCallback(false); | 346 mock_proxy_->CompleteOnePendingCallback(false); |
346 EXPECT_FALSE(IsPrimed(cached_area.get())); | 347 EXPECT_FALSE(IsPrimed(cached_area.get())); |
347 } | 348 } |
348 | 349 |
349 } // namespace dom_storage | 350 } // namespace dom_storage |
OLD | NEW |