OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/physical_web_collection_view_controller.
h" | 5 #import "ios/chrome/browser/ui/settings/physical_web_collection_view_controller.
h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.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 #include "ios/chrome/browser/physical_web/physical_web_constants.h" | 16 #include "ios/chrome/browser/physical_web/physical_web_constants.h" |
17 #include "ios/chrome/browser/pref_names.h" | 17 #include "ios/chrome/browser/pref_names.h" |
18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" | 18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" |
19 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item
.h" | 19 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item
.h" |
20 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" | 20 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" |
21 #include "ios/chrome/grit/ios_chromium_strings.h" | 21 #include "ios/chrome/grit/ios_chromium_strings.h" |
22 #include "ios/chrome/grit/ios_strings.h" | 22 #include "ios/chrome/grit/ios_strings.h" |
23 | 23 |
| 24 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 25 #error "This file requires ARC support." |
| 26 #endif |
| 27 |
24 @interface PhysicalWebCollectionViewController (ExposedForTesting) | 28 @interface PhysicalWebCollectionViewController (ExposedForTesting) |
25 - (void)updatePhysicalWebEnabled:(BOOL)enabled; | 29 - (void)updatePhysicalWebEnabled:(BOOL)enabled; |
26 @end | 30 @end |
27 | 31 |
28 namespace { | 32 namespace { |
29 | 33 |
30 class PhysicalWebCollectionViewControllerTest | 34 class PhysicalWebCollectionViewControllerTest |
31 : public CollectionViewControllerTest { | 35 : public CollectionViewControllerTest { |
32 protected: | 36 protected: |
33 void SetUp() override { | 37 void SetUp() override { |
34 CollectionViewControllerTest::SetUp(); | 38 CollectionViewControllerTest::SetUp(); |
35 pref_service_ = CreateLocalState(); | 39 pref_service_ = CreateLocalState(); |
36 CreateController(); | 40 CreateController(); |
37 } | 41 } |
38 | 42 |
39 CollectionViewController* NewController() override { | 43 CollectionViewController* InstantiateController() override { |
40 physicalWebController_.reset([[PhysicalWebCollectionViewController alloc] | 44 physicalWebController_ = [[PhysicalWebCollectionViewController alloc] |
41 initWithPrefs:pref_service_.get()]); | 45 initWithPrefs:pref_service_.get()]; |
42 return [physicalWebController_ retain]; | 46 return physicalWebController_; |
43 } | 47 } |
44 | 48 |
45 std::unique_ptr<PrefService> CreateLocalState() { | 49 std::unique_ptr<PrefService> CreateLocalState() { |
46 scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple()); | 50 scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple()); |
47 registry->RegisterIntegerPref(prefs::kIosPhysicalWebEnabled, | 51 registry->RegisterIntegerPref(prefs::kIosPhysicalWebEnabled, |
48 physical_web::kPhysicalWebOnboarding); | 52 physical_web::kPhysicalWebOnboarding); |
49 | 53 |
50 sync_preferences::PrefServiceMockFactory factory; | 54 sync_preferences::PrefServiceMockFactory factory; |
51 base::FilePath path("PhysicalWebCollectionViewControllerTest.pref"); | 55 base::FilePath path("PhysicalWebCollectionViewControllerTest.pref"); |
52 factory.SetUserPrefsFile(path, message_loop_.task_runner().get()); | 56 factory.SetUserPrefsFile(path, message_loop_.task_runner().get()); |
53 return factory.Create(registry.get()); | 57 return factory.Create(registry.get()); |
54 } | 58 } |
55 | 59 |
56 base::MessageLoopForUI message_loop_; | 60 base::MessageLoopForUI message_loop_; |
57 std::unique_ptr<PrefService> pref_service_; | 61 std::unique_ptr<PrefService> pref_service_; |
58 base::scoped_nsobject<PhysicalWebCollectionViewController> | 62 PhysicalWebCollectionViewController* physicalWebController_; |
59 physicalWebController_; | |
60 }; | 63 }; |
61 | 64 |
62 // Tests PhysicalWebCollectionViewController is set up with all appropriate | 65 // Tests PhysicalWebCollectionViewController is set up with all appropriate |
63 // items and sections. | 66 // items and sections. |
64 TEST_F(PhysicalWebCollectionViewControllerTest, TestModel) { | 67 TEST_F(PhysicalWebCollectionViewControllerTest, TestModel) { |
65 CheckController(); | 68 CheckController(); |
66 EXPECT_EQ(2, NumberOfSections()); | 69 EXPECT_EQ(2, NumberOfSections()); |
67 | 70 |
68 // First section should have no section header and one row (switch item). | 71 // First section should have no section header and one row (switch item). |
69 EXPECT_EQ(1, NumberOfItemsInSection(0)); | 72 EXPECT_EQ(1, NumberOfItemsInSection(0)); |
70 CheckSwitchCellStateAndTitleWithId(NO, IDS_IOS_OPTIONS_ENABLE_PHYSICAL_WEB, 0, | 73 CheckSwitchCellStateAndTitleWithId(NO, IDS_IOS_OPTIONS_ENABLE_PHYSICAL_WEB, 0, |
71 0); | 74 0); |
72 | 75 |
73 // Section section should have no section header and one row (footer item). | 76 // Section section should have no section header and one row (footer item). |
74 EXPECT_EQ(1, NumberOfItemsInSection(1)); | 77 EXPECT_EQ(1, NumberOfItemsInSection(1)); |
75 CheckSectionFooterWithId(IDS_IOS_OPTIONS_ENABLE_PHYSICAL_WEB_DETAILS, 1); | 78 CheckSectionFooterWithId(IDS_IOS_OPTIONS_ENABLE_PHYSICAL_WEB_DETAILS, 1); |
76 } | 79 } |
77 | 80 |
78 TEST_F(PhysicalWebCollectionViewControllerTest, TestUpdateCheckedState) { | 81 TEST_F(PhysicalWebCollectionViewControllerTest, TestUpdateCheckedState) { |
79 CheckController(); | 82 CheckController(); |
80 ASSERT_EQ(2, NumberOfSections()); | 83 ASSERT_EQ(2, NumberOfSections()); |
81 ASSERT_EQ(1, NumberOfItemsInSection(0)); | 84 ASSERT_EQ(1, NumberOfItemsInSection(0)); |
82 | 85 |
83 [physicalWebController_ | 86 [physicalWebController_ |
84 updatePhysicalWebEnabled:physical_web::kPhysicalWebOn]; | 87 updatePhysicalWebEnabled:physical_web::kPhysicalWebOn]; |
85 } | 88 } |
86 | 89 |
87 } // namespace | 90 } // namespace |
OLD | NEW |