Commit 454efabe authored by Gregory Chatzinoff's avatar Gregory Chatzinoff Committed by Commit Bot

Revert "Add the header section to ContentSuggestions"

This reverts commit ce6be2e5.

Reason for revert: This CL along with https://chromium-review.googlesource.com/c/536915/ broke a variety of external
url tests on ipad 32-bit configs.

Original change's description:
> Add the header section to ContentSuggestions
> 
> ContentSuggestions is supposed to replace the current NTP and display the logo
> and the fake omnibox.
> This CL adds the section which will contain the header to the content suggestions.
> 
> Bug: 700375
> Change-Id: I4b9eac70b0464b3e289daf036323398b7704ba9f
> Reviewed-on: https://chromium-review.googlesource.com/538693
> Commit-Queue: Gauthier Ambard <gambard@chromium.org>
> Reviewed-by: Louis Romero <lpromero@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#480763}

TBR=lpromero@chromium.org,gambard@chromium.org

Change-Id: I4b6d25b4852428d73f077168cba57d302dd5ca8a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 700375
Reviewed-on: https://chromium-review.googlesource.com/541760Reviewed-by: default avatarGregory Chatzinoff <gchatz@chromium.org>
Commit-Queue: Gregory Chatzinoff <gchatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#480956}
parent 00f82a9f
......@@ -9,7 +9,6 @@ source_set("content_suggestions") {
"content_suggestions_category_wrapper.mm",
"content_suggestions_coordinator.h",
"content_suggestions_coordinator.mm",
"content_suggestions_header_provider.h",
"content_suggestions_mediator.h",
"content_suggestions_mediator.mm",
"content_suggestions_service_bridge_observer.h",
......
// Copyright 2017 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_CONTENT_SUGGESTIONS_CONTENT_SUGGESTIONS_HEADER_PROVIDER_H_
#define IOS_CHROME_BROWSER_CONTENT_SUGGESTIONS_CONTENT_SUGGESTIONS_HEADER_PROVIDER_H_
// Object providing a header view for the content suggestions.
@protocol ContentSuggestionsHeaderProvider
- (nullable UIView*)header;
@end
#endif // IOS_CHROME_BROWSER_CONTENT_SUGGESTIONS_CONTENT_SUGGESTIONS_HEADER_PROVIDER_H_
......@@ -25,7 +25,6 @@ class MostVisitedSites;
}
@protocol ContentSuggestionsCommands;
@protocol ContentSuggestionsHeaderProvider;
@class ContentSuggestionIdentifier;
class GURL;
......@@ -49,9 +48,6 @@ initWithContentService:
@property(nonatomic, weak, nullable) id<ContentSuggestionsCommands>
commandHandler;
@property(nonatomic, weak, nullable) id<ContentSuggestionsHeaderProvider>
headerProvider;
// Blacklists the URL from the Most Visited sites.
- (void)blacklistMostVisitedURL:(GURL)URL;
......
......@@ -15,7 +15,6 @@
#include "components/ntp_tiles/most_visited_sites.h"
#include "components/ntp_tiles/ntp_tile.h"
#import "ios/chrome/browser/content_suggestions/content_suggestions_category_wrapper.h"
#import "ios/chrome/browser/content_suggestions/content_suggestions_header_provider.h"
#import "ios/chrome/browser/content_suggestions/content_suggestions_service_bridge_observer.h"
#import "ios/chrome/browser/content_suggestions/mediator_util.h"
#include "ios/chrome/browser/ntp_tiles/most_visited_sites_observer_bridge.h"
......@@ -61,9 +60,6 @@ const NSInteger kMaxNumMostVisitedTiles = 8;
// the callback). Those items are up to date with the model.
@property(nonatomic, strong)
NSMutableArray<ContentSuggestionsMostVisitedItem*>* freshMostVisitedItems;
// Section Info for the logo and omnibox section.
@property(nonatomic, strong)
ContentSuggestionsSectionInformation* logoSectionInfo;
// Section Info for the Most Visited section.
@property(nonatomic, strong)
ContentSuggestionsSectionInformation* mostVisitedSectionInfo;
......@@ -87,7 +83,6 @@ const NSInteger kMaxNumMostVisitedTiles = 8;
@synthesize mostVisitedItems = _mostVisitedItems;
@synthesize freshMostVisitedItems = _freshMostVisitedItems;
@synthesize logoSectionInfo = _logoSectionInfo;
@synthesize mostVisitedSectionInfo = _mostVisitedSectionInfo;
@synthesize recordedPageImpression = _recordedPageImpression;
@synthesize contentService = _contentService;
......@@ -95,7 +90,6 @@ const NSInteger kMaxNumMostVisitedTiles = 8;
@synthesize sectionInformationByCategory = _sectionInformationByCategory;
@synthesize attributesProvider = _attributesProvider;
@synthesize commandHandler = _commandHandler;
@synthesize headerProvider = _headerProvider;
#pragma mark - Public
......@@ -116,7 +110,6 @@ initWithContentService:(ntp_snippets::ContentSuggestionsService*)contentService
largeIconService:largeIconService];
_mostVisitedSectionInfo = MostVisitedSectionInformation();
_logoSectionInfo = LogoSectionInformation();
_mostVisitedSites = std::move(mostVisitedSites);
_mostVisitedBridge =
base::MakeUnique<ntp_tiles::MostVisitedSitesObserverBridge>(self);
......@@ -142,8 +135,6 @@ initWithContentService:(ntp_snippets::ContentSuggestionsService*)contentService
NSMutableArray<ContentSuggestionsSectionInformation*>* sectionsInfo =
[NSMutableArray array];
[sectionsInfo addObject:self.logoSectionInfo];
if (self.mostVisitedItems.count > 0) {
[sectionsInfo addObject:self.mostVisitedSectionInfo];
}
......@@ -168,9 +159,7 @@ initWithContentService:(ntp_snippets::ContentSuggestionsService*)contentService
NSMutableArray<CSCollectionViewItem*>* convertedSuggestions =
[NSMutableArray array];
if (sectionInfo == self.logoSectionInfo) {
// TODO(crbug.com/732416): Add promo.
} else if (sectionInfo == self.mostVisitedSectionInfo) {
if (sectionInfo == self.mostVisitedSectionInfo) {
[convertedSuggestions addObjectsFromArray:self.mostVisitedItems];
} else {
ntp_snippets::Category category =
......@@ -256,14 +245,14 @@ initWithContentService:(ntp_snippets::ContentSuggestionsService*)contentService
ContentSuggestionsSectionInformation* sectionInfo =
item.suggestionIdentifier.sectionInfo;
GURL url;
if ([self isRelatedToContentSuggestionsService:sectionInfo]) {
ContentSuggestionsItem* suggestionItem =
base::mac::ObjCCast<ContentSuggestionsItem>(item);
url = suggestionItem.URL;
} else if (sectionInfo == self.mostVisitedSectionInfo) {
if (![self isRelatedToContentSuggestionsService:sectionInfo]) {
ContentSuggestionsMostVisitedItem* mostVisited =
base::mac::ObjCCast<ContentSuggestionsMostVisitedItem>(item);
url = mostVisited.URL;
} else {
ContentSuggestionsItem* suggestionItem =
base::mac::ObjCCast<ContentSuggestionsItem>(item);
url = suggestionItem.URL;
}
[self.attributesProvider fetchFaviconAttributesForURL:url
completion:completion];
......@@ -309,10 +298,6 @@ initWithContentService:(ntp_snippets::ContentSuggestionsService*)contentService
self.contentService->DismissSuggestion(suggestion_id);
}
- (UIView*)headerView {
return [self.headerProvider header];
}
#pragma mark - ContentSuggestionsServiceObserver
- (void)contentSuggestionsService:
......@@ -488,8 +473,7 @@ initWithContentService:(ntp_snippets::ContentSuggestionsService*)contentService
// content suggestions service.
- (BOOL)isRelatedToContentSuggestionsService:
(ContentSuggestionsSectionInformation*)sectionInfo {
return sectionInfo != self.mostVisitedSectionInfo &&
sectionInfo != self.logoSectionInfo;
return sectionInfo != self.mostVisitedSectionInfo;
}
// Replaces the Most Visited items currently displayed by the most recent ones.
......
......@@ -54,10 +54,6 @@ ntp_snippets::ContentSuggestion::ID SuggestionIDForSectionID(
ContentSuggestionsCategoryWrapper* category,
const std::string& id_in_category);
// Creates and returns a SectionInfo for the section containing the logo and
// omnibox.
ContentSuggestionsSectionInformation* LogoSectionInformation();
// Creates and returns a SectionInfo for the Most Visited section.
ContentSuggestionsSectionInformation* MostVisitedSectionInformation();
......
......@@ -100,18 +100,6 @@ ntp_snippets::ContentSuggestion::ID SuggestionIDForSectionID(
return ntp_snippets::ContentSuggestion::ID(category.category, id_in_category);
}
ContentSuggestionsSectionInformation* LogoSectionInformation() {
ContentSuggestionsSectionInformation* sectionInfo =
[[ContentSuggestionsSectionInformation alloc]
initWithSectionID:ContentSuggestionsSectionLogo];
sectionInfo.title = nil;
sectionInfo.footerTitle = nil;
sectionInfo.showIfEmpty = YES;
sectionInfo.layout = ContentSuggestionsSectionLayoutCustom;
return sectionInfo;
}
ContentSuggestionsSectionInformation* MostVisitedSectionInformation() {
ContentSuggestionsSectionInformation* sectionInfo =
[[ContentSuggestionsSectionInformation alloc]
......
......@@ -29,8 +29,6 @@ source_set("cells_ui") {
"content_suggestions_cell.mm",
"content_suggestions_footer_item.h",
"content_suggestions_footer_item.mm",
"content_suggestions_header_item.h",
"content_suggestions_header_item.mm",
"content_suggestions_most_visited_cell.h",
"content_suggestions_most_visited_cell.mm",
"content_suggestions_text_item.h",
......@@ -54,7 +52,6 @@ source_set("unit_tests") {
testonly = true
sources = [
"content_suggestions_footer_item_unittest.mm",
"content_suggestions_header_item_unittest.mm",
"content_suggestions_item_unittest.mm",
"content_suggestions_most_visited_item_unittest.mm",
]
......
// Copyright 2017 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_CONTENT_SUGGESTIONS_CELLS_CONTENT_SUGGESTIONS_HEADER_ITEM_H_
#define IOS_CHROME_BROWSER_UI_CONTENT_SUGGESTIONS_CELLS_CONTENT_SUGGESTIONS_HEADER_ITEM_H_
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/third_party/material_components_ios/src/components/CollectionCells/src/MaterialCollectionCells.h"
// Item to display a view cell.
@interface ContentSuggestionsHeaderItem : CollectionViewItem
// The view to be displayed.
@property(nonatomic, strong) UIView* view;
@end
// Corresponding cell.
@interface ContentSuggestionsHeaderCell : MDCCollectionViewCell
// The header view to be displayed.
@property(nonatomic, strong) UIView* headerView;
@end
#endif // IOS_CHROME_BROWSER_UI_CONTENT_SUGGESTIONS_CELLS_CONTENT_SUGGESTIONS_HEADER_ITEM_H_
// Copyright 2017 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/content_suggestions/cells/content_suggestions_header_item.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation ContentSuggestionsHeaderItem
@synthesize view;
- (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type];
if (self) {
self.cellClass = [ContentSuggestionsHeaderCell class];
}
return self;
}
- (void)configureCell:(ContentSuggestionsHeaderCell*)cell {
[super configureCell:cell];
[cell setHeaderView:self.view];
}
@end
@implementation ContentSuggestionsHeaderCell
@synthesize headerView = _headerView;
- (void)setHeaderView:(UIView*)header {
[_headerView removeFromSuperview];
_headerView = header;
if (!header)
return;
header.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:header];
AddSameConstraints(self.contentView, header);
}
- (void)prepareForReuse {
[super prepareForReuse];
self.headerView = nil;
}
@end
// Copyright 2017 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/content_suggestions/cells/content_suggestions_header_item.h"
#include "testing/gtest/include/gtest/gtest.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
TEST(ContentSuggestionsHeaderItemTest, CellClass) {
// Setup.
ContentSuggestionsHeaderItem* item =
[[ContentSuggestionsHeaderItem alloc] initWithType:0];
// Action.
ContentSuggestionsHeaderCell* cell = [[[item cellClass] alloc] init];
// Test.
EXPECT_EQ([ContentSuggestionsHeaderCell class], [cell class]);
}
TEST(ContentSuggestionsHeaderItemTest, Configure) {
// Setup.
UIView* view = [[UIView alloc] init];
ContentSuggestionsHeaderItem* item =
[[ContentSuggestionsHeaderItem alloc] initWithType:0];
item.view = view;
ContentSuggestionsHeaderCell* cell = [[[item cellClass] alloc] init];
// Action.
[item configureCell:cell];
// Test.
ASSERT_EQ(1U, [cell.contentView.subviews count]);
EXPECT_EQ(view, cell.contentView.subviews[0]);
}
}
......@@ -65,7 +65,6 @@ addSuggestionsToModel:
// Adds an empty item to this |section| and returns its index path. The updater
// does not do any check about the number of elements in the section.
// Returns nil if there is no empty item for this section.
- (NSIndexPath*)addEmptyItemForSection:(NSInteger)section;
// Returns whether |section| contains the Most Visited tiles.
......
......@@ -14,7 +14,6 @@
#import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_footer_item.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_header_item.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_text_item.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/suggested_content.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_utils.h"
......@@ -44,7 +43,6 @@ typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeEmpty,
ItemTypeReadingList,
ItemTypeMostVisited,
ItemTypePromo,
ItemTypeUnknown,
};
......@@ -54,7 +52,6 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) {
SectionIdentifierArticles = kSectionIdentifierEnumZero,
SectionIdentifierReadingList,
SectionIdentifierMostVisited,
SectionIdentifierLogo,
SectionIdentifierDefault,
};
......@@ -74,7 +71,7 @@ ContentSuggestionType ContentSuggestionTypeForItemType(NSInteger type) {
return ContentSuggestionTypeEmpty;
}
// Returns the item type corresponding to the section |info|.
// Returns the section identifier corresponding to the section |info|.
ItemType ItemTypeForInfo(ContentSuggestionsSectionInformation* info) {
switch (info.sectionID) {
case ContentSuggestionsSectionArticles:
......@@ -83,8 +80,6 @@ ItemType ItemTypeForInfo(ContentSuggestionsSectionInformation* info) {
return ItemTypeReadingList;
case ContentSuggestionsSectionMostVisited:
return ItemTypeMostVisited;
case ContentSuggestionsSectionLogo:
return ItemTypePromo;
case ContentSuggestionsSectionUnknown:
return ItemTypeUnknown;
......@@ -101,8 +96,6 @@ SectionIdentifier SectionIdentifierForInfo(
return SectionIdentifierReadingList;
case ContentSuggestionsSectionMostVisited:
return SectionIdentifierMostVisited;
case ContentSuggestionsSectionLogo:
return SectionIdentifierLogo;
case ContentSuggestionsSectionUnknown:
return SectionIdentifierDefault;
......@@ -308,12 +301,11 @@ addSuggestionsToModel:(NSArray<CSCollectionViewItem*>*)suggestions
if ([model hasSectionForSectionIdentifier:sectionIdentifier] &&
[model numberOfItemsInSection:[model sectionForSectionIdentifier:
sectionIdentifier]] == 0) {
NSIndexPath* emptyItemIndexPath =
[self addEmptyItemForSection:
[model sectionForSectionIdentifier:sectionIdentifier]];
if (emptyItemIndexPath) {
[indexPaths addObject:emptyItemIndexPath];
}
[indexPaths
addObject:[self
addEmptyItemForSection:[model
sectionForSectionIdentifier:
sectionIdentifier]]];
}
return indexPaths;
}
......@@ -361,9 +353,6 @@ addSuggestionsToModel:(NSArray<CSCollectionViewItem*>*)suggestions
orderedSectionsInfo) {
NSInteger orderedSectionIdentifier =
SectionIdentifierForInfo(orderedSectionInfo);
if (orderedSectionIdentifier == sectionIdentifier) {
continue;
}
if ([model hasSectionForSectionIdentifier:orderedSectionIdentifier]) {
sectionIndex++;
}
......@@ -373,11 +362,7 @@ addSuggestionsToModel:(NSArray<CSCollectionViewItem*>*)suggestions
self.sectionInfoBySectionIdentifier[@(sectionIdentifier)] = sectionInfo;
[addedSectionIdentifiers addIndex:sectionIdentifier];
if (sectionIdentifier == SectionIdentifierLogo) {
[self addLogoHeaderIfNeeded];
} else {
[self addHeaderIfNeeded:sectionInfo];
}
[self addHeaderIfNeeded:sectionInfo];
[self addFooterIfNeeded:sectionInfo];
}
......@@ -398,9 +383,6 @@ addSuggestionsToModel:(NSArray<CSCollectionViewItem*>*)suggestions
self.sectionInfoBySectionIdentifier[@(sectionIdentifier)];
CSCollectionViewItem* item = [self emptyItemForSectionInfo:sectionInfo];
if (!item) {
return nil;
}
return [self addItem:item toSectionWithIdentifier:sectionIdentifier];
}
......@@ -519,20 +501,6 @@ addSuggestionsToModel:(NSArray<CSCollectionViewItem*>*)suggestions
}
}
// Adds the header for the first section, containing the logo and the omnibox,
// if there is no header for the section.
- (void)addLogoHeaderIfNeeded {
if (![self.collectionViewController.collectionViewModel
headerForSectionWithIdentifier:SectionIdentifierLogo]) {
ContentSuggestionsHeaderItem* header =
[[ContentSuggestionsHeaderItem alloc] initWithType:ItemTypeHeader];
header.view = self.dataSource.headerView;
[self.collectionViewController.collectionViewModel
setHeader:header
forSectionWithIdentifier:SectionIdentifierLogo];
}
}
// Resets the models, removing the current CollectionViewItem and the
// SectionInfo.
- (void)resetModels {
......@@ -631,11 +599,8 @@ addSuggestionsToModel:(NSArray<CSCollectionViewItem*>*)suggestions
// Returns a item to be displayed when the section identified by |sectionInfo|
// is empty.
// Returns nil if there is no empty item for this section info.
- (CSCollectionViewItem*)emptyItemForSectionInfo:
(ContentSuggestionsSectionInformation*)sectionInfo {
if (!sectionInfo.emptyText)
return nil;
ContentSuggestionsTextItem* item =
[[ContentSuggestionsTextItem alloc] initWithType:ItemTypeEmpty];
item.text = l10n_util::GetNSString(IDS_NTP_TITLE_NO_SUGGESTIONS);
......
......@@ -4,7 +4,6 @@
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_text_item.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/suggested_content.h"
......@@ -23,7 +22,6 @@ namespace {
TEST(ContentSuggestionsCollectionUpdaterTest, addEmptyItemToEmptySection) {
// Setup.
NSString* emptyString = @"test empty";
ContentSuggestionsCollectionUpdater* updater =
[[ContentSuggestionsCollectionUpdater alloc] initWithDataSource:nil];
CollectionViewModel* model = [[CollectionViewModel alloc] init];
......@@ -38,7 +36,6 @@ TEST(ContentSuggestionsCollectionUpdaterTest, addEmptyItemToEmptySection) {
[[ContentSuggestionsSectionInformation alloc]
initWithSectionID:ContentSuggestionsSectionArticles];
suggestion.suggestionIdentifier.sectionInfo.showIfEmpty = YES;
suggestion.suggestionIdentifier.sectionInfo.emptyText = emptyString;
[updater addSectionsForSectionInfoToModel:@[
suggestion.suggestionIdentifier.sectionInfo
]];
......@@ -49,42 +46,7 @@ TEST(ContentSuggestionsCollectionUpdaterTest, addEmptyItemToEmptySection) {
// Test.
EXPECT_TRUE([[NSIndexPath indexPathForItem:0 inSection:0] isEqual:addedItem]);
NSArray* items = [model
itemsInSectionWithIdentifier:[model sectionIdentifierForSection:0]];
ASSERT_EQ(1, [model numberOfItemsInSection:0]);
ContentSuggestionsTextItem* item = items[0];
EXPECT_EQ(emptyString, item.detailText);
}
TEST(ContentSuggestionsCollectionUpdaterTest,
addEmptyItemToSectionWithoutText) {
// Setup.
ContentSuggestionsCollectionUpdater* updater =
[[ContentSuggestionsCollectionUpdater alloc] initWithDataSource:nil];
CollectionViewModel* model = [[CollectionViewModel alloc] init];
id mockCollection = OCMClassMock([ContentSuggestionsViewController class]);
OCMStub([mockCollection collectionViewModel]).andReturn(model);
updater.collectionViewController = mockCollection;
CollectionViewItem<SuggestedContent>* suggestion =
[[ContentSuggestionsTextItem alloc] initWithType:kItemTypeEnumZero];
suggestion.suggestionIdentifier = [[ContentSuggestionIdentifier alloc] init];
suggestion.suggestionIdentifier.sectionInfo =
[[ContentSuggestionsSectionInformation alloc]
initWithSectionID:ContentSuggestionsSectionArticles];
suggestion.suggestionIdentifier.sectionInfo.showIfEmpty = YES;
suggestion.suggestionIdentifier.sectionInfo.emptyText = nil;
[updater addSectionsForSectionInfoToModel:@[
suggestion.suggestionIdentifier.sectionInfo
]];
ASSERT_EQ(0, [model numberOfItemsInSection:0]);
// Action.
NSIndexPath* addedItem = [updater addEmptyItemForSection:0];
// Test.
EXPECT_EQ(nil, addedItem);
ASSERT_EQ(0, [model numberOfItemsInSection:0]);
}
TEST(ContentSuggestionsCollectionUpdaterTest, addEmptyItemToSection) {
......@@ -103,7 +65,6 @@ TEST(ContentSuggestionsCollectionUpdaterTest, addEmptyItemToSection) {
[[ContentSuggestionsSectionInformation alloc]
initWithSectionID:ContentSuggestionsSectionArticles];
suggestion.suggestionIdentifier.sectionInfo.showIfEmpty = YES;
suggestion.suggestionIdentifier.sectionInfo.emptyText = @"empty";
[updater addSectionsForSectionInfoToModel:@[
suggestion.suggestionIdentifier.sectionInfo
]];
......
......@@ -67,9 +67,6 @@ fetchFaviconImageForItem:(nonnull CollectionViewItem<SuggestedContent>*)item
- (void)dismissSuggestion:
(nonnull ContentSuggestionIdentifier*)suggestionIdentifier;
// Returns the header view containing the logo and omnibox to be displayed.
- (nullable UIView*)headerView;
@end
#endif // IOS_CHROME_BROWSER_UI_CONTENT_SUGGESTIONS_CONTENT_SUGGESTIONS_DATA_SOURCE_H_
......@@ -272,19 +272,6 @@ BOOL ShouldCellsBeFullWidth(UITraitCollection* collection) {
return [UIColor whiteColor];
}
- (CGSize)collectionView:(UICollectionView*)collectionView
layout:
(UICollectionViewLayout*)collectionViewLayout
referenceSizeForHeaderInSection:(NSInteger)section {
// TODO(crbug.com/635604): Once the headers support dynamic sizing, use it
// instead of this.
if (section == 0)
return CGSizeMake(0, 270);
return [super collectionView:collectionView
layout:collectionViewLayout
referenceSizeForHeaderInSection:section];
}
- (BOOL)collectionView:(nonnull UICollectionView*)collectionView
shouldHideItemBackgroundAtIndexPath:(nonnull NSIndexPath*)indexPath {
return
......@@ -384,8 +371,7 @@ BOOL ShouldCellsBeFullWidth(UITraitCollection* collection) {
NSIndexPath* emptyItem =
[self.collectionUpdater addEmptyItemForSection:section];
if (emptyItem)
[self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]];
[self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]];
}
// Tells WebToolbarController to resign focus to the omnibox.
......
......@@ -18,8 +18,7 @@ typedef NS_ENUM(NSInteger, ContentSuggestionsSectionLayout) {
// This enum is used for identifying the section. All section should have a
// different ID.
typedef NS_ENUM(NSInteger, ContentSuggestionsSectionID) {
ContentSuggestionsSectionLogo = 0,
ContentSuggestionsSectionMostVisited,
ContentSuggestionsSectionMostVisited = 0,
ContentSuggestionsSectionArticles,
ContentSuggestionsSectionReadingList,
......
......@@ -28,9 +28,6 @@ using CSCollectionViewItem = CollectionViewItem<SuggestedContent>;
@interface SCContentSuggestionsDataSource ()<ContentSuggestionsImageFetcher>
// Section Info of type Logo header. Created lazily.
@property(nonatomic, strong)
ContentSuggestionsSectionInformation* logoHeaderSection;
// Section Info of type MostVisited. Created lazily.
@property(nonatomic, strong)
ContentSuggestionsSectionInformation* mostVisitedSection;
......@@ -46,7 +43,6 @@ using CSCollectionViewItem = CollectionViewItem<SuggestedContent>;
@implementation SCContentSuggestionsDataSource
@synthesize dataSink = _dataSink;
@synthesize logoHeaderSection = _logoHeaderSection;
@synthesize mostVisitedSection = _mostVisitedSection;
@synthesize readingListSection = _readingListSection;
@synthesize articleSection = _articleSection;
......@@ -65,8 +61,7 @@ using CSCollectionViewItem = CollectionViewItem<SuggestedContent>;
- (NSArray<ContentSuggestionsSectionInformation*>*)sectionsInfo {
return @[
self.logoHeaderSection, self.mostVisitedSection, self.readingListSection,
self.articleSection
self.mostVisitedSection, self.readingListSection, self.articleSection
];
}
......@@ -108,9 +103,6 @@ using CSCollectionViewItem = CollectionViewItem<SuggestedContent>;
}
return items;
}
case ContentSuggestionsSectionLogo: {
return @[];
}
case ContentSuggestionsSectionUnknown:
return @[];
}
......@@ -138,10 +130,6 @@ using CSCollectionViewItem = CollectionViewItem<SuggestedContent>;
- (void)dismissSuggestion:(ContentSuggestionIdentifier*)suggestionIdentifier {
}
- (UIView*)headerView {
return nil;
}
#pragma mark - ContentSuggestionsImageFetcher
- (void)fetchImageForSuggestion:
......@@ -154,27 +142,11 @@ using CSCollectionViewItem = CollectionViewItem<SuggestedContent>;
#pragma mark - Property
- (ContentSuggestionsSectionInformation*)logoHeaderSection {
if (!_logoHeaderSection) {
_logoHeaderSection = [[ContentSuggestionsSectionInformation alloc]
initWithSectionID:ContentSuggestionsSectionLogo];
_logoHeaderSection.showIfEmpty = YES;
_logoHeaderSection.layout = ContentSuggestionsSectionLayoutCustom;
_logoHeaderSection.title = nil;
_logoHeaderSection.footerTitle = nil;
_logoHeaderSection.emptyText = nil;
}
return _logoHeaderSection;
}
- (ContentSuggestionsSectionInformation*)mostVisitedSection {
if (!_mostVisitedSection) {
_mostVisitedSection = [[ContentSuggestionsSectionInformation alloc]
initWithSectionID:ContentSuggestionsSectionMostVisited];
_mostVisitedSection.layout = ContentSuggestionsSectionLayoutCustom;
_mostVisitedSection.title = nil;
_mostVisitedSection.footerTitle = nil;
_mostVisitedSection.emptyText = nil;
}
return _mostVisitedSection;
}
......
......@@ -35,20 +35,15 @@ id<GREYMatcher> TextBeginsWith(NSString* text) {
matcher, nil);
}
// Select the cell with the |matcher| by scrolling the collection.
GREYElementInteraction* CellWithMatcher(id<GREYMatcher> matcher) {
// Select the cell with the |ID| by scrolling the collection.
GREYElementInteraction* CellWithID(NSString* ID) {
return [[EarlGrey
selectElementWithMatcher:grey_allOf(matcher, grey_sufficientlyVisible(),
nil)]
selectElementWithMatcher:grey_allOf(grey_accessibilityID(ID),
grey_sufficientlyVisible(), nil)]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 150)
onElementWithMatcher:grey_kindOfClass([UICollectionView class])];
}
// Select the cell with the |ID| by scrolling the collection.
GREYElementInteraction* CellWithID(NSString* ID) {
return CellWithMatcher(grey_accessibilityID(ID));
}
// Returns the string displayed when the Reading List section is empty.
NSString* ReadingListEmptySection() {
return [NSString
......@@ -68,12 +63,14 @@ NSString* ReadingListEmptySection() {
// Tests launching ContentSuggestionsViewController.
- (void)testLaunch {
showcase_utils::Open(@"ContentSuggestionsViewController");
[CellWithMatcher(chrome_test_util::ButtonWithAccessibilityLabelId(
IDS_IOS_CONTENT_SUGGESTIONS_FOOTER_TITLE))
[[EarlGrey
selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId(
IDS_IOS_CONTENT_SUGGESTIONS_FOOTER_TITLE)]
assertWithMatcher:grey_interactable()];
[CellWithMatcher(chrome_test_util::StaticTextWithAccessibilityLabelId(
IDS_NTP_ARTICLE_SUGGESTIONS_SECTION_HEADER))
assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:
chrome_test_util::StaticTextWithAccessibilityLabelId(
IDS_NTP_ARTICLE_SUGGESTIONS_SECTION_HEADER)]
assertWithMatcher:grey_sufficientlyVisible()];
showcase_utils::Close();
}
......
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