Chromium Code Reviews| Index: net/http/http_network_transaction_unittest.cc |
| diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc |
| index 542cb97379222e6e117adad2075faab94c0c9dca..6f38348a25a8038ca3610cb416381f0ee2006b8b 100644 |
| --- a/net/http/http_network_transaction_unittest.cc |
| +++ b/net/http/http_network_transaction_unittest.cc |
| @@ -27,7 +27,7 @@ |
| #include "base/run_loop.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| -#include "base/test/scoped_task_scheduler.h" |
| +#include "base/task_scheduler/task_scheduler.h" |
| #include "base/test/test_file_util.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| #include "net/base/auth.h" |
| @@ -16762,11 +16762,50 @@ TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| } |
| #if !defined(OS_IOS) |
| -TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
| - // Required by ChannelIDService. |
| - base::test::ScopedTaskScheduler scoped_task_scheduler( |
| - base::MessageLoop::current()); |
| +namespace { |
| + |
| +// TODO(fdoray): Use ScopedTaskEnvironment::RunUntilIdle() instead of this once |
| +// implemented. https://crbug.com/708584 |
| +class TaskObserver : public base::MessageLoop::TaskObserver { |
| + public: |
| + TaskObserver() : ran_task_(false) {} |
| + ~TaskObserver() override {} |
| + |
| + // MessageLoop::TaskObserver overrides. |
| + void WillProcessTask(const base::PendingTask& pending_task) override {} |
| + void DidProcessTask(const base::PendingTask& pending_task) override { |
| + ran_task_ = true; |
| + } |
| + |
| + bool ran_task() const { return ran_task_; } |
| + |
| + private: |
| + bool ran_task_ = false; |
| + DISALLOW_COPY_AND_ASSIGN(TaskObserver); |
| +}; |
| + |
| +// Run tasks on the main thread until there are no more main thread or |
| +// TaskScheduler tasks. |
| +void RunMainThreadAndTaskSchedulerUntilIdle() { |
| + for (;;) { |
| + base::TaskScheduler::GetInstance()->FlushForTesting(); |
|
mmenke
2017/05/09 15:40:44
Why are both this and RunUntilIdle needed?
fdoray
2017/05/09 21:43:47
n/a with latest patch set
|
| + |
| + // Setup a task observer to determine if main thread tasks have run in the |
| + // current loop iteration. |
| + TaskObserver task_observer; |
| + base::MessageLoop::current()->AddTaskObserver(&task_observer); |
| + base::RunLoop().RunUntilIdle(); |
| + base::MessageLoop::current()->RemoveTaskObserver(&task_observer); |
| + |
| + if (!task_observer.ran_task()) |
| + break; |
| + } |
| +} |
| + |
| +} // namespace |
| + |
| +TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
| const std::string https_url = "https://www.example.com"; |
| HttpRequestInfo request; |
| request.url = GURL(https_url); |
| @@ -16792,7 +16831,8 @@ TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
| TestCompletionCallback callback; |
| EXPECT_EQ(ERR_IO_PENDING, |
| trans.Start(&request, callback.callback(), NetLogWithSource())); |
| - base::RunLoop().RunUntilIdle(); |
| + |
| + RunMainThreadAndTaskSchedulerUntilIdle(); |
| EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| HttpRequestHeaders headers; |