| 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 virtual 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 virtual 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 virtual 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 } | 53 } |
| 54 | 54 |
| 55 virtual void RemoveItem(int connection_id, | 55 virtual void RemoveItem(int connection_id, |
| 56 const base::string16& key, | 56 const base::string16& key, |
| 57 const GURL& page_url, | 57 const GURL& page_url, |
| 58 const CompletionCallback& callback) OVERRIDE { | 58 const CompletionCallback& callback) override { |
| 59 pending_callbacks_.push_back(callback); | 59 pending_callbacks_.push_back(callback); |
| 60 observed_remove_item_ = true; | 60 observed_remove_item_ = true; |
| 61 observed_connection_id_ = connection_id; | 61 observed_connection_id_ = connection_id; |
| 62 observed_key_ = key; | 62 observed_key_ = key; |
| 63 observed_page_url_ = page_url; | 63 observed_page_url_ = page_url; |
| 64 } | 64 } |
| 65 | 65 |
| 66 virtual void ClearArea(int connection_id, | 66 virtual void ClearArea(int connection_id, |
| 67 const GURL& page_url, | 67 const GURL& page_url, |
| 68 const CompletionCallback& callback) OVERRIDE { | 68 const CompletionCallback& callback) override { |
| 69 pending_callbacks_.push_back(callback); | 69 pending_callbacks_.push_back(callback); |
| 70 observed_clear_area_ = true; | 70 observed_clear_area_ = true; |
| 71 observed_connection_id_ = connection_id; | 71 observed_connection_id_ = connection_id; |
| 72 observed_page_url_ = page_url; | 72 observed_page_url_ = page_url; |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Methods and members for use by test fixtures. | 75 // Methods and members for use by test fixtures. |
| 76 | 76 |
| 77 void ResetObservations() { | 77 void ResetObservations() { |
| 78 observed_load_area_ = false; | 78 observed_load_area_ = false; |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 EXPECT_FALSE(IsIgnoringKeyMutations(cached_area.get(), kKey)); | 354 EXPECT_FALSE(IsIgnoringKeyMutations(cached_area.get(), kKey)); |
| 355 | 355 |
| 356 // A failed set item operation should Reset the cache. | 356 // A failed set item operation should Reset the cache. |
| 357 EXPECT_TRUE(cached_area->SetItem(kConnectionId, kKey, kValue, kPageUrl)); | 357 EXPECT_TRUE(cached_area->SetItem(kConnectionId, kKey, kValue, kPageUrl)); |
| 358 EXPECT_TRUE(IsIgnoringKeyMutations(cached_area.get(), kKey)); | 358 EXPECT_TRUE(IsIgnoringKeyMutations(cached_area.get(), kKey)); |
| 359 mock_proxy_->CompleteOnePendingCallback(false); | 359 mock_proxy_->CompleteOnePendingCallback(false); |
| 360 EXPECT_FALSE(IsPrimed(cached_area.get())); | 360 EXPECT_FALSE(IsPrimed(cached_area.get())); |
| 361 } | 361 } |
| 362 | 362 |
| 363 } // namespace content | 363 } // namespace content |
| OLD | NEW |