| 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 "base/files/file.h" | 5 #include "base/files/file.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 : new_notification_received_(false), | 36 : new_notification_received_(false), |
| 37 observe_size_changes_(true), | 37 observe_size_changes_(true), |
| 38 observe_scheduled_deletions_(true) { | 38 observe_scheduled_deletions_(true) { |
| 39 } | 39 } |
| 40 TestObserver(bool observe_size_changes, bool observe_scheduled_deletions) | 40 TestObserver(bool observe_size_changes, bool observe_scheduled_deletions) |
| 41 : new_notification_received_(false), | 41 : new_notification_received_(false), |
| 42 observe_size_changes_(observe_size_changes), | 42 observe_size_changes_(observe_size_changes), |
| 43 observe_scheduled_deletions_(observe_scheduled_deletions) { | 43 observe_scheduled_deletions_(observe_scheduled_deletions) { |
| 44 } | 44 } |
| 45 | 45 |
| 46 virtual ~TestObserver() {} | 46 ~TestObserver() override {} |
| 47 virtual void OnDatabaseSizeChanged(const std::string& origin_identifier, | 47 void OnDatabaseSizeChanged(const std::string& origin_identifier, |
| 48 const base::string16& database_name, | 48 const base::string16& database_name, |
| 49 int64 database_size) override { | 49 int64 database_size) override { |
| 50 if (!observe_size_changes_) | 50 if (!observe_size_changes_) |
| 51 return; | 51 return; |
| 52 new_notification_received_ = true; | 52 new_notification_received_ = true; |
| 53 origin_identifier_ = origin_identifier; | 53 origin_identifier_ = origin_identifier; |
| 54 database_name_ = database_name; | 54 database_name_ = database_name; |
| 55 database_size_ = database_size; | 55 database_size_ = database_size; |
| 56 } | 56 } |
| 57 virtual void OnDatabaseScheduledForDeletion( | 57 void OnDatabaseScheduledForDeletion( |
| 58 const std::string& origin_identifier, | 58 const std::string& origin_identifier, |
| 59 const base::string16& database_name) override { | 59 const base::string16& database_name) override { |
| 60 if (!observe_scheduled_deletions_) | 60 if (!observe_scheduled_deletions_) |
| 61 return; | 61 return; |
| 62 new_notification_received_ = true; | 62 new_notification_received_ = true; |
| 63 origin_identifier_ = origin_identifier; | 63 origin_identifier_ = origin_identifier; |
| 64 database_name_ = database_name; | 64 database_name_ = database_name; |
| 65 } | 65 } |
| 66 bool DidReceiveNewNotification() { | 66 bool DidReceiveNewNotification() { |
| 67 bool temp_new_notification_received = new_notification_received_; | 67 bool temp_new_notification_received = new_notification_received_; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 96 observer->GetNotificationDatabaseSize()); | 96 observer->GetNotificationDatabaseSize()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 class TestQuotaManagerProxy : public storage::QuotaManagerProxy { | 99 class TestQuotaManagerProxy : public storage::QuotaManagerProxy { |
| 100 public: | 100 public: |
| 101 TestQuotaManagerProxy() | 101 TestQuotaManagerProxy() |
| 102 : QuotaManagerProxy(NULL, NULL), | 102 : QuotaManagerProxy(NULL, NULL), |
| 103 registered_client_(NULL) { | 103 registered_client_(NULL) { |
| 104 } | 104 } |
| 105 | 105 |
| 106 virtual void RegisterClient(storage::QuotaClient* client) override { | 106 void RegisterClient(storage::QuotaClient* client) override { |
| 107 EXPECT_FALSE(registered_client_); | 107 EXPECT_FALSE(registered_client_); |
| 108 registered_client_ = client; | 108 registered_client_ = client; |
| 109 } | 109 } |
| 110 | 110 |
| 111 virtual void NotifyStorageAccessed(storage::QuotaClient::ID client_id, | 111 void NotifyStorageAccessed(storage::QuotaClient::ID client_id, |
| 112 const GURL& origin, | 112 const GURL& origin, |
| 113 storage::StorageType type) override { | 113 storage::StorageType type) override { |
| 114 EXPECT_EQ(storage::QuotaClient::kDatabase, client_id); | 114 EXPECT_EQ(storage::QuotaClient::kDatabase, client_id); |
| 115 EXPECT_EQ(storage::kStorageTypeTemporary, type); | 115 EXPECT_EQ(storage::kStorageTypeTemporary, type); |
| 116 accesses_[origin] += 1; | 116 accesses_[origin] += 1; |
| 117 } | 117 } |
| 118 | 118 |
| 119 virtual void NotifyStorageModified(storage::QuotaClient::ID client_id, | 119 void NotifyStorageModified(storage::QuotaClient::ID client_id, |
| 120 const GURL& origin, | 120 const GURL& origin, |
| 121 storage::StorageType type, | 121 storage::StorageType type, |
| 122 int64 delta) override { | 122 int64 delta) override { |
| 123 EXPECT_EQ(storage::QuotaClient::kDatabase, client_id); | 123 EXPECT_EQ(storage::QuotaClient::kDatabase, client_id); |
| 124 EXPECT_EQ(storage::kStorageTypeTemporary, type); | 124 EXPECT_EQ(storage::kStorageTypeTemporary, type); |
| 125 modifications_[origin].first += 1; | 125 modifications_[origin].first += 1; |
| 126 modifications_[origin].second += delta; | 126 modifications_[origin].second += delta; |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Not needed for our tests. | 129 // Not needed for our tests. |
| 130 virtual void NotifyOriginInUse(const GURL& origin) override {} | 130 void NotifyOriginInUse(const GURL& origin) override {} |
| 131 virtual void NotifyOriginNoLongerInUse(const GURL& origin) override {} | 131 void NotifyOriginNoLongerInUse(const GURL& origin) override {} |
| 132 virtual void SetUsageCacheEnabled(storage::QuotaClient::ID client_id, | 132 void SetUsageCacheEnabled(storage::QuotaClient::ID client_id, |
| 133 const GURL& origin, | 133 const GURL& origin, |
| 134 storage::StorageType type, | 134 storage::StorageType type, |
| 135 bool enabled) override {} | 135 bool enabled) override {} |
| 136 virtual void GetUsageAndQuota( | 136 void GetUsageAndQuota(base::SequencedTaskRunner* original_task_runner, |
| 137 base::SequencedTaskRunner* original_task_runner, | 137 const GURL& origin, |
| 138 const GURL& origin, | 138 storage::StorageType type, |
| 139 storage::StorageType type, | 139 const GetUsageAndQuotaCallback& callback) override {} |
| 140 const GetUsageAndQuotaCallback& callback) override {} | |
| 141 | 140 |
| 142 void SimulateQuotaManagerDestroyed() { | 141 void SimulateQuotaManagerDestroyed() { |
| 143 if (registered_client_) { | 142 if (registered_client_) { |
| 144 registered_client_->OnQuotaManagerDestroyed(); | 143 registered_client_->OnQuotaManagerDestroyed(); |
| 145 registered_client_ = NULL; | 144 registered_client_ = NULL; |
| 146 } | 145 } |
| 147 } | 146 } |
| 148 | 147 |
| 149 bool WasAccessNotified(const GURL& origin) { | 148 bool WasAccessNotified(const GURL& origin) { |
| 150 return accesses_[origin] != 0; | 149 return accesses_[origin] != 0; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 162 | 161 |
| 163 storage::QuotaClient* registered_client_; | 162 storage::QuotaClient* registered_client_; |
| 164 | 163 |
| 165 // Map from origin to count of access notifications. | 164 // Map from origin to count of access notifications. |
| 166 std::map<GURL, int> accesses_; | 165 std::map<GURL, int> accesses_; |
| 167 | 166 |
| 168 // Map from origin to <count, sum of deltas> | 167 // Map from origin to <count, sum of deltas> |
| 169 std::map<GURL, std::pair<int, int64> > modifications_; | 168 std::map<GURL, std::pair<int, int64> > modifications_; |
| 170 | 169 |
| 171 protected: | 170 protected: |
| 172 virtual ~TestQuotaManagerProxy() { | 171 ~TestQuotaManagerProxy() override { EXPECT_FALSE(registered_client_); } |
| 173 EXPECT_FALSE(registered_client_); | |
| 174 } | |
| 175 }; | 172 }; |
| 176 | 173 |
| 177 | 174 |
| 178 bool EnsureFileOfSize(const base::FilePath& file_path, int64 length) { | 175 bool EnsureFileOfSize(const base::FilePath& file_path, int64 length) { |
| 179 base::File file(file_path, | 176 base::File file(file_path, |
| 180 base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE); | 177 base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE); |
| 181 if (!file.IsValid()) | 178 if (!file.IsValid()) |
| 182 return false; | 179 return false; |
| 183 return file.SetLength(length); | 180 return file.SetLength(length); |
| 184 } | 181 } |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 | 860 |
| 864 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) { | 861 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) { |
| 865 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid(); | 862 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid(); |
| 866 } | 863 } |
| 867 | 864 |
| 868 TEST(DatabaseTrackerTest, HandleSqliteError) { | 865 TEST(DatabaseTrackerTest, HandleSqliteError) { |
| 869 DatabaseTracker_TestHelper_Test::HandleSqliteError(); | 866 DatabaseTracker_TestHelper_Test::HandleSqliteError(); |
| 870 } | 867 } |
| 871 | 868 |
| 872 } // namespace content | 869 } // namespace content |
| OLD | NEW |