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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 // Mock tracker class the mocks up those methods of the tracker | 25 // Mock tracker class the mocks up those methods of the tracker |
26 // that are used by the QuotaClient. | 26 // that are used by the QuotaClient. |
27 class MockDatabaseTracker : public DatabaseTracker { | 27 class MockDatabaseTracker : public DatabaseTracker { |
28 public: | 28 public: |
29 MockDatabaseTracker() | 29 MockDatabaseTracker() |
30 : DatabaseTracker(FilePath(), false, NULL, NULL, NULL), | 30 : DatabaseTracker(FilePath(), false, NULL, NULL, NULL), |
31 delete_called_count_(0), | 31 delete_called_count_(0), |
32 async_delete_(false) {} | 32 async_delete_(false) {} |
33 | 33 |
34 virtual ~MockDatabaseTracker() {} | |
35 | |
36 virtual bool GetOriginInfo( | 34 virtual bool GetOriginInfo( |
37 const string16& origin_identifier, | 35 const string16& origin_identifier, |
38 OriginInfo* info) OVERRIDE { | 36 OriginInfo* info) OVERRIDE { |
39 std::map<GURL, MockOriginInfo>::const_iterator found = | 37 std::map<GURL, MockOriginInfo>::const_iterator found = |
40 mock_origin_infos_.find( | 38 mock_origin_infos_.find( |
41 DatabaseUtil::GetOriginFromIdentifier(origin_identifier)); | 39 DatabaseUtil::GetOriginFromIdentifier(origin_identifier)); |
42 if (found == mock_origin_infos_.end()) | 40 if (found == mock_origin_infos_.end()) |
43 return false; | 41 return false; |
44 *info = OriginInfo(found->second); | 42 *info = OriginInfo(found->second); |
45 return true; | 43 return true; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 void AddMockDatabase(const GURL& origin, const char* name, int size) { | 86 void AddMockDatabase(const GURL& origin, const char* name, int size) { |
89 MockOriginInfo& info = mock_origin_infos_[origin]; | 87 MockOriginInfo& info = mock_origin_infos_[origin]; |
90 info.set_origin(DatabaseUtil::GetOriginIdentifier(origin)); | 88 info.set_origin(DatabaseUtil::GetOriginIdentifier(origin)); |
91 info.AddMockDatabase(ASCIIToUTF16(name), size); | 89 info.AddMockDatabase(ASCIIToUTF16(name), size); |
92 } | 90 } |
93 | 91 |
94 int delete_called_count() { return delete_called_count_; } | 92 int delete_called_count() { return delete_called_count_; } |
95 bool async_delete() { return async_delete_; } | 93 bool async_delete() { return async_delete_; } |
96 void set_async_delete(bool async) { async_delete_ = async; } | 94 void set_async_delete(bool async) { async_delete_ = async; } |
97 | 95 |
| 96 protected: |
| 97 virtual ~MockDatabaseTracker() {} |
| 98 |
98 private: | 99 private: |
99 class MockOriginInfo : public OriginInfo { | 100 class MockOriginInfo : public OriginInfo { |
100 public: | 101 public: |
101 void set_origin(const string16& origin_id) { | 102 void set_origin(const string16& origin_id) { |
102 origin_ = origin_id; | 103 origin_ = origin_id; |
103 } | 104 } |
104 | 105 |
105 void AddMockDatabase(const string16& name, int size) { | 106 void AddMockDatabase(const string16& name, int size) { |
106 EXPECT_TRUE(database_info_.find(name) == database_info_.end()); | 107 EXPECT_TRUE(database_info_.find(name) == database_info_.end()); |
107 database_info_[name].first = size; | 108 database_info_[name].first = size; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 mock_tracker()->set_async_delete(false); | 281 mock_tracker()->set_async_delete(false); |
281 EXPECT_TRUE(DeleteOriginData(&client, kTemp, kOriginA)); | 282 EXPECT_TRUE(DeleteOriginData(&client, kTemp, kOriginA)); |
282 EXPECT_EQ(1, mock_tracker()->delete_called_count()); | 283 EXPECT_EQ(1, mock_tracker()->delete_called_count()); |
283 | 284 |
284 mock_tracker()->set_async_delete(true); | 285 mock_tracker()->set_async_delete(true); |
285 EXPECT_TRUE(DeleteOriginData(&client, kTemp, kOriginA)); | 286 EXPECT_TRUE(DeleteOriginData(&client, kTemp, kOriginA)); |
286 EXPECT_EQ(2, mock_tracker()->delete_called_count()); | 287 EXPECT_EQ(2, mock_tracker()->delete_called_count()); |
287 } | 288 } |
288 | 289 |
289 } // namespace webkit_database | 290 } // namespace webkit_database |
OLD | NEW |