[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 4d99be5 | 2011-10-18 14:11:03 | [diff] [blame] | 5 | #include "base/bind.h" |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 6 | #include "base/basictypes.h" |
| 7 | #include "base/file_util.h" |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 8 | #include "base/message_loop.h" |
| 9 | #include "base/message_loop_proxy.h" |
| 10 | #include "base/platform_file.h" |
[email protected] | e078590 | 2011-05-19 23:34:17 | [diff] [blame] | 11 | #include "base/scoped_temp_dir.h" |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 12 | #include "googleurl/src/gurl.h" |
| 13 | #include "testing/gtest/include/gtest/gtest.h" |
| 14 | #include "webkit/fileapi/file_system_context.h" |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 15 | #include "webkit/fileapi/file_system_operation_context.h" |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 16 | #include "webkit/fileapi/file_system_quota_client.h" |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 17 | #include "webkit/fileapi/file_system_types.h" |
| 18 | #include "webkit/fileapi/file_system_usage_cache.h" |
| 19 | #include "webkit/fileapi/file_system_util.h" |
[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 20 | #include "webkit/fileapi/mock_file_system_options.h" |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 21 | #include "webkit/fileapi/obfuscated_file_util.h" |
[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 22 | #include "webkit/fileapi/sandbox_mount_point_provider.h" |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 23 | #include "webkit/quota/quota_types.h" |
| 24 | |
[email protected] | 4ce4e79d | 2011-05-13 16:27:15 | [diff] [blame] | 25 | namespace fileapi { |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 26 | namespace { |
[email protected] | 4ce4e79d | 2011-05-13 16:27:15 | [diff] [blame] | 27 | |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 28 | const char kDummyURL1[] = "http://www.dummy.org"; |
| 29 | const char kDummyURL2[] = "http://www.example.com"; |
| 30 | const char kDummyURL3[] = "http://www.bleh"; |
| 31 | |
| 32 | // Declared to shorten the variable names. |
| 33 | const quota::StorageType kTemporary = quota::kStorageTypeTemporary; |
| 34 | const quota::StorageType kPersistent = quota::kStorageTypePersistent; |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 35 | |
[email protected] | 4ce4e79d | 2011-05-13 16:27:15 | [diff] [blame] | 36 | } // namespace |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 37 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 38 | class FileSystemQuotaClientTest : public testing::Test { |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 39 | public: |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 40 | FileSystemQuotaClientTest() |
[email protected] | 4d99be5 | 2011-10-18 14:11:03 | [diff] [blame] | 41 | : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
[email protected] | 4b66b65 | 2011-05-17 03:31:31 | [diff] [blame] | 42 | additional_callback_count_(0), |
| 43 | deletion_status_(quota::kQuotaStatusUnknown) { |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void SetUp() { |
| 47 | ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| 48 | file_system_context_ = |
| 49 | new FileSystemContext( |
[email protected] | edd685f | 2011-08-15 20:33:46 | [diff] [blame] | 50 | base::MessageLoopProxy::current(), |
| 51 | base::MessageLoopProxy::current(), |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 52 | NULL, NULL, |
[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 53 | data_dir_.path(), |
| 54 | CreateDisallowFileAccessOptions()); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | struct TestFile { |
| 58 | bool isDirectory; |
| 59 | const char* name; |
| 60 | int64 size; |
| 61 | const char* origin_url; |
| 62 | quota::StorageType type; |
| 63 | }; |
| 64 | |
| 65 | protected: |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 66 | FileSystemQuotaClient* NewQuotaClient(bool is_incognito) { |
| 67 | return new FileSystemQuotaClient( |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 68 | file_system_context_, is_incognito); |
| 69 | } |
| 70 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 71 | void GetOriginUsageAsync(FileSystemQuotaClient* quota_client, |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 72 | const std::string& origin_url, |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 73 | quota::StorageType type) { |
[email protected] | 4d99be5 | 2011-10-18 14:11:03 | [diff] [blame] | 74 | quota_client->GetOriginUsage( |
| 75 | GURL(origin_url), type, |
| 76 | base::Bind(&FileSystemQuotaClientTest::OnGetUsage, |
| 77 | weak_factory_.GetWeakPtr())); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 78 | } |
| 79 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 80 | int64 GetOriginUsage(FileSystemQuotaClient* quota_client, |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 81 | const std::string& origin_url, |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 82 | quota::StorageType type) { |
| 83 | GetOriginUsageAsync(quota_client, origin_url, type); |
| 84 | MessageLoop::current()->RunAllPending(); |
| 85 | return usage_; |
| 86 | } |
| 87 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 88 | const std::set<GURL>& GetOriginsForType(FileSystemQuotaClient* quota_client, |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 89 | quota::StorageType type) { |
| 90 | origins_.clear(); |
[email protected] | 4d99be5 | 2011-10-18 14:11:03 | [diff] [blame] | 91 | quota_client->GetOriginsForType( |
| 92 | type, |
| 93 | base::Bind(&FileSystemQuotaClientTest::OnGetOrigins, |
| 94 | weak_factory_.GetWeakPtr())); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 95 | MessageLoop::current()->RunAllPending(); |
| 96 | return origins_; |
| 97 | } |
| 98 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 99 | const std::set<GURL>& GetOriginsForHost(FileSystemQuotaClient* quota_client, |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 100 | quota::StorageType type, |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 101 | const std::string& host) { |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 102 | origins_.clear(); |
[email protected] | 4d99be5 | 2011-10-18 14:11:03 | [diff] [blame] | 103 | quota_client->GetOriginsForHost( |
| 104 | type, host, |
| 105 | base::Bind(&FileSystemQuotaClientTest::OnGetOrigins, |
| 106 | weak_factory_.GetWeakPtr())); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 107 | MessageLoop::current()->RunAllPending(); |
| 108 | return origins_; |
| 109 | } |
| 110 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 111 | void RunAdditionalOriginUsageTask(FileSystemQuotaClient* quota_client, |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 112 | const std::string& origin_url, |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 113 | quota::StorageType type) { |
[email protected] | 4d99be5 | 2011-10-18 14:11:03 | [diff] [blame] | 114 | quota_client->GetOriginUsage( |
| 115 | GURL(origin_url), type, |
| 116 | base::Bind(&FileSystemQuotaClientTest::OnGetAdditionalUsage, |
| 117 | weak_factory_.GetWeakPtr())); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 118 | } |
| 119 | |
[email protected] | 08f8feb | 2012-02-26 11:53:50 | [diff] [blame] | 120 | FileSystemOperationContext* CreateFileSystemOperationContext() { |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 121 | FileSystemOperationContext* context = |
[email protected] | 08f8feb | 2012-02-26 11:53:50 | [diff] [blame] | 122 | new FileSystemOperationContext(file_system_context_); |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 123 | context->set_allowed_bytes_growth(100000000); |
| 124 | return context; |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 125 | } |
| 126 | |
[email protected] | 08f8feb | 2012-02-26 11:53:50 | [diff] [blame] | 127 | bool CreateFileSystemDirectory(const FilePath& file_path, |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 128 | const std::string& origin_url, |
[email protected] | 08f8feb | 2012-02-26 11:53:50 | [diff] [blame] | 129 | quota::StorageType storage_type) { |
| 130 | FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
| 131 | FileSystemFileUtil* file_util = file_system_context_->GetFileUtil(type); |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 132 | |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 133 | FileSystemURL url(GURL(origin_url), type, file_path); |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 134 | scoped_ptr<FileSystemOperationContext> context( |
[email protected] | 08f8feb | 2012-02-26 11:53:50 | [diff] [blame] | 135 | CreateFileSystemOperationContext()); |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 136 | |
| 137 | base::PlatformFileError result = |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 138 | file_util->CreateDirectory(context.get(), url, false, false); |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 139 | if (result != base::PLATFORM_FILE_OK) |
| 140 | return false; |
| 141 | return true; |
| 142 | } |
| 143 | |
[email protected] | 08f8feb | 2012-02-26 11:53:50 | [diff] [blame] | 144 | bool CreateFileSystemFile(const FilePath& file_path, |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 145 | int64 file_size, |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 146 | const std::string& origin_url, |
[email protected] | 08f8feb | 2012-02-26 11:53:50 | [diff] [blame] | 147 | quota::StorageType storage_type) { |
| 148 | if (file_path.empty()) |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 149 | return false; |
| 150 | |
[email protected] | 08f8feb | 2012-02-26 11:53:50 | [diff] [blame] | 151 | FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 152 | FileSystemFileUtil* file_util = file_system_context_-> |
| 153 | sandbox_provider()->GetFileUtil(type); |
| 154 | |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 155 | FileSystemURL url(GURL(origin_url), type, file_path); |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 156 | scoped_ptr<FileSystemOperationContext> context( |
[email protected] | 08f8feb | 2012-02-26 11:53:50 | [diff] [blame] | 157 | CreateFileSystemOperationContext()); |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 158 | |
| 159 | bool created = false; |
| 160 | if (base::PLATFORM_FILE_OK != |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 161 | file_util->EnsureFileExists(context.get(), url, &created)) |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 162 | return false; |
| 163 | EXPECT_TRUE(created); |
| 164 | if (base::PLATFORM_FILE_OK != |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 165 | file_util->Truncate(context.get(), url, file_size)) |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 166 | return false; |
| 167 | return true; |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 168 | } |
| 169 | |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 170 | void InitializeOriginFiles(FileSystemQuotaClient* quota_client, |
| 171 | const TestFile* files, |
| 172 | int num_files) { |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 173 | for (int i = 0; i < num_files; i++) { |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 174 | FilePath path = FilePath().AppendASCII(files[i].name); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 175 | if (files[i].isDirectory) { |
| 176 | ASSERT_TRUE(CreateFileSystemDirectory( |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 177 | path, files[i].origin_url, files[i].type)); |
| 178 | if (path.empty()) { |
| 179 | // Create the usage cache. |
[email protected] | 0c5ebe3 | 2011-08-19 22:37:16 | [diff] [blame] | 180 | // HACK--we always create the root [an empty path] first. If we |
| 181 | // create it later, this will fail due to a quota mismatch. If we |
| 182 | // call this before we create the root, it succeeds, but hasn't |
| 183 | // actually created the cache. |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 184 | ASSERT_EQ(0, GetOriginUsage( |
| 185 | quota_client, files[i].origin_url, files[i].type)); |
| 186 | } |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 187 | } else { |
| 188 | ASSERT_TRUE(CreateFileSystemFile( |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 189 | path, files[i].size, files[i].origin_url, files[i].type)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
[email protected] | 0c5ebe3 | 2011-08-19 22:37:16 | [diff] [blame] | 194 | // This is a bit fragile--it depends on the test data always creating a |
| 195 | // directory before adding a file or directory to it, so that we can just |
| 196 | // count the basename of each addition. A recursive creation of a path, which |
| 197 | // created more than one directory in a single shot, would break this. |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 198 | int64 ComputeFilePathsCostForOriginAndType(const TestFile* files, |
| 199 | int num_files, |
| 200 | const std::string& origin_url, |
| 201 | quota::StorageType type) { |
| 202 | int64 file_paths_cost = 0; |
| 203 | for (int i = 0; i < num_files; i++) { |
| 204 | if (files[i].type == type && |
| 205 | GURL(files[i].origin_url) == GURL(origin_url)) { |
| 206 | FilePath path = FilePath().AppendASCII(files[i].name); |
| 207 | if (!path.empty()) { |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 208 | file_paths_cost += ObfuscatedFileUtil::ComputeFilePathCost(path); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | } |
| 212 | return file_paths_cost; |
| 213 | } |
| 214 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 215 | void DeleteOriginData(FileSystemQuotaClient* quota_client, |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 216 | const std::string& origin, |
[email protected] | 4b66b65 | 2011-05-17 03:31:31 | [diff] [blame] | 217 | quota::StorageType type) { |
| 218 | deletion_status_ = quota::kQuotaStatusUnknown; |
| 219 | quota_client->DeleteOriginData( |
| 220 | GURL(origin), type, |
[email protected] | 4d99be5 | 2011-10-18 14:11:03 | [diff] [blame] | 221 | base::Bind(&FileSystemQuotaClientTest::OnDeleteOrigin, |
| 222 | weak_factory_.GetWeakPtr())); |
[email protected] | 4b66b65 | 2011-05-17 03:31:31 | [diff] [blame] | 223 | } |
| 224 | |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 225 | int64 usage() const { return usage_; } |
[email protected] | 4b66b65 | 2011-05-17 03:31:31 | [diff] [blame] | 226 | quota::QuotaStatusCode status() { return deletion_status_; } |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 227 | int additional_callback_count() const { return additional_callback_count_; } |
| 228 | void set_additional_callback_count(int count) { |
| 229 | additional_callback_count_ = count; |
| 230 | } |
| 231 | |
| 232 | private: |
| 233 | void OnGetUsage(int64 usage) { |
| 234 | usage_ = usage; |
| 235 | } |
| 236 | |
[email protected] | 4ac23ad2 | 2011-08-05 08:39:54 | [diff] [blame] | 237 | void OnGetOrigins(const std::set<GURL>& origins, |
| 238 | quota::StorageType type) { |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 239 | origins_ = origins; |
[email protected] | 4ac23ad2 | 2011-08-05 08:39:54 | [diff] [blame] | 240 | type_ = type; |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 241 | } |
| 242 | |
[email protected] | 4b66b65 | 2011-05-17 03:31:31 | [diff] [blame] | 243 | void OnGetAdditionalUsage(int64 usage_unused) { |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 244 | ++additional_callback_count_; |
| 245 | } |
| 246 | |
[email protected] | 4b66b65 | 2011-05-17 03:31:31 | [diff] [blame] | 247 | void OnDeleteOrigin(quota::QuotaStatusCode status) { |
| 248 | deletion_status_ = status; |
| 249 | } |
| 250 | |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 251 | ScopedTempDir data_dir_; |
[email protected] | 3ed847a6 | 2012-06-07 01:20:01 | [diff] [blame] | 252 | MessageLoop message_loop_; |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 253 | scoped_refptr<FileSystemContext> file_system_context_; |
[email protected] | 4d99be5 | 2011-10-18 14:11:03 | [diff] [blame] | 254 | base::WeakPtrFactory<FileSystemQuotaClientTest> weak_factory_; |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 255 | int64 usage_; |
| 256 | int additional_callback_count_; |
| 257 | std::set<GURL> origins_; |
[email protected] | 4ac23ad2 | 2011-08-05 08:39:54 | [diff] [blame] | 258 | quota::StorageType type_; |
[email protected] | 4b66b65 | 2011-05-17 03:31:31 | [diff] [blame] | 259 | quota::QuotaStatusCode deletion_status_; |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 260 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 261 | DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaClientTest); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 262 | }; |
| 263 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 264 | TEST_F(FileSystemQuotaClientTest, NoFileSystemTest) { |
| 265 | scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 266 | |
| 267 | EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
| 268 | } |
| 269 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 270 | TEST_F(FileSystemQuotaClientTest, NoFileTest) { |
| 271 | scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 272 | const TestFile kFiles[] = { |
| 273 | {true, NULL, 0, kDummyURL1, kTemporary}, |
| 274 | }; |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 275 | InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 276 | |
| 277 | for (int i = 0; i < 2; i++) { |
[email protected] | 0c5ebe3 | 2011-08-19 22:37:16 | [diff] [blame] | 278 | EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 282 | TEST_F(FileSystemQuotaClientTest, OneFileTest) { |
| 283 | scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 284 | const TestFile kFiles[] = { |
| 285 | {true, NULL, 0, kDummyURL1, kTemporary}, |
| 286 | {false, "foo", 4921, kDummyURL1, kTemporary}, |
| 287 | }; |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 288 | InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles)); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 289 | const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType( |
| 290 | kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 291 | |
| 292 | for (int i = 0; i < 2; i++) { |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 293 | EXPECT_EQ(4921 + file_paths_cost, |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 294 | GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
| 295 | } |
| 296 | } |
| 297 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 298 | TEST_F(FileSystemQuotaClientTest, TwoFilesTest) { |
| 299 | scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 300 | const TestFile kFiles[] = { |
| 301 | {true, NULL, 0, kDummyURL1, kTemporary}, |
| 302 | {false, "foo", 10310, kDummyURL1, kTemporary}, |
| 303 | {false, "bar", 41, kDummyURL1, kTemporary}, |
| 304 | }; |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 305 | InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles)); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 306 | const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType( |
| 307 | kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 308 | |
| 309 | for (int i = 0; i < 2; i++) { |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 310 | EXPECT_EQ(10310 + 41 + file_paths_cost, |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 311 | GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
| 312 | } |
| 313 | } |
| 314 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 315 | TEST_F(FileSystemQuotaClientTest, EmptyFilesTest) { |
| 316 | scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 317 | const TestFile kFiles[] = { |
| 318 | {true, NULL, 0, kDummyURL1, kTemporary}, |
| 319 | {false, "foo", 0, kDummyURL1, kTemporary}, |
| 320 | {false, "bar", 0, kDummyURL1, kTemporary}, |
| 321 | {false, "baz", 0, kDummyURL1, kTemporary}, |
| 322 | }; |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 323 | InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles)); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 324 | const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType( |
| 325 | kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 326 | |
| 327 | for (int i = 0; i < 2; i++) { |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 328 | EXPECT_EQ(file_paths_cost, |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 329 | GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
| 330 | } |
| 331 | } |
| 332 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 333 | TEST_F(FileSystemQuotaClientTest, SubDirectoryTest) { |
| 334 | scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 335 | const TestFile kFiles[] = { |
| 336 | {true, NULL, 0, kDummyURL1, kTemporary}, |
| 337 | {true, "dirtest", 0, kDummyURL1, kTemporary}, |
| 338 | {false, "dirtest/foo", 11921, kDummyURL1, kTemporary}, |
| 339 | {false, "bar", 4814, kDummyURL1, kTemporary}, |
| 340 | }; |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 341 | InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles)); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 342 | const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType( |
| 343 | kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 344 | |
| 345 | for (int i = 0; i < 2; i++) { |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 346 | EXPECT_EQ(11921 + 4814 + file_paths_cost, |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 347 | GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
| 348 | } |
| 349 | } |
| 350 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 351 | TEST_F(FileSystemQuotaClientTest, MultiTypeTest) { |
| 352 | scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 353 | const TestFile kFiles[] = { |
| 354 | {true, NULL, 0, kDummyURL1, kTemporary}, |
| 355 | {true, "dirtest", 0, kDummyURL1, kTemporary}, |
| 356 | {false, "dirtest/foo", 133, kDummyURL1, kTemporary}, |
| 357 | {false, "bar", 14, kDummyURL1, kTemporary}, |
| 358 | {true, NULL, 0, kDummyURL1, kPersistent}, |
| 359 | {true, "dirtest", 0, kDummyURL1, kPersistent}, |
| 360 | {false, "dirtest/foo", 193, kDummyURL1, kPersistent}, |
| 361 | {false, "bar", 9, kDummyURL1, kPersistent}, |
| 362 | }; |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 363 | InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles)); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 364 | const int64 file_paths_cost_temporary = ComputeFilePathsCostForOriginAndType( |
| 365 | kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary); |
| 366 | const int64 file_paths_cost_persistent = ComputeFilePathsCostForOriginAndType( |
| 367 | kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 368 | |
| 369 | for (int i = 0; i < 2; i++) { |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 370 | EXPECT_EQ(133 + 14 + file_paths_cost_temporary, |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 371 | GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 372 | EXPECT_EQ(193 + 9 + file_paths_cost_persistent, |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 373 | GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent)); |
| 374 | } |
| 375 | } |
| 376 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 377 | TEST_F(FileSystemQuotaClientTest, MultiDomainTest) { |
| 378 | scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 379 | const TestFile kFiles[] = { |
| 380 | {true, NULL, 0, kDummyURL1, kTemporary}, |
| 381 | {true, "dir1", 0, kDummyURL1, kTemporary}, |
| 382 | {false, "dir1/foo", 1331, kDummyURL1, kTemporary}, |
| 383 | {false, "bar", 134, kDummyURL1, kTemporary}, |
| 384 | {true, NULL, 0, kDummyURL1, kPersistent}, |
| 385 | {true, "dir2", 0, kDummyURL1, kPersistent}, |
| 386 | {false, "dir2/foo", 1903, kDummyURL1, kPersistent}, |
| 387 | {false, "bar", 19, kDummyURL1, kPersistent}, |
| 388 | {true, NULL, 0, kDummyURL2, kTemporary}, |
| 389 | {true, "dom", 0, kDummyURL2, kTemporary}, |
| 390 | {false, "dom/fan", 1319, kDummyURL2, kTemporary}, |
| 391 | {false, "bar", 113, kDummyURL2, kTemporary}, |
| 392 | {true, NULL, 0, kDummyURL2, kPersistent}, |
| 393 | {true, "dom", 0, kDummyURL2, kPersistent}, |
| 394 | {false, "dom/fan", 2013, kDummyURL2, kPersistent}, |
| 395 | {false, "baz", 18, kDummyURL2, kPersistent}, |
| 396 | }; |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 397 | InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles)); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 398 | const int64 file_paths_cost_temporary1 = ComputeFilePathsCostForOriginAndType( |
| 399 | kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary); |
| 400 | const int64 file_paths_cost_persistent1 = |
| 401 | ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles), |
| 402 | kDummyURL1, kPersistent); |
| 403 | const int64 file_paths_cost_temporary2 = ComputeFilePathsCostForOriginAndType( |
| 404 | kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL2, kTemporary); |
| 405 | const int64 file_paths_cost_persistent2 = |
| 406 | ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles), |
| 407 | kDummyURL2, kPersistent); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 408 | |
| 409 | for (int i = 0; i < 2; i++) { |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 410 | EXPECT_EQ(1331 + 134 + file_paths_cost_temporary1, |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 411 | GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 412 | EXPECT_EQ(1903 + 19 + file_paths_cost_persistent1, |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 413 | GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent)); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 414 | EXPECT_EQ(1319 + 113 + file_paths_cost_temporary2, |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 415 | GetOriginUsage(quota_client.get(), kDummyURL2, kTemporary)); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 416 | EXPECT_EQ(2013 + 18 + file_paths_cost_persistent2, |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 417 | GetOriginUsage(quota_client.get(), kDummyURL2, kPersistent)); |
| 418 | } |
| 419 | } |
| 420 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 421 | TEST_F(FileSystemQuotaClientTest, GetUsage_MultipleTasks) { |
| 422 | scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 423 | const TestFile kFiles[] = { |
| 424 | {true, NULL, 0, kDummyURL1, kTemporary}, |
| 425 | {false, "foo", 11, kDummyURL1, kTemporary}, |
| 426 | {false, "bar", 22, kDummyURL1, kTemporary}, |
| 427 | }; |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 428 | InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles)); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 429 | const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType( |
| 430 | kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 431 | |
| 432 | // Dispatching three GetUsage tasks. |
| 433 | set_additional_callback_count(0); |
| 434 | GetOriginUsageAsync(quota_client.get(), kDummyURL1, kTemporary); |
| 435 | RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary); |
| 436 | RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary); |
| 437 | MessageLoop::current()->RunAllPending(); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 438 | EXPECT_EQ(11 + 22 + file_paths_cost, usage()); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 439 | EXPECT_EQ(2, additional_callback_count()); |
| 440 | |
| 441 | // Once more, in a different order. |
| 442 | set_additional_callback_count(0); |
| 443 | RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary); |
| 444 | GetOriginUsageAsync(quota_client.get(), kDummyURL1, kTemporary); |
| 445 | RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary); |
| 446 | MessageLoop::current()->RunAllPending(); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 447 | EXPECT_EQ(11 + 22 + file_paths_cost, usage()); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 448 | EXPECT_EQ(2, additional_callback_count()); |
| 449 | } |
| 450 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 451 | TEST_F(FileSystemQuotaClientTest, GetOriginsForType) { |
| 452 | scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 453 | const TestFile kFiles[] = { |
| 454 | {true, NULL, 0, kDummyURL1, kTemporary}, |
| 455 | {true, NULL, 0, kDummyURL2, kTemporary}, |
| 456 | {true, NULL, 0, kDummyURL3, kPersistent}, |
| 457 | }; |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 458 | InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 459 | |
| 460 | std::set<GURL> origins = GetOriginsForType(quota_client.get(), kTemporary); |
| 461 | EXPECT_EQ(2U, origins.size()); |
| 462 | EXPECT_TRUE(origins.find(GURL(kDummyURL1)) != origins.end()); |
| 463 | EXPECT_TRUE(origins.find(GURL(kDummyURL2)) != origins.end()); |
| 464 | EXPECT_TRUE(origins.find(GURL(kDummyURL3)) == origins.end()); |
| 465 | } |
| 466 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 467 | TEST_F(FileSystemQuotaClientTest, GetOriginsForHost) { |
| 468 | scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 469 | const char* kURL1 = "http://foo.com/"; |
| 470 | const char* kURL2 = "https://foo.com/"; |
| 471 | const char* kURL3 = "http://foo.com:1/"; |
| 472 | const char* kURL4 = "http://foo2.com/"; |
| 473 | const char* kURL5 = "http://foo.com:2/"; |
| 474 | const TestFile kFiles[] = { |
| 475 | {true, NULL, 0, kURL1, kTemporary}, |
| 476 | {true, NULL, 0, kURL2, kTemporary}, |
| 477 | {true, NULL, 0, kURL3, kTemporary}, |
| 478 | {true, NULL, 0, kURL4, kTemporary}, |
| 479 | {true, NULL, 0, kURL5, kPersistent}, |
| 480 | }; |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 481 | InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 482 | |
| 483 | std::set<GURL> origins = GetOriginsForHost( |
| 484 | quota_client.get(), kTemporary, "foo.com"); |
| 485 | EXPECT_EQ(3U, origins.size()); |
| 486 | EXPECT_TRUE(origins.find(GURL(kURL1)) != origins.end()); |
| 487 | EXPECT_TRUE(origins.find(GURL(kURL2)) != origins.end()); |
| 488 | EXPECT_TRUE(origins.find(GURL(kURL3)) != origins.end()); |
| 489 | EXPECT_TRUE(origins.find(GURL(kURL4)) == origins.end()); // Different host. |
| 490 | EXPECT_TRUE(origins.find(GURL(kURL5)) == origins.end()); // Different type. |
| 491 | } |
| 492 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 493 | TEST_F(FileSystemQuotaClientTest, IncognitoTest) { |
| 494 | scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(true)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 495 | const TestFile kFiles[] = { |
| 496 | {true, NULL, 0, kDummyURL1, kTemporary}, |
| 497 | {false, "foo", 10, kDummyURL1, kTemporary}, |
| 498 | }; |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 499 | InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles)); |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 500 | |
| 501 | // Having files in the usual directory wouldn't affect the result |
| 502 | // queried in incognito mode. |
| 503 | EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
| 504 | EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent)); |
| 505 | |
| 506 | std::set<GURL> origins = GetOriginsForType(quota_client.get(), kTemporary); |
| 507 | EXPECT_EQ(0U, origins.size()); |
| 508 | origins = GetOriginsForHost(quota_client.get(), kTemporary, "www.dummy.org"); |
| 509 | EXPECT_EQ(0U, origins.size()); |
| 510 | } |
[email protected] | 4ce4e79d | 2011-05-13 16:27:15 | [diff] [blame] | 511 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 512 | TEST_F(FileSystemQuotaClientTest, DeleteOriginTest) { |
| 513 | scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
[email protected] | 4b66b65 | 2011-05-17 03:31:31 | [diff] [blame] | 514 | const TestFile kFiles[] = { |
| 515 | {true, NULL, 0, "http://foo.com/", kTemporary}, |
| 516 | {false, "a", 1, "http://foo.com/", kTemporary}, |
| 517 | {true, NULL, 0, "https://foo.com/", kTemporary}, |
| 518 | {false, "b", 2, "https://foo.com/", kTemporary}, |
| 519 | {true, NULL, 0, "http://foo.com/", kPersistent}, |
| 520 | {false, "c", 4, "http://foo.com/", kPersistent}, |
| 521 | {true, NULL, 0, "http://bar.com/", kTemporary}, |
| 522 | {false, "d", 8, "http://bar.com/", kTemporary}, |
| 523 | {true, NULL, 0, "http://bar.com/", kPersistent}, |
| 524 | {false, "e", 16, "http://bar.com/", kPersistent}, |
| 525 | {true, NULL, 0, "https://bar.com/", kPersistent}, |
| 526 | {false, "f", 32, "https://bar.com/", kPersistent}, |
| 527 | {true, NULL, 0, "https://bar.com/", kTemporary}, |
| 528 | {false, "g", 64, "https://bar.com/", kTemporary}, |
| 529 | }; |
[email protected] | 6ff1705 | 2011-07-12 06:06:07 | [diff] [blame] | 530 | InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles)); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 531 | const int64 file_paths_cost_temporary_foo_https = |
| 532 | ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles), |
| 533 | "https://foo.com/", kTemporary); |
| 534 | const int64 file_paths_cost_persistent_foo = |
| 535 | ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles), |
| 536 | "http://foo.com/", kPersistent); |
| 537 | const int64 file_paths_cost_temporary_bar = |
| 538 | ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles), |
| 539 | "http://bar.com/", kTemporary); |
| 540 | const int64 file_paths_cost_temporary_bar_https = |
| 541 | ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles), |
| 542 | "https://bar.com/", kTemporary); |
| 543 | const int64 file_paths_cost_persistent_bar_https = |
| 544 | ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles), |
| 545 | "https://bar.com/", kPersistent); |
[email protected] | 4b66b65 | 2011-05-17 03:31:31 | [diff] [blame] | 546 | |
| 547 | DeleteOriginData(quota_client.get(), "http://foo.com/", kTemporary); |
| 548 | MessageLoop::current()->RunAllPending(); |
| 549 | EXPECT_EQ(quota::kQuotaStatusOk, status()); |
| 550 | |
| 551 | DeleteOriginData(quota_client.get(), "http://bar.com/", kPersistent); |
| 552 | MessageLoop::current()->RunAllPending(); |
| 553 | EXPECT_EQ(quota::kQuotaStatusOk, status()); |
| 554 | |
| 555 | DeleteOriginData(quota_client.get(), "http://buz.com/", kTemporary); |
| 556 | MessageLoop::current()->RunAllPending(); |
| 557 | EXPECT_EQ(quota::kQuotaStatusOk, status()); |
| 558 | |
| 559 | EXPECT_EQ(0, GetOriginUsage( |
| 560 | quota_client.get(), "http://foo.com/", kTemporary)); |
| 561 | EXPECT_EQ(0, GetOriginUsage( |
| 562 | quota_client.get(), "http://bar.com/", kPersistent)); |
| 563 | EXPECT_EQ(0, GetOriginUsage( |
| 564 | quota_client.get(), "http://buz.com/", kTemporary)); |
| 565 | |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 566 | EXPECT_EQ(2 + file_paths_cost_temporary_foo_https, |
[email protected] | 4b66b65 | 2011-05-17 03:31:31 | [diff] [blame] | 567 | GetOriginUsage(quota_client.get(), |
| 568 | "https://foo.com/", |
| 569 | kTemporary)); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 570 | EXPECT_EQ(4 + file_paths_cost_persistent_foo, |
[email protected] | 4b66b65 | 2011-05-17 03:31:31 | [diff] [blame] | 571 | GetOriginUsage(quota_client.get(), |
| 572 | "http://foo.com/", |
| 573 | kPersistent)); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 574 | EXPECT_EQ(8 + file_paths_cost_temporary_bar, |
[email protected] | 4b66b65 | 2011-05-17 03:31:31 | [diff] [blame] | 575 | GetOriginUsage(quota_client.get(), |
| 576 | "http://bar.com/", |
| 577 | kTemporary)); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 578 | EXPECT_EQ(32 + file_paths_cost_persistent_bar_https, |
[email protected] | 4b66b65 | 2011-05-17 03:31:31 | [diff] [blame] | 579 | GetOriginUsage(quota_client.get(), |
| 580 | "https://bar.com/", |
| 581 | kPersistent)); |
[email protected] | ffac1ac4 | 2011-07-25 15:03:15 | [diff] [blame] | 582 | EXPECT_EQ(64 + file_paths_cost_temporary_bar_https, |
[email protected] | 4b66b65 | 2011-05-17 03:31:31 | [diff] [blame] | 583 | GetOriginUsage(quota_client.get(), |
| 584 | "https://bar.com/", |
| 585 | kTemporary)); |
| 586 | } |
| 587 | |
[email protected] | 4ce4e79d | 2011-05-13 16:27:15 | [diff] [blame] | 588 | } // namespace fileapi |