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 "content/renderer/dom_storage/dom_storage_cached_area.h" | 5 #include "content/renderer/dom_storage/dom_storage_cached_area.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "content/renderer/dom_storage/dom_storage_proxy.h" | 11 #include "content/renderer/dom_storage/dom_storage_proxy.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 namespace { | 16 namespace { |
17 // A mock implementation of the DOMStorageProxy interface. | 17 // A mock implementation of the DOMStorageProxy interface. |
18 class MockProxy : public DOMStorageProxy { | 18 class MockProxy : public DOMStorageProxy { |
19 public: | 19 public: |
20 MockProxy() { | 20 MockProxy() { |
21 ResetObservations(); | 21 ResetObservations(); |
22 } | 22 } |
23 | 23 |
24 // DOMStorageProxy interface for use by DOMStorageCachedArea. | 24 // DOMStorageProxy interface for use by DOMStorageCachedArea. |
25 | 25 |
26 void LoadArea(int connection_id, | 26 void LoadArea(int connection_id, |
27 DOMStorageValuesMap* values, | 27 DOMStorageValuesMap* values, |
28 bool* send_log_get_messages, | |
29 const CompletionCallback& callback) override { | 28 const CompletionCallback& callback) override { |
30 pending_callbacks_.push_back(callback); | 29 pending_callbacks_.push_back(callback); |
31 observed_load_area_ = true; | 30 observed_load_area_ = true; |
32 observed_connection_id_ = connection_id; | 31 observed_connection_id_ = connection_id; |
33 *values = load_area_return_values_; | 32 *values = load_area_return_values_; |
34 *send_log_get_messages = false; | |
35 } | 33 } |
36 | 34 |
37 void SetItem(int connection_id, | 35 void SetItem(int connection_id, |
38 const base::string16& key, | 36 const base::string16& key, |
39 const base::string16& value, | 37 const base::string16& value, |
40 const GURL& page_url, | 38 const GURL& page_url, |
41 const CompletionCallback& callback) override { | 39 const CompletionCallback& callback) override { |
42 pending_callbacks_.push_back(callback); | 40 pending_callbacks_.push_back(callback); |
43 observed_set_item_ = true; | 41 observed_set_item_ = true; |
44 observed_connection_id_ = connection_id; | 42 observed_connection_id_ = connection_id; |
45 observed_key_ = key; | 43 observed_key_ = key; |
46 observed_value_ = value; | 44 observed_value_ = value; |
47 observed_page_url_ = page_url; | 45 observed_page_url_ = page_url; |
48 } | 46 } |
49 | 47 |
50 void LogGetItem(int connection_id, | |
51 const base::string16& key, | |
52 const base::NullableString16& value) override {} | |
53 | |
54 void RemoveItem(int connection_id, | 48 void RemoveItem(int connection_id, |
55 const base::string16& key, | 49 const base::string16& key, |
56 const GURL& page_url, | 50 const GURL& page_url, |
57 const CompletionCallback& callback) override { | 51 const CompletionCallback& callback) override { |
58 pending_callbacks_.push_back(callback); | 52 pending_callbacks_.push_back(callback); |
59 observed_remove_item_ = true; | 53 observed_remove_item_ = true; |
60 observed_connection_id_ = connection_id; | 54 observed_connection_id_ = connection_id; |
61 observed_key_ = key; | 55 observed_key_ = key; |
62 observed_page_url_ = page_url; | 56 observed_page_url_ = page_url; |
63 } | 57 } |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 EXPECT_FALSE(IsIgnoringKeyMutations(cached_area.get(), kKey)); | 345 EXPECT_FALSE(IsIgnoringKeyMutations(cached_area.get(), kKey)); |
352 | 346 |
353 // A failed set item operation should Reset the cache. | 347 // A failed set item operation should Reset the cache. |
354 EXPECT_TRUE(cached_area->SetItem(kConnectionId, kKey, kValue, kPageUrl)); | 348 EXPECT_TRUE(cached_area->SetItem(kConnectionId, kKey, kValue, kPageUrl)); |
355 EXPECT_TRUE(IsIgnoringKeyMutations(cached_area.get(), kKey)); | 349 EXPECT_TRUE(IsIgnoringKeyMutations(cached_area.get(), kKey)); |
356 mock_proxy_->CompleteOnePendingCallback(false); | 350 mock_proxy_->CompleteOnePendingCallback(false); |
357 EXPECT_FALSE(IsPrimed(cached_area.get())); | 351 EXPECT_FALSE(IsPrimed(cached_area.get())); |
358 } | 352 } |
359 | 353 |
360 } // namespace content | 354 } // namespace content |
OLD | NEW |