0

StorageBuckets: Bad optional access tests

Tests for the 'bad optional access' crash fix.
Fix CL: https://crrev.com/c/3106032

Bug: 1241358
Change-Id: I83e5551efc1b1815c370c48aaae74a0f63d4af7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3110911
Commit-Queue: Ayu Ishii <ayui@chromium.org>
Reviewed-by: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/main@{#913948}
This commit is contained in:
Ayu Ishii
2021-08-20 20:13:56 +00:00
committed by Chromium LUCI CQ
parent 92965bc0bc
commit 2f1d0e5476
2 changed files with 34 additions and 0 deletions

@ -193,6 +193,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaDatabase {
bool IsBootstrappedForEviction();
bool SetBootstrappedForEviction(bool bootstrap_flag);
// Manually disable database to test database error scenarios for testing.
void SetDisabledForTesting(bool disable) { is_disabled_ = disable; }
private:
struct COMPONENT_EXPORT(STORAGE_BROWSER) QuotaTableEntry {
std::string host;

@ -147,6 +147,8 @@ class QuotaManagerImplTest : public testing::Test {
return mock_quota_client_ptr;
}
void OpenDatabase() { quota_manager_impl_->EnsureDatabaseOpened(); }
void GetOrCreateBucket(const StorageKey& storage_key,
const std::string& bucket_name) {
base::RunLoop run_loop;
@ -572,6 +574,10 @@ class QuotaManagerImplTest : public testing::Test {
bool is_db_disabled() { return quota_manager_impl_->db_disabled_; }
void disable_quota_database(bool disable) {
quota_manager_impl_->database_->SetDisabledForTesting(disable);
}
QuotaStatusCode status() const { return quota_status_; }
const UsageInfoEntries& usage_info() const { return usage_info_; }
int64_t usage() const { return usage_; }
@ -731,6 +737,17 @@ TEST_F(QuotaManagerImplTest, GetStorageKeysForType) {
testing::UnorderedElementsAre(storage_key_c));
}
TEST_F(QuotaManagerImplTest, GetStorageKeysForTypeWithDatabaseError) {
OpenDatabase();
// Disable quota database for database error behavior.
disable_quota_database(true);
// Return empty set when error is encountered.
GetStorageKeysForType(kTemp);
EXPECT_TRUE(storage_keys_.value().empty());
}
TEST_F(QuotaManagerImplTest, GetUsageAndQuota_Simple) {
static const MockStorageKeyData kData[] = {
{"http://foo.com/", kTemp, 10},
@ -2854,6 +2871,20 @@ TEST_F(QuotaManagerImplTest, GetBucketsModifiedBetween) {
EXPECT_EQ(modified_buckets_type(), kTemp);
}
TEST_F(QuotaManagerImplTest, GetBucketsModifiedBetweenWithDatabaseError) {
OpenDatabase();
// Disable quota database for database error behavior.
disable_quota_database(true);
GetBucketsModifiedBetween(kTemp, base::Time(), base::Time::Max());
task_environment_.RunUntilIdle();
// Return empty set when error is encountered.
EXPECT_TRUE(modified_buckets().empty());
EXPECT_EQ(modified_buckets_type(), kTemp);
}
TEST_F(QuotaManagerImplTest, DumpQuotaTable) {
SetPersistentHostQuota("example1.com", 1);
SetPersistentHostQuota("example2.com", 20);