Commit 4eff0969 authored by Victor Costan's avatar Victor Costan Committed by Chromium LUCI CQ

Quota: Remove RunUntilIdle() usage from QuotaSettingsTest.

This CL replaces calls to base::TaskEnvironment::RunUntilIdle() with a
base::RunLoop that is Quit() when the tested function's base::Callback
is executed. A few minor cleanups are included.

Change-Id: I94488c922df13fe67bdd246c80c7f15064a1bda8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2644144
Commit-Queue: Jarryd Goodman <jarrydg@chromium.org>
Reviewed-by: default avatarJarryd Goodman <jarrydg@chromium.org>
Auto-Submit: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846287}
parent 053aa6ca
......@@ -8,6 +8,8 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/files/scoped_temp_dir.h"
#include "base/optional.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
......@@ -39,15 +41,28 @@ class QuotaSettingsTest : public testing::Test {
QuotaSettingsTest() = default;
void SetUp() override { ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); }
protected:
base::test::ScopedFeatureList scoped_feature_list_;
base::test::TaskEnvironment task_environment_;
// Synchronous proxy to GetNominalDynamicSettings().
base::Optional<QuotaSettings> GetSettings(
bool is_incognito,
QuotaDeviceInfoHelper* device_info_helper) {
base::Optional<QuotaSettings> quota_settings;
base::RunLoop run_loop;
GetNominalDynamicSettings(
profile_path(), is_incognito, device_info_helper,
base::BindLambdaForTesting([&](base::Optional<QuotaSettings> settings) {
quota_settings = std::move(settings);
run_loop.Quit();
}));
run_loop.Run();
return quota_settings;
}
const base::FilePath& profile_path() const { return data_dir_.GetPath(); }
private:
protected:
base::test::ScopedFeatureList scoped_feature_list_;
base::ScopedTempDir data_dir_;
QuotaSettings quota_settings_;
DISALLOW_COPY_AND_ASSIGN(QuotaSettingsTest);
base::test::TaskEnvironment task_environment_;
};
class QuotaSettingsIncognitoTest : public QuotaSettingsTest {
......@@ -64,24 +79,15 @@ class QuotaSettingsIncognitoTest : public QuotaSettingsTest {
}
void GetAndTestSettings(const int64_t physical_memory_amount) {
bool callback_executed = false;
GetNominalDynamicSettings(
profile_path(), true, device_info_helper(),
base::BindLambdaForTesting([&](base::Optional<QuotaSettings> settings) {
callback_executed = true;
EXPECT_LE(physical_memory_amount *
GetIncognitoQuotaRatioLowerBound_ForTesting(),
settings->pool_size);
EXPECT_GE(physical_memory_amount *
GetIncognitoQuotaRatioUpperBound_ForTesting(),
settings->pool_size);
}));
task_environment_.RunUntilIdle();
EXPECT_TRUE(callback_executed);
}
MockQuotaDeviceInfoHelper* device_info_helper() {
return &device_info_helper_;
base::Optional<QuotaSettings> settings =
GetSettings(true, &device_info_helper_);
ASSERT_TRUE(settings.has_value());
EXPECT_LE(
physical_memory_amount * GetIncognitoQuotaRatioLowerBound_ForTesting(),
settings->pool_size);
EXPECT_GE(
physical_memory_amount * GetIncognitoQuotaRatioUpperBound_ForTesting(),
settings->pool_size);
}
private:
......@@ -93,19 +99,13 @@ TEST_F(QuotaSettingsTest, Default) {
ON_CALL(device_info_helper, AmountOfTotalDiskSpace(_))
.WillByDefault(::testing::Return(2000));
bool callback_executed = false;
GetNominalDynamicSettings(
profile_path(), false, &device_info_helper,
base::BindLambdaForTesting([&](base::Optional<QuotaSettings> settings) {
callback_executed = true;
ASSERT_NE(settings, base::nullopt);
// 1600 = 2000 * default PoolSizeRatio (0.8)
EXPECT_EQ(settings->pool_size, 1600);
// 1200 = 1600 * default PerHostRatio (.75)
EXPECT_EQ(settings->per_host_quota, 1200);
}));
task_environment_.RunUntilIdle();
EXPECT_TRUE(callback_executed);
base::Optional<QuotaSettings> settings =
GetSettings(false, &device_info_helper);
ASSERT_TRUE(settings.has_value());
// 1600 = 2000 * default PoolSizeRatio (0.8)
EXPECT_EQ(settings->pool_size, 1600);
// 1200 = 1600 * default PerHostRatio (.75)
EXPECT_EQ(settings->per_host_quota, 1200);
}
TEST_F(QuotaSettingsIncognitoTest, IncognitoDynamicQuota_LowPhysicalMemory) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment