| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "base/memory/scoped_callback_factory.h" | 8 #include "base/memory/scoped_callback_factory.h" |
| 8 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 9 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| 10 #include "chrome/browser/browsing_data_quota_helper_impl.h" | 11 #include "chrome/browser/browsing_data_quota_helper_impl.h" |
| 11 #include "webkit/quota/mock_storage_client.h" | 12 #include "webkit/quota/mock_storage_client.h" |
| 12 #include "webkit/quota/quota_manager.h" | 13 #include "webkit/quota/quota_manager.h" |
| 13 | 14 |
| 14 class BrowsingDataQuotaHelperTest : public testing::Test { | 15 class BrowsingDataQuotaHelperTest : public testing::Test { |
| 15 public: | 16 public: |
| 16 typedef BrowsingDataQuotaHelper::QuotaInfo QuotaInfo; | 17 typedef BrowsingDataQuotaHelper::QuotaInfo QuotaInfo; |
| 17 typedef BrowsingDataQuotaHelper::QuotaInfoArray QuotaInfoArray; | 18 typedef BrowsingDataQuotaHelper::QuotaInfoArray QuotaInfoArray; |
| 18 | 19 |
| 19 BrowsingDataQuotaHelperTest() | 20 BrowsingDataQuotaHelperTest() |
| 20 : ui_thread_(BrowserThread::UI, &message_loop_), | 21 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 21 db_thread_(BrowserThread::DB, &message_loop_), | 22 db_thread_(BrowserThread::DB, &message_loop_), |
| 22 io_thread_(BrowserThread::IO, &message_loop_), | 23 io_thread_(BrowserThread::IO, &message_loop_), |
| 23 fetching_completed_(true), | 24 fetching_completed_(true), |
| 24 quota_(-1), | 25 quota_(-1), |
| 26 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 25 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} | 27 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} |
| 26 | 28 |
| 27 virtual ~BrowsingDataQuotaHelperTest() {} | 29 virtual ~BrowsingDataQuotaHelperTest() {} |
| 28 | 30 |
| 29 virtual void SetUp() OVERRIDE { | 31 virtual void SetUp() OVERRIDE { |
| 30 EXPECT_TRUE(dir_.CreateUniqueTempDir()); | 32 EXPECT_TRUE(dir_.CreateUniqueTempDir()); |
| 31 quota_manager_ = new quota::QuotaManager( | 33 quota_manager_ = new quota::QuotaManager( |
| 32 false, dir_.path(), | 34 false, dir_.path(), |
| 33 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 35 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 34 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | 36 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 quota::MockStorageClient* client = | 68 quota::MockStorageClient* client = |
| 67 new quota::MockStorageClient( | 69 new quota::MockStorageClient( |
| 68 quota_manager_->proxy(), data, data_len); | 70 quota_manager_->proxy(), data, data_len); |
| 69 quota_manager_->proxy()->RegisterClient(client); | 71 quota_manager_->proxy()->RegisterClient(client); |
| 70 client->TouchAllOriginsAndNotify(); | 72 client->TouchAllOriginsAndNotify(); |
| 71 } | 73 } |
| 72 | 74 |
| 73 void SetPersistentHostQuota(const std::string& host, int64 quota) { | 75 void SetPersistentHostQuota(const std::string& host, int64 quota) { |
| 74 quota_ = -1; | 76 quota_ = -1; |
| 75 quota_manager_->SetPersistentHostQuota( | 77 quota_manager_->SetPersistentHostQuota( |
| 76 host, quota, callback_factory_.NewCallback( | 78 host, quota, |
| 77 &BrowsingDataQuotaHelperTest::GotPersistentHostQuota)); | 79 base::Bind(&BrowsingDataQuotaHelperTest::GotPersistentHostQuota, |
| 80 weak_factory_.GetWeakPtr())); |
| 78 } | 81 } |
| 79 | 82 |
| 80 void GetPersistentHostQuota(const std::string& host) { | 83 void GetPersistentHostQuota(const std::string& host) { |
| 81 quota_ = -1; | 84 quota_ = -1; |
| 82 quota_manager_->GetPersistentHostQuota( | 85 quota_manager_->GetPersistentHostQuota( |
| 83 host, callback_factory_.NewCallback( | 86 host, |
| 84 &BrowsingDataQuotaHelperTest::GotPersistentHostQuota)); | 87 base::Bind(&BrowsingDataQuotaHelperTest::GotPersistentHostQuota, |
| 88 weak_factory_.GetWeakPtr())); |
| 85 } | 89 } |
| 86 | 90 |
| 87 void GotPersistentHostQuota(quota::QuotaStatusCode status, | 91 void GotPersistentHostQuota(quota::QuotaStatusCode status, |
| 88 const std::string& host, | 92 const std::string& host, |
| 89 quota::StorageType type, | 93 quota::StorageType type, |
| 90 int64 quota) { | 94 int64 quota) { |
| 91 EXPECT_EQ(quota::kQuotaStatusOk, status); | 95 EXPECT_EQ(quota::kQuotaStatusOk, status); |
| 92 EXPECT_EQ(quota::kStorageTypePersistent, type); | 96 EXPECT_EQ(quota::kStorageTypePersistent, type); |
| 93 quota_ = quota; | 97 quota_ = quota; |
| 94 } | 98 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 112 BrowserThread db_thread_; | 116 BrowserThread db_thread_; |
| 113 BrowserThread io_thread_; | 117 BrowserThread io_thread_; |
| 114 scoped_refptr<quota::QuotaManager> quota_manager_; | 118 scoped_refptr<quota::QuotaManager> quota_manager_; |
| 115 | 119 |
| 116 ScopedTempDir dir_; | 120 ScopedTempDir dir_; |
| 117 scoped_refptr<BrowsingDataQuotaHelper> helper_; | 121 scoped_refptr<BrowsingDataQuotaHelper> helper_; |
| 118 | 122 |
| 119 bool fetching_completed_; | 123 bool fetching_completed_; |
| 120 QuotaInfoArray quota_info_; | 124 QuotaInfoArray quota_info_; |
| 121 int64 quota_; | 125 int64 quota_; |
| 126 base::WeakPtrFactory<BrowsingDataQuotaHelperTest> weak_factory_; |
| 122 base::ScopedCallbackFactory<BrowsingDataQuotaHelperTest> callback_factory_; | 127 base::ScopedCallbackFactory<BrowsingDataQuotaHelperTest> callback_factory_; |
| 123 | 128 |
| 124 DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelperTest); | 129 DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelperTest); |
| 125 }; | 130 }; |
| 126 | 131 |
| 127 TEST_F(BrowsingDataQuotaHelperTest, Empty) { | 132 TEST_F(BrowsingDataQuotaHelperTest, Empty) { |
| 128 StartFetching(); | 133 StartFetching(); |
| 129 MessageLoop::current()->RunAllPending(); | 134 MessageLoop::current()->RunAllPending(); |
| 130 EXPECT_TRUE(fetching_completed()); | 135 EXPECT_TRUE(fetching_completed()); |
| 131 EXPECT_TRUE(quota_info().empty()); | 136 EXPECT_TRUE(quota_info().empty()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 MessageLoop::current()->RunAllPending(); | 168 MessageLoop::current()->RunAllPending(); |
| 164 | 169 |
| 165 GetPersistentHostQuota(kHost1); | 170 GetPersistentHostQuota(kHost1); |
| 166 MessageLoop::current()->RunAllPending(); | 171 MessageLoop::current()->RunAllPending(); |
| 167 EXPECT_EQ(0, quota()); | 172 EXPECT_EQ(0, quota()); |
| 168 | 173 |
| 169 GetPersistentHostQuota(kHost2); | 174 GetPersistentHostQuota(kHost2); |
| 170 MessageLoop::current()->RunAllPending(); | 175 MessageLoop::current()->RunAllPending(); |
| 171 EXPECT_EQ(10, quota()); | 176 EXPECT_EQ(10, quota()); |
| 172 } | 177 } |
| OLD | NEW |