Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <map> | |
| 6 | |
| 7 #include "base/file_path.h" | |
| 8 #include "base/file_util.h" | |
| 9 #include "base/memory/scoped_callback_factory.h" | |
| 10 #include "base/message_loop.h" | |
| 11 #include "base/message_loop_proxy.h" | |
| 12 #include "base/utf_string_conversions.h" | |
|
michaeln
2011/05/26 08:40:35
still needed?
dgrogan
2011/05/26 20:56:04
Nope, deleted.
| |
| 13 #include "chrome/test/testing_profile.h" | |
| 14 #include "content/browser/in_process_webkit/indexed_db_context.h" | |
| 15 #include "content/browser/in_process_webkit/indexed_db_quota_client.h" | |
| 16 #include "content/browser/in_process_webkit/webkit_context.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | |
| 18 #include "webkit/database/database_tracker.h" | |
|
michaeln
2011/05/26 08:40:35
needed or copy/paste artifact?
dgrogan
2011/05/26 20:56:04
Artifact, apparently; deleted.
| |
| 19 #include "webkit/database/database_util.h" | |
| 20 | |
| 21 // Declared to shorten the line lengths. | |
| 22 static const quota::StorageType kTemp = quota::kStorageTypeTemporary; | |
| 23 static const quota::StorageType kPerm = quota::kStorageTypePersistent; | |
| 24 | |
| 25 using namespace webkit_database; | |
| 26 | |
| 27 // Base class for our test fixtures. | |
| 28 class IndexedDBQuotaClientTest : public testing::Test { | |
| 29 public: | |
| 30 const GURL kOriginA; | |
| 31 const GURL kOriginB; | |
| 32 | |
| 33 IndexedDBQuotaClientTest() | |
| 34 : kOriginA("http://host"), | |
| 35 kOriginB("http://host:8000"), | |
| 36 usage_(0), | |
| 37 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | |
| 38 message_loop_(MessageLoop::TYPE_IO) { | |
| 39 TestingProfile profile; | |
| 40 idb_context_ = new IndexedDBContext(profile.GetWebKitContext(), NULL, | |
| 41 NULL, NULL); | |
|
michaeln
2011/05/26 08:40:35
indent is off
dgrogan
2011/05/26 20:56:04
Done.
| |
| 42 } | |
| 43 | |
| 44 int64 GetOriginUsage( | |
| 45 quota::QuotaClient* client, | |
| 46 const GURL& origin, | |
| 47 quota::StorageType type) { | |
| 48 usage_ = 0; | |
|
michaeln
2011/05/26 08:40:35
maybe init to -1 to ensure something happened in t
dgrogan
2011/05/26 20:56:04
Done.
| |
| 49 client->GetOriginUsage(origin, type, | |
| 50 callback_factory_.NewCallback( | |
| 51 &IndexedDBQuotaClientTest::OnGetOriginUsageComplete)); | |
| 52 MessageLoop::current()->RunAllPending(); | |
| 53 return usage_; | |
| 54 } | |
| 55 | |
| 56 IndexedDBContext* idb_context() { return idb_context_.get(); } | |
| 57 | |
| 58 void SetFileSizeTo(const FilePath& path, int size) { | |
| 59 std::string junk(size, 'a'); | |
| 60 ASSERT_EQ(size, file_util::WriteFile(path, junk.c_str(), size)); | |
| 61 } | |
| 62 | |
| 63 | |
| 64 private: | |
| 65 void OnGetOriginUsageComplete(int64 usage) { | |
| 66 usage_ = usage; | |
| 67 } | |
| 68 | |
| 69 int64 usage_; | |
| 70 scoped_refptr<IndexedDBContext> idb_context_; | |
| 71 base::ScopedCallbackFactory<IndexedDBQuotaClientTest> callback_factory_; | |
| 72 MessageLoop message_loop_; | |
| 73 }; | |
| 74 | |
| 75 | |
| 76 TEST_F(IndexedDBQuotaClientTest, GetOriginUsage) { | |
| 77 IndexedDBQuotaClient client( | |
| 78 base::MessageLoopProxy::CreateForCurrentThread(), | |
| 79 idb_context()); | |
| 80 | |
| 81 ScopedTempDir temp_dir; | |
| 82 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 83 FilePath indexeddb_dir = temp_dir.path().Append( | |
| 84 IndexedDBContext::kIndexedDBDirectory); | |
| 85 ASSERT_TRUE(file_util::CreateDirectory(indexeddb_dir)); | |
| 86 | |
| 87 idb_context()->set_data_path(indexeddb_dir); | |
| 88 FilePath file_path_origin_a = idb_context()->GetIndexedDBFilePath(DatabaseUtil ::GetOriginIdentifier(GURL("http://host/"))); | |
|
michaeln
2011/05/26 08:40:35
you can use kOriginA here and B below
dgrogan
2011/05/26 20:56:04
Done.
| |
| 89 FilePath file_path_origin_b = idb_context()->GetIndexedDBFilePath(DatabaseUtil ::GetOriginIdentifier(GURL("http://host:8000/"))); | |
|
michaeln
2011/05/26 08:40:35
nit: line lengths
dgrogan
2011/05/26 20:56:04
Done.
| |
| 90 | |
| 91 SetFileSizeTo(file_path_origin_a, 6); | |
| 92 SetFileSizeTo(file_path_origin_b, 3); | |
| 93 EXPECT_EQ(6, GetOriginUsage(&client, kOriginA, kTemp)); | |
| 94 EXPECT_EQ(0, GetOriginUsage(&client, kOriginA, kPerm)); | |
| 95 EXPECT_EQ(3, GetOriginUsage(&client, kOriginB, kTemp)); | |
| 96 EXPECT_EQ(0, GetOriginUsage(&client, kOriginB, kPerm)); | |
| 97 | |
| 98 SetFileSizeTo(file_path_origin_a, 1000); | |
| 99 EXPECT_EQ(1000, GetOriginUsage(&client, kOriginA, kTemp)); | |
| 100 EXPECT_EQ(0, GetOriginUsage(&client, kOriginA, kPerm)); | |
| 101 EXPECT_EQ(3, GetOriginUsage(&client, kOriginB, kTemp)); | |
| 102 EXPECT_EQ(0, GetOriginUsage(&client, kOriginB, kPerm)); | |
| 103 } | |
| OLD | NEW |