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

Side by Side Diff: ios/chrome/browser/ui/settings/voicesearch_collection_view_controller_unittest.mm

Issue 2846073002: Use ScopedTaskEnvironment instead of MessageLoopForUI in ios tests. (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/ui/settings/voicesearch_collection_view_controller.h " 5 #import "ios/chrome/browser/ui/settings/voicesearch_collection_view_controller.h "
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/mac/foundation_util.h" 11 #include "base/mac/foundation_util.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/test/scoped_task_environment.h"
13 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
14 #include "components/prefs/pref_member.h" 14 #include "components/prefs/pref_member.h"
15 #include "components/prefs/pref_registry_simple.h" 15 #include "components/prefs/pref_registry_simple.h"
16 #include "components/prefs/testing_pref_service.h" 16 #include "components/prefs/testing_pref_service.h"
17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item .h" 17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item .h"
18 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" 18 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
19 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h " 19 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h "
20 #include "ios/chrome/browser/voice/speech_input_locale_config_impl.h" 20 #include "ios/chrome/browser/voice/speech_input_locale_config_impl.h"
21 #include "ios/public/provider/chrome/browser/voice/voice_search_prefs.h" 21 #include "ios/public/provider/chrome/browser/voice/voice_search_prefs.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 #import "testing/gtest_mac.h" 23 #import "testing/gtest_mac.h"
24 #include "testing/platform_test.h" 24 #include "testing/platform_test.h"
25 #include "ui/base/l10n/l10n_util_mac.h" 25 #include "ui/base/l10n/l10n_util_mac.h"
26 26
27 #if !defined(__has_feature) || !__has_feature(objc_arc) 27 #if !defined(__has_feature) || !__has_feature(objc_arc)
28 #error "This file requires ARC support." 28 #error "This file requires ARC support."
29 #endif 29 #endif
30 30
31 namespace { 31 namespace {
32 32
33 class VoicesearchCollectionViewControllerTest 33 class VoicesearchCollectionViewControllerTest
34 : public CollectionViewControllerTest { 34 : public CollectionViewControllerTest {
35 protected: 35 protected:
36 VoicesearchCollectionViewControllerTest()
37 : scoped_task_environment_(
38 base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
39
36 void SetUp() override { 40 void SetUp() override {
37 CollectionViewControllerTest::SetUp(); 41 CollectionViewControllerTest::SetUp();
38 pref_service_ = CreateLocalState(); 42 pref_service_ = CreateLocalState();
39 } 43 }
40 44
41 CollectionViewController* InstantiateController() override { 45 CollectionViewController* InstantiateController() override {
42 return [[VoicesearchCollectionViewController alloc] 46 return [[VoicesearchCollectionViewController alloc]
43 initWithPrefs:pref_service_.get()]; 47 initWithPrefs:pref_service_.get()];
44 } 48 }
45 49
46 std::unique_ptr<PrefService> CreateLocalState() { 50 std::unique_ptr<PrefService> CreateLocalState() {
47 TestingPrefServiceSimple* prefs = new TestingPrefServiceSimple(); 51 TestingPrefServiceSimple* prefs = new TestingPrefServiceSimple();
48 PrefRegistrySimple* registry = prefs->registry(); 52 PrefRegistrySimple* registry = prefs->registry();
49 registry->RegisterBooleanPref(prefs::kVoiceSearchTTS, false); 53 registry->RegisterBooleanPref(prefs::kVoiceSearchTTS, false);
50 registry->RegisterStringPref(prefs::kVoiceSearchLocale, "en-US"); 54 registry->RegisterStringPref(prefs::kVoiceSearchLocale, "en-US");
51 return std::unique_ptr<PrefService>(prefs); 55 return std::unique_ptr<PrefService>(prefs);
52 } 56 }
53 57
54 CollectionViewSwitchCell* GetSwitchCell() { 58 CollectionViewSwitchCell* GetSwitchCell() {
55 return base::mac::ObjCCastStrict<CollectionViewSwitchCell>( 59 return base::mac::ObjCCastStrict<CollectionViewSwitchCell>(
56 [controller().collectionView 60 [controller().collectionView
57 cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 61 cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0
58 inSection:0]]); 62 inSection:0]]);
59 } 63 }
60 64
61 base::MessageLoopForUI message_loop_; 65 base::test::ScopedTaskEnvironment scoped_task_environment_;
62 std::unique_ptr<PrefService> pref_service_; 66 std::unique_ptr<PrefService> pref_service_;
63 }; 67 };
64 68
65 TEST_F(VoicesearchCollectionViewControllerTest, NumberOfSectionsAndItems) { 69 TEST_F(VoicesearchCollectionViewControllerTest, NumberOfSectionsAndItems) {
66 CreateController(); 70 CreateController();
67 CheckController(); 71 CheckController();
68 72
69 EXPECT_EQ(2, NumberOfSections()); 73 EXPECT_EQ(2, NumberOfSections());
70 EXPECT_EQ(1, NumberOfItemsInSection(0)); 74 EXPECT_EQ(1, NumberOfItemsInSection(0));
71 const std::vector<voice::SpeechInputLocale>& locales = 75 const std::vector<voice::SpeechInputLocale>& locales =
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 textToSpeechEnabled.Init(prefs::kVoiceSearchTTS, pref_service_.get()); 144 textToSpeechEnabled.Init(prefs::kVoiceSearchTTS, pref_service_.get());
141 textToSpeechEnabled.SetValue(true); 145 textToSpeechEnabled.SetValue(true);
142 146
143 CreateController(); 147 CreateController();
144 CollectionViewSwitchItem* switchItem = GetCollectionViewItem(0, 0); 148 CollectionViewSwitchItem* switchItem = GetCollectionViewItem(0, 0);
145 EXPECT_TRUE(switchItem.isOn); 149 EXPECT_TRUE(switchItem.isOn);
146 EXPECT_FALSE(switchItem.isEnabled); 150 EXPECT_FALSE(switchItem.isEnabled);
147 } 151 }
148 152
149 } // namespace 153 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698