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 virtual void LoadArea(int connection_id, | 26 void LoadArea(int connection_id, |
27 DOMStorageValuesMap* values, | 27 DOMStorageValuesMap* values, |
28 bool* send_log_get_messages, | 28 bool* send_log_get_messages, |
29 const CompletionCallback& callback) override { | 29 const CompletionCallback& callback) override { |
30 pending_callbacks_.push_back(callback); | 30 pending_callbacks_.push_back(callback); |
31 observed_load_area_ = true; | 31 observed_load_area_ = true; |
32 observed_connection_id_ = connection_id; | 32 observed_connection_id_ = connection_id; |
33 *values = load_area_return_values_; | 33 *values = load_area_return_values_; |
34 *send_log_get_messages = false; | 34 *send_log_get_messages = false; |
35 } | 35 } |
36 | 36 |
37 virtual void SetItem(int connection_id, | 37 void SetItem(int connection_id, |
38 const base::string16& key, | 38 const base::string16& key, |
39 const base::string16& value, | 39 const base::string16& value, |
40 const GURL& page_url, | 40 const GURL& page_url, |
41 const CompletionCallback& callback) override { | 41 const CompletionCallback& callback) override { |
42 pending_callbacks_.push_back(callback); | 42 pending_callbacks_.push_back(callback); |
43 observed_set_item_ = true; | 43 observed_set_item_ = true; |
44 observed_connection_id_ = connection_id; | 44 observed_connection_id_ = connection_id; |
45 observed_key_ = key; | 45 observed_key_ = key; |
46 observed_value_ = value; | 46 observed_value_ = value; |
47 observed_page_url_ = page_url; | 47 observed_page_url_ = page_url; |
48 } | 48 } |
49 | 49 |
50 virtual void LogGetItem(int connection_id, | 50 void LogGetItem(int connection_id, |
51 const base::string16& key, | 51 const base::string16& key, |
52 const base::NullableString16& value) override { | 52 const base::NullableString16& value) override {} |
53 } | |
54 | 53 |
55 virtual void RemoveItem(int connection_id, | 54 void RemoveItem(int connection_id, |
56 const base::string16& key, | 55 const base::string16& key, |
57 const GURL& page_url, | 56 const GURL& page_url, |
58 const CompletionCallback& callback) override { | 57 const CompletionCallback& callback) override { |
59 pending_callbacks_.push_back(callback); | 58 pending_callbacks_.push_back(callback); |
60 observed_remove_item_ = true; | 59 observed_remove_item_ = true; |
61 observed_connection_id_ = connection_id; | 60 observed_connection_id_ = connection_id; |
62 observed_key_ = key; | 61 observed_key_ = key; |
63 observed_page_url_ = page_url; | 62 observed_page_url_ = page_url; |
64 } | 63 } |
65 | 64 |
66 virtual void ClearArea(int connection_id, | 65 void ClearArea(int connection_id, |
67 const GURL& page_url, | 66 const GURL& page_url, |
68 const CompletionCallback& callback) override { | 67 const CompletionCallback& callback) override { |
69 pending_callbacks_.push_back(callback); | 68 pending_callbacks_.push_back(callback); |
70 observed_clear_area_ = true; | 69 observed_clear_area_ = true; |
71 observed_connection_id_ = connection_id; | 70 observed_connection_id_ = connection_id; |
72 observed_page_url_ = page_url; | 71 observed_page_url_ = page_url; |
73 } | 72 } |
74 | 73 |
75 // Methods and members for use by test fixtures. | 74 // Methods and members for use by test fixtures. |
76 | 75 |
77 void ResetObservations() { | 76 void ResetObservations() { |
78 observed_load_area_ = false; | 77 observed_load_area_ = false; |
(...skipping 24 matching lines...) Expand all Loading... |
103 bool observed_load_area_; | 102 bool observed_load_area_; |
104 bool observed_set_item_; | 103 bool observed_set_item_; |
105 bool observed_remove_item_; | 104 bool observed_remove_item_; |
106 bool observed_clear_area_; | 105 bool observed_clear_area_; |
107 int observed_connection_id_; | 106 int observed_connection_id_; |
108 base::string16 observed_key_; | 107 base::string16 observed_key_; |
109 base::string16 observed_value_; | 108 base::string16 observed_value_; |
110 GURL observed_page_url_; | 109 GURL observed_page_url_; |
111 | 110 |
112 private: | 111 private: |
113 virtual ~MockProxy() {} | 112 ~MockProxy() override {} |
114 }; | 113 }; |
115 | 114 |
116 } // namespace | 115 } // namespace |
117 | 116 |
118 class DOMStorageCachedAreaTest : public testing::Test { | 117 class DOMStorageCachedAreaTest : public testing::Test { |
119 public: | 118 public: |
120 DOMStorageCachedAreaTest() | 119 DOMStorageCachedAreaTest() |
121 : kNamespaceId(10), | 120 : kNamespaceId(10), |
122 kOrigin("http://dom_storage/"), | 121 kOrigin("http://dom_storage/"), |
123 kKey(base::ASCIIToUTF16("key")), | 122 kKey(base::ASCIIToUTF16("key")), |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 EXPECT_FALSE(IsIgnoringKeyMutations(cached_area.get(), kKey)); | 353 EXPECT_FALSE(IsIgnoringKeyMutations(cached_area.get(), kKey)); |
355 | 354 |
356 // A failed set item operation should Reset the cache. | 355 // A failed set item operation should Reset the cache. |
357 EXPECT_TRUE(cached_area->SetItem(kConnectionId, kKey, kValue, kPageUrl)); | 356 EXPECT_TRUE(cached_area->SetItem(kConnectionId, kKey, kValue, kPageUrl)); |
358 EXPECT_TRUE(IsIgnoringKeyMutations(cached_area.get(), kKey)); | 357 EXPECT_TRUE(IsIgnoringKeyMutations(cached_area.get(), kKey)); |
359 mock_proxy_->CompleteOnePendingCallback(false); | 358 mock_proxy_->CompleteOnePendingCallback(false); |
360 EXPECT_FALSE(IsPrimed(cached_area.get())); | 359 EXPECT_FALSE(IsPrimed(cached_area.get())); |
361 } | 360 } |
362 | 361 |
363 } // namespace content | 362 } // namespace content |
OLD | NEW |