[go: nahoru, domu]

blob: ae131a1a5464da4cf7a74b60a4ab1456e9c07950 [file] [log] [blame]
Gauthier Ambard9f3a49f2022-01-03 13:45:271// Copyright 2022 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/content_settings/default_page_mode_table_view_controller.h"
6
7#import "base/mac/foundation_util.h"
8#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller_test.h"
Gauthier Ambardccb4210c2022-02-10 18:05:069#include "ios/chrome/grit/ios_strings.h"
Gauthier Ambard9f3a49f2022-01-03 13:45:2710#include "testing/gtest_mac.h"
Gauthier Ambardccb4210c2022-02-10 18:05:0611#include "ui/base/l10n/l10n_util.h"
Gauthier Ambard9f3a49f2022-01-03 13:45:2712
13#if !defined(__has_feature) || !__has_feature(objc_arc)
14#error "This file requires ARC support."
15#endif
16
17class DefaultPageModeTableViewControllerTest
18 : public ChromeTableViewControllerTest {
19 protected:
20 ChromeTableViewController* InstantiateController() override {
21 return [[DefaultPageModeTableViewController alloc]
22 initWithStyle:UITableViewStyleGrouped];
23 }
24};
25
26// Tests that there are 2 items in the Table View.
27TEST_F(DefaultPageModeTableViewControllerTest, TestItems) {
28 CreateController();
29 CheckController();
Gauthier Ambardccb4210c2022-02-10 18:05:0630 CheckTitle(l10n_util::GetNSString(IDS_IOS_DEFAULT_PAGE_MODE_TITLE));
Gauthier Ambard9f3a49f2022-01-03 13:45:2731
32 ASSERT_EQ(1, NumberOfSections());
33 ASSERT_EQ(2, NumberOfItemsInSection(0));
Gauthier Ambard6498e1b2022-02-04 10:07:5234 CheckTextCellText(@"Mobile", 0, 0);
35 CheckTextCellText(@"Desktop", 0, 1);
Gauthier Ambard9f3a49f2022-01-03 13:45:2736
37 CheckAccessoryType(UITableViewCellAccessoryNone, 0, 0);
38 CheckAccessoryType(UITableViewCellAccessoryNone, 0, 1);
39}
40
41// Tests that the checkmark gets correctly updated when set before the model is
42// loaded.
43TEST_F(DefaultPageModeTableViewControllerTest, TestCheckmarkAtLoad) {
44 // Load the controller manually as this is testing setting the DefaultPageMode
45 // before the model is loaded.
46 DefaultPageModeTableViewController* controller =
47 [[DefaultPageModeTableViewController alloc]
48 initWithStyle:UITableViewStyleGrouped];
49
50 [controller setDefaultPageMode:DefaultPageModeDesktop];
51
52 [controller loadModel];
53 // Force the tableView to be built.
54 ASSERT_TRUE([controller view]);
55
56 UITableViewCellAccessoryType first_accesory =
57 [controller.tableViewModel
58 itemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]
59 .accessoryType;
60 EXPECT_EQ(UITableViewCellAccessoryNone, first_accesory);
61 UITableViewCellAccessoryType second_accesory =
62 [controller.tableViewModel
63 itemAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]]
64 .accessoryType;
65 EXPECT_EQ(UITableViewCellAccessoryCheckmark, second_accesory);
66}
67
68// Tests that the checkmark gets correctly updated.
69TEST_F(DefaultPageModeTableViewControllerTest, TestCheckmark) {
70 ChromeTableViewController* chrome_controller = controller();
71 DefaultPageModeTableViewController* controller =
72 base::mac::ObjCCastStrict<DefaultPageModeTableViewController>(
73 chrome_controller);
74
75 CheckAccessoryType(UITableViewCellAccessoryNone, 0, 0);
76 CheckAccessoryType(UITableViewCellAccessoryNone, 0, 1);
77
78 [controller setDefaultPageMode:DefaultPageModeMobile];
79
80 CheckAccessoryType(UITableViewCellAccessoryCheckmark, 0, 0);
81 CheckAccessoryType(UITableViewCellAccessoryNone, 0, 1);
82
83 [controller setDefaultPageMode:DefaultPageModeDesktop];
84
85 CheckAccessoryType(UITableViewCellAccessoryNone, 0, 0);
86 CheckAccessoryType(UITableViewCellAccessoryCheckmark, 0, 1);
87}