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 @@ ...@@ -12,6 +12,7 @@
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
...@@ -79,11 +80,13 @@ class IndexedDBQuotaClientTest : public testing::Test { ...@@ -79,11 +80,13 @@ class IndexedDBQuotaClientTest : public testing::Test {
const url::Origin& origin, const url::Origin& origin,
StorageType type) { StorageType type) {
usage_ = -1; usage_ = -1;
client->GetOriginUsage( base::RunLoop loop;
origin, type, client->GetOriginUsage(origin, type,
base::BindOnce(&IndexedDBQuotaClientTest::OnGetOriginUsageComplete, base::BindLambdaForTesting([&](int64_t usage) {
weak_factory_.GetWeakPtr())); usage_ = usage;
RunAllTasksUntilIdle(); loop.Quit();
}));
loop.Run();
EXPECT_GT(usage_, -1); EXPECT_GT(usage_, -1);
return usage_; return usage_;
} }
...@@ -91,10 +94,14 @@ class IndexedDBQuotaClientTest : public testing::Test { ...@@ -91,10 +94,14 @@ class IndexedDBQuotaClientTest : public testing::Test {
const std::set<url::Origin>& GetOriginsForType(storage::QuotaClient* client, const std::set<url::Origin>& GetOriginsForType(storage::QuotaClient* client,
StorageType type) { StorageType type) {
origins_.clear(); origins_.clear();
base::RunLoop loop;
client->GetOriginsForType( client->GetOriginsForType(
type, base::BindOnce(&IndexedDBQuotaClientTest::OnGetOriginsComplete, type,
weak_factory_.GetWeakPtr())); base::BindLambdaForTesting([&](const std::set<url::Origin>& origins) {
RunAllTasksUntilIdle(); origins_ = origins;
loop.Quit();
}));
loop.Run();
return origins_; return origins_;
} }
...@@ -102,11 +109,14 @@ class IndexedDBQuotaClientTest : public testing::Test { ...@@ -102,11 +109,14 @@ class IndexedDBQuotaClientTest : public testing::Test {
StorageType type, StorageType type,
const std::string& host) { const std::string& host) {
origins_.clear(); origins_.clear();
base::RunLoop loop;
client->GetOriginsForHost( client->GetOriginsForHost(
type, host, type, host,
base::BindOnce(&IndexedDBQuotaClientTest::OnGetOriginsComplete, base::BindLambdaForTesting([&](const std::set<url::Origin>& origins) {
weak_factory_.GetWeakPtr())); origins_ = origins;
RunAllTasksUntilIdle(); loop.Quit();
}));
loop.Run();
return origins_; return origins_;
} }
...@@ -114,11 +124,14 @@ class IndexedDBQuotaClientTest : public testing::Test { ...@@ -114,11 +124,14 @@ class IndexedDBQuotaClientTest : public testing::Test {
const url::Origin& origin, const url::Origin& origin,
StorageType type) { StorageType type) {
delete_status_ = blink::mojom::QuotaStatusCode::kUnknown; delete_status_ = blink::mojom::QuotaStatusCode::kUnknown;
base::RunLoop loop;
client->DeleteOriginData( client->DeleteOriginData(
origin, type, origin, type,
base::BindOnce(&IndexedDBQuotaClientTest::OnDeleteOriginComplete, base::BindLambdaForTesting([&](blink::mojom::QuotaStatusCode code) {
weak_factory_.GetWeakPtr())); delete_status_ = code;
RunAllTasksUntilIdle(); loop.Quit();
}));
loop.Run();
return delete_status_; return delete_status_;
} }
...@@ -142,16 +155,6 @@ class IndexedDBQuotaClientTest : public testing::Test { ...@@ -142,16 +155,6 @@ class IndexedDBQuotaClientTest : public testing::Test {
} }
private: 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_; content::TestBrowserThreadBundle thread_bundle_;
base::ScopedTempDir temp_dir_; base::ScopedTempDir temp_dir_;
int64_t usage_; 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