OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 const StorageObserver::Event& LastEvent() const { | 44 const StorageObserver::Event& LastEvent() const { |
45 CHECK(!events_.empty()); | 45 CHECK(!events_.empty()); |
46 return events_.back(); | 46 return events_.back(); |
47 } | 47 } |
48 | 48 |
49 int EventCount() const { | 49 int EventCount() const { |
50 return events_.size(); | 50 return events_.size(); |
51 } | 51 } |
52 | 52 |
53 // StorageObserver implementation: | 53 // StorageObserver implementation: |
54 virtual void OnStorageEvent(const StorageObserver::Event& event) override { | 54 void OnStorageEvent(const StorageObserver::Event& event) override { |
55 events_.push_back(event); | 55 events_.push_back(event); |
56 } | 56 } |
57 | 57 |
58 private: | 58 private: |
59 std::vector<StorageObserver::Event> events_; | 59 std::vector<StorageObserver::Event> events_; |
60 }; | 60 }; |
61 | 61 |
62 // A mock quota manager for overriding GetUsageAndQuotaForWebApps(). | 62 // A mock quota manager for overriding GetUsageAndQuotaForWebApps(). |
63 class UsageMockQuotaManager : public QuotaManager { | 63 class UsageMockQuotaManager : public QuotaManager { |
64 public: | 64 public: |
(...skipping 14 matching lines...) Expand all Loading... |
79 initialized_ = true; | 79 initialized_ = true; |
80 callback_quota_ = quota; | 80 callback_quota_ = quota; |
81 callback_usage_ = usage; | 81 callback_usage_ = usage; |
82 callback_status_ = status; | 82 callback_status_ = status; |
83 } | 83 } |
84 | 84 |
85 void InvokeCallback() { | 85 void InvokeCallback() { |
86 delayed_callback_.Run(callback_status_, callback_usage_, callback_quota_); | 86 delayed_callback_.Run(callback_status_, callback_usage_, callback_quota_); |
87 } | 87 } |
88 | 88 |
89 virtual void GetUsageAndQuotaForWebApps( | 89 void GetUsageAndQuotaForWebApps( |
90 const GURL& origin, | 90 const GURL& origin, |
91 StorageType type, | 91 StorageType type, |
92 const GetUsageAndQuotaCallback& callback) override { | 92 const GetUsageAndQuotaCallback& callback) override { |
93 if (initialized_) | 93 if (initialized_) |
94 callback.Run(callback_status_, callback_usage_, callback_quota_); | 94 callback.Run(callback_status_, callback_usage_, callback_quota_); |
95 else | 95 else |
96 delayed_callback_ = callback; | 96 delayed_callback_ = callback; |
97 } | 97 } |
98 | 98 |
99 protected: | 99 protected: |
100 virtual ~UsageMockQuotaManager() {} | 100 ~UsageMockQuotaManager() override {} |
101 | 101 |
102 private: | 102 private: |
103 int64 callback_usage_; | 103 int64 callback_usage_; |
104 int64 callback_quota_; | 104 int64 callback_quota_; |
105 QuotaStatusCode callback_status_; | 105 QuotaStatusCode callback_status_; |
106 bool initialized_; | 106 bool initialized_; |
107 GetUsageAndQuotaCallback delayed_callback_; | 107 GetUsageAndQuotaCallback delayed_callback_; |
108 }; | 108 }; |
109 | 109 |
110 } // namespace | 110 } // namespace |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 base::RunLoop().RunUntilIdle(); | 698 base::RunLoop().RunUntilIdle(); |
699 | 699 |
700 // Verify that the observer receives it. | 700 // Verify that the observer receives it. |
701 ASSERT_EQ(1, mock_observer.EventCount()); | 701 ASSERT_EQ(1, mock_observer.EventCount()); |
702 const StorageObserver::Event& event = mock_observer.LastEvent(); | 702 const StorageObserver::Event& event = mock_observer.LastEvent(); |
703 EXPECT_EQ(params.filter, event.filter); | 703 EXPECT_EQ(params.filter, event.filter); |
704 EXPECT_EQ(kTestUsage, event.usage); | 704 EXPECT_EQ(kTestUsage, event.usage); |
705 } | 705 } |
706 | 706 |
707 } // namespace content | 707 } // namespace content |
OLD | NEW |