Commit cf877fb4 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Creates ChromeTableViewController

-Creates ChromeTableViewController with basic unittests.
-Implements basic UITableViewDataSource methods.

Bug: 805136
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Idbc59f0c0b71c01b9c8513e8bd7907b0f9713971
Reviewed-on: https://chromium-review.googlesource.com/915261
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536942}
parent 6de124ad
...@@ -3,18 +3,30 @@ ...@@ -3,18 +3,30 @@
# found in the LICENSE file. # found in the LICENSE file.
source_set("table_view") { source_set("table_view") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
"chrome_table_view_controller.h",
"chrome_table_view_controller.mm",
"table_view_model.h", "table_view_model.h",
"table_view_model.mm", "table_view_model.mm",
] ]
deps = [ deps = [
"//ios/chrome/browser/ui/list_model", "//ios/chrome/browser/ui/list_model",
] ]
public_deps = [ public_deps = [
"//ios/chrome/browser/ui/table_view/cells", "//ios/chrome/browser/ui/table_view/cells",
] ]
}
source_set("unit_tests") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"chrome_table_view_controller_unittest.mm",
]
deps = [
":table_view",
"//ios/chrome/browser/ui/table_view/cells",
"//testing/gtest",
]
} }
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_TABLE_VIEW_CHROME_TABLE_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_TABLE_VIEW_CHROME_TABLE_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/table_view/table_view_model.h"
@class TableViewItem;
// Chrome-specific TableViewController.
@interface ChromeTableViewController : UITableViewController
// The model of this controller.
@property(nonatomic, readonly, strong)
TableViewModel<TableViewItem*>* tableViewModel;
// Initializes the collection view model. Must be called by subclasses if they
// override this method in order to get a clean tableViewModel.
- (void)loadModel NS_REQUIRES_SUPER;
@end
#endif // IOS_CHROME_BROWSER_UI_TABLE_VIEW_CHROME_TABLE_VIEW_CONTROLLER_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_item.h"
#import "ios/chrome/browser/ui/table_view/table_view_model.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation ChromeTableViewController
@synthesize tableViewModel = _tableViewModel;
#pragma mark - Public Interface
- (void)loadModel {
_tableViewModel = [[TableViewModel alloc] init];
}
#pragma mark - UITableViewDataSource
- (UITableViewCell*)tableView:(UITableView*)tableView
cellForRowAtIndexPath:(NSIndexPath*)indexPath {
TableViewItem* item = [self.tableViewModel itemAtIndexPath:indexPath];
Class cellClass = [item cellClass];
NSString* reuseIdentifier = NSStringFromClass(cellClass);
[self.tableView registerClass:cellClass
forCellReuseIdentifier:reuseIdentifier];
UITableViewCell* cell =
[self.tableView dequeueReusableCellWithIdentifier:reuseIdentifier
forIndexPath:indexPath];
[item configureCell:cell];
return cell;
}
- (NSInteger)tableView:(UITableView*)tableView
numberOfRowsInSection:(NSInteger)section {
return [self.tableViewModel numberOfItemsInSection:section];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {
return [self.tableViewModel numberOfSections];
}
@end
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_item.h"
#import "ios/chrome/browser/ui/table_view/table_view_model.h"
#include "testing/platform_test.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// Checks that key methods are called.
// TableViewItem can't easily be mocked via OCMock as one of the methods to
// mock returns a Class type.
@interface FakeTableViewItem : TableViewItem
@property(nonatomic, assign) BOOL configureCellCalled;
@end
@implementation FakeTableViewItem
@synthesize configureCellCalled = _configureCellCalled;
- (void)configureCell:(UITableViewCell*)cell {
self.configureCellCalled = YES;
[super configureCell:cell];
}
@end
namespace {
typedef NS_ENUM(NSInteger, SectionIdentifier) {
SectionIdentifierFoo = kSectionIdentifierEnumZero,
};
typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeFooBar = kItemTypeEnumZero,
};
using ChromeTableViewControllerTest = PlatformTest;
TEST_F(ChromeTableViewControllerTest, CellForItemAtIndexPath) {
ChromeTableViewController* controller =
[[ChromeTableViewController alloc] initWithStyle:UITableViewStylePlain];
[controller loadModel];
[[controller tableViewModel] addSectionWithIdentifier:SectionIdentifierFoo];
FakeTableViewItem* someItem =
[[FakeTableViewItem alloc] initWithType:ItemTypeFooBar];
[[controller tableViewModel] addItem:someItem
toSectionWithIdentifier:SectionIdentifierFoo];
ASSERT_EQ(NO, [someItem configureCellCalled]);
[controller tableView:[controller tableView]
cellForRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
EXPECT_EQ(YES, [someItem configureCellCalled]);
}
} // namespace
...@@ -220,6 +220,7 @@ test("ios_chrome_unittests") { ...@@ -220,6 +220,7 @@ test("ios_chrome_unittests") {
"//ios/chrome/browser/ui/stack_view:unit_tests", "//ios/chrome/browser/ui/stack_view:unit_tests",
"//ios/chrome/browser/ui/static_content:unit_tests", "//ios/chrome/browser/ui/static_content:unit_tests",
"//ios/chrome/browser/ui/tab_switcher:unit_tests", "//ios/chrome/browser/ui/tab_switcher:unit_tests",
"//ios/chrome/browser/ui/table_view:unit_tests",
"//ios/chrome/browser/ui/table_view/cells:unit_tests", "//ios/chrome/browser/ui/table_view/cells:unit_tests",
"//ios/chrome/browser/ui/tabs:unit_tests", "//ios/chrome/browser/ui/tabs:unit_tests",
"//ios/chrome/browser/ui/toolbar:unit_tests", "//ios/chrome/browser/ui/toolbar:unit_tests",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment