| OLD | NEW |
| 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/contextual_search_collection_view_contro
ller.h" | 5 #import "ios/chrome/browser/ui/settings/contextual_search_collection_view_contro
ller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | 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
" | 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" | 11 #import "ios/chrome/browser/ui/contextual_search/touch_to_search_permissions_med
iator.h" |
| 12 #include "ios/chrome/grit/ios_strings.h" | 12 #include "ios/chrome/grit/ios_strings.h" |
| 13 #include "ios/web/public/test/test_web_thread_bundle.h" | 13 #include "ios/web/public/test/test_web_thread_bundle.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #import "testing/gtest_mac.h" | 15 #import "testing/gtest_mac.h" |
| 16 #include "testing/platform_test.h" | 16 #include "testing/platform_test.h" |
| 17 #include "ui/base/l10n/l10n_util_mac.h" | 17 #include "ui/base/l10n/l10n_util_mac.h" |
| 18 | 18 |
| 19 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 20 #error "This file requires ARC support." |
| 21 #endif |
| 22 |
| 19 namespace { | 23 namespace { |
| 20 | 24 |
| 21 class ContextualSearchCollectionViewControllerTest | 25 class ContextualSearchCollectionViewControllerTest |
| 22 : public CollectionViewControllerTest { | 26 : public CollectionViewControllerTest { |
| 23 protected: | 27 protected: |
| 24 ContextualSearchCollectionViewControllerTest() { | 28 ContextualSearchCollectionViewControllerTest() { |
| 25 TestChromeBrowserState::Builder browserStateBuilder; | 29 TestChromeBrowserState::Builder browserStateBuilder; |
| 26 browser_state_ = browserStateBuilder.Build(); | 30 browser_state_ = browserStateBuilder.Build(); |
| 27 tts_permissions_.reset([[TouchToSearchPermissionsMediator alloc] | 31 tts_permissions_ = [[TouchToSearchPermissionsMediator alloc] |
| 28 initWithBrowserState:browser_state_.get()]); | 32 initWithBrowserState:browser_state_.get()]; |
| 29 } | 33 } |
| 30 | 34 |
| 31 CollectionViewController* NewController() override NS_RETURNS_RETAINED { | 35 CollectionViewController* InstantiateController() override { |
| 32 return [[ContextualSearchCollectionViewController alloc] | 36 return [[ContextualSearchCollectionViewController alloc] |
| 33 initWithPermissions:tts_permissions_]; | 37 initWithPermissions:tts_permissions_]; |
| 34 } | 38 } |
| 35 | 39 |
| 36 web::TestWebThreadBundle thread_bundle_; | 40 web::TestWebThreadBundle thread_bundle_; |
| 37 std::unique_ptr<TestChromeBrowserState> browser_state_; | 41 std::unique_ptr<TestChromeBrowserState> browser_state_; |
| 38 base::scoped_nsobject<TouchToSearchPermissionsMediator> tts_permissions_; | 42 TouchToSearchPermissionsMediator* tts_permissions_; |
| 39 }; | 43 }; |
| 40 | 44 |
| 41 TEST_F(ContextualSearchCollectionViewControllerTest, | 45 TEST_F(ContextualSearchCollectionViewControllerTest, |
| 42 TestModelContextualSearchOff) { | 46 TestModelContextualSearchOff) { |
| 43 [tts_permissions_ setPreferenceState:TouchToSearch::DISABLED]; | 47 [tts_permissions_ setPreferenceState:TouchToSearch::DISABLED]; |
| 44 CreateController(); | 48 CreateController(); |
| 45 CheckController(); | 49 CheckController(); |
| 46 EXPECT_EQ(2, NumberOfSections()); | 50 EXPECT_EQ(2, NumberOfSections()); |
| 47 EXPECT_EQ(1, NumberOfItemsInSection(0)); | 51 EXPECT_EQ(1, NumberOfItemsInSection(0)); |
| 48 CheckSwitchCellStateAndTitleWithId(NO, IDS_IOS_CONTEXTUAL_SEARCH_TITLE, 0, 0); | 52 CheckSwitchCellStateAndTitleWithId(NO, IDS_IOS_CONTEXTUAL_SEARCH_TITLE, 0, 0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 62 TestModelContextualSearchUndecided) { | 66 TestModelContextualSearchUndecided) { |
| 63 [tts_permissions_ setPreferenceState:TouchToSearch::UNDECIDED]; | 67 [tts_permissions_ setPreferenceState:TouchToSearch::UNDECIDED]; |
| 64 CreateController(); | 68 CreateController(); |
| 65 EXPECT_EQ(2, NumberOfSections()); | 69 EXPECT_EQ(2, NumberOfSections()); |
| 66 EXPECT_EQ(1, NumberOfItemsInSection(0)); | 70 EXPECT_EQ(1, NumberOfItemsInSection(0)); |
| 67 CheckSwitchCellStateAndTitleWithId(YES, IDS_IOS_CONTEXTUAL_SEARCH_TITLE, 0, | 71 CheckSwitchCellStateAndTitleWithId(YES, IDS_IOS_CONTEXTUAL_SEARCH_TITLE, 0, |
| 68 0); | 72 0); |
| 69 } | 73 } |
| 70 | 74 |
| 71 } // namespace | 75 } // namespace |
| OLD | NEW |