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

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

Issue 2806323003: [ObjC ARC] Converts ios/chrome/browser/ui/settings:unit_tests to ARC. (Closed)
Patch Set: rebase Created 3 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/dataplan_usage_collection_view_controlle r.h" 5 #import "ios/chrome/browser/ui/settings/dataplan_usage_collection_view_controlle r.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/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "components/prefs/pref_registry_simple.h" 13 #include "components/prefs/pref_registry_simple.h"
14 #include "components/prefs/pref_service.h" 14 #include "components/prefs/pref_service.h"
15 #include "components/sync_preferences/pref_service_mock_factory.h" 15 #include "components/sync_preferences/pref_service_mock_factory.h"
16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h " 16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
17 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h " 17 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h "
18 #include "ios/chrome/grit/ios_strings.h" 18 #include "ios/chrome/grit/ios_strings.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/base/l10n/l10n_util_mac.h" 20 #include "ui/base/l10n/l10n_util_mac.h"
21 21
22 #if !defined(__has_feature) || !__has_feature(objc_arc)
23 #error "This file requires ARC support."
24 #endif
25
22 @interface DataplanUsageCollectionViewController (ExposedForTesting) 26 @interface DataplanUsageCollectionViewController (ExposedForTesting)
23 - (void)updateBasePref:(BOOL)basePref wifiPref:(BOOL)wifiPref; 27 - (void)updateBasePref:(BOOL)basePref wifiPref:(BOOL)wifiPref;
24 @end 28 @end
25 29
26 namespace { 30 namespace {
27 31
28 const char* kBasePref = "BasePref"; 32 const char* kBasePref = "BasePref";
29 const char* kWifiPref = "WifiPref"; 33 const char* kWifiPref = "WifiPref";
30 34
31 class DataplanUsageCollectionViewControllerTest 35 class DataplanUsageCollectionViewControllerTest
32 : public CollectionViewControllerTest { 36 : public CollectionViewControllerTest {
33 protected: 37 protected:
34 void SetUp() override { 38 void SetUp() override {
35 CollectionViewControllerTest::SetUp(); 39 CollectionViewControllerTest::SetUp();
36 pref_service_ = CreateLocalState(); 40 pref_service_ = CreateLocalState();
37 CreateController(); 41 CreateController();
38 } 42 }
39 43
40 CollectionViewController* NewController() override NS_RETURNS_RETAINED { 44 CollectionViewController* InstantiateController() override {
41 dataplanController_.reset([[DataplanUsageCollectionViewController alloc] 45 dataplanController_ = [[DataplanUsageCollectionViewController alloc]
42 initWithPrefs:pref_service_.get() 46 initWithPrefs:pref_service_.get()
43 basePref:kBasePref 47 basePref:kBasePref
44 wifiPref:kWifiPref 48 wifiPref:kWifiPref
45 title:@"CollectionTitle"]); 49 title:@"CollectionTitle"];
46 return [dataplanController_ retain]; 50 return dataplanController_;
47 } 51 }
48 52
49 std::unique_ptr<PrefService> CreateLocalState() { 53 std::unique_ptr<PrefService> CreateLocalState() {
50 scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple()); 54 scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple());
51 registry->RegisterBooleanPref(kBasePref, false); 55 registry->RegisterBooleanPref(kBasePref, false);
52 registry->RegisterBooleanPref(kWifiPref, false); 56 registry->RegisterBooleanPref(kWifiPref, false);
53 57
54 sync_preferences::PrefServiceMockFactory factory; 58 sync_preferences::PrefServiceMockFactory factory;
55 base::FilePath path("DataplanUsageCollectionViewControllerTest.pref"); 59 base::FilePath path("DataplanUsageCollectionViewControllerTest.pref");
56 factory.SetUserPrefsFile(path, message_loop_.task_runner().get()); 60 factory.SetUserPrefsFile(path, message_loop_.task_runner().get());
57 return factory.Create(registry.get()); 61 return factory.Create(registry.get());
58 } 62 }
59 63
60 // Verifies that the cell at |item| in |section| has the given |accessory| 64 // Verifies that the cell at |item| in |section| has the given |accessory|
61 // type. 65 // type.
62 void CheckTextItemAccessoryType(int accessory_type, int section, int item) { 66 void CheckTextItemAccessoryType(int accessory_type, int section, int item) {
63 CollectionViewTextItem* cell = GetCollectionViewItem(section, item); 67 CollectionViewTextItem* cell = GetCollectionViewItem(section, item);
64 EXPECT_EQ(accessory_type, cell.accessoryType); 68 EXPECT_EQ(accessory_type, cell.accessoryType);
65 } 69 }
66 70
67 base::MessageLoopForUI message_loop_; 71 base::MessageLoopForUI message_loop_;
68 std::unique_ptr<PrefService> pref_service_; 72 std::unique_ptr<PrefService> pref_service_;
69 base::scoped_nsobject<DataplanUsageCollectionViewController> 73 DataplanUsageCollectionViewController* dataplanController_;
70 dataplanController_;
71 }; 74 };
72 75
73 TEST_F(DataplanUsageCollectionViewControllerTest, TestModel) { 76 TEST_F(DataplanUsageCollectionViewControllerTest, TestModel) {
74 CheckController(); 77 CheckController();
75 EXPECT_EQ(1, NumberOfSections()); 78 EXPECT_EQ(1, NumberOfSections());
76 79
77 // No section header + 3 rows 80 // No section header + 3 rows
78 EXPECT_EQ(3, NumberOfItemsInSection(0)); 81 EXPECT_EQ(3, NumberOfItemsInSection(0));
79 CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 0); 82 CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 0);
80 CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 1); 83 CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 1);
(...skipping 24 matching lines...) Expand all
105 CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 1); 108 CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 1);
106 CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryCheckmark, 0, 2); 109 CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryCheckmark, 0, 2);
107 110
108 [dataplanController_ updateBasePref:NO wifiPref:NO]; 111 [dataplanController_ updateBasePref:NO wifiPref:NO];
109 CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 0); 112 CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 0);
110 CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 1); 113 CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 1);
111 CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryCheckmark, 0, 2); 114 CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryCheckmark, 0, 2);
112 } 115 }
113 116
114 } // namespace 117 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698