Commit bc235568 authored by fdoray's avatar fdoray Committed by Commit bot

Use ScopedTaskEnvironment instead of MessageLoopForUI in ios 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=marq@chromium.org

Review-Url: https://codereview.chromium.org/2846073002
Cr-Commit-Position: refs/heads/master@{#467968}
parent 01014b7c
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#import "ios/chrome/browser/ui/settings/time_range_selector_collection_view_controller.h" #import "ios/chrome/browser/ui/settings/time_range_selector_collection_view_controller.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/message_loop/message_loop.h" #include "base/test/scoped_task_environment.h"
#include "components/browsing_data/core/pref_names.h" #include "components/browsing_data/core/pref_names.h"
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
...@@ -32,6 +32,10 @@ const NSInteger kNumberOfItems = 5; ...@@ -32,6 +32,10 @@ const NSInteger kNumberOfItems = 5;
class TimeRangeSelectorCollectionViewControllerTest class TimeRangeSelectorCollectionViewControllerTest
: public CollectionViewControllerTest { : public CollectionViewControllerTest {
protected: protected:
TimeRangeSelectorCollectionViewControllerTest()
: scoped_task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
void SetUp() override { void SetUp() override {
CollectionViewControllerTest::SetUp(); CollectionViewControllerTest::SetUp();
pref_service_ = CreateLocalState(); pref_service_ = CreateLocalState();
...@@ -64,7 +68,7 @@ class TimeRangeSelectorCollectionViewControllerTest ...@@ -64,7 +68,7 @@ class TimeRangeSelectorCollectionViewControllerTest
EXPECT_EQ(accessory_type, cell.accessoryType); EXPECT_EQ(accessory_type, cell.accessoryType);
} }
base::MessageLoopForUI message_loop_; base::test::ScopedTaskEnvironment scoped_task_environment_;
std::unique_ptr<PrefService> pref_service_; std::unique_ptr<PrefService> pref_service_;
id delegate_; id delegate_;
TimeRangeSelectorCollectionViewController* time_range_selector_controller_; TimeRangeSelectorCollectionViewController* time_range_selector_controller_;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/message_loop/message_loop.h" #include "base/test/scoped_task_environment.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_member.h" #include "components/prefs/pref_member.h"
...@@ -42,6 +42,10 @@ const char kLanguage2[] = "pirate"; ...@@ -42,6 +42,10 @@ const char kLanguage2[] = "pirate";
class TranslateCollectionViewControllerTest class TranslateCollectionViewControllerTest
: public CollectionViewControllerTest { : public CollectionViewControllerTest {
protected: protected:
TranslateCollectionViewControllerTest()
: scoped_task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
void SetUp() override { void SetUp() override {
CollectionViewControllerTest::SetUp(); CollectionViewControllerTest::SetUp();
pref_service_ = CreateLocalState(); pref_service_ = CreateLocalState();
...@@ -66,7 +70,7 @@ class TranslateCollectionViewControllerTest ...@@ -66,7 +70,7 @@ class TranslateCollectionViewControllerTest
return factory.Create(registry.get()); return factory.Create(registry.get());
} }
base::MessageLoopForUI message_loop_; base::test::ScopedTaskEnvironment scoped_task_environment_;
std::unique_ptr<PrefService> pref_service_; std::unique_ptr<PrefService> pref_service_;
}; };
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/message_loop/message_loop.h" #include "base/test/scoped_task_environment.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "components/prefs/pref_member.h" #include "components/prefs/pref_member.h"
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
...@@ -33,6 +33,10 @@ namespace { ...@@ -33,6 +33,10 @@ namespace {
class VoicesearchCollectionViewControllerTest class VoicesearchCollectionViewControllerTest
: public CollectionViewControllerTest { : public CollectionViewControllerTest {
protected: protected:
VoicesearchCollectionViewControllerTest()
: scoped_task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
void SetUp() override { void SetUp() override {
CollectionViewControllerTest::SetUp(); CollectionViewControllerTest::SetUp();
pref_service_ = CreateLocalState(); pref_service_ = CreateLocalState();
...@@ -58,7 +62,7 @@ class VoicesearchCollectionViewControllerTest ...@@ -58,7 +62,7 @@ class VoicesearchCollectionViewControllerTest
inSection:0]]); inSection:0]]);
} }
base::MessageLoopForUI message_loop_; base::test::ScopedTaskEnvironment scoped_task_environment_;
std::unique_ptr<PrefService> pref_service_; std::unique_ptr<PrefService> pref_service_;
}; };
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/test/scoped_task_environment.h"
#include "net/url_request/test_url_fetcher_factory.h" #include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_request_status.h" #include "net/url_request/url_request_status.h"
#include "net/url_request/url_request_test_util.h" #include "net/url_request/url_request_test_util.h"
...@@ -22,8 +23,12 @@ namespace web { ...@@ -22,8 +23,12 @@ namespace web {
// Test fixture for URLFetcherBlockAdapter. // Test fixture for URLFetcherBlockAdapter.
class URLFetcherBlockAdapterTest : public PlatformTest { class URLFetcherBlockAdapterTest : public PlatformTest {
protected: protected:
URLFetcherBlockAdapterTest()
: scoped_task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
// Required for base::MessageLoop::current(). // Required for base::MessageLoop::current().
base::MessageLoopForUI loop_; base::test::ScopedTaskEnvironment scoped_task_environment_;
}; };
// Tests that URLFetcherBlockAdapter calls its completion handler with the // Tests that URLFetcherBlockAdapter calls its completion handler with the
......
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