OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
5 #include <algorithm> | 8 #include <algorithm> |
6 #include <iterator> | 9 #include <iterator> |
7 #include <set> | 10 #include <set> |
8 | 11 |
9 #include "base/bind.h" | 12 #include "base/bind.h" |
10 #include "base/callback.h" | 13 #include "base/callback.h" |
11 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
12 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
| 16 #include "base/macros.h" |
13 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
14 #include "content/public/test/mock_special_storage_policy.h" | 18 #include "content/public/test/mock_special_storage_policy.h" |
15 #include "sql/connection.h" | 19 #include "sql/connection.h" |
16 #include "sql/meta_table.h" | 20 #include "sql/meta_table.h" |
17 #include "sql/statement.h" | 21 #include "sql/statement.h" |
18 #include "sql/test/scoped_error_ignorer.h" | 22 #include "sql/test/scoped_error_ignorer.h" |
19 #include "sql/test/test_helpers.h" | 23 #include "sql/test/test_helpers.h" |
20 #include "storage/browser/quota/quota_database.h" | 24 #include "storage/browser/quota/quota_database.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "url/gurl.h" | 26 #include "url/gurl.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 84 } |
81 | 85 |
82 void HostQuota(const base::FilePath& kDbFile) { | 86 void HostQuota(const base::FilePath& kDbFile) { |
83 QuotaDatabase db(kDbFile); | 87 QuotaDatabase db(kDbFile); |
84 ASSERT_TRUE(db.LazyOpen(true)); | 88 ASSERT_TRUE(db.LazyOpen(true)); |
85 | 89 |
86 const char* kHost = "foo.com"; | 90 const char* kHost = "foo.com"; |
87 const int kQuota1 = 13579; | 91 const int kQuota1 = 13579; |
88 const int kQuota2 = kQuota1 + 1024; | 92 const int kQuota2 = kQuota1 + 1024; |
89 | 93 |
90 int64 quota = -1; | 94 int64_t quota = -1; |
91 EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypeTemporary, "a)); | 95 EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypeTemporary, "a)); |
92 EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypePersistent, "a)); | 96 EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypePersistent, "a)); |
93 | 97 |
94 // Insert quota for temporary. | 98 // Insert quota for temporary. |
95 EXPECT_TRUE(db.SetHostQuota(kHost, kStorageTypeTemporary, kQuota1)); | 99 EXPECT_TRUE(db.SetHostQuota(kHost, kStorageTypeTemporary, kQuota1)); |
96 EXPECT_TRUE(db.GetHostQuota(kHost, kStorageTypeTemporary, "a)); | 100 EXPECT_TRUE(db.GetHostQuota(kHost, kStorageTypeTemporary, "a)); |
97 EXPECT_EQ(kQuota1, quota); | 101 EXPECT_EQ(kQuota1, quota); |
98 | 102 |
99 // Update quota for temporary. | 103 // Update quota for temporary. |
100 EXPECT_TRUE(db.SetHostQuota(kHost, kStorageTypeTemporary, kQuota2)); | 104 EXPECT_TRUE(db.SetHostQuota(kHost, kStorageTypeTemporary, kQuota2)); |
101 EXPECT_TRUE(db.GetHostQuota(kHost, kStorageTypeTemporary, "a)); | 105 EXPECT_TRUE(db.GetHostQuota(kHost, kStorageTypeTemporary, "a)); |
102 EXPECT_EQ(kQuota2, quota); | 106 EXPECT_EQ(kQuota2, quota); |
103 | 107 |
104 // Quota for persistent must not be updated. | 108 // Quota for persistent must not be updated. |
105 EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypePersistent, "a)); | 109 EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypePersistent, "a)); |
106 | 110 |
107 // Delete temporary storage quota. | 111 // Delete temporary storage quota. |
108 EXPECT_TRUE(db.DeleteHostQuota(kHost, kStorageTypeTemporary)); | 112 EXPECT_TRUE(db.DeleteHostQuota(kHost, kStorageTypeTemporary)); |
109 EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypeTemporary, "a)); | 113 EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypeTemporary, "a)); |
110 } | 114 } |
111 | 115 |
112 void GlobalQuota(const base::FilePath& kDbFile) { | 116 void GlobalQuota(const base::FilePath& kDbFile) { |
113 QuotaDatabase db(kDbFile); | 117 QuotaDatabase db(kDbFile); |
114 ASSERT_TRUE(db.LazyOpen(true)); | 118 ASSERT_TRUE(db.LazyOpen(true)); |
115 | 119 |
116 const char* kTempQuotaKey = QuotaDatabase::kTemporaryQuotaOverrideKey; | 120 const char* kTempQuotaKey = QuotaDatabase::kTemporaryQuotaOverrideKey; |
117 const char* kAvailSpaceKey = QuotaDatabase::kDesiredAvailableSpaceKey; | 121 const char* kAvailSpaceKey = QuotaDatabase::kDesiredAvailableSpaceKey; |
118 | 122 |
119 int64 value = 0; | 123 int64_t value = 0; |
120 const int64 kValue1 = 456; | 124 const int64_t kValue1 = 456; |
121 const int64 kValue2 = 123000; | 125 const int64_t kValue2 = 123000; |
122 EXPECT_FALSE(db.GetQuotaConfigValue(kTempQuotaKey, &value)); | 126 EXPECT_FALSE(db.GetQuotaConfigValue(kTempQuotaKey, &value)); |
123 EXPECT_FALSE(db.GetQuotaConfigValue(kAvailSpaceKey, &value)); | 127 EXPECT_FALSE(db.GetQuotaConfigValue(kAvailSpaceKey, &value)); |
124 | 128 |
125 EXPECT_TRUE(db.SetQuotaConfigValue(kTempQuotaKey, kValue1)); | 129 EXPECT_TRUE(db.SetQuotaConfigValue(kTempQuotaKey, kValue1)); |
126 EXPECT_TRUE(db.GetQuotaConfigValue(kTempQuotaKey, &value)); | 130 EXPECT_TRUE(db.GetQuotaConfigValue(kTempQuotaKey, &value)); |
127 EXPECT_EQ(kValue1, value); | 131 EXPECT_EQ(kValue1, value); |
128 | 132 |
129 EXPECT_TRUE(db.SetQuotaConfigValue(kTempQuotaKey, kValue2)); | 133 EXPECT_TRUE(db.SetQuotaConfigValue(kTempQuotaKey, kValue2)); |
130 EXPECT_TRUE(db.GetQuotaConfigValue(kTempQuotaKey, &value)); | 134 EXPECT_TRUE(db.GetQuotaConfigValue(kTempQuotaKey, &value)); |
131 EXPECT_EQ(kValue2, value); | 135 EXPECT_EQ(kValue2, value); |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName); | 689 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName); |
686 LazyOpen(kDbFile); | 690 LazyOpen(kDbFile); |
687 ASSERT_TRUE(sql::test::CorruptSizeInHeader(kDbFile)); | 691 ASSERT_TRUE(sql::test::CorruptSizeInHeader(kDbFile)); |
688 sql::ScopedErrorIgnorer ignore_errors; | 692 sql::ScopedErrorIgnorer ignore_errors; |
689 ignore_errors.IgnoreError(SQLITE_CORRUPT); | 693 ignore_errors.IgnoreError(SQLITE_CORRUPT); |
690 Reopen(kDbFile); | 694 Reopen(kDbFile); |
691 EXPECT_TRUE(ignore_errors.CheckIgnoredErrors()); | 695 EXPECT_TRUE(ignore_errors.CheckIgnoredErrors()); |
692 } | 696 } |
693 | 697 |
694 } // namespace content | 698 } // namespace content |
OLD | NEW |