Commit 40b0d9ca authored by fdoray's avatar fdoray Committed by Commit bot

Use ScopedTaskEnvironment instead of MessageLoopForUI in ash tests.

ScopedTaskEnvironment allows usage of ThreadTaskRunnerHandle and
base/task_scheduler/post_task.h within its scope. It should be
instantiated in everytest that uses either of these APIs
(i.e. no test should instantiate a MessageLoop directly).

Motivation for ScopedTaskEnvironment can be found in:
https://docs.google.com/document/d/1QabRo8c7D9LsYY3cEcaPQbOCLo8Tu-6VLykYXyl3Pkk/edit

BUG=708584
R=gab@chromium.org
TBR=sky@chromium.org

Review-Url: https://codereview.chromium.org/2846723004
Cr-Commit-Position: refs/heads/master@{#467987}
parent 992dc1ad
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#include <memory> #include <memory>
#include "ash/resources/vector_icons/vector_icons.h" #include "ash/resources/vector_icons/vector_icons.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/scoped_task_environment.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/cros_system_api/dbus/service_constants.h" #include "third_party/cros_system_api/dbus/service_constants.h"
...@@ -38,7 +38,10 @@ class TestObserver : public PowerStatus::Observer { ...@@ -38,7 +38,10 @@ class TestObserver : public PowerStatus::Observer {
class PowerStatusTest : public testing::Test { class PowerStatusTest : public testing::Test {
public: public:
PowerStatusTest() : power_status_(NULL) {} PowerStatusTest()
: scoped_task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::UI),
power_status_(NULL) {}
~PowerStatusTest() override {} ~PowerStatusTest() override {}
void SetUp() override { void SetUp() override {
...@@ -57,7 +60,7 @@ class PowerStatusTest : public testing::Test { ...@@ -57,7 +60,7 @@ class PowerStatusTest : public testing::Test {
} }
protected: protected:
base::MessageLoopForUI message_loop_; base::test::ScopedTaskEnvironment scoped_task_environment_;
PowerStatus* power_status_; // Not owned. PowerStatus* power_status_; // Not owned.
std::unique_ptr<TestObserver> test_observer_; std::unique_ptr<TestObserver> test_observer_;
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "ash/test/ash_test_views_delegate.h" #include "ash/test/ash_test_views_delegate.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/scoped_task_environment.h"
#include "base/test/sequenced_worker_pool_owner.h" #include "base/test/sequenced_worker_pool_owner.h"
#include "base/threading/sequenced_worker_pool.h" #include "base/threading/sequenced_worker_pool.h"
...@@ -17,7 +17,9 @@ namespace { ...@@ -17,7 +17,9 @@ namespace {
class AshTestEnvironmentDefault : public AshTestEnvironment { class AshTestEnvironmentDefault : public AshTestEnvironment {
public: public:
AshTestEnvironmentDefault() {} AshTestEnvironmentDefault()
: scoped_task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
~AshTestEnvironmentDefault() override { ~AshTestEnvironmentDefault() override {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -40,7 +42,7 @@ class AshTestEnvironmentDefault : public AshTestEnvironment { ...@@ -40,7 +42,7 @@ class AshTestEnvironmentDefault : public AshTestEnvironment {
} }
private: private:
base::MessageLoopForUI message_loop_; base::test::ScopedTaskEnvironment scoped_task_environment_;
std::unique_ptr<base::SequencedWorkerPoolOwner> blocking_pool_owner_; std::unique_ptr<base::SequencedWorkerPoolOwner> blocking_pool_owner_;
DISALLOW_COPY_AND_ASSIGN(AshTestEnvironmentDefault); DISALLOW_COPY_AND_ASSIGN(AshTestEnvironmentDefault);
......
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