Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Unified Diff: net/url_request/url_fetcher_impl_unittest.cc

Issue 2839663002: Instantiate ScopedTaskEnvironment in net unittests. (Closed)
Patch Set: self-review Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/url_request/url_fetcher_impl_unittest.cc
diff --git a/net/url_request/url_fetcher_impl_unittest.cc b/net/url_request/url_fetcher_impl_unittest.cc
index b4dbcf6c9c05048a84c5bdcfa87c123a2da56b07..794979a2a5fd9939137d93247b5e7f31e2f9bf00 100644
--- a/net/url_request/url_fetcher_impl_unittest.cc
+++ b/net/url_request/url_fetcher_impl_unittest.cc
@@ -26,7 +26,7 @@
#include "base/strings/stringprintf.h"
#include "base/synchronization/waitable_event.h"
#include "base/task_scheduler/post_task.h"
-#include "base/test/scoped_task_scheduler.h"
+#include "base/task_scheduler/task_scheduler.h"
#include "base/test/test_timeouts.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread.h"
@@ -111,13 +111,16 @@ class WaitingURLFetcherDelegate : public URLFetcherDelegate {
// Wait until the request has completed or been canceled. Does not start the
// request.
- void WaitForComplete() { run_loop_.Run(); }
+ void WaitForComplete() {
+ EXPECT_TRUE(task_runner_->BelongsToCurrentThread());
+ run_loop_.Run();
+ }
// Cancels the fetch by deleting the fetcher.
void CancelFetch() {
EXPECT_TRUE(fetcher_);
fetcher_.reset();
- run_loop_.Quit();
+ task_runner_->PostTask(FROM_HERE, run_loop_.QuitClosure());
}
// URLFetcherDelegate:
@@ -126,7 +129,7 @@ class WaitingURLFetcherDelegate : public URLFetcherDelegate {
EXPECT_TRUE(fetcher_);
EXPECT_EQ(fetcher_.get(), source);
did_complete_ = true;
- run_loop_.Quit();
+ task_runner_->PostTask(FROM_HERE, run_loop_.QuitClosure());
}
void OnURLFetchDownloadProgress(const URLFetcher* source,
@@ -166,6 +169,8 @@ class WaitingURLFetcherDelegate : public URLFetcherDelegate {
bool did_complete_;
std::unique_ptr<URLFetcherImpl> fetcher_;
+ const scoped_refptr<base::SingleThreadTaskRunner> task_runner_ =
+ base::ThreadTaskRunnerHandle::Get();
base::RunLoop run_loop_;
DISALLOW_COPY_AND_ASSIGN(WaitingURLFetcherDelegate);
@@ -522,17 +527,14 @@ TEST_F(URLFetcherTest, DifferentThreadsTest) {
// Create the fetcher from a sequenced (not single-threaded) task. Verify that
// the expected response is received.
TEST_F(URLFetcherTest, SequencedTaskTest) {
- base::test::ScopedTaskScheduler scoped_task_scheduler(
- base::MessageLoop::current());
auto sequenced_task_runner = base::CreateSequencedTaskRunnerWithTraits({});
-
auto delegate = base::MakeUnique<WaitingURLFetcherDelegate>();
sequenced_task_runner->PostTask(
FROM_HERE, base::Bind(&WaitingURLFetcherDelegate::CreateFetcher,
base::Unretained(delegate.get()),
test_server_->GetURL(kDefaultResponsePath),
URLFetcher::GET, CreateCrossThreadContextGetter()));
- base::RunLoop().RunUntilIdle();
+ base::TaskScheduler::GetInstance()->FlushForTesting();
mmenke 2017/05/09 15:40:44 In most of the other tests you do a flush + RunUnt
fdoray 2017/05/09 21:43:47 Because the RunLoop::RunUntilIdle() was not requir
delegate->StartFetcherAndWait();
EXPECT_TRUE(delegate->fetcher()->GetStatus().is_success());
@@ -542,7 +544,7 @@ TEST_F(URLFetcherTest, SequencedTaskTest) {
EXPECT_EQ(kDefaultResponseBody, data);
sequenced_task_runner->DeleteSoon(FROM_HERE, delegate.release());
- base::RunLoop().RunUntilIdle();
+ base::TaskScheduler::GetInstance()->FlushForTesting();
}
// Tests to make sure CancelAll() will successfully cancel existing URLFetchers.

Powered by Google App Engine
This is Rietveld 408576698