Skip to content

Commit

Permalink
Simplify MediaLicenseManager tests
Browse files Browse the repository at this point in the history
A FSContext is no longer required for these tests, allowing us to share
setup code between the incognito and non-incognito tests suites.

Bug: 1231162
Change-Id: Icf80124f8a772803ac1d128271c4bcb684f7ffd4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3704167
Commit-Queue: Austin Sullivan <asully@chromium.org>
Reviewed-by: John Rummell <jrummell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1014635}
  • Loading branch information
a-sully authored and Chromium LUCI CQ committed Jun 15, 2022
1 parent af77d8d commit 925d578
Showing 1 changed file with 15 additions and 31 deletions.
46 changes: 15 additions & 31 deletions content/browser/media/media_license_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,20 @@ const char kExampleOrigin[] = "https://example.com";

class MediaLicenseManagerTest : public testing::Test {
public:
MediaLicenseManagerTest() = default;
MediaLicenseManagerTest() : in_memory_(false) {}
explicit MediaLicenseManagerTest(bool in_memory) : in_memory_(in_memory) {}

void SetUp() override {
ASSERT_TRUE(profile_path_.CreateUniqueTempDir());
ASSERT_TRUE(file_system_context_path_.CreateUniqueTempDir());
quota_manager_ = base::MakeRefCounted<storage::MockQuotaManager>(
/*is_incognito=*/false, profile_path_.GetPath(),
in_memory_, in_memory_ ? base::FilePath() : profile_path_.GetPath(),
base::ThreadTaskRunnerHandle::Get().get(),
/*special storage policy=*/nullptr);
quota_manager_proxy_ = base::MakeRefCounted<storage::MockQuotaManagerProxy>(
static_cast<storage::MockQuotaManager*>(quota_manager_.get()),
base::ThreadTaskRunnerHandle::Get());
file_system_context_ = storage::CreateFileSystemContextForTesting(
/*quota_manager_proxy=*/nullptr, file_system_context_path_.GetPath());
manager_ = std::make_unique<MediaLicenseManager>(
file_system_context_->is_incognito(),
in_memory_,
/*special storage policy=*/nullptr, quota_manager_proxy_);
}

Expand Down Expand Up @@ -126,14 +124,14 @@ class MediaLicenseManagerTest : public testing::Test {
}

protected:
const bool in_memory_;

scoped_refptr<storage::MockQuotaManager> quota_manager_;
scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_;
scoped_refptr<storage::FileSystemContext> file_system_context_;

// This must be above MediaLicenseManager, to ensure that no file is accessed
// when the temporary directory is deleted.
base::ScopedTempDir profile_path_;
base::ScopedTempDir file_system_context_path_;
base::test::TaskEnvironment task_environment_;

std::unique_ptr<MediaLicenseManager> manager_;
Expand Down Expand Up @@ -179,6 +177,9 @@ TEST_F(MediaLicenseManagerTest, DeleteBucketData) {
// not.
EXPECT_FALSE(base::PathExists(database_file));
EXPECT_TRUE(base::DirectoryExists(database_file.DirName()));

// Confirm that the file is now empty.
ExpectFileContents(cdm_file, "");
}

TEST_F(MediaLicenseManagerTest, DeleteBucketDataClosedStorage) {
Expand Down Expand Up @@ -268,6 +269,9 @@ TEST_F(MediaLicenseManagerTest, DeleteBucketDataOpenConnection) {
EXPECT_FALSE(base::PathExists(database_file));
EXPECT_TRUE(base::DirectoryExists(database_file.DirName()));

// Confirm that the file is now empty.
ExpectFileContents(cdm_file, "");

// Write some more data. This should succeed.
Write(cdm_file, kTestData);

Expand Down Expand Up @@ -300,30 +304,10 @@ TEST_F(MediaLicenseManagerTest, BucketCreationFailed) {
EXPECT_FALSE(std::get<1>(result).is_valid());
}

// TODO(asully): Consider templating MediaLicenseManagerTest to run all tests in
// incognito and remove `file_system_context_`.
class MediaLicenseManagerIncognitoTest : public MediaLicenseManagerTest {
void SetUp() override {
// Still create this dir so the teardown will confirm it remains empty (on
// Windows, at least).
ASSERT_TRUE(profile_path_.CreateUniqueTempDir());
ASSERT_TRUE(file_system_context_path_.CreateUniqueTempDir());

quota_manager_ = base::MakeRefCounted<storage::MockQuotaManager>(
/*is_incognito=*/true, /*profile_path=*/base::FilePath(),
base::ThreadTaskRunnerHandle::Get().get(),
/*special storage policy=*/nullptr);
quota_manager_proxy_ = base::MakeRefCounted<storage::MockQuotaManagerProxy>(
static_cast<storage::MockQuotaManager*>(quota_manager_.get()),
base::ThreadTaskRunnerHandle::Get());
file_system_context_ = storage::CreateIncognitoFileSystemContextForTesting(
base::ThreadTaskRunnerHandle::Get(),
base::ThreadTaskRunnerHandle::Get(), /*quota_manager_proxy=*/nullptr,
file_system_context_path_.GetPath());
manager_ = std::make_unique<MediaLicenseManager>(
file_system_context_->is_incognito(),
/*special storage policy=*/nullptr, quota_manager_proxy_);
}
public:
MediaLicenseManagerIncognitoTest()
: MediaLicenseManagerTest(/*in_memory=*/true) {}
};

TEST_F(MediaLicenseManagerIncognitoTest, DeleteBucketData) {
Expand Down

0 comments on commit 925d578

Please sign in to comment.