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 | 5 |
6 #include <set> | 6 #include <set> |
7 | 7 |
| 8 #include "base/bind.h" |
8 #include "base/file_util.h" | 9 #include "base/file_util.h" |
9 #include "base/memory/scoped_callback_factory.h" | |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
13 #include "base/scoped_temp_dir.h" | 13 #include "base/scoped_temp_dir.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "webkit/quota/mock_quota_manager.h" | 15 #include "webkit/quota/mock_quota_manager.h" |
16 #include "webkit/quota/mock_special_storage_policy.h" | 16 #include "webkit/quota/mock_special_storage_policy.h" |
17 #include "webkit/quota/mock_storage_client.h" | 17 #include "webkit/quota/mock_storage_client.h" |
18 | 18 |
19 namespace quota { | 19 namespace quota { |
20 | 20 |
21 const char kTestOrigin1[] = "http://host1:1/"; | 21 const char kTestOrigin1[] = "http://host1:1/"; |
22 const char kTestOrigin2[] = "http://host2:1/"; | 22 const char kTestOrigin2[] = "http://host2:1/"; |
23 const char kTestOrigin3[] = "http://host3:1/"; | 23 const char kTestOrigin3[] = "http://host3:1/"; |
24 | 24 |
25 const GURL kOrigin1(kTestOrigin1); | 25 const GURL kOrigin1(kTestOrigin1); |
26 const GURL kOrigin2(kTestOrigin2); | 26 const GURL kOrigin2(kTestOrigin2); |
27 const GURL kOrigin3(kTestOrigin3); | 27 const GURL kOrigin3(kTestOrigin3); |
28 | 28 |
29 class MockQuotaManagerTest : public testing::Test { | 29 class MockQuotaManagerTest : public testing::Test { |
30 public: | 30 public: |
31 MockQuotaManagerTest() | 31 MockQuotaManagerTest() |
32 : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 32 : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
33 deletion_callback_count_(0) { | 33 deletion_callback_count_(0) { |
34 } | 34 } |
35 | 35 |
36 void SetUp() { | 36 void SetUp() { |
37 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 37 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
38 policy_ = new MockSpecialStoragePolicy; | 38 policy_ = new MockSpecialStoragePolicy; |
39 manager_ = new MockQuotaManager( | 39 manager_ = new MockQuotaManager( |
40 false /* is_incognito */, | 40 false /* is_incognito */, |
41 data_dir_.path(), | 41 data_dir_.path(), |
42 base::MessageLoopProxy::current(), | 42 base::MessageLoopProxy::current(), |
43 base::MessageLoopProxy::current(), | 43 base::MessageLoopProxy::current(), |
44 policy_); | 44 policy_); |
45 } | 45 } |
46 | 46 |
47 void TearDown() { | 47 void TearDown() { |
48 // Make sure the quota manager cleans up correctly. | 48 // Make sure the quota manager cleans up correctly. |
49 manager_ = NULL; | 49 manager_ = NULL; |
50 MessageLoop::current()->RunAllPending(); | 50 MessageLoop::current()->RunAllPending(); |
51 } | 51 } |
52 | 52 |
53 void GetModifiedOrigins(StorageType type, base::Time since) { | 53 void GetModifiedOrigins(StorageType type, base::Time since) { |
54 manager_->GetOriginsModifiedSince(type, since, | 54 manager_->GetOriginsModifiedSince( |
55 callback_factory_.NewCallback( | 55 type, since, |
56 &MockQuotaManagerTest::GotModifiedOrigins)); | 56 base::Bind(&MockQuotaManagerTest::GotModifiedOrigins, |
| 57 weak_factory_.GetWeakPtr())); |
57 } | 58 } |
58 | 59 |
59 void GotModifiedOrigins(const std::set<GURL>& origins, StorageType type) { | 60 void GotModifiedOrigins(const std::set<GURL>& origins, StorageType type) { |
60 origins_ = origins; | 61 origins_ = origins; |
61 type_ = type; | 62 type_ = type; |
62 } | 63 } |
63 | 64 |
64 void DeleteOriginData(const GURL& origin, StorageType type) { | 65 void DeleteOriginData(const GURL& origin, StorageType type) { |
65 manager_->DeleteOriginData(origin, type, | 66 manager_->DeleteOriginData( |
66 callback_factory_.NewCallback( | 67 origin, type, |
67 &MockQuotaManagerTest::DeletedOriginData)); | 68 base::Bind(&MockQuotaManagerTest::DeletedOriginData, |
| 69 weak_factory_.GetWeakPtr())); |
68 } | 70 } |
69 | 71 |
70 void DeletedOriginData(QuotaStatusCode status) { | 72 void DeletedOriginData(QuotaStatusCode status) { |
71 ++deletion_callback_count_; | 73 ++deletion_callback_count_; |
72 EXPECT_EQ(quota::kQuotaStatusOk, status); | 74 EXPECT_EQ(quota::kQuotaStatusOk, status); |
73 } | 75 } |
74 | 76 |
75 int deletion_callback_count() const { | 77 int deletion_callback_count() const { |
76 return deletion_callback_count_; | 78 return deletion_callback_count_; |
77 } | 79 } |
78 | 80 |
79 MockQuotaManager* manager() const { | 81 MockQuotaManager* manager() const { |
80 return manager_.get(); | 82 return manager_.get(); |
81 } | 83 } |
82 | 84 |
83 const std::set<GURL>& origins() const { | 85 const std::set<GURL>& origins() const { |
84 return origins_; | 86 return origins_; |
85 } | 87 } |
86 | 88 |
87 const StorageType& type() const { | 89 const StorageType& type() const { |
88 return type_; | 90 return type_; |
89 } | 91 } |
90 | 92 |
91 private: | 93 private: |
92 ScopedTempDir data_dir_; | 94 ScopedTempDir data_dir_; |
93 base::ScopedCallbackFactory<MockQuotaManagerTest> callback_factory_; | 95 base::WeakPtrFactory<MockQuotaManagerTest> weak_factory_; |
94 scoped_refptr<MockQuotaManager> manager_; | 96 scoped_refptr<MockQuotaManager> manager_; |
95 scoped_refptr<MockSpecialStoragePolicy> policy_; | 97 scoped_refptr<MockSpecialStoragePolicy> policy_; |
96 | 98 |
97 int deletion_callback_count_; | 99 int deletion_callback_count_; |
98 | 100 |
99 std::set<GURL> origins_; | 101 std::set<GURL> origins_; |
100 StorageType type_; | 102 StorageType type_; |
101 | 103 |
102 DISALLOW_COPY_AND_ASSIGN(MockQuotaManagerTest); | 104 DISALLOW_COPY_AND_ASSIGN(MockQuotaManagerTest); |
103 }; | 105 }; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 173 |
172 GetModifiedOrigins(kStorageTypeTemporary, now - a_minute); | 174 GetModifiedOrigins(kStorageTypeTemporary, now - a_minute); |
173 MessageLoop::current()->RunAllPending(); | 175 MessageLoop::current()->RunAllPending(); |
174 | 176 |
175 EXPECT_EQ(kStorageTypeTemporary, type()); | 177 EXPECT_EQ(kStorageTypeTemporary, type()); |
176 EXPECT_EQ(1UL, origins().size()); | 178 EXPECT_EQ(1UL, origins().size()); |
177 EXPECT_EQ(0UL, origins().count(kOrigin1)); | 179 EXPECT_EQ(0UL, origins().count(kOrigin1)); |
178 EXPECT_EQ(1UL, origins().count(kOrigin2)); | 180 EXPECT_EQ(1UL, origins().count(kOrigin2)); |
179 } | 181 } |
180 } // Namespace quota | 182 } // Namespace quota |
OLD | NEW |