Commit c7586428 authored by Mario Sanchez Prada's avatar Mario Sanchez Prada Committed by Commit Bot

Migrate clear_browsing_data_collection_view_controller_unittest.mm to IdentityManager

Use IdentityTestEnvironmentChromeBrowserStateAdaptor instead of manually
creating the browser's state by providing specific factories, and then
use the APIs from IdentityTestEnvironment, instead of SigninManagerBase.

Also remove an unnecessary DCHECK in clear_browsing_data_manager_unittest.mm,
as pointed out post-review when fixing crbug.com/890826 (CL 1318974).

Bug: 903703
Change-Id: I9d4dd625441005a36c962628fe3fe1f15ab56bb6
Reviewed-on: https://chromium-review.googlesource.com/c/1328985Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Cr-Commit-Position: refs/heads/master@{#606894}
parent 8c3cd622
...@@ -314,7 +314,6 @@ source_set("unit_tests") { ...@@ -314,7 +314,6 @@ source_set("unit_tests") {
"//components/pref_registry", "//components/pref_registry",
"//components/prefs:test_support", "//components/prefs:test_support",
"//components/search_engines", "//components/search_engines",
"//components/signin/core/browser:test_support",
"//components/strings", "//components/strings",
"//components/sync_preferences", "//components/sync_preferences",
"//components/sync_preferences:test_support", "//components/sync_preferences:test_support",
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "components/browsing_data/core/browsing_data_utils.h" #include "components/browsing_data/core/browsing_data_utils.h"
#include "components/browsing_data/core/pref_names.h" #include "components/browsing_data/core/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.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_mock_factory.h"
#include "components/sync_preferences/pref_service_syncable.h" #include "components/sync_preferences/pref_service_syncable.h"
#include "ios/chrome/browser/application_context.h" #include "ios/chrome/browser/application_context.h"
...@@ -22,10 +21,7 @@ ...@@ -22,10 +21,7 @@
#include "ios/chrome/browser/experimental_flags.h" #include "ios/chrome/browser/experimental_flags.h"
#include "ios/chrome/browser/pref_names.h" #include "ios/chrome/browser/pref_names.h"
#include "ios/chrome/browser/prefs/browser_prefs.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/identity_test_environment_chrome_browser_state_adaptor.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/ios_chrome_profile_sync_test_util.h"
#include "ios/chrome/browser/sync/profile_sync_service_factory.h" #include "ios/chrome/browser/sync/profile_sync_service_factory.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h" #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h"
...@@ -33,6 +29,7 @@ ...@@ -33,6 +29,7 @@
#import "ios/chrome/common/string_util.h" #import "ios/chrome/common/string_util.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#include "ios/web/public/test/test_web_thread_bundle.h" #include "ios/web/public/test/test_web_thread_bundle.h"
#include "services/identity/public/cpp/identity_test_environment.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#import "testing/gtest_mac.h" #import "testing/gtest_mac.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -65,21 +62,17 @@ class ClearBrowsingDataCollectionViewControllerTest ...@@ -65,21 +62,17 @@ class ClearBrowsingDataCollectionViewControllerTest
CollectionViewControllerTest::SetUp(); CollectionViewControllerTest::SetUp();
// Setup identity services. // Setup identity services.
TestChromeBrowserState::Builder builder; TestChromeBrowserState::TestingFactories factories = {
builder.SetPrefService(CreatePrefService()); {ProfileSyncServiceFactory::GetInstance(),
builder.AddTestingFactory( base::BindRepeating(&BuildMockProfileSyncService)},
ProfileOAuth2TokenServiceFactory::GetInstance(), };
base::BindRepeating(&BuildFakeOAuth2TokenService)); browser_state_ = IdentityTestEnvironmentChromeBrowserStateAdaptor::
builder.AddTestingFactory( CreateChromeBrowserStateForIdentityTestEnvironment(factories);
ios::SigninManagerFactory::GetInstance(),
base::BindRepeating(&ios::BuildFakeSigninManager)); identity_test_env_adaptor_.reset(
builder.AddTestingFactory( new IdentityTestEnvironmentChromeBrowserStateAdaptor(
ProfileSyncServiceFactory::GetInstance(), browser_state_.get()));
base::BindRepeating(&BuildMockProfileSyncService));
browser_state_ = builder.Build();
signin_manager_ =
ios::SigninManagerFactory::GetForBrowserState(browser_state_.get());
mock_sync_service_ = static_cast<browser_sync::ProfileSyncServiceMock*>( mock_sync_service_ = static_cast<browser_sync::ProfileSyncServiceMock*>(
ProfileSyncServiceFactory::GetForBrowserState(browser_state_.get())); ProfileSyncServiceFactory::GetForBrowserState(browser_state_.get()));
} }
...@@ -106,9 +99,14 @@ class ClearBrowsingDataCollectionViewControllerTest ...@@ -106,9 +99,14 @@ class ClearBrowsingDataCollectionViewControllerTest
didSelectItemAtIndexPath:indexPath]; didSelectItemAtIndexPath:indexPath];
} }
identity::IdentityTestEnvironment* identity_test_env() {
return identity_test_env_adaptor_->identity_test_env();
}
web::TestWebThreadBundle thread_bundle_; web::TestWebThreadBundle thread_bundle_;
std::unique_ptr<TestChromeBrowserState> browser_state_; std::unique_ptr<TestChromeBrowserState> browser_state_;
SigninManagerBase* signin_manager_; std::unique_ptr<IdentityTestEnvironmentChromeBrowserStateAdaptor>
identity_test_env_adaptor_;
browser_sync::ProfileSyncServiceMock* mock_sync_service_; browser_sync::ProfileSyncServiceMock* mock_sync_service_;
}; };
...@@ -151,7 +149,7 @@ TEST_F(ClearBrowsingDataCollectionViewControllerTest, ...@@ -151,7 +149,7 @@ TEST_F(ClearBrowsingDataCollectionViewControllerTest,
TestItemsSignedInSyncOff) { TestItemsSignedInSyncOff) {
EXPECT_CALL(*mock_sync_service_, GetDisableReasons()) EXPECT_CALL(*mock_sync_service_, GetDisableReasons())
.WillRepeatedly(Return(syncer::SyncService::DISABLE_REASON_USER_CHOICE)); .WillRepeatedly(Return(syncer::SyncService::DISABLE_REASON_USER_CHOICE));
signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com"); identity_test_env()->SetPrimaryAccount("syncuser@example.com");
CreateController(); CreateController();
CheckController(); CheckController();
...@@ -188,7 +186,7 @@ TEST_F(ClearBrowsingDataCollectionViewControllerTest, ...@@ -188,7 +186,7 @@ TEST_F(ClearBrowsingDataCollectionViewControllerTest,
EXPECT_CALL(*mock_sync_service_, IsUsingSecondaryPassphrase()) EXPECT_CALL(*mock_sync_service_, IsUsingSecondaryPassphrase())
.WillRepeatedly(Return(true)); .WillRepeatedly(Return(true));
signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com"); identity_test_env()->SetPrimaryAccount("syncuser@example.com");
CreateController(); CreateController();
CheckController(); CheckController();
......
...@@ -69,7 +69,6 @@ class ClearBrowsingDataManagerTest : public PlatformTest { ...@@ -69,7 +69,6 @@ class ClearBrowsingDataManagerTest : public PlatformTest {
} }
identity::IdentityTestEnvironment* identity_test_env() { identity::IdentityTestEnvironment* identity_test_env() {
DCHECK(identity_test_env_adaptor_);
return identity_test_env_adaptor_->identity_test_env(); return identity_test_env_adaptor_->identity_test_env();
} }
......
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