Commit 367ea86a authored by Jarryd's avatar Jarryd Committed by Commit Bot

Quota: Make settings test more robust.

Change the QuotaSettings tests to better cover the incognito quota
experiment, as described by pwnall@ in https://crrev.com/c/1895074/4/

Bug: 1017120
Change-Id: Idd55ca10f1215908a80e98bdedce48d137100244
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1913172Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Commit-Queue: Jarryd Goodman <jarrydg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718942}
parent 48a096b8
......@@ -18,6 +18,21 @@
using ::testing::_;
namespace {
constexpr int64_t kMBytes = 1024 * 1024;
// 10% is the non-experimental incognito pool size ratio
// as defined in storage/browser/quota/quota_settings.cc line 37.
constexpr double kIncognitoPoolSizeRatio = 0.1;
// 300 MB + 10% is the max incognito pool size as set in
// storage/browser/quota/quota_settings.cc line 48.
constexpr int64_t kMaxIncognitoPoolSize =
(300 + 300 * kIncognitoPoolSizeRatio) * kMBytes;
} // namespace
namespace storage {
class MockQuotaDeviceInfoHelper : public QuotaDeviceInfoHelper {
......@@ -43,6 +58,68 @@ class QuotaSettingsTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(QuotaSettingsTest);
};
class QuotaSettingsIncognitoTest : public QuotaSettingsTest {
public:
QuotaSettingsIncognitoTest() = default;
protected:
void SetUpDeviceInfoHelper(const int expected_calls,
const int64_t physical_memory_amount) {
ON_CALL(device_info_helper_, AmountOfPhysicalMemory())
.WillByDefault(::testing::Return(physical_memory_amount));
EXPECT_CALL(device_info_helper_, AmountOfPhysicalMemory())
.Times(expected_calls);
}
void EnableFeature() {
scoped_feature_list_.Reset();
scoped_feature_list_.InitAndEnableFeatureWithParameters(
features::kIncognitoDynamicQuota,
{{"IncognitoQuotaRatioLowerBound", ratio_lower_bound_},
{"IncognitoQuotaRatioUpperBound", ratio_upper_bound_}});
}
void DisableFeature() {
scoped_feature_list_.Reset();
scoped_feature_list_.InitAndDisableFeature(
features::kIncognitoDynamicQuota);
}
void GetAndTestExperimentalSettings(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 * 0.2, settings->pool_size);
EXPECT_GE(physical_memory_amount * 0.3, settings->pool_size);
}));
task_environment_.RunUntilIdle();
EXPECT_TRUE(callback_executed);
}
void GetAndTestDefaultSettings() {
bool callback_executed = false;
GetNominalDynamicSettings(
profile_path(), true, device_info_helper(),
base::BindLambdaForTesting([&](base::Optional<QuotaSettings> settings) {
callback_executed = true;
EXPECT_GE(kMaxIncognitoPoolSize, settings->pool_size);
}));
task_environment_.RunUntilIdle();
EXPECT_TRUE(callback_executed);
}
MockQuotaDeviceInfoHelper* device_info_helper() {
return &device_info_helper_;
}
private:
MockQuotaDeviceInfoHelper device_info_helper_;
std::string ratio_lower_bound_ = "0.2";
std::string ratio_upper_bound_ = "0.3";
};
TEST_F(QuotaSettingsTest, Default) {
MockQuotaDeviceInfoHelper device_info_helper;
ON_CALL(device_info_helper, AmountOfTotalDiskSpace(_))
......@@ -106,10 +183,8 @@ TEST_F(QuotaSettingsTest, UnlimitedTempPool) {
}
TEST_F(QuotaSettingsTest, IncognitoQuotaCapped) {
const int64_t kMBytes = 1024 * 1024;
const int64_t kMaxIncognitoPoolSize = 330 * kMBytes; // 300 MB + 10%
MockQuotaDeviceInfoHelper device_info_helper;
EXPECT_CALL(device_info_helper, AmountOfPhysicalMemory()).Times(1);
ON_CALL(device_info_helper, AmountOfPhysicalMemory())
.WillByDefault(::testing::Return(kMaxIncognitoPoolSize));
......@@ -125,108 +200,46 @@ TEST_F(QuotaSettingsTest, IncognitoQuotaCapped) {
EXPECT_TRUE(callback_executed);
}
TEST_F(QuotaSettingsTest, IncognitoDynamicQuota1) {
const int64_t kMBytes = 1024 * 1024;
const int64_t kMaxIncognitoPoolSize = 330 * kMBytes; // 300 MB + 10%
const int64_t physical_memory_amount = kMaxIncognitoPoolSize / 10;
MockQuotaDeviceInfoHelper device_info_helper;
ON_CALL(device_info_helper, AmountOfPhysicalMemory())
.WillByDefault(::testing::Return(physical_memory_amount));
scoped_feature_list_.InitAndEnableFeatureWithParameters(
features::kIncognitoDynamicQuota,
{{"IncognitoQuotaRatioLowerBound", "0.1"},
{"IncognitoQuotaRatioUpperBound", "0.2"}});
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 / 10, settings->pool_size);
EXPECT_GE(physical_memory_amount / 5, settings->pool_size);
}));
task_environment_.RunUntilIdle();
EXPECT_TRUE(callback_executed);
TEST_F(QuotaSettingsIncognitoTest, IncognitoDynamicQuota_BelowStaticLimit) {
const int expected_device_info_calls = 2;
const int64_t physical_memory_amount = 1000 * kMBytes;
static_assert(
physical_memory_amount * kIncognitoPoolSizeRatio < kMaxIncognitoPoolSize,
"10% of physical_memory_amount should be less than "
"kMaxIncognitoPoolSize");
SetUpDeviceInfoHelper(expected_device_info_calls, physical_memory_amount);
EnableFeature();
GetAndTestExperimentalSettings(physical_memory_amount);
DisableFeature();
GetAndTestDefaultSettings();
}
TEST_F(QuotaSettingsTest, IncognitoDynamicQuota2) {
const int64_t kMBytes = 1024 * 1024;
const int64_t kMaxIncognitoPoolSize = 330 * kMBytes; // 300 MB + 10%
const int64_t physical_memory_amount = kMaxIncognitoPoolSize;
MockQuotaDeviceInfoHelper device_info_helper;
ON_CALL(device_info_helper, AmountOfPhysicalMemory())
.WillByDefault(::testing::Return(physical_memory_amount));
scoped_feature_list_.InitAndEnableFeatureWithParameters(
features::kIncognitoDynamicQuota,
{{"IncognitoQuotaRatioLowerBound", "0.1"},
{"IncognitoQuotaRatioUpperBound", "0.2"}});
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 / 10, settings->pool_size);
EXPECT_GE(physical_memory_amount / 5, settings->pool_size);
}));
task_environment_.RunUntilIdle();
EXPECT_TRUE(callback_executed);
TEST_F(QuotaSettingsIncognitoTest, IncognitoDynamicQuota_AtStaticLimit) {
const int expected_device_info_calls = 2;
const int64_t physical_memory_amount = 3300 * kMBytes;
static_assert(physical_memory_amount * 0.1 == kMaxIncognitoPoolSize,
"10% of physical_memory_amount should be equal to "
"kMaxIncognitoPoolSize");
SetUpDeviceInfoHelper(expected_device_info_calls, physical_memory_amount);
EnableFeature();
GetAndTestExperimentalSettings(physical_memory_amount);
DisableFeature();
GetAndTestDefaultSettings();
}
TEST_F(QuotaSettingsTest, IncognitoDynamicQuota3) {
const int64_t kMBytes = 1024 * 1024;
const int64_t kMaxIncognitoPoolSize = 330 * kMBytes; // 300 MB + 10%
const int64_t physical_memory_amount = kMaxIncognitoPoolSize * 100;
MockQuotaDeviceInfoHelper device_info_helper;
ON_CALL(device_info_helper, AmountOfPhysicalMemory())
.WillByDefault(::testing::Return(physical_memory_amount));
scoped_feature_list_.InitAndEnableFeatureWithParameters(
features::kIncognitoDynamicQuota,
{{"IncognitoQuotaRatioLowerBound", "0.1"},
{"IncognitoQuotaRatioUpperBound", "0.2"}});
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 / 10, settings->pool_size);
EXPECT_GE(physical_memory_amount / 5, settings->pool_size);
}));
task_environment_.RunUntilIdle();
EXPECT_TRUE(callback_executed);
}
TEST_F(QuotaSettingsTest, IncognitoDynamicQuota4) {
const int64_t kMBytes = 1024 * 1024;
const int64_t kMaxIncognitoPoolSize = 330 * kMBytes; // 300 MB + 10%
const int64_t physical_memory_amount = kMaxIncognitoPoolSize * 1000;
MockQuotaDeviceInfoHelper device_info_helper;
ON_CALL(device_info_helper, AmountOfPhysicalMemory())
.WillByDefault(::testing::Return(physical_memory_amount));
scoped_feature_list_.InitAndEnableFeatureWithParameters(
features::kIncognitoDynamicQuota,
{{"IncognitoQuotaRatioLowerBound", "0.1"},
{"IncognitoQuotaRatioUpperBound", "0.2"}});
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 / 10, settings->pool_size);
EXPECT_GE(physical_memory_amount / 5, settings->pool_size);
}));
task_environment_.RunUntilIdle();
EXPECT_TRUE(callback_executed);
TEST_F(QuotaSettingsIncognitoTest, IncognitoDynamicQuota_AboveStaticLimit) {
const int expected_device_info_calls = 1;
const int64_t physical_memory_amount = 10000 * kMBytes;
static_assert(
physical_memory_amount * kIncognitoPoolSizeRatio > kMaxIncognitoPoolSize,
"10% of physical_memory_amount should "
"be greater than kMaxIncognitoPoolSize");
SetUpDeviceInfoHelper(expected_device_info_calls, physical_memory_amount);
EnableFeature();
GetAndTestExperimentalSettings(physical_memory_amount);
}
} // namespace storage
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