Skip to content

Commit

Permalink
Use ScopedTaskEnvironment instead of MessageLoop in /components/cronet
Browse files Browse the repository at this point in the history
MessageLoop will go away, eventually.

ScopedTaskEnvironment will per default start a ThreadPool, which should
be fine in most of the cases. If you belive your test needs to make sure
that no ThreadPool runs let me know and I will update the patch.

BUG=891670
This CL was uploaded by git cl split.

R=mef@chromium.org

Change-Id: Icd3adfdfc99f8d1cc3a6b09022c829bd33706949
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1649734
Auto-Submit: Carlos Caballero <carlscab@google.com>
Reviewed-by: Misha Efimov <mef@chromium.org>
Commit-Queue: Misha Efimov <mef@chromium.org>
Cr-Commit-Position: refs/heads/master@{#667132}
  • Loading branch information
carlscabgro authored and Commit Bot committed Jun 7, 2019
1 parent 462a6ec commit b9815e4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 5 additions & 3 deletions components/cronet/native/test/buffer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include "base/logging.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/test/scoped_task_environment.h"
#include "components/cronet/native/test/test_util.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand All @@ -25,8 +25,10 @@ class BufferTest : public ::testing::Test {
Cronet_BufferPtr buffer);
bool on_destroy_called() const { return on_destroy_called_; }

// Provide a message loop for use by TestExecutor instances.
base::MessageLoop message_loop_;
// Provide a task environment for use by TestExecutor instances. Do not
// initialize the ThreadPool as this is done by the Cronet_Engine
base::test::ScopedTaskEnvironment scoped_task_environment_{
base::test::ScopedTaskEnvironment::ThreadingMode::MAIN_THREAD_ONLY};

private:
void set_on_destroy_called(bool value) { on_destroy_called_ = value; }
Expand Down
8 changes: 5 additions & 3 deletions components/cronet/native/test/executors_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include "base/logging.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/test/scoped_task_environment.h"
#include "components/cronet/native/test/test_util.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand All @@ -22,8 +22,10 @@ class ExecutorsTest : public ::testing::Test {
static void TestRunnable_Run(Cronet_RunnablePtr self);
bool runnable_called() const { return runnable_called_; }

// Provide a message loop for use by TestExecutor instances.
base::MessageLoop message_loop_;
// Provide a task environment for use by TestExecutor instances. Do not
// initialize the ThreadPool as this is done by the Cronet_Engine
base::test::ScopedTaskEnvironment scoped_task_environment_{
base::test::ScopedTaskEnvironment::ThreadingMode::MAIN_THREAD_ONLY};

private:
void set_runnable_called(bool value) { runnable_called_ = value; }
Expand Down
8 changes: 5 additions & 3 deletions components/cronet/native/test/url_request_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/scoped_task_environment.h"
#include "components/cronet/native/test/test_request_finished_info_listener.h"
#include "components/cronet/native/test/test_upload_data_provider.h"
#include "components/cronet/native/test/test_url_request_callback.h"
Expand Down Expand Up @@ -484,8 +484,10 @@ class UrlRequestTest : public ::testing::TestWithParam<
bool expect_error);

protected:
// Provide a message loop for use by TestExecutor instances.
base::MessageLoop message_loop_;
// Provide a task environment for use by TestExecutor instances. Do not
// initialize the ThreadPool as this is done by the Cronet_Engine
base::test::ScopedTaskEnvironment scoped_task_environment_{
base::test::ScopedTaskEnvironment::ThreadingMode::MAIN_THREAD_ONLY};

// Not owned, |request_finished_listener_| destroys itself when run. This
// pointer is only needed to unregister the listener from the Engine in
Expand Down

0 comments on commit b9815e4

Please sign in to comment.