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_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 const GURL kOriginA; | 32 const GURL kOriginA; |
33 const GURL kOriginB; | 33 const GURL kOriginB; |
34 const GURL kOriginOther; | 34 const GURL kOriginOther; |
35 | 35 |
36 IndexedDBQuotaClientTest() | 36 IndexedDBQuotaClientTest() |
37 : kOriginA("http://host"), | 37 : kOriginA("http://host"), |
38 kOriginB("http://host:8000"), | 38 kOriginB("http://host:8000"), |
39 kOriginOther("http://other"), | 39 kOriginOther("http://other"), |
40 usage_(0), | 40 usage_(0), |
41 weak_factory_(this), | 41 weak_factory_(this), |
42 message_loop_(MessageLoop::TYPE_IO), | 42 message_loop_(base::MessageLoop::TYPE_IO), |
43 db_thread_(BrowserThread::DB, &message_loop_), | 43 db_thread_(BrowserThread::DB, &message_loop_), |
44 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_), | 44 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_), |
45 file_thread_(BrowserThread::FILE, &message_loop_), | 45 file_thread_(BrowserThread::FILE, &message_loop_), |
46 file_user_blocking_thread_( | 46 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, |
47 BrowserThread::FILE_USER_BLOCKING, &message_loop_), | 47 &message_loop_), |
48 io_thread_(BrowserThread::IO, &message_loop_) { | 48 io_thread_(BrowserThread::IO, &message_loop_) { |
49 browser_context_.reset(new TestBrowserContext()); | 49 browser_context_.reset(new TestBrowserContext()); |
50 idb_context_ = static_cast<IndexedDBContextImpl*>( | 50 idb_context_ = static_cast<IndexedDBContextImpl*>( |
51 BrowserContext::GetDefaultStoragePartition(browser_context_.get())-> | 51 BrowserContext::GetDefaultStoragePartition(browser_context_.get())-> |
52 GetIndexedDBContext()); | 52 GetIndexedDBContext()); |
53 message_loop_.RunUntilIdle(); | 53 message_loop_.RunUntilIdle(); |
54 setup_temp_dir(); | 54 setup_temp_dir(); |
55 } | 55 } |
56 void setup_temp_dir() { | 56 void setup_temp_dir() { |
57 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 57 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
58 base::FilePath indexeddb_dir = temp_dir_.path().Append( | 58 base::FilePath indexeddb_dir = temp_dir_.path().Append( |
59 IndexedDBContextImpl::kIndexedDBDirectory); | 59 IndexedDBContextImpl::kIndexedDBDirectory); |
60 ASSERT_TRUE(file_util::CreateDirectory(indexeddb_dir)); | 60 ASSERT_TRUE(file_util::CreateDirectory(indexeddb_dir)); |
61 idb_context()->set_data_path_for_testing(indexeddb_dir); | 61 idb_context()->set_data_path_for_testing(indexeddb_dir); |
62 } | 62 } |
63 | 63 |
64 virtual ~IndexedDBQuotaClientTest() { | 64 virtual ~IndexedDBQuotaClientTest() { |
65 // IndexedDBContext needs to be destructed on | 65 // IndexedDBContext needs to be destructed on |
66 // BrowserThread::WEBKIT_DEPRECATED, which is also a member variable of this | 66 // BrowserThread::WEBKIT_DEPRECATED, which is also a member variable of this |
67 // class. Cause IndexedDBContext's destruction now to ensure that it | 67 // class. Cause IndexedDBContext's destruction now to ensure that it |
68 // doesn't outlive BrowserThread::WEBKIT_DEPRECATED. | 68 // doesn't outlive BrowserThread::WEBKIT_DEPRECATED. |
69 idb_context_ = NULL; | 69 idb_context_ = NULL; |
70 browser_context_.reset(); | 70 browser_context_.reset(); |
71 MessageLoop::current()->RunUntilIdle(); | 71 base::MessageLoop::current()->RunUntilIdle(); |
72 } | 72 } |
73 | 73 |
74 int64 GetOriginUsage( | 74 int64 GetOriginUsage( |
75 quota::QuotaClient* client, | 75 quota::QuotaClient* client, |
76 const GURL& origin, | 76 const GURL& origin, |
77 quota::StorageType type) { | 77 quota::StorageType type) { |
78 usage_ = -1; | 78 usage_ = -1; |
79 client->GetOriginUsage( | 79 client->GetOriginUsage( |
80 origin, type, | 80 origin, type, |
81 base::Bind(&IndexedDBQuotaClientTest::OnGetOriginUsageComplete, | 81 base::Bind(&IndexedDBQuotaClientTest::OnGetOriginUsageComplete, |
82 weak_factory_.GetWeakPtr())); | 82 weak_factory_.GetWeakPtr())); |
83 MessageLoop::current()->RunUntilIdle(); | 83 base::MessageLoop::current()->RunUntilIdle(); |
84 EXPECT_GT(usage_, -1); | 84 EXPECT_GT(usage_, -1); |
85 return usage_; | 85 return usage_; |
86 } | 86 } |
87 | 87 |
88 const std::set<GURL>& GetOriginsForType( | 88 const std::set<GURL>& GetOriginsForType( |
89 quota::QuotaClient* client, | 89 quota::QuotaClient* client, |
90 quota::StorageType type) { | 90 quota::StorageType type) { |
91 origins_.clear(); | 91 origins_.clear(); |
92 type_ = quota::kStorageTypeTemporary; | 92 type_ = quota::kStorageTypeTemporary; |
93 client->GetOriginsForType( | 93 client->GetOriginsForType( |
94 type, | 94 type, |
95 base::Bind(&IndexedDBQuotaClientTest::OnGetOriginsComplete, | 95 base::Bind(&IndexedDBQuotaClientTest::OnGetOriginsComplete, |
96 weak_factory_.GetWeakPtr())); | 96 weak_factory_.GetWeakPtr())); |
97 MessageLoop::current()->RunUntilIdle(); | 97 base::MessageLoop::current()->RunUntilIdle(); |
98 return origins_; | 98 return origins_; |
99 } | 99 } |
100 | 100 |
101 const std::set<GURL>& GetOriginsForHost( | 101 const std::set<GURL>& GetOriginsForHost( |
102 quota::QuotaClient* client, | 102 quota::QuotaClient* client, |
103 quota::StorageType type, | 103 quota::StorageType type, |
104 const std::string& host) { | 104 const std::string& host) { |
105 origins_.clear(); | 105 origins_.clear(); |
106 type_ = quota::kStorageTypeTemporary; | 106 type_ = quota::kStorageTypeTemporary; |
107 client->GetOriginsForHost( | 107 client->GetOriginsForHost( |
108 type, host, | 108 type, host, |
109 base::Bind(&IndexedDBQuotaClientTest::OnGetOriginsComplete, | 109 base::Bind(&IndexedDBQuotaClientTest::OnGetOriginsComplete, |
110 weak_factory_.GetWeakPtr())); | 110 weak_factory_.GetWeakPtr())); |
111 MessageLoop::current()->RunUntilIdle(); | 111 base::MessageLoop::current()->RunUntilIdle(); |
112 return origins_; | 112 return origins_; |
113 } | 113 } |
114 | 114 |
115 quota::QuotaStatusCode DeleteOrigin(quota::QuotaClient* client, | 115 quota::QuotaStatusCode DeleteOrigin(quota::QuotaClient* client, |
116 const GURL& origin_url) { | 116 const GURL& origin_url) { |
117 delete_status_ = quota::kQuotaStatusUnknown; | 117 delete_status_ = quota::kQuotaStatusUnknown; |
118 client->DeleteOriginData( | 118 client->DeleteOriginData( |
119 origin_url, kTemp, | 119 origin_url, kTemp, |
120 base::Bind(&IndexedDBQuotaClientTest::OnDeleteOriginComplete, | 120 base::Bind(&IndexedDBQuotaClientTest::OnDeleteOriginComplete, |
121 weak_factory_.GetWeakPtr())); | 121 weak_factory_.GetWeakPtr())); |
122 MessageLoop::current()->RunUntilIdle(); | 122 base::MessageLoop::current()->RunUntilIdle(); |
123 return delete_status_; | 123 return delete_status_; |
124 } | 124 } |
125 | 125 |
126 IndexedDBContextImpl* idb_context() { return idb_context_.get(); } | 126 IndexedDBContextImpl* idb_context() { return idb_context_.get(); } |
127 | 127 |
128 void SetFileSizeTo(const base::FilePath& path, int size) { | 128 void SetFileSizeTo(const base::FilePath& path, int size) { |
129 std::string junk(size, 'a'); | 129 std::string junk(size, 'a'); |
130 ASSERT_EQ(size, file_util::WriteFile(path, junk.c_str(), size)); | 130 ASSERT_EQ(size, file_util::WriteFile(path, junk.c_str(), size)); |
131 } | 131 } |
132 | 132 |
(...skipping 23 matching lines...) Expand all Loading... |
156 void OnDeleteOriginComplete(quota::QuotaStatusCode code) { | 156 void OnDeleteOriginComplete(quota::QuotaStatusCode code) { |
157 delete_status_ = code; | 157 delete_status_ = code; |
158 } | 158 } |
159 | 159 |
160 base::ScopedTempDir temp_dir_; | 160 base::ScopedTempDir temp_dir_; |
161 int64 usage_; | 161 int64 usage_; |
162 std::set<GURL> origins_; | 162 std::set<GURL> origins_; |
163 quota::StorageType type_; | 163 quota::StorageType type_; |
164 scoped_refptr<IndexedDBContextImpl> idb_context_; | 164 scoped_refptr<IndexedDBContextImpl> idb_context_; |
165 base::WeakPtrFactory<IndexedDBQuotaClientTest> weak_factory_; | 165 base::WeakPtrFactory<IndexedDBQuotaClientTest> weak_factory_; |
166 MessageLoop message_loop_; | 166 base::MessageLoop message_loop_; |
167 BrowserThreadImpl db_thread_; | 167 BrowserThreadImpl db_thread_; |
168 BrowserThreadImpl webkit_thread_; | 168 BrowserThreadImpl webkit_thread_; |
169 BrowserThreadImpl file_thread_; | 169 BrowserThreadImpl file_thread_; |
170 BrowserThreadImpl file_user_blocking_thread_; | 170 BrowserThreadImpl file_user_blocking_thread_; |
171 BrowserThreadImpl io_thread_; | 171 BrowserThreadImpl io_thread_; |
172 scoped_ptr<TestBrowserContext> browser_context_; | 172 scoped_ptr<TestBrowserContext> browser_context_; |
173 quota::QuotaStatusCode delete_status_; | 173 quota::QuotaStatusCode delete_status_; |
174 }; | 174 }; |
175 | 175 |
176 TEST_F(IndexedDBQuotaClientTest, GetOriginUsage) { | 176 TEST_F(IndexedDBQuotaClientTest, GetOriginUsage) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 EXPECT_EQ(1000, GetOriginUsage(&client, kOriginA, kTemp)); | 244 EXPECT_EQ(1000, GetOriginUsage(&client, kOriginA, kTemp)); |
245 EXPECT_EQ(50, GetOriginUsage(&client, kOriginB, kTemp)); | 245 EXPECT_EQ(50, GetOriginUsage(&client, kOriginB, kTemp)); |
246 | 246 |
247 quota::QuotaStatusCode delete_status = DeleteOrigin(&client, kOriginA); | 247 quota::QuotaStatusCode delete_status = DeleteOrigin(&client, kOriginA); |
248 EXPECT_EQ(quota::kQuotaStatusOk, delete_status); | 248 EXPECT_EQ(quota::kQuotaStatusOk, delete_status); |
249 EXPECT_EQ(0, GetOriginUsage(&client, kOriginA, kTemp)); | 249 EXPECT_EQ(0, GetOriginUsage(&client, kOriginA, kTemp)); |
250 EXPECT_EQ(50, GetOriginUsage(&client, kOriginB, kTemp)); | 250 EXPECT_EQ(50, GetOriginUsage(&client, kOriginB, kTemp)); |
251 } | 251 } |
252 | 252 |
253 } // namespace content | 253 } // namespace content |
OLD | NEW |