Commit e8c5b5f5 authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Create ClearBrowsingDataManager to hold bulk of ClearBrowsingData logic...

[ios] Create ClearBrowsingDataManager to hold bulk of ClearBrowsingData logic that can be shared between CollectionVC and TableVC

Moves appropriate unit tests to new manager unittest file. Also creates ClearBrowsingDataConsumer for mediator to communicate with view controller.

Change-Id: Ia60b78ff49c77b526aff5bf3034c06e35bda7b48
Reviewed-on: https://chromium-review.googlesource.com/1086240
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565301}
parent a194776f
...@@ -26,8 +26,11 @@ source_set("settings") { ...@@ -26,8 +26,11 @@ source_set("settings") {
"block_popups_collection_view_controller.mm", "block_popups_collection_view_controller.mm",
"clear_browsing_data_collection_view_controller.h", "clear_browsing_data_collection_view_controller.h",
"clear_browsing_data_collection_view_controller.mm", "clear_browsing_data_collection_view_controller.mm",
"clear_browsing_data_consumer.h",
"clear_browsing_data_coordinator.h", "clear_browsing_data_coordinator.h",
"clear_browsing_data_coordinator.mm", "clear_browsing_data_coordinator.mm",
"clear_browsing_data_manager.h",
"clear_browsing_data_manager.mm",
"clear_browsing_data_table_view_controller.h", "clear_browsing_data_table_view_controller.h",
"clear_browsing_data_table_view_controller.mm", "clear_browsing_data_table_view_controller.mm",
"compose_email_handler_collection_view_controller.h", "compose_email_handler_collection_view_controller.h",
...@@ -152,6 +155,7 @@ source_set("settings") { ...@@ -152,6 +155,7 @@ source_set("settings") {
"//ios/chrome/browser/ui/coordinators:chrome_coordinators", "//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/icons", "//ios/chrome/browser/ui/icons",
"//ios/chrome/browser/ui/keyboard", "//ios/chrome/browser/ui/keyboard",
"//ios/chrome/browser/ui/list_model",
"//ios/chrome/browser/ui/material_components", "//ios/chrome/browser/ui/material_components",
"//ios/chrome/browser/ui/payments/cells", "//ios/chrome/browser/ui/payments/cells",
"//ios/chrome/browser/ui/settings/cells", "//ios/chrome/browser/ui/settings/cells",
...@@ -237,6 +241,7 @@ source_set("unit_tests") { ...@@ -237,6 +241,7 @@ source_set("unit_tests") {
"bandwidth_management_collection_view_controller_unittest.mm", "bandwidth_management_collection_view_controller_unittest.mm",
"block_popups_collection_view_controller_unittest.mm", "block_popups_collection_view_controller_unittest.mm",
"clear_browsing_data_collection_view_controller_unittest.mm", "clear_browsing_data_collection_view_controller_unittest.mm",
"clear_browsing_data_manager_unittest.mm",
"compose_email_handler_collection_view_controller_unittest.mm", "compose_email_handler_collection_view_controller_unittest.mm",
"content_settings_collection_view_controller_unittest.mm", "content_settings_collection_view_controller_unittest.mm",
"dataplan_usage_collection_view_controller_unittest.mm", "dataplan_usage_collection_view_controller_unittest.mm",
......
...@@ -363,11 +363,11 @@ void BrowsingDataRemoverObserverWrapper::OnBrowsingDataRemoved( ...@@ -363,11 +363,11 @@ void BrowsingDataRemoverObserverWrapper::OnBrowsingDataRemoved(
__weak ClearBrowsingDataCollectionViewController* weakSelf = self; __weak ClearBrowsingDataCollectionViewController* weakSelf = self;
counter = BrowsingDataCounterWrapper::CreateCounterWrapper( counter = BrowsingDataCounterWrapper::CreateCounterWrapper(
prefName, _browserState, prefs, prefName, _browserState, prefs,
base::BindRepeating(^( base::BindRepeating(
const browsing_data::BrowsingDataCounter::Result& result) { ^(const browsing_data::BrowsingDataCounter::Result& result) {
[weakSelf updateCounter:itemType [weakSelf updateCounter:itemType
detailText:[weakSelf getCounterTextFromResult:result]]; detailText:[weakSelf counterTextFromResult:result]];
})); }));
} }
ClearBrowsingDataItem* clearDataItem = ClearBrowsingDataItem* clearDataItem =
...@@ -542,8 +542,6 @@ void BrowsingDataRemoverObserverWrapper::OnBrowsingDataRemoved( ...@@ -542,8 +542,6 @@ void BrowsingDataRemoverObserverWrapper::OnBrowsingDataRemoved(
case ItemTypeClearBrowsingDataButton: case ItemTypeClearBrowsingDataButton:
[self alertAndClearData]; [self alertAndClearData];
break; break;
default:
break;
} }
} }
...@@ -762,7 +760,7 @@ void BrowsingDataRemoverObserverWrapper::OnBrowsingDataRemoved( ...@@ -762,7 +760,7 @@ void BrowsingDataRemoverObserverWrapper::OnBrowsingDataRemoved(
[autofillItem restartCounter]; [autofillItem restartCounter];
} }
} }
- (NSString*)getCounterTextFromResult: - (NSString*)counterTextFromResult:
(const browsing_data::BrowsingDataCounter::Result&)result { (const browsing_data::BrowsingDataCounter::Result&)result {
if (!result.Finished()) { if (!result.Finished()) {
// The counter is still counting. // The counter is still counting.
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
using testing::Return; using testing::Return;
@interface ClearBrowsingDataCollectionViewController (ExposedForTesting) @interface ClearBrowsingDataCollectionViewController (ExposedForTesting)
- (NSString*)getCounterTextFromResult: - (NSString*)counterTextFromResult:
(const browsing_data::BrowsingDataCounter::Result&)result; (const browsing_data::BrowsingDataCounter::Result&)result;
@end @end
...@@ -119,14 +119,9 @@ TEST_F(ClearBrowsingDataCollectionViewControllerTest, TestModel) { ...@@ -119,14 +119,9 @@ TEST_F(ClearBrowsingDataCollectionViewControllerTest, TestModel) {
int section_offset = 0; int section_offset = 0;
if (experimental_flags::IsNewClearBrowsingDataUIEnabled()) { if (experimental_flags::IsNewClearBrowsingDataUIEnabled()) {
EXPECT_EQ(4, NumberOfSections());
EXPECT_EQ(1, NumberOfItemsInSection(0));
section_offset = 1; section_offset = 1;
} else {
EXPECT_EQ(3, NumberOfSections());
} }
EXPECT_EQ(5, NumberOfItemsInSection(0 + section_offset));
CheckTextCellTitleWithId(IDS_IOS_CLEAR_BROWSING_HISTORY, 0 + section_offset, CheckTextCellTitleWithId(IDS_IOS_CLEAR_BROWSING_HISTORY, 0 + section_offset,
0); 0);
CheckAccessoryType(MDCCollectionViewCellAccessoryCheckmark, CheckAccessoryType(MDCCollectionViewCellAccessoryCheckmark,
...@@ -143,16 +138,14 @@ TEST_F(ClearBrowsingDataCollectionViewControllerTest, TestModel) { ...@@ -143,16 +138,14 @@ TEST_F(ClearBrowsingDataCollectionViewControllerTest, TestModel) {
CheckTextCellTitleWithId(IDS_IOS_CLEAR_AUTOFILL, 0 + section_offset, 4); CheckTextCellTitleWithId(IDS_IOS_CLEAR_AUTOFILL, 0 + section_offset, 4);
CheckAccessoryType(MDCCollectionViewCellAccessoryNone, 0 + section_offset, 4); CheckAccessoryType(MDCCollectionViewCellAccessoryNone, 0 + section_offset, 4);
EXPECT_EQ(1, NumberOfItemsInSection(1 + section_offset));
CheckTextCellTitleWithId(IDS_IOS_CLEAR_BUTTON, 1 + section_offset, 0); CheckTextCellTitleWithId(IDS_IOS_CLEAR_BUTTON, 1 + section_offset, 0);
EXPECT_EQ(1, NumberOfItemsInSection(2 + section_offset));
CheckSectionFooterWithId(IDS_IOS_CLEAR_BROWSING_DATA_FOOTER_SAVED_SITE_DATA, CheckSectionFooterWithId(IDS_IOS_CLEAR_BROWSING_DATA_FOOTER_SAVED_SITE_DATA,
2 + section_offset); 2 + section_offset);
} }
TEST_F(ClearBrowsingDataCollectionViewControllerTest, TEST_F(ClearBrowsingDataCollectionViewControllerTest,
TestModelSignedInSyncOff) { TestItemsSignedInSyncOff) {
EXPECT_CALL(*mock_sync_service_, IsSyncActive()) EXPECT_CALL(*mock_sync_service_, IsSyncActive())
.WillRepeatedly(Return(false)); .WillRepeatedly(Return(false));
signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com"); signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com");
...@@ -180,7 +173,7 @@ TEST_F(ClearBrowsingDataCollectionViewControllerTest, ...@@ -180,7 +173,7 @@ TEST_F(ClearBrowsingDataCollectionViewControllerTest,
} }
TEST_F(ClearBrowsingDataCollectionViewControllerTest, TEST_F(ClearBrowsingDataCollectionViewControllerTest,
TestModelSignedInSyncActiveHistoryOff) { TestItemsSignedInSyncActiveHistoryOff) {
EXPECT_CALL(*mock_sync_service_, IsSyncActive()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_sync_service_, IsSyncActive()).WillRepeatedly(Return(true));
EXPECT_CALL(*mock_sync_service_, GetActiveDataTypes()) EXPECT_CALL(*mock_sync_service_, GetActiveDataTypes())
.WillRepeatedly(Return(syncer::ModelTypeSet())); .WillRepeatedly(Return(syncer::ModelTypeSet()));
...@@ -193,21 +186,12 @@ TEST_F(ClearBrowsingDataCollectionViewControllerTest, ...@@ -193,21 +186,12 @@ TEST_F(ClearBrowsingDataCollectionViewControllerTest,
int section_offset = 0; int section_offset = 0;
if (experimental_flags::IsNewClearBrowsingDataUIEnabled()) { if (experimental_flags::IsNewClearBrowsingDataUIEnabled()) {
EXPECT_EQ(5, NumberOfSections());
EXPECT_EQ(1, NumberOfItemsInSection(0));
section_offset = 1; section_offset = 1;
} else {
EXPECT_EQ(4, NumberOfSections());
} }
EXPECT_EQ(5, NumberOfItemsInSection(0 + section_offset));
EXPECT_EQ(1, NumberOfItemsInSection(1 + section_offset));
EXPECT_EQ(1, NumberOfItemsInSection(2 + section_offset));
CheckSectionFooterWithId(IDS_IOS_CLEAR_BROWSING_DATA_FOOTER_ACCOUNT, CheckSectionFooterWithId(IDS_IOS_CLEAR_BROWSING_DATA_FOOTER_ACCOUNT,
2 + section_offset); 2 + section_offset);
EXPECT_EQ(1, NumberOfItemsInSection(3 + section_offset));
CheckSectionFooterWithId( CheckSectionFooterWithId(
IDS_IOS_CLEAR_BROWSING_DATA_FOOTER_CLEAR_SYNC_AND_SAVED_SITE_DATA, IDS_IOS_CLEAR_BROWSING_DATA_FOOTER_CLEAR_SYNC_AND_SAVED_SITE_DATA,
3 + section_offset); 3 + section_offset);
...@@ -233,78 +217,4 @@ TEST_F(ClearBrowsingDataCollectionViewControllerTest, TestUpdatePrefWithValue) { ...@@ -233,78 +217,4 @@ TEST_F(ClearBrowsingDataCollectionViewControllerTest, TestUpdatePrefWithValue) {
EXPECT_TRUE(prefs->GetBoolean(browsing_data::prefs::kDeleteFormData)); EXPECT_TRUE(prefs->GetBoolean(browsing_data::prefs::kDeleteFormData));
} }
TEST_F(ClearBrowsingDataCollectionViewControllerTest,
TestCacheCounterFormattingForAllTime) {
ASSERT_EQ("en", GetApplicationContext()->GetApplicationLocale());
PrefService* prefs = browser_state_->GetPrefs();
prefs->SetInteger(browsing_data::prefs::kDeleteTimePeriod,
static_cast<int>(browsing_data::TimePeriod::ALL_TIME));
CacheCounter counter(browser_state_.get());
// Test multiple possible types of formatting.
// clang-format off
const struct TestCase {
int cache_size;
NSString* expected_output;
} kTestCases[] = {
{0, @"Less than 1 MB"},
{(1 << 20) - 1, @"Less than 1 MB"},
{(1 << 20), @"1 MB"},
{(1 << 20) + (1 << 19), @"1.5 MB"},
{(1 << 21), @"2 MB"},
{(1 << 30), @"1 GB"}
};
// clang-format on
ClearBrowsingDataCollectionViewController* viewController =
base::mac::ObjCCastStrict<ClearBrowsingDataCollectionViewController>(
controller());
for (const TestCase& test_case : kTestCases) {
browsing_data::BrowsingDataCounter::FinishedResult result(
&counter, test_case.cache_size);
NSString* output = [viewController getCounterTextFromResult:result];
EXPECT_NSEQ(test_case.expected_output, output);
}
}
TEST_F(ClearBrowsingDataCollectionViewControllerTest,
TestCacheCounterFormattingForLessThanAllTime) {
ASSERT_EQ("en", GetApplicationContext()->GetApplicationLocale());
// If the new UI is not enabled then the pref value for the time period
// is ignored and the time period defaults to ALL_TIME.
if (!experimental_flags::IsNewClearBrowsingDataUIEnabled()) {
return;
}
PrefService* prefs = browser_state_->GetPrefs();
prefs->SetInteger(browsing_data::prefs::kDeleteTimePeriod,
static_cast<int>(browsing_data::TimePeriod::LAST_HOUR));
CacheCounter counter(browser_state_.get());
// Test multiple possible types of formatting.
// clang-format off
const struct TestCase {
int cache_size;
NSString* expected_output;
} kTestCases[] = {
{0, @"Less than 1 MB"},
{(1 << 20) - 1, @"Less than 1 MB"},
{(1 << 20), @"Less than 1 MB"},
{(1 << 20) + (1 << 19), @"Less than 1.5 MB"},
{(1 << 21), @"Less than 2 MB"},
{(1 << 30), @"Less than 1 GB"}
};
// clang-format on
ClearBrowsingDataCollectionViewController* viewController =
base::mac::ObjCCastStrict<ClearBrowsingDataCollectionViewController>(
controller());
for (const TestCase& test_case : kTestCases) {
browsing_data::BrowsingDataCounter::FinishedResult result(
&counter, test_case.cache_size);
NSString* output = [viewController getCounterTextFromResult:result];
EXPECT_NSEQ(test_case.expected_output, output);
}
}
} // namespace } // namespace
// 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_SETTINGS_CLEAR_BROWSING_DATA_CONSUMER_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_CLEAR_BROWSING_DATA_CONSUMER_H_
#import <Foundation/Foundation.h>
#include "base/ios/block_types.h"
@class ListItem;
namespace ios {
class ChromeBrowserState;
}
namespace browsing_data {
enum class TimePeriod;
}
enum class BrowsingDataRemoveMask;
@protocol ClearBrowsingDataConsumer<NSObject>
// Updates contents of a cell for a given item.
- (void)updateCellsForItem:(ListItem*)item;
// Updates item of |itemType| with |detailText|.
- (void)updateCounter:(NSInteger)itemType detailText:(NSString*)detailText;
// Indicate to user that data has been cleared.
- (void)showBrowsingHistoryRemovedDialog;
// Execute action to clear browsing data.
- (void)removeBrowsingDataForBrowserState:(ios::ChromeBrowserState*)browserState
timePeriod:(browsing_data::TimePeriod)timePeriod
removeMask:(BrowsingDataRemoveMask)removeMask
completionBlock:(ProceduralBlock)completionBlock;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_CLEAR_BROWSING_DATA_CONSUMER_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.
#ifndef IOS_CHROME_BROWSER_UI_SETTINGS_CLEAR_BROWSING_DATA_MANAGER_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_CLEAR_BROWSING_DATA_MANAGER_H_
#import <Foundation/Foundation.h>
#import "ios/chrome/browser/ui/settings/clear_browsing_data_consumer.h"
#import "ios/chrome/browser/ui/settings/time_range_selector_collection_view_controller.h"
@class ListModel;
// Clear Browswing Data Section Identifiers.
enum ClearBrowsingDataSectionIdentifier {
// Section holding types of data that can be cleared.
SectionDataTypes = kSectionIdentifierEnumZero,
// Section containing button to clear browsing data.
SectionClearBrowsingDataButton,
// Section for informational footnote about user's Google Account data.
SectionGoogleAccount,
// Section for footnote about synced data being cleared.
SectionClearSyncAndSavedSiteData,
// Section for informational footnote about site settings remaining.
SectionSavedSiteData,
// Section containing cell displaying time range to remove data.
SectionTimeRange,
};
// Clear Browsing Data Item Types.
enum ClearBrowsingDataItemType {
// Item representing browsing history data.
DataTypeBrowsingHistory = kItemTypeEnumZero,
// Item representing cookies and site data.
DataTypeCookiesSiteData,
// Items representing cached data.
DataTypeCache,
// Items representing saved passwords.
DataTypeSavedPasswords,
// Items representing autofill data.
DataTypeAutofill,
// Clear data button.
ClearBrowsingDataButton,
// Footer noting account will not be signed out.
FooterGoogleAccount,
// Footer noting user will not be signed out of chrome and other forms of
// browsing history will still be available.
FooterGoogleAccountAndMyActivity,
// Footer noting site settings will remain.
FooterSavedSiteData,
// Footer noting data will be cleared on all devices except for saved
// settings.
FooterClearSyncAndSavedSiteData,
// Item showing time range to remove data and allowing user to edit time
// range.
TimeRange,
};
// Manager that serves as the bulk of the logic for
// ClearBrowsingDataConsumer.
@interface ClearBrowsingDataManager
: NSObject<TimeRangeSelectorCollectionViewControllerDelegate>
// The manager's consumer.
@property(nonatomic, assign) id<ClearBrowsingDataConsumer> consumer;
// Reference to the LinkDelegate for CollectionViewFooterItem.
@property(nonatomic, strong) id<CollectionViewFooterLinkDelegate> linkDelegate;
// Default init method with |browserState| that can't be nil.
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState
NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
// Fills |model| with appropriate sections and items.
- (void)loadModel:(ListModel*)model;
// Returns a UIAlertController that has action block to clear data of type
// |dataTypeMaskToRemove|.
- (UIAlertController*)alertControllerWithDataTypesToRemove:
(BrowsingDataRemoveMask)dataTypeMaskToRemove;
// Get the text to be displayed by a counter from the given |result|
- (NSString*)counterTextFromResult:
(const browsing_data::BrowsingDataCounter::Result&)result;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_CLEAR_BROWSING_DATA_MANAGER_H_
This diff is collapsed.
// 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/settings/clear_browsing_data_manager.h"
#include "components/browser_sync/profile_sync_service_mock.h"
#include "components/browsing_data/core/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/signin/core/browser/fake_signin_manager.h"
#include "components/sync_preferences/pref_service_mock_factory.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#include "ios/chrome/browser/browsing_data/cache_counter.h"
#include "ios/chrome/browser/experimental_flags.h"
#include "ios/chrome/browser/pref_names.h"
#include "ios/chrome/browser/prefs/browser_prefs.h"
#include "ios/chrome/browser/signin/fake_oauth2_token_service_builder.h"
#include "ios/chrome/browser/signin/fake_signin_manager_builder.h"
#include "ios/chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "ios/chrome/browser/signin/signin_manager_factory.h"
#include "ios/chrome/browser/sync/ios_chrome_profile_sync_test_util.h"
#include "ios/chrome/browser/sync/profile_sync_service_factory.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#include "ios/web/public/test/test_web_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
#import "testing/gtest_mac.h"
#include "testing/platform_test.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using testing::Return;
@interface ClearBrowsingDataManager (ExposedForTesting)
- (void)loadModel:(ListModel*)model;
@end
namespace {
class ClearBrowsingDataManagerTest : public PlatformTest {
public:
ClearBrowsingDataManagerTest() {
sync_preferences::PrefServiceMockFactory factory;
scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
new user_prefs::PrefRegistrySyncable);
std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs =
factory.CreateSyncable(registry.get());
RegisterBrowserStatePrefs(registry.get());
// Setup identity services.
TestChromeBrowserState::Builder builder;
builder.SetPrefService(std::move(prefs));
builder.AddTestingFactory(ProfileSyncServiceFactory::GetInstance(),
&BuildMockProfileSyncService);
builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(),
&BuildFakeOAuth2TokenService);
builder.AddTestingFactory(ios::SigninManagerFactory::GetInstance(),
&ios::BuildFakeSigninManager);
browser_state_ = builder.Build();
model_ = [[CollectionViewModel alloc] init];
manager_ = [[ClearBrowsingDataManager alloc]
initWithBrowserState:browser_state_.get()];
signin_manager_ =
ios::SigninManagerFactory::GetForBrowserState(browser_state_.get());
mock_sync_service_ = static_cast<browser_sync::ProfileSyncServiceMock*>(
ProfileSyncServiceFactory::GetForBrowserState(browser_state_.get()));
}
protected:
std::unique_ptr<TestChromeBrowserState> browser_state_;
CollectionViewModel* model_;
ClearBrowsingDataManager* manager_;
SigninManagerBase* signin_manager_;
browser_sync::ProfileSyncServiceMock* mock_sync_service_;
web::TestWebThreadBundle thread_bundle_;
};
// Tests model is set up with all appropriate items and sections.
TEST_F(ClearBrowsingDataManagerTest, TestModel) {
[manager_ loadModel:model_];
int section_offset = 0;
if (experimental_flags::IsNewClearBrowsingDataUIEnabled()) {
EXPECT_EQ(4, [model_ numberOfSections]);
EXPECT_EQ(1, [model_ numberOfItemsInSection:0]);
section_offset = 1;
} else {
EXPECT_EQ(3, [model_ numberOfSections]);
}
EXPECT_EQ(5, [model_ numberOfItemsInSection:0 + section_offset]);
EXPECT_EQ(1, [model_ numberOfItemsInSection:1 + section_offset]);
EXPECT_EQ(1, [model_ numberOfItemsInSection:2 + section_offset]);
}
// Tests model is set up with correct number of items and sections if signed in
// but sync is off.
TEST_F(ClearBrowsingDataManagerTest, TestModelSignedInSyncOff) {
// Ensure that sync is not running.
EXPECT_CALL(*mock_sync_service_, IsSyncActive())
.WillRepeatedly(Return(false));
signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com");
[manager_ loadModel:model_];
int section_offset = 0;
if (experimental_flags::IsNewClearBrowsingDataUIEnabled()) {
EXPECT_EQ(5, [model_ numberOfSections]);
EXPECT_EQ(1, [model_ numberOfItemsInSection:0]);
section_offset = 1;
} else {
EXPECT_EQ(4, [model_ numberOfSections]);
}
EXPECT_EQ(5, [model_ numberOfItemsInSection:0 + section_offset]);
EXPECT_EQ(1, [model_ numberOfItemsInSection:1 + section_offset]);
EXPECT_EQ(1, [model_ numberOfItemsInSection:2 + section_offset]);
EXPECT_EQ(1, [model_ numberOfItemsInSection:3 + section_offset]);
}
TEST_F(ClearBrowsingDataManagerTest, TestCacheCounterFormattingForAllTime) {
ASSERT_EQ("en", GetApplicationContext()->GetApplicationLocale());
PrefService* prefs = browser_state_->GetPrefs();
prefs->SetInteger(browsing_data::prefs::kDeleteTimePeriod,
static_cast<int>(browsing_data::TimePeriod::ALL_TIME));
CacheCounter counter(browser_state_.get());
// Test multiple possible types of formatting.
// clang-format off
const struct TestCase {
int cache_size;
NSString* expected_output;
} kTestCases[] = {
{0, @"Less than 1 MB"},
{(1 << 20) - 1, @"Less than 1 MB"},
{(1 << 20), @"1 MB"},
{(1 << 20) + (1 << 19), @"1.5 MB"},
{(1 << 21), @"2 MB"},
{(1 << 30), @"1 GB"}
};
// clang-format on
for (const TestCase& test_case : kTestCases) {
browsing_data::BrowsingDataCounter::FinishedResult result(
&counter, test_case.cache_size);
NSString* output = [manager_ counterTextFromResult:result];
EXPECT_NSEQ(test_case.expected_output, output);
}
}
TEST_F(ClearBrowsingDataManagerTest,
TestCacheCounterFormattingForLessThanAllTime) {
ASSERT_EQ("en", GetApplicationContext()->GetApplicationLocale());
// If the new UI is not enabled then the pref value for the time period
// is ignored and the time period defaults to ALL_TIME.
if (!experimental_flags::IsNewClearBrowsingDataUIEnabled()) {
return;
}
PrefService* prefs = browser_state_->GetPrefs();
prefs->SetInteger(browsing_data::prefs::kDeleteTimePeriod,
static_cast<int>(browsing_data::TimePeriod::LAST_HOUR));
CacheCounter counter(browser_state_.get());
// Test multiple possible types of formatting.
// clang-format off
const struct TestCase {
int cache_size;
NSString* expected_output;
} kTestCases[] = {
{0, @"Less than 1 MB"},
{(1 << 20) - 1, @"Less than 1 MB"},
{(1 << 20), @"Less than 1 MB"},
{(1 << 20) + (1 << 19), @"Less than 1.5 MB"},
{(1 << 21), @"Less than 2 MB"},
{(1 << 30), @"Less than 1 GB"}
};
// clang-format on
for (const TestCase& test_case : kTestCases) {
browsing_data::BrowsingDataCounter::FinishedResult result(
&counter, test_case.cache_size);
NSString* output = [manager_ counterTextFromResult:result];
EXPECT_NSEQ(test_case.expected_output, output);
}
}
} // namespace
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