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