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

Unified Diff: net/url_request/url_fetcher_impl_unittest.cc

Issue 2599873002: Allow URLFetcher to be used from sequenced tasks. (Closed)
Patch Set: remove get() Created 3 years, 11 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
« no previous file with comments | « net/url_request/url_fetcher_core.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 d48f74987debc3d921b93c86ed83808dc1e3726a..62777bfa014f3226e52c68acb9e516c212465df9 100644
--- a/net/url_request/url_fetcher_impl_unittest.cc
+++ b/net/url_request/url_fetcher_impl_unittest.cc
@@ -25,6 +25,8 @@
#include "base/strings/string_util.h"
#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/test/test_timeouts.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread.h"
@@ -515,6 +517,33 @@ TEST_F(URLFetcherTest, DifferentThreadsTest) {
EXPECT_EQ(kDefaultResponseBody, data);
}
+// 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(base::TaskTraits());
+
+ 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();
+ delegate->StartFetcherAndWait();
+
+ EXPECT_TRUE(delegate->fetcher()->GetStatus().is_success());
+ EXPECT_EQ(200, delegate->fetcher()->GetResponseCode());
+ std::string data;
+ ASSERT_TRUE(delegate->fetcher()->GetResponseAsString(&data));
+ EXPECT_EQ(kDefaultResponseBody, data);
+
+ sequenced_task_runner->DeleteSoon(FROM_HERE, delegate.release());
+ base::RunLoop().RunUntilIdle();
+}
+
// Tests to make sure CancelAll() will successfully cancel existing URLFetchers.
TEST_F(URLFetcherTest, CancelAll) {
EXPECT_EQ(0, GetNumFetcherCores());
« no previous file with comments | « net/url_request/url_fetcher_core.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698