Avi Drissman | ea1be23 | 2022-09-14 23:29:06 | [diff] [blame] | 1 | // Copyright 2022 The Chromium Authors |
Gauthier Ambard | 9f3a49f | 2022-01-03 13:45:27 | [diff] [blame] | 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/content_settings/default_page_mode_table_view_controller.h" |
| 6 | |
Avi Drissman | eac566b0 | 2023-08-18 02:56:21 | [diff] [blame^] | 7 | #import "base/apple/foundation_util.h" |
Gauthier Ambard | 287c1a1a | 2023-03-14 10:33:43 | [diff] [blame] | 8 | #import "ios/chrome/browser/shared/ui/table_view/chrome_table_view_controller_test.h" |
Gauthier Ambard | 999088c | 2022-09-13 08:36:57 | [diff] [blame] | 9 | #import "ios/chrome/grit/ios_strings.h" |
| 10 | #import "testing/gtest_mac.h" |
| 11 | #import "ui/base/l10n/l10n_util.h" |
Gauthier Ambard | 9f3a49f | 2022-01-03 13:45:27 | [diff] [blame] | 12 | |
Gauthier Ambard | 9f3a49f | 2022-01-03 13:45:27 | [diff] [blame] | 13 | class DefaultPageModeTableViewControllerTest |
| 14 | : public ChromeTableViewControllerTest { |
| 15 | protected: |
| 16 | ChromeTableViewController* InstantiateController() override { |
| 17 | return [[DefaultPageModeTableViewController alloc] |
| 18 | initWithStyle:UITableViewStyleGrouped]; |
| 19 | } |
| 20 | }; |
| 21 | |
| 22 | // Tests that there are 2 items in the Table View. |
| 23 | TEST_F(DefaultPageModeTableViewControllerTest, TestItems) { |
| 24 | CreateController(); |
| 25 | CheckController(); |
Gauthier Ambard | ccb4210c | 2022-02-10 18:05:06 | [diff] [blame] | 26 | CheckTitle(l10n_util::GetNSString(IDS_IOS_DEFAULT_PAGE_MODE_TITLE)); |
Gauthier Ambard | 9f3a49f | 2022-01-03 13:45:27 | [diff] [blame] | 27 | |
| 28 | ASSERT_EQ(1, NumberOfSections()); |
| 29 | ASSERT_EQ(2, NumberOfItemsInSection(0)); |
Gauthier Ambard | 6498e1b | 2022-02-04 10:07:52 | [diff] [blame] | 30 | CheckTextCellText(@"Mobile", 0, 0); |
| 31 | CheckTextCellText(@"Desktop", 0, 1); |
Gauthier Ambard | 9f3a49f | 2022-01-03 13:45:27 | [diff] [blame] | 32 | |
| 33 | CheckAccessoryType(UITableViewCellAccessoryNone, 0, 0); |
| 34 | CheckAccessoryType(UITableViewCellAccessoryNone, 0, 1); |
| 35 | } |
| 36 | |
| 37 | // Tests that the checkmark gets correctly updated when set before the model is |
| 38 | // loaded. |
| 39 | TEST_F(DefaultPageModeTableViewControllerTest, TestCheckmarkAtLoad) { |
| 40 | // Load the controller manually as this is testing setting the DefaultPageMode |
| 41 | // before the model is loaded. |
| 42 | DefaultPageModeTableViewController* controller = |
| 43 | [[DefaultPageModeTableViewController alloc] |
| 44 | initWithStyle:UITableViewStyleGrouped]; |
| 45 | |
| 46 | [controller setDefaultPageMode:DefaultPageModeDesktop]; |
| 47 | |
| 48 | [controller loadModel]; |
| 49 | // Force the tableView to be built. |
| 50 | ASSERT_TRUE([controller view]); |
| 51 | |
| 52 | UITableViewCellAccessoryType first_accesory = |
| 53 | [controller.tableViewModel |
| 54 | itemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] |
| 55 | .accessoryType; |
| 56 | EXPECT_EQ(UITableViewCellAccessoryNone, first_accesory); |
| 57 | UITableViewCellAccessoryType second_accesory = |
| 58 | [controller.tableViewModel |
| 59 | itemAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]] |
| 60 | .accessoryType; |
| 61 | EXPECT_EQ(UITableViewCellAccessoryCheckmark, second_accesory); |
| 62 | } |
| 63 | |
| 64 | // Tests that the checkmark gets correctly updated. |
| 65 | TEST_F(DefaultPageModeTableViewControllerTest, TestCheckmark) { |
| 66 | ChromeTableViewController* chrome_controller = controller(); |
| 67 | DefaultPageModeTableViewController* controller = |
Avi Drissman | eac566b0 | 2023-08-18 02:56:21 | [diff] [blame^] | 68 | base::apple::ObjCCastStrict<DefaultPageModeTableViewController>( |
Gauthier Ambard | 9f3a49f | 2022-01-03 13:45:27 | [diff] [blame] | 69 | chrome_controller); |
| 70 | |
| 71 | CheckAccessoryType(UITableViewCellAccessoryNone, 0, 0); |
| 72 | CheckAccessoryType(UITableViewCellAccessoryNone, 0, 1); |
| 73 | |
| 74 | [controller setDefaultPageMode:DefaultPageModeMobile]; |
| 75 | |
| 76 | CheckAccessoryType(UITableViewCellAccessoryCheckmark, 0, 0); |
| 77 | CheckAccessoryType(UITableViewCellAccessoryNone, 0, 1); |
| 78 | |
| 79 | [controller setDefaultPageMode:DefaultPageModeDesktop]; |
| 80 | |
| 81 | CheckAccessoryType(UITableViewCellAccessoryNone, 0, 0); |
| 82 | CheckAccessoryType(UITableViewCellAccessoryCheckmark, 0, 1); |
| 83 | } |