OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/ui/settings/contextual_search_collection_view_contro
ller.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
| 10 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" |
| 11 #import "ios/chrome/browser/ui/contextual_search/touch_to_search_permissions_med
iator.h" |
| 12 #include "ios/chrome/grit/ios_strings.h" |
| 13 #include "ios/web/public/test/test_web_thread_bundle.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "testing/gtest_mac.h" |
| 16 #include "testing/platform_test.h" |
| 17 #include "ui/base/l10n/l10n_util_mac.h" |
| 18 |
| 19 namespace { |
| 20 |
| 21 class ContextualSearchCollectionViewControllerTest |
| 22 : public CollectionViewControllerTest { |
| 23 protected: |
| 24 ContextualSearchCollectionViewControllerTest() { |
| 25 TestChromeBrowserState::Builder browserStateBuilder; |
| 26 browser_state_ = browserStateBuilder.Build(); |
| 27 tts_permissions_.reset([[TouchToSearchPermissionsMediator alloc] |
| 28 initWithBrowserState:browser_state_.get()]); |
| 29 } |
| 30 |
| 31 CollectionViewController* NewController() override NS_RETURNS_RETAINED { |
| 32 return [[ContextualSearchCollectionViewController alloc] |
| 33 initWithPermissions:tts_permissions_]; |
| 34 } |
| 35 |
| 36 web::TestWebThreadBundle thread_bundle_; |
| 37 std::unique_ptr<TestChromeBrowserState> browser_state_; |
| 38 base::scoped_nsobject<TouchToSearchPermissionsMediator> tts_permissions_; |
| 39 }; |
| 40 |
| 41 TEST_F(ContextualSearchCollectionViewControllerTest, |
| 42 TestModelContextualSearchOff) { |
| 43 [tts_permissions_ setPreferenceState:TouchToSearch::DISABLED]; |
| 44 CreateController(); |
| 45 CheckController(); |
| 46 EXPECT_EQ(2, NumberOfSections()); |
| 47 EXPECT_EQ(1, NumberOfItemsInSection(0)); |
| 48 CheckSwitchCellStateAndTitleWithId(NO, IDS_IOS_CONTEXTUAL_SEARCH_TITLE, 0, 0); |
| 49 } |
| 50 |
| 51 TEST_F(ContextualSearchCollectionViewControllerTest, |
| 52 TestModelContextualSearchOn) { |
| 53 [tts_permissions_ setPreferenceState:TouchToSearch::ENABLED]; |
| 54 CreateController(); |
| 55 EXPECT_EQ(2, NumberOfSections()); |
| 56 EXPECT_EQ(1, NumberOfItemsInSection(0)); |
| 57 CheckSwitchCellStateAndTitleWithId(YES, IDS_IOS_CONTEXTUAL_SEARCH_TITLE, 0, |
| 58 0); |
| 59 } |
| 60 |
| 61 TEST_F(ContextualSearchCollectionViewControllerTest, |
| 62 TestModelContextualSearchUndecided) { |
| 63 [tts_permissions_ setPreferenceState:TouchToSearch::UNDECIDED]; |
| 64 CreateController(); |
| 65 EXPECT_EQ(2, NumberOfSections()); |
| 66 EXPECT_EQ(1, NumberOfItemsInSection(0)); |
| 67 CheckSwitchCellStateAndTitleWithId(YES, IDS_IOS_CONTEXTUAL_SEARCH_TITLE, 0, |
| 68 0); |
| 69 } |
| 70 |
| 71 } // namespace |
OLD | NEW |