Commit 20fb03e9 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

IndexedDB: Push state to functions in IndexedDBQuotaClientTest.

The test has a few sync wrappers for QuotaClient's async methods. The
wrappers store the async method results as test fixture members. This
scope is unnecessarily large, which is an unnecessary mental burden on
folks who need to understand the test.

This CL stores each async method result as a local variable in the
method's sync wrapper and removes the member variables.

Change-Id: Ie85aa31688643b4de163a8b0a415b3aec2e54241
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2247216
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Auto-Submit: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779524}
parent 21ef90f1
...@@ -24,7 +24,11 @@ ...@@ -24,7 +24,11 @@
#include "content/browser/indexed_db/indexed_db_context_impl.h" #include "content/browser/indexed_db/indexed_db_context_impl.h"
#include "content/browser/indexed_db/indexed_db_quota_client.h" #include "content/browser/indexed_db/indexed_db_quota_client.h"
#include "storage/browser/test/mock_quota_manager.h" #include "storage/browser/test/mock_quota_manager.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom-shared.h"
#include "url/gurl.h"
#include "url/origin.h"
using blink::mojom::StorageType; using blink::mojom::StorageType;
...@@ -43,8 +47,7 @@ class IndexedDBQuotaClientTest : public testing::Test { ...@@ -43,8 +47,7 @@ class IndexedDBQuotaClientTest : public testing::Test {
IndexedDBQuotaClientTest() IndexedDBQuotaClientTest()
: kOriginA(url::Origin::Create(GURL("http://host"))), : kOriginA(url::Origin::Create(GURL("http://host"))),
kOriginB(url::Origin::Create(GURL("http://host:8000"))), kOriginB(url::Origin::Create(GURL("http://host:8000"))),
kOriginOther(url::Origin::Create(GURL("http://other"))), kOriginOther(url::Origin::Create(GURL("http://other"))) {
usage_(0) {
CreateTempDir(); CreateTempDir();
auto quota_manager = base::MakeRefCounted<storage::MockQuotaManager>( auto quota_manager = base::MakeRefCounted<storage::MockQuotaManager>(
/*in_memory=*/false, temp_dir_.GetPath(), /*in_memory=*/false, temp_dir_.GetPath(),
...@@ -76,66 +79,67 @@ class IndexedDBQuotaClientTest : public testing::Test { ...@@ -76,66 +79,67 @@ class IndexedDBQuotaClientTest : public testing::Test {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
int64_t GetOriginUsage(scoped_refptr<storage::QuotaClient> client, static int64_t GetOriginUsage(scoped_refptr<storage::QuotaClient> client,
const url::Origin& origin, const url::Origin& origin,
StorageType type) { StorageType type) {
usage_ = -1; int result = -1;
base::RunLoop loop; base::RunLoop loop;
client->GetOriginUsage(origin, type, client->GetOriginUsage(origin, type,
base::BindLambdaForTesting([&](int64_t usage) { base::BindLambdaForTesting([&](int64_t usage) {
usage_ = usage; result = usage;
loop.Quit(); loop.Quit();
})); }));
loop.Run(); loop.Run();
EXPECT_GT(usage_, -1); EXPECT_GT(result, -1);
return usage_; return result;
} }
const std::set<url::Origin>& GetOriginsForType( static std::set<url::Origin> GetOriginsForType(
scoped_refptr<storage::QuotaClient> client, scoped_refptr<storage::QuotaClient> client,
StorageType type) { StorageType type) {
origins_.clear(); std::set<url::Origin> result;
base::RunLoop loop; base::RunLoop loop;
client->GetOriginsForType( client->GetOriginsForType(
type, type,
base::BindLambdaForTesting([&](const std::set<url::Origin>& origins) { base::BindLambdaForTesting([&](const std::set<url::Origin>& origins) {
origins_ = origins; result = origins;
loop.Quit(); loop.Quit();
})); }));
loop.Run(); loop.Run();
return origins_; return result;
} }
const std::set<url::Origin>& GetOriginsForHost( static std::set<url::Origin> GetOriginsForHost(
scoped_refptr<storage::QuotaClient> client, scoped_refptr<storage::QuotaClient> client,
StorageType type, StorageType type,
const std::string& host) { const std::string& host) {
origins_.clear(); std::set<url::Origin> result;
base::RunLoop loop; base::RunLoop loop;
client->GetOriginsForHost( client->GetOriginsForHost(
type, host, type, host,
base::BindLambdaForTesting([&](const std::set<url::Origin>& origins) { base::BindLambdaForTesting([&](const std::set<url::Origin>& origins) {
origins_ = origins; result = origins;
loop.Quit(); loop.Quit();
})); }));
loop.Run(); loop.Run();
return origins_; return result;
} }
blink::mojom::QuotaStatusCode DeleteOrigin( static blink::mojom::QuotaStatusCode DeleteOriginData(
scoped_refptr<storage::QuotaClient> client, scoped_refptr<storage::QuotaClient> client,
const url::Origin& origin, const url::Origin& origin,
StorageType type) { StorageType type) {
delete_status_ = blink::mojom::QuotaStatusCode::kUnknown; blink::mojom::QuotaStatusCode result =
blink::mojom::QuotaStatusCode::kUnknown;
base::RunLoop loop; base::RunLoop loop;
client->DeleteOriginData( client->DeleteOriginData(
origin, type, origin, type,
base::BindLambdaForTesting([&](blink::mojom::QuotaStatusCode code) { base::BindLambdaForTesting([&](blink::mojom::QuotaStatusCode code) {
delete_status_ = code; result = code;
loop.Quit(); loop.Quit();
})); }));
loop.Run(); loop.Run();
return delete_status_; return result;
} }
IndexedDBContextImpl* idb_context() { return idb_context_.get(); } IndexedDBContextImpl* idb_context() { return idb_context_.get(); }
...@@ -173,10 +177,7 @@ class IndexedDBQuotaClientTest : public testing::Test { ...@@ -173,10 +177,7 @@ class IndexedDBQuotaClientTest : public testing::Test {
private: private:
base::test::TaskEnvironment task_environment_; base::test::TaskEnvironment task_environment_;
base::ScopedTempDir temp_dir_; base::ScopedTempDir temp_dir_;
int64_t usage_;
std::set<url::Origin> origins_;
scoped_refptr<IndexedDBContextImpl> idb_context_; scoped_refptr<IndexedDBContextImpl> idb_context_;
blink::mojom::QuotaStatusCode delete_status_;
base::WeakPtrFactory<IndexedDBQuotaClientTest> weak_factory_{this}; base::WeakPtrFactory<IndexedDBQuotaClientTest> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(IndexedDBQuotaClientTest); DISALLOW_COPY_AND_ASSIGN(IndexedDBQuotaClientTest);
...@@ -239,7 +240,7 @@ TEST_F(IndexedDBQuotaClientTest, DeleteOrigin) { ...@@ -239,7 +240,7 @@ TEST_F(IndexedDBQuotaClientTest, DeleteOrigin) {
EXPECT_EQ(50, GetOriginUsage(client, kOriginB, kTemp)); EXPECT_EQ(50, GetOriginUsage(client, kOriginB, kTemp));
blink::mojom::QuotaStatusCode delete_status = blink::mojom::QuotaStatusCode delete_status =
DeleteOrigin(client, kOriginA, kTemp); DeleteOriginData(client, kOriginA, kTemp);
EXPECT_EQ(blink::mojom::QuotaStatusCode::kOk, delete_status); EXPECT_EQ(blink::mojom::QuotaStatusCode::kOk, delete_status);
EXPECT_EQ(0, GetOriginUsage(client, kOriginA, kTemp)); EXPECT_EQ(0, GetOriginUsage(client, kOriginA, kTemp));
EXPECT_EQ(50, GetOriginUsage(client, kOriginB, kTemp)); EXPECT_EQ(50, GetOriginUsage(client, kOriginB, kTemp));
......
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