Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Unified Diff: content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc

Issue 7310022: Implement GetOrigins for indexeddb quota (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove url_constants.h include Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/in_process_webkit/indexed_db_quota_client.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc
diff --git a/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc b/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc
index b0dd9f20208f0df3c1ff2a62bf669acba0acede3..cd7d819d523c15d76a5173d2c0da5e38a6d4716e 100644
--- a/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc
+++ b/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc
@@ -27,10 +27,12 @@ class IndexedDBQuotaClientTest : public testing::Test {
public:
const GURL kOriginA;
const GURL kOriginB;
+ const GURL kOriginOther;
IndexedDBQuotaClientTest()
: kOriginA("http://host"),
kOriginB("http://host:8000"),
+ kOriginOther("http://other"),
usage_(0),
callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
message_loop_(MessageLoop::TYPE_IO),
@@ -68,6 +70,29 @@ class IndexedDBQuotaClientTest : public testing::Test {
return usage_;
}
+ const std::set<GURL>& GetOriginsForType(
+ quota::QuotaClient* client,
+ quota::StorageType type) {
+ origins_.clear();
+ client->GetOriginsForType(type,
+ callback_factory_.NewCallback(
+ &IndexedDBQuotaClientTest::OnGetOriginsComplete));
+ MessageLoop::current()->RunAllPending();
+ return origins_;
+ }
+
+ const std::set<GURL>& GetOriginsForHost(
+ quota::QuotaClient* client,
+ quota::StorageType type,
+ const std::string& host) {
+ origins_.clear();
+ client->GetOriginsForHost(type, host,
+ callback_factory_.NewCallback(
+ &IndexedDBQuotaClientTest::OnGetOriginsComplete));
+ MessageLoop::current()->RunAllPending();
+ return origins_;
+ }
+
IndexedDBContext* idb_context() { return idb_context_.get(); }
void SetFileSizeTo(const FilePath& path, int size) {
@@ -91,8 +116,13 @@ class IndexedDBQuotaClientTest : public testing::Test {
usage_ = usage;
}
+ void OnGetOriginsComplete(const std::set<GURL>& origins) {
+ origins_ = origins;
+ }
+
ScopedTempDir temp_dir_;
int64 usage_;
+ std::set<GURL> origins_;
scoped_refptr<IndexedDBContext> idb_context_;
base::ScopedCallbackFactory<IndexedDBQuotaClientTest> callback_factory_;
MessageLoop message_loop_;
@@ -118,3 +148,45 @@ TEST_F(IndexedDBQuotaClientTest, GetOriginUsage) {
EXPECT_EQ(3, GetOriginUsage(&client, kOriginB, kTemp));
EXPECT_EQ(0, GetOriginUsage(&client, kOriginB, kPerm));
}
+
+TEST_F(IndexedDBQuotaClientTest, GetOriginsForHost) {
+ IndexedDBQuotaClient client(
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ idb_context());
+
+ EXPECT_EQ(kOriginA.host(), kOriginB.host());
+ EXPECT_NE(kOriginA.host(), kOriginOther.host());
+
+ std::set<GURL> origins = GetOriginsForHost(&client, kTemp, kOriginA.host());
+ EXPECT_TRUE(origins.empty());
+
+ AddFakeIndexedDB(kOriginA, 1000);
+ origins = GetOriginsForHost(&client, kTemp, kOriginA.host());
+ EXPECT_EQ(origins.size(), 1ul);
+ EXPECT_TRUE(origins.find(kOriginA) != origins.end());
+
+ AddFakeIndexedDB(kOriginB, 1000);
+ origins = GetOriginsForHost(&client, kTemp, kOriginA.host());
+ EXPECT_EQ(origins.size(), 2ul);
+ EXPECT_TRUE(origins.find(kOriginA) != origins.end());
+ EXPECT_TRUE(origins.find(kOriginB) != origins.end());
+
+ EXPECT_TRUE(GetOriginsForHost(&client, kPerm, kOriginA.host()).empty());
+ EXPECT_TRUE(GetOriginsForHost(&client, kTemp, kOriginOther.host()).empty());
+}
+
+TEST_F(IndexedDBQuotaClientTest, GetOriginsForType) {
+ IndexedDBQuotaClient client(
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ idb_context());
+
+ EXPECT_TRUE(GetOriginsForType(&client, kTemp).empty());
+ EXPECT_TRUE(GetOriginsForType(&client, kPerm).empty());
+
+ AddFakeIndexedDB(kOriginA, 1000);
+ std::set<GURL> origins = GetOriginsForType(&client, kTemp);
+ EXPECT_EQ(origins.size(), 1ul);
+ EXPECT_TRUE(origins.find(kOriginA) != origins.end());
+
+ EXPECT_TRUE(GetOriginsForType(&client, kPerm).empty());
+}
« no previous file with comments | « content/browser/in_process_webkit/indexed_db_quota_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698