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/about_chrome_collection_view_controller.
h" |
| 6 |
| 7 #include "base/compiler_specific.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/mac/scoped_nsobject.h" |
| 10 #include "ios/chrome/browser/chrome_url_constants.h" |
| 11 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" |
| 12 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 13 #import "ios/chrome/browser/ui/commands/open_url_command.h" |
| 14 #include "ios/chrome/grit/ios_strings.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "url/gurl.h" |
| 18 |
| 19 // An AboutChromeTableViewController that intercepts calls to |
| 20 // |chromeExecuteCommand:| in order to test the commands. |
| 21 @interface TestAboutChromeCollectionViewController |
| 22 : AboutChromeCollectionViewController |
| 23 |
| 24 // The intercepted chrome command. |
| 25 @property(nonatomic, readonly) OpenUrlCommand* command; |
| 26 |
| 27 @end |
| 28 |
| 29 @implementation TestAboutChromeCollectionViewController { |
| 30 base::scoped_nsobject<OpenUrlCommand> command_; |
| 31 } |
| 32 |
| 33 - (IBAction)chromeExecuteCommand:(id)sender { |
| 34 DCHECK([sender isKindOfClass:[OpenUrlCommand class]]); |
| 35 command_.reset([static_cast<OpenUrlCommand*>(sender) retain]); |
| 36 } |
| 37 |
| 38 - (OpenUrlCommand*)command { |
| 39 return command_; |
| 40 } |
| 41 |
| 42 @end |
| 43 |
| 44 namespace { |
| 45 |
| 46 class AboutChromeCollectionViewControllerTest |
| 47 : public CollectionViewControllerTest { |
| 48 public: |
| 49 CollectionViewController* NewController() override NS_RETURNS_RETAINED { |
| 50 return [[TestAboutChromeCollectionViewController alloc] init]; |
| 51 } |
| 52 }; |
| 53 |
| 54 TEST_F(AboutChromeCollectionViewControllerTest, TestModel) { |
| 55 CreateController(); |
| 56 CheckController(); |
| 57 |
| 58 EXPECT_EQ(2, NumberOfSections()); |
| 59 EXPECT_EQ(3, NumberOfItemsInSection(0)); |
| 60 CheckTextCellTitleWithId(IDS_IOS_OPEN_SOURCE_LICENSES, 0, 0); |
| 61 CheckTextCellTitleWithId(IDS_IOS_TERMS_OF_SERVICE, 0, 1); |
| 62 CheckTextCellTitleWithId(IDS_IOS_PRIVACY_POLICY, 0, 2); |
| 63 } |
| 64 |
| 65 TEST_F(AboutChromeCollectionViewControllerTest, TestOpenUrls) { |
| 66 CreateController(); |
| 67 |
| 68 TestAboutChromeCollectionViewController* about_chrome_controller = |
| 69 static_cast<TestAboutChromeCollectionViewController*>(controller()); |
| 70 [about_chrome_controller |
| 71 collectionView:about_chrome_controller.collectionView |
| 72 didSelectItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; |
| 73 EXPECT_TRUE([about_chrome_controller command]); |
| 74 EXPECT_EQ(GURL(kChromeUICreditsURL), [about_chrome_controller command].url); |
| 75 |
| 76 [about_chrome_controller |
| 77 collectionView:about_chrome_controller.collectionView |
| 78 didSelectItemAtIndexPath:[NSIndexPath indexPathForItem:1 inSection:0]]; |
| 79 EXPECT_TRUE([about_chrome_controller command]); |
| 80 EXPECT_EQ(GURL(kChromeUITermsURL), [about_chrome_controller command].url); |
| 81 |
| 82 [about_chrome_controller |
| 83 collectionView:about_chrome_controller.collectionView |
| 84 didSelectItemAtIndexPath:[NSIndexPath indexPathForItem:2 inSection:0]]; |
| 85 EXPECT_TRUE([about_chrome_controller command]); |
| 86 EXPECT_EQ(GURL(l10n_util::GetStringUTF8(IDS_IOS_PRIVACY_POLICY_URL)), |
| 87 [about_chrome_controller command].url); |
| 88 } |
| 89 |
| 90 } // namespace |
OLD | NEW |