Chromium Code Reviews| Index: ios/chrome/browser/ui/authentication/signin_promo_view_mediator_unittest.mm |
| diff --git a/ios/chrome/browser/ui/authentication/signin_promo_view_mediator_unittest.mm b/ios/chrome/browser/ui/authentication/signin_promo_view_mediator_unittest.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2d15bd68f2bf601b337c706c7f92b2f20366e9c7 |
| --- /dev/null |
| +++ b/ios/chrome/browser/ui/authentication/signin_promo_view_mediator_unittest.mm |
| @@ -0,0 +1,152 @@ |
| +// 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/authentication/signin_promo_view_mediator.h" |
| + |
| +#import "ios/third_party/material_components_ios/src/components/Buttons/src/MaterialButtons.h" |
| +#import "testing/platform_test.h" |
| +#import "third_party/ocmock/OCMock/OCMock.h" |
| +#include "third_party/ocmock/gtest_support.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +namespace { |
| + |
| +class SigninPromoViewMediatorTest : public PlatformTest { |
| + protected: |
| + void SetUp() override { |
| + _mediator = [[SigninPromoViewMediator alloc] init]; |
| + |
| + _signinPromoView = OCMStrictClassMock([SigninPromoView class]); |
|
lpromero
2017/03/24 10:36:20
Why not just a real SigninPromoView? You don't rea
jlebel
2017/03/24 20:59:09
I have a better control about what is done on Sign
lpromero
2017/03/27 13:14:46
You mean that the view takes the configurator data
|
| + _primaryButton = OCMStrictClassMock([MDCFlatButton class]); |
| + OCMStub([_signinPromoView primaryButton]).andReturn(_primaryButton); |
| + _secondaryButton = OCMStrictClassMock([MDCFlatButton class]); |
| + OCMStub([_signinPromoView secondaryButton]).andReturn(_secondaryButton); |
| + } |
| + |
| + void TearDown() override { |
| + _mediator = nil; |
| + EXPECT_OCMOCK_VERIFY((id)_signinPromoView); |
| + EXPECT_OCMOCK_VERIFY((id)_primaryButton); |
| + EXPECT_OCMOCK_VERIFY((id)_secondaryButton); |
| + } |
| + |
| + void ExpectColdStartConfiguration() { |
| + OCMExpect([_signinPromoView setMode:SigninPromoViewColdStartMode]); |
| + _imageViewProfileImage = nil; |
| + _primaryButtonTitle = nil; |
| + OCMExpect([_primaryButton setTitle:[OCMArg checkWithBlock:^BOOL(id value) { |
| + _primaryButtonTitle = value; |
| + return YES; |
| + }] |
| + forState:UIControlStateNormal]); |
| + _secondaryButtonTitle = nil; |
| + } |
| + |
| + void CheckColdStartConfiguration() { |
| + EXPECT_EQ(nil, _imageViewProfileImage); |
| + EXPECT_NE(nil, _primaryButtonTitle); |
| + EXPECT_EQ(nil, _secondaryButtonTitle); |
| + } |
| + |
| + void ExpectWarmStartConfiguration() { |
| + OCMExpect([_signinPromoView setMode:SigninPromoViewWarmStartMode]); |
| + OCMExpect([_signinPromoView |
| + setProfileImage:[OCMArg checkWithBlock:^BOOL(id value) { |
| + _imageViewProfileImage = value; |
| + return YES; |
| + }]]); |
| + _primaryButtonTitle = nil; |
| + OCMExpect([_primaryButton setTitle:[OCMArg checkWithBlock:^BOOL(id value) { |
| + _primaryButtonTitle = value; |
| + return YES; |
| + }] |
| + forState:UIControlStateNormal]); |
| + _secondaryButtonTitle = nil; |
| + OCMExpect([_secondaryButton |
| + setTitle:[OCMArg checkWithBlock:^BOOL(id value) { |
| + _secondaryButtonTitle = value; |
| + return YES; |
| + }] |
| + forState:UIControlStateNormal]); |
| + } |
| + |
| + void CheckWarmStartConfiguration() { |
| + EXPECT_NE(nil, _imageViewProfileImage); |
| + NSRange profileNameRange = |
| + [_primaryButtonTitle rangeOfString:_mediator.userFullName]; |
| + EXPECT_NE(profileNameRange.length, 0u); |
| + NSRange profileEmailRange = |
| + [_secondaryButtonTitle rangeOfString:_mediator.userEmail]; |
| + EXPECT_NE(profileEmailRange.length, 0u); |
| + } |
| + |
| + // Mediator used for the tests. |
| + SigninPromoViewMediator* _mediator; |
|
lpromero
2017/03/24 10:36:20
C++ class, so use trailing underscore and snake ca
jlebel
2017/03/24 20:59:09
Done.
|
| + |
| + // Mocks. |
| + SigninPromoView* _signinPromoView; |
| + MDCFlatButton* _primaryButton; |
| + MDCFlatButton* _secondaryButton; |
| + |
| + // Value set by -[SigninPromoView setProfileImage:]. |
| + UIImage* _imageViewProfileImage; |
| + // Value set by -[_primaryButton setTitle: forState:UIControlStateNormal]. |
| + NSString* _primaryButtonTitle; |
| + // Value set by -[_secondaryButton setTitle: forState:UIControlStateNormal]. |
| + NSString* _secondaryButtonTitle; |
| +}; |
| + |
| +TEST_F(SigninPromoViewMediatorTest, ColdStartConfigureSigninPromoView) { |
| + EXPECT_TRUE(_mediator.coldStart); |
|
lpromero
2017/03/24 10:36:20
I don;t see this property on the mediator. Where i
jlebel
2017/03/24 20:59:10
Done.
|
| + EXPECT_EQ(nil, _mediator.userFullName); |
| + EXPECT_EQ(nil, _mediator.userEmail); |
| + EXPECT_EQ(nil, _mediator.userImage); |
| + |
| + ExpectColdStartConfiguration(); |
| + [_mediator configureSigninPromoView:_signinPromoView]; |
| + CheckColdStartConfiguration(); |
| +} |
| + |
| +TEST_F(SigninPromoViewMediatorTest, |
| + WarmStartConfigureSigninPromoViewWithoutImage) { |
| + _mediator.userFullName = @"John Doe"; |
| + _mediator.userEmail = @"johndoe@example.com"; |
| + EXPECT_FALSE(_mediator.coldStart); |
| + |
| + ExpectWarmStartConfiguration(); |
| + [_mediator configureSigninPromoView:_signinPromoView]; |
| + CheckWarmStartConfiguration(); |
| +} |
| + |
| +TEST_F(SigninPromoViewMediatorTest, |
| + WarmStartConfigureSigninPromoViewWithImage) { |
| + _mediator.userFullName = @"John Doe"; |
| + _mediator.userEmail = @"johndoe@example.com"; |
| + _mediator.userImage = [[UIImage alloc] init]; |
| + EXPECT_FALSE(_mediator.coldStart); |
| + |
| + ExpectWarmStartConfiguration(); |
| + [_mediator configureSigninPromoView:_signinPromoView]; |
| + CheckWarmStartConfiguration(); |
| + EXPECT_EQ(_mediator.userImage, _imageViewProfileImage); |
| +} |
| + |
| +// Cold start configuration and then warm start configuration. |
| +TEST_F(SigninPromoViewMediatorTest, TwoConfigureSigninPromoView) { |
| + ExpectColdStartConfiguration(); |
| + [_mediator configureSigninPromoView:_signinPromoView]; |
| + CheckColdStartConfiguration(); |
| + |
| + _mediator.userFullName = @"John Doe"; |
| + _mediator.userEmail = @"johndoe@example.com"; |
| + |
| + ExpectWarmStartConfiguration(); |
| + [_mediator configureSigninPromoView:_signinPromoView]; |
| + CheckWarmStartConfiguration(); |
| +} |
| + |
| +} // namespace |