Commit 2eb46b48 authored by Joshua Bell's avatar Joshua Bell Committed by Commit Bot

Indexed DB: Simplify cross-sequence test code

Now that base::BindLambdaForTesting() can be used, tasks posted to the
Indexed DB task runner in tests don't need to explicitly bring along
ambient state. Also, use an explicit RunLoop's Run()/Quit() instead of
RunAllTasksUntilIdle() where possible, and 'auto' for readability.

Change-Id: Iede419cda01c166e8fe2047c901f528f687f940d
Reviewed-on: https://chromium-review.googlesource.com/c/1298416
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603052}
parent 221ff95e
......@@ -12,6 +12,7 @@
#include "base/files/scoped_temp_dir.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
......@@ -79,11 +80,13 @@ class IndexedDBQuotaClientTest : public testing::Test {
const url::Origin& origin,
StorageType type) {
usage_ = -1;
client->GetOriginUsage(
origin, type,
base::BindOnce(&IndexedDBQuotaClientTest::OnGetOriginUsageComplete,
weak_factory_.GetWeakPtr()));
RunAllTasksUntilIdle();
base::RunLoop loop;
client->GetOriginUsage(origin, type,
base::BindLambdaForTesting([&](int64_t usage) {
usage_ = usage;
loop.Quit();
}));
loop.Run();
EXPECT_GT(usage_, -1);
return usage_;
}
......@@ -91,10 +94,14 @@ class IndexedDBQuotaClientTest : public testing::Test {
const std::set<url::Origin>& GetOriginsForType(storage::QuotaClient* client,
StorageType type) {
origins_.clear();
base::RunLoop loop;
client->GetOriginsForType(
type, base::BindOnce(&IndexedDBQuotaClientTest::OnGetOriginsComplete,
weak_factory_.GetWeakPtr()));
RunAllTasksUntilIdle();
type,
base::BindLambdaForTesting([&](const std::set<url::Origin>& origins) {
origins_ = origins;
loop.Quit();
}));
loop.Run();
return origins_;
}
......@@ -102,11 +109,14 @@ class IndexedDBQuotaClientTest : public testing::Test {
StorageType type,
const std::string& host) {
origins_.clear();
base::RunLoop loop;
client->GetOriginsForHost(
type, host,
base::BindOnce(&IndexedDBQuotaClientTest::OnGetOriginsComplete,
weak_factory_.GetWeakPtr()));
RunAllTasksUntilIdle();
base::BindLambdaForTesting([&](const std::set<url::Origin>& origins) {
origins_ = origins;
loop.Quit();
}));
loop.Run();
return origins_;
}
......@@ -114,11 +124,14 @@ class IndexedDBQuotaClientTest : public testing::Test {
const url::Origin& origin,
StorageType type) {
delete_status_ = blink::mojom::QuotaStatusCode::kUnknown;
base::RunLoop loop;
client->DeleteOriginData(
origin, type,
base::BindOnce(&IndexedDBQuotaClientTest::OnDeleteOriginComplete,
weak_factory_.GetWeakPtr()));
RunAllTasksUntilIdle();
base::BindLambdaForTesting([&](blink::mojom::QuotaStatusCode code) {
delete_status_ = code;
loop.Quit();
}));
loop.Run();
return delete_status_;
}
......@@ -142,16 +155,6 @@ class IndexedDBQuotaClientTest : public testing::Test {
}
private:
void OnGetOriginUsageComplete(int64_t usage) { usage_ = usage; }
void OnGetOriginsComplete(const std::set<url::Origin>& origins) {
origins_ = origins;
}
void OnDeleteOriginComplete(blink::mojom::QuotaStatusCode code) {
delete_status_ = code;
}
content::TestBrowserThreadBundle thread_bundle_;
base::ScopedTempDir temp_dir_;
int64_t usage_;
......
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