Commit 4b4be847 authored by Nohemi Fernandez's avatar Nohemi Fernandez Committed by Commit Bot

[iOS] Consolidate Identity test APIs.

Removes duplicate Identity test APIs with similar intent, as well as
duplicated code to create identities.

Bug: 1103274
Change-Id: I2730287d5efe430dd0b9ef8dfb255648c5c82329
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2332673Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Commit-Queue: Nohemi Fernandez <fernandex@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795478}
parent 9a62ac5d
...@@ -544,8 +544,7 @@ void ChooseImportOrKeepDataSepareteDialog(id<GREYMatcher> choiceButtonMatcher) { ...@@ -544,8 +544,7 @@ void ChooseImportOrKeepDataSepareteDialog(id<GREYMatcher> choiceButtonMatcher) {
fakeIdentity.userEmail)]; fakeIdentity.userEmail)];
// Remove the fake identity. // Remove the fake identity.
[SigninEarlGrey removeFakeIdentity:fakeIdentity]; [SigninEarlGrey forgetFakeIdentity:fakeIdentity];
[ChromeEarlGreyUI waitForAppToIdle];
// Check that the identity has been removed. // Check that the identity has been removed.
[[EarlGrey selectElementWithMatcher:identityChooserButtonMatcherWithEmail( [[EarlGrey selectElementWithMatcher:identityChooserButtonMatcherWithEmail(
......
...@@ -199,7 +199,7 @@ TEST_F(SigninUtilsTest, TestWillNotShowWithAccountRemoved) { ...@@ -199,7 +199,7 @@ TEST_F(SigninUtilsTest, TestWillNotShowWithAccountRemoved) {
} }
ASSERT_NE(nil, foo1Identity); ASSERT_NE(nil, foo1Identity);
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider() ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()
->RemoveIdentity(foo1Identity); ->ForgetIdentity(foo1Identity, nil);
EXPECT_FALSE( EXPECT_FALSE(
SigninShouldPresentUserSigninUpgrade(chrome_browser_state_.get())); SigninShouldPresentUserSigninUpgrade(chrome_browser_state_.get()));
} }
......
...@@ -32,8 +32,8 @@ ...@@ -32,8 +32,8 @@
// Adds |fakeIdentity| to the fake identity service. // Adds |fakeIdentity| to the fake identity service.
- (void)addFakeIdentity:(FakeChromeIdentity*)fakeIdentity; - (void)addFakeIdentity:(FakeChromeIdentity*)fakeIdentity;
// Removes |fakeIdentity| from the fake chrome identity service, to simulate // Removes |fakeIdentity| from the fake identity service asynchronously to
// identity removal from the device. // simulate identity removal from the device.
- (void)forgetFakeIdentity:(FakeChromeIdentity*)fakeIdentity; - (void)forgetFakeIdentity:(FakeChromeIdentity*)fakeIdentity;
// Induces a GREYAssert if |fakeIdentity| is not signed in to the active // Induces a GREYAssert if |fakeIdentity| is not signed in to the active
...@@ -43,9 +43,6 @@ ...@@ -43,9 +43,6 @@
// Induces a GREYAssert if an identity is signed in. // Induces a GREYAssert if an identity is signed in.
- (void)checkSignedOut; - (void)checkSignedOut;
// Removes |fakeIdentity| from the fake identity service.
- (void)removeFakeIdentity:(FakeChromeIdentity*)fakeIdentity;
// Wait until |matcher| is accessible (not nil). // Wait until |matcher| is accessible (not nil).
- (void)waitForMatcher:(id<GREYMatcher>)matcher; - (void)waitForMatcher:(id<GREYMatcher>)matcher;
......
...@@ -16,21 +16,15 @@ ...@@ -16,21 +16,15 @@
@implementation SigninEarlGreyImpl @implementation SigninEarlGreyImpl
- (FakeChromeIdentity*)fakeIdentity1 { - (FakeChromeIdentity*)fakeIdentity1 {
return [FakeChromeIdentity identityWithEmail:@"foo1@gmail.com" return [SigninEarlGreyAppInterface fakeIdentity1];
gaiaID:@"foo1ID"
name:@"Fake Foo 1"];
} }
- (FakeChromeIdentity*)fakeIdentity2 { - (FakeChromeIdentity*)fakeIdentity2 {
return [FakeChromeIdentity identityWithEmail:@"foo2@gmail.com" return [SigninEarlGreyAppInterface fakeIdentity2];
gaiaID:@"foo2ID"
name:@"Fake Foo 2"];
} }
- (FakeChromeIdentity*)fakeManagedIdentity { - (FakeChromeIdentity*)fakeManagedIdentity {
return [FakeChromeIdentity identityWithEmail:@"foo@managed.com" return [SigninEarlGreyAppInterface fakeManagedIdentity];
gaiaID:@"fooManagedID"
name:@"Fake Managed"];
} }
- (void)addFakeIdentity:(FakeChromeIdentity*)fakeIdentity { - (void)addFakeIdentity:(FakeChromeIdentity*)fakeIdentity {
...@@ -79,10 +73,6 @@ ...@@ -79,10 +73,6 @@
@"Unexpected signed in user"); @"Unexpected signed in user");
} }
- (void)removeFakeIdentity:(FakeChromeIdentity*)fakeIdentity {
[SigninEarlGreyAppInterface removeFakeIdentity:fakeIdentity];
}
- (void)waitForMatcher:(id<GREYMatcher>)matcher { - (void)waitForMatcher:(id<GREYMatcher>)matcher {
ConditionBlock condition = ^{ ConditionBlock condition = ^{
NSError* error = nil; NSError* error = nil;
......
...@@ -21,11 +21,14 @@ ...@@ -21,11 +21,14 @@
// Returns a second fake identity. // Returns a second fake identity.
+ (FakeChromeIdentity*)fakeIdentity2; + (FakeChromeIdentity*)fakeIdentity2;
// Returns a fake managed identity.
+ (FakeChromeIdentity*)fakeManagedIdentity;
// Adds |fakeIdentity| to the fake identity service. // Adds |fakeIdentity| to the fake identity service.
+ (void)addFakeIdentity:(FakeChromeIdentity*)fakeIdentity; + (void)addFakeIdentity:(FakeChromeIdentity*)fakeIdentity;
// Removes |fakeIdentity| from the fake chrome identity service, to simulate // Removes |fakeIdentity| from the fake chrome identity service asynchronously
// identity removal from the device. // to simulate identity removal from the device.
+ (void)forgetFakeIdentity:(FakeChromeIdentity*)fakeIdentity; + (void)forgetFakeIdentity:(FakeChromeIdentity*)fakeIdentity;
// Returns the gaia ID of the signed-in account. // Returns the gaia ID of the signed-in account.
...@@ -37,9 +40,6 @@ ...@@ -37,9 +40,6 @@
// Returns a matcher for an identity picker cell for |email|. // Returns a matcher for an identity picker cell for |email|.
+ (id<GREYMatcher>)identityCellMatcherForEmail:(NSString*)email; + (id<GREYMatcher>)identityCellMatcherForEmail:(NSString*)email;
// Removes |fakeIdentity| from the fake identity service.
+ (void)removeFakeIdentity:(FakeChromeIdentity*)fakeIdentity;
// Checks if any identity is currently authenticated. // Checks if any identity is currently authenticated.
+ (BOOL)isAuthenticated; + (BOOL)isAuthenticated;
......
...@@ -40,6 +40,12 @@ ...@@ -40,6 +40,12 @@
name:@"Fake Foo 2"]; name:@"Fake Foo 2"];
} }
+ (FakeChromeIdentity*)fakeManagedIdentity {
return [FakeChromeIdentity identityWithEmail:@"foo@managed.com"
gaiaID:@"fooManagedID"
name:@"Fake Managed"];
}
+ (void)addFakeIdentity:(FakeChromeIdentity*)fakeIdentity { + (void)addFakeIdentity:(FakeChromeIdentity*)fakeIdentity {
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
fakeIdentity); fakeIdentity);
...@@ -74,11 +80,6 @@ ...@@ -74,11 +80,6 @@
grey_sufficientlyVisible(), nil); grey_sufficientlyVisible(), nil);
} }
+ (void)removeFakeIdentity:(FakeChromeIdentity*)fakeIdentity {
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()
->RemoveIdentity(fakeIdentity);
}
+ (BOOL)isAuthenticated { + (BOOL)isAuthenticated {
ChromeBrowserState* browser_state = ChromeBrowserState* browser_state =
chrome_test_util::GetOriginalBrowserState(); chrome_test_util::GetOriginalBrowserState();
......
...@@ -43,11 +43,9 @@ class SigninPromoViewMediatorTest : public PlatformTest { ...@@ -43,11 +43,9 @@ class SigninPromoViewMediatorTest : public PlatformTest {
void TearDown() override { void TearDown() override {
// All callbacks should be triggered to make sure tests are working // All callbacks should be triggered to make sure tests are working
// correctly. If this test fails, // correctly.
// |WaitUntilFakeChromeIdentityServiceCallbackCompleted| should be called EXPECT_TRUE(ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()
// in the test. ->WaitForServiceCallbacksToComplete());
EXPECT_FALSE(ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()
->HasPendingCallback());
[mediator_ signinPromoViewIsRemoved]; [mediator_ signinPromoViewIsRemoved];
EXPECT_EQ(ios::SigninPromoViewState::Invalid, EXPECT_EQ(ios::SigninPromoViewState::Invalid,
mediator_.signinPromoViewState); mediator_.signinPromoViewState);
...@@ -175,22 +173,12 @@ class SigninPromoViewMediatorTest : public PlatformTest { ...@@ -175,22 +173,12 @@ class SigninPromoViewMediatorTest : public PlatformTest {
void CheckForImageNotification() { void CheckForImageNotification() {
configurator_ = nil; configurator_ = nil;
ExpectConfiguratorNotification(NO /* identity changed */); ExpectConfiguratorNotification(NO /* identity changed */);
WaitUntilFakeChromeIdentityServiceCallbackCompleted(); EXPECT_TRUE(ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()
->WaitForServiceCallbacksToComplete());
// Check the configurator received by the consumer. // Check the configurator received by the consumer.
CheckWarmStateConfigurator(configurator_); CheckWarmStateConfigurator(configurator_);
} }
// Runs the runloop until all callback from FakeChromeIdentityService are
// called.
void WaitUntilFakeChromeIdentityServiceCallbackCompleted() {
ConditionBlock condition = ^() {
return !ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()
->HasPendingCallback();
};
EXPECT_TRUE(
WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, condition));
}
// Mediator used for the tests. // Mediator used for the tests.
SigninPromoViewMediator* mediator_; SigninPromoViewMediator* mediator_;
...@@ -261,7 +249,7 @@ TEST_F(SigninPromoViewMediatorTest, ConfigureSigninPromoViewWithWarmAndCold) { ...@@ -261,7 +249,7 @@ TEST_F(SigninPromoViewMediatorTest, ConfigureSigninPromoViewWithWarmAndCold) {
// configureSigninPromoWithConfigurator:identityChanged:]. // configureSigninPromoWithConfigurator:identityChanged:].
ExpectConfiguratorNotification(YES /* identity changed */); ExpectConfiguratorNotification(YES /* identity changed */);
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider() ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()
->RemoveIdentity(expected_default_identity_); ->ForgetIdentity(expected_default_identity_, nil);
expected_default_identity_ = nil; expected_default_identity_ = nil;
// Check the received configurator. // Check the received configurator.
CheckColdStateConfigurator(configurator_); CheckColdStateConfigurator(configurator_);
...@@ -334,7 +322,8 @@ TEST_F(SigninPromoViewMediatorTest, ...@@ -334,7 +322,8 @@ TEST_F(SigninPromoViewMediatorTest,
// Adds an identity while doing sign-in. // Adds an identity while doing sign-in.
AddDefaultIdentity(); AddDefaultIdentity();
// No consumer notification should be expected. // No consumer notification should be expected.
WaitUntilFakeChromeIdentityServiceCallbackCompleted(); EXPECT_TRUE(ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()
->WaitForServiceCallbacksToComplete());
// Finishs the sign-in. // Finishs the sign-in.
OCMExpect([consumer_ signinDidFinish]); OCMExpect([consumer_ signinDidFinish]);
completion(YES); completion(YES);
...@@ -367,7 +356,8 @@ TEST_F(SigninPromoViewMediatorTest, ...@@ -367,7 +356,8 @@ TEST_F(SigninPromoViewMediatorTest,
// Simulates an identity update. // Simulates an identity update.
[chromeIdentityServiceObserver profileUpdate:expected_default_identity_]; [chromeIdentityServiceObserver profileUpdate:expected_default_identity_];
// Spins the run loop to wait for the profile image update. // Spins the run loop to wait for the profile image update.
WaitUntilFakeChromeIdentityServiceCallbackCompleted(); EXPECT_TRUE(ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()
->WaitForServiceCallbacksToComplete());
// Finishs the sign-in. // Finishs the sign-in.
OCMExpect([consumer_ signinDidFinish]); OCMExpect([consumer_ signinDidFinish]);
completion(YES); completion(YES);
......
...@@ -168,7 +168,7 @@ id<GREYMatcher> TitleOfTestPage() { ...@@ -168,7 +168,7 @@ id<GREYMatcher> TitleOfTestPage() {
[SigninEarlGreyUI checkSigninPromoVisibleWithMode:SigninPromoViewModeWarmState [SigninEarlGreyUI checkSigninPromoVisibleWithMode:SigninPromoViewModeWarmState
closeButton:NO]; closeButton:NO];
[self closeRecentTabs]; [self closeRecentTabs];
[SigninEarlGrey removeFakeIdentity:fakeIdentity]; [SigninEarlGrey forgetFakeIdentity:fakeIdentity];
} }
// Tests that the sign-in promo can be reloaded correctly while being hidden. // Tests that the sign-in promo can be reloaded correctly while being hidden.
...@@ -198,7 +198,7 @@ id<GREYMatcher> TitleOfTestPage() { ...@@ -198,7 +198,7 @@ id<GREYMatcher> TitleOfTestPage() {
[SigninEarlGreyUI checkSigninPromoVisibleWithMode:SigninPromoViewModeWarmState [SigninEarlGreyUI checkSigninPromoVisibleWithMode:SigninPromoViewModeWarmState
closeButton:NO]; closeButton:NO];
[self closeRecentTabs]; [self closeRecentTabs];
[SigninEarlGrey removeFakeIdentity:fakeIdentity]; [SigninEarlGrey forgetFakeIdentity:fakeIdentity];
} }
// Tests that the VC can be dismissed by swiping down. // Tests that the VC can be dismissed by swiping down.
......
...@@ -42,6 +42,7 @@ source_set("test_support") { ...@@ -42,6 +42,7 @@ source_set("test_support") {
":fake_chrome_identity", ":fake_chrome_identity",
":signin", ":signin",
"//base", "//base",
"//base/test:test_support",
"//components/signin/public/identity_manager", "//components/signin/public/identity_manager",
"//google_apis", "//google_apis",
"//ios/public/provider/chrome/browser", "//ios/public/provider/chrome/browser",
...@@ -60,6 +61,7 @@ source_set("fake_chrome_identity") { ...@@ -60,6 +61,7 @@ source_set("fake_chrome_identity") {
deps = [ deps = [
":signin", ":signin",
"//base", "//base",
"//base/test:test_support",
] ]
} }
......
...@@ -87,14 +87,12 @@ class FakeChromeIdentityService : public ChromeIdentityService { ...@@ -87,14 +87,12 @@ class FakeChromeIdentityService : public ChromeIdentityService {
// is already added. // is already added.
void AddIdentity(ChromeIdentity* identity); void AddIdentity(ChromeIdentity* identity);
// Removes |identity| from the available identities. No-op if the identity
// is unknown.
void RemoveIdentity(ChromeIdentity* identity);
// When set to true, call to GetAccessToken() fakes a MDM error. // When set to true, call to GetAccessToken() fakes a MDM error.
void SetFakeMDMError(bool fakeMDMError); void SetFakeMDMError(bool fakeMDMError);
bool HasPendingCallback(); // Waits until all asynchronous callbacks have been completed by the service.
// Returns true on successful completion.
bool WaitForServiceCallbacksToComplete();
private: private:
NSMutableArray* identities_; NSMutableArray* identities_;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
#include "google_apis/gaia/gaia_auth_util.h" #include "google_apis/gaia/gaia_auth_util.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h" #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
...@@ -19,6 +20,8 @@ ...@@ -19,6 +20,8 @@
using ::testing::_; using ::testing::_;
using ::testing::Invoke; using ::testing::Invoke;
using base::test::ios::kWaitForUIElementTimeout;
using base::test::ios::WaitUntilConditionOrTimeout;
namespace { namespace {
...@@ -327,19 +330,15 @@ void FakeChromeIdentityService::AddIdentity(ChromeIdentity* identity) { ...@@ -327,19 +330,15 @@ void FakeChromeIdentityService::AddIdentity(ChromeIdentity* identity) {
FireIdentityListChanged(); FireIdentityListChanged();
} }
void FakeChromeIdentityService::RemoveIdentity(ChromeIdentity* identity) {
if ([identities_ indexOfObject:identity] != NSNotFound) {
[identities_ removeObject:identity];
FireIdentityListChanged();
}
}
void FakeChromeIdentityService::SetFakeMDMError(bool fakeMDMError) { void FakeChromeIdentityService::SetFakeMDMError(bool fakeMDMError) {
_fakeMDMError = fakeMDMError; _fakeMDMError = fakeMDMError;
} }
bool FakeChromeIdentityService::HasPendingCallback() { bool FakeChromeIdentityService::WaitForServiceCallbacksToComplete() {
return _pendingCallback > 0; ConditionBlock condition = ^() {
return _pendingCallback == 0;
};
return WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, condition);
} }
} // namespace ios } // namespace ios
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