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