| 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 virtual 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 17 matching lines...) Expand all Loading... |
| 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 virtual 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 virtual ~UsageMockQuotaManager() {} |
| 101 | 101 |
| 102 private: | 102 private: |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 SetLastNotificationTime(host_observers.observers_, observer); | 157 SetLastNotificationTime(host_observers.observers_, observer); |
| 158 } | 158 } |
| 159 | 159 |
| 160 int GetObserverCount(const HostStorageObservers& host_observers) { | 160 int GetObserverCount(const HostStorageObservers& host_observers) { |
| 161 return host_observers.observers_.ObserverCount(); | 161 return host_observers.observers_.ObserverCount(); |
| 162 } | 162 } |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 class StorageTestWithManagerBase : public StorageMonitorTestBase { | 165 class StorageTestWithManagerBase : public StorageMonitorTestBase { |
| 166 public: | 166 public: |
| 167 virtual void SetUp() OVERRIDE { | 167 virtual void SetUp() override { |
| 168 storage_policy_ = new MockSpecialStoragePolicy(); | 168 storage_policy_ = new MockSpecialStoragePolicy(); |
| 169 quota_manager_ = new UsageMockQuotaManager(storage_policy_.get()); | 169 quota_manager_ = new UsageMockQuotaManager(storage_policy_.get()); |
| 170 } | 170 } |
| 171 | 171 |
| 172 virtual void TearDown() OVERRIDE { | 172 virtual void TearDown() override { |
| 173 // This ensures the quota manager is destroyed correctly. | 173 // This ensures the quota manager is destroyed correctly. |
| 174 quota_manager_ = NULL; | 174 quota_manager_ = NULL; |
| 175 base::RunLoop().RunUntilIdle(); | 175 base::RunLoop().RunUntilIdle(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 protected: | 178 protected: |
| 179 base::MessageLoop message_loop_; | 179 base::MessageLoop message_loop_; |
| 180 scoped_refptr<MockSpecialStoragePolicy> storage_policy_; | 180 scoped_refptr<MockSpecialStoragePolicy> storage_policy_; |
| 181 scoped_refptr<UsageMockQuotaManager> quota_manager_; | 181 scoped_refptr<UsageMockQuotaManager> quota_manager_; |
| 182 }; | 182 }; |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 GURL(kDefaultOrigin), | 556 GURL(kDefaultOrigin), |
| 557 base::TimeDelta::FromHours(1), | 557 base::TimeDelta::FromHours(1), |
| 558 false), | 558 false), |
| 559 params2_(kStorageTypePersistent, | 559 params2_(kStorageTypePersistent, |
| 560 GURL(kDefaultOrigin), | 560 GURL(kDefaultOrigin), |
| 561 base::TimeDelta::FromHours(1), | 561 base::TimeDelta::FromHours(1), |
| 562 false) { | 562 false) { |
| 563 } | 563 } |
| 564 | 564 |
| 565 protected: | 565 protected: |
| 566 virtual void SetUp() OVERRIDE { | 566 virtual void SetUp() override { |
| 567 StorageTestWithManagerBase::SetUp(); | 567 StorageTestWithManagerBase::SetUp(); |
| 568 | 568 |
| 569 storage_monitor_ = quota_manager_->storage_monitor_.get(); | 569 storage_monitor_ = quota_manager_->storage_monitor_.get(); |
| 570 host_ = net::GetHostOrSpecFromURL(params1_.filter.origin); | 570 host_ = net::GetHostOrSpecFromURL(params1_.filter.origin); |
| 571 | 571 |
| 572 storage_monitor_->AddObserver(&mock_observer1_, params1_); | 572 storage_monitor_->AddObserver(&mock_observer1_, params1_); |
| 573 storage_monitor_->AddObserver(&mock_observer2_, params1_); | 573 storage_monitor_->AddObserver(&mock_observer2_, params1_); |
| 574 | 574 |
| 575 storage_monitor_->AddObserver(&mock_observer1_, params2_); | 575 storage_monitor_->AddObserver(&mock_observer1_, params2_); |
| 576 storage_monitor_->AddObserver(&mock_observer2_, params2_); | 576 storage_monitor_->AddObserver(&mock_observer2_, params2_); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 // Test removing an observer for a specific filter. | 638 // Test removing an observer for a specific filter. |
| 639 TEST_F(StorageMonitorTest, RemoveObserverForFilter) { | 639 TEST_F(StorageMonitorTest, RemoveObserverForFilter) { |
| 640 storage_monitor_->RemoveObserverForFilter(&mock_observer1_, params2_.filter); | 640 storage_monitor_->RemoveObserverForFilter(&mock_observer1_, params2_.filter); |
| 641 CheckObserverCount(2, 2); | 641 CheckObserverCount(2, 2); |
| 642 } | 642 } |
| 643 | 643 |
| 644 // Integration test for QuotaManager and StorageMonitor: | 644 // Integration test for QuotaManager and StorageMonitor: |
| 645 | 645 |
| 646 class StorageMonitorIntegrationTest : public testing::Test { | 646 class StorageMonitorIntegrationTest : public testing::Test { |
| 647 public: | 647 public: |
| 648 virtual void SetUp() OVERRIDE { | 648 virtual void SetUp() override { |
| 649 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 649 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| 650 storage_policy_ = new MockSpecialStoragePolicy(); | 650 storage_policy_ = new MockSpecialStoragePolicy(); |
| 651 quota_manager_ = new QuotaManager( | 651 quota_manager_ = new QuotaManager( |
| 652 false, | 652 false, |
| 653 data_dir_.path(), | 653 data_dir_.path(), |
| 654 base::MessageLoopProxy::current().get(), | 654 base::MessageLoopProxy::current().get(), |
| 655 base::MessageLoopProxy::current().get(), | 655 base::MessageLoopProxy::current().get(), |
| 656 storage_policy_.get()); | 656 storage_policy_.get()); |
| 657 | 657 |
| 658 client_ = new MockStorageClient(quota_manager_->proxy(), | 658 client_ = new MockStorageClient(quota_manager_->proxy(), |
| 659 NULL, | 659 NULL, |
| 660 QuotaClient::kFileSystem, | 660 QuotaClient::kFileSystem, |
| 661 0); | 661 0); |
| 662 | 662 |
| 663 quota_manager_->proxy()->RegisterClient(client_); | 663 quota_manager_->proxy()->RegisterClient(client_); |
| 664 } | 664 } |
| 665 | 665 |
| 666 virtual void TearDown() OVERRIDE { | 666 virtual void TearDown() override { |
| 667 // This ensures the quota manager is destroyed correctly. | 667 // This ensures the quota manager is destroyed correctly. |
| 668 quota_manager_ = NULL; | 668 quota_manager_ = NULL; |
| 669 base::RunLoop().RunUntilIdle(); | 669 base::RunLoop().RunUntilIdle(); |
| 670 } | 670 } |
| 671 | 671 |
| 672 protected: | 672 protected: |
| 673 base::MessageLoop message_loop_; | 673 base::MessageLoop message_loop_; |
| 674 base::ScopedTempDir data_dir_; | 674 base::ScopedTempDir data_dir_; |
| 675 scoped_refptr<MockSpecialStoragePolicy> storage_policy_; | 675 scoped_refptr<MockSpecialStoragePolicy> storage_policy_; |
| 676 scoped_refptr<QuotaManager> quota_manager_; | 676 scoped_refptr<QuotaManager> quota_manager_; |
| (...skipping 21 matching lines...) Expand all 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 |