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/about_chrome_collection_view_controller.
h" | 5 #import "ios/chrome/browser/ui/settings/about_chrome_collection_view_controller.
h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #import "base/mac/scoped_nsobject.h" | |
10 #include "ios/chrome/browser/chrome_url_constants.h" | 9 #include "ios/chrome/browser/chrome_url_constants.h" |
11 #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
" |
12 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 11 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
13 #import "ios/chrome/browser/ui/commands/open_url_command.h" | 12 #import "ios/chrome/browser/ui/commands/open_url_command.h" |
14 #include "ios/chrome/grit/ios_strings.h" | 13 #include "ios/chrome/grit/ios_strings.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
17 #include "url/gurl.h" | 16 #include "url/gurl.h" |
18 | 17 |
| 18 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 19 #error "This file requires ARC support." |
| 20 #endif |
| 21 |
19 // An AboutChromeTableViewController that intercepts calls to | 22 // An AboutChromeTableViewController that intercepts calls to |
20 // |chromeExecuteCommand:| in order to test the commands. | 23 // |chromeExecuteCommand:| in order to test the commands. |
21 @interface TestAboutChromeCollectionViewController | 24 @interface TestAboutChromeCollectionViewController |
22 : AboutChromeCollectionViewController | 25 : AboutChromeCollectionViewController |
23 | 26 |
24 // The intercepted chrome command. | 27 // The intercepted chrome command. |
25 @property(nonatomic, readonly) OpenUrlCommand* command; | 28 @property(nonatomic, readonly) OpenUrlCommand* command; |
26 | 29 |
27 @end | 30 @end |
28 | 31 |
29 @implementation TestAboutChromeCollectionViewController { | 32 @implementation TestAboutChromeCollectionViewController { |
30 base::scoped_nsobject<OpenUrlCommand> command_; | 33 OpenUrlCommand* command_; |
31 } | 34 } |
32 | 35 |
33 - (IBAction)chromeExecuteCommand:(id)sender { | 36 - (IBAction)chromeExecuteCommand:(id)sender { |
34 DCHECK([sender isKindOfClass:[OpenUrlCommand class]]); | 37 DCHECK([sender isKindOfClass:[OpenUrlCommand class]]); |
35 command_.reset([static_cast<OpenUrlCommand*>(sender) retain]); | 38 command_ = static_cast<OpenUrlCommand*>(sender); |
36 } | 39 } |
37 | 40 |
38 - (OpenUrlCommand*)command { | 41 - (OpenUrlCommand*)command { |
39 return command_; | 42 return command_; |
40 } | 43 } |
41 | 44 |
42 @end | 45 @end |
43 | 46 |
44 namespace { | 47 namespace { |
45 | 48 |
46 class AboutChromeCollectionViewControllerTest | 49 class AboutChromeCollectionViewControllerTest |
47 : public CollectionViewControllerTest { | 50 : public CollectionViewControllerTest { |
48 public: | 51 public: |
49 CollectionViewController* NewController() override NS_RETURNS_RETAINED { | 52 CollectionViewController* InstantiateController() override { |
50 return [[TestAboutChromeCollectionViewController alloc] init]; | 53 return [[TestAboutChromeCollectionViewController alloc] init]; |
51 } | 54 } |
52 }; | 55 }; |
53 | 56 |
54 TEST_F(AboutChromeCollectionViewControllerTest, TestModel) { | 57 TEST_F(AboutChromeCollectionViewControllerTest, TestModel) { |
55 CreateController(); | 58 CreateController(); |
56 CheckController(); | 59 CheckController(); |
57 | 60 |
58 EXPECT_EQ(2, NumberOfSections()); | 61 EXPECT_EQ(2, NumberOfSections()); |
59 EXPECT_EQ(3, NumberOfItemsInSection(0)); | 62 EXPECT_EQ(3, NumberOfItemsInSection(0)); |
(...skipping 21 matching lines...) Expand all Loading... |
81 | 84 |
82 [about_chrome_controller | 85 [about_chrome_controller |
83 collectionView:about_chrome_controller.collectionView | 86 collectionView:about_chrome_controller.collectionView |
84 didSelectItemAtIndexPath:[NSIndexPath indexPathForItem:2 inSection:0]]; | 87 didSelectItemAtIndexPath:[NSIndexPath indexPathForItem:2 inSection:0]]; |
85 EXPECT_TRUE([about_chrome_controller command]); | 88 EXPECT_TRUE([about_chrome_controller command]); |
86 EXPECT_EQ(GURL(l10n_util::GetStringUTF8(IDS_IOS_PRIVACY_POLICY_URL)), | 89 EXPECT_EQ(GURL(l10n_util::GetStringUTF8(IDS_IOS_PRIVACY_POLICY_URL)), |
87 [about_chrome_controller command].url); | 90 [about_chrome_controller command].url); |
88 } | 91 } |
89 | 92 |
90 } // namespace | 93 } // namespace |
OLD | NEW |