Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "ios/chrome/browser/ui/authentication/signin_promo_view_mediator.h" | |
| 6 | |
| 7 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" | |
| 8 #import "testing/platform_test.h" | |
| 9 #import "third_party/ocmock/OCMock/OCMock.h" | |
| 10 #include "third_party/ocmock/gtest_support.h" | |
| 11 | |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 13 #error "This file requires ARC support." | |
| 14 #endif | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 class SigninPromoViewMediatorTest : public PlatformTest { | |
| 19 protected: | |
| 20 void SetUp() override { | |
| 21 _mediator = [[SigninPromoViewMediator alloc] init]; | |
| 22 | |
| 23 _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
| |
| 24 _primaryButton = OCMStrictClassMock([MDCFlatButton class]); | |
| 25 OCMStub([_signinPromoView primaryButton]).andReturn(_primaryButton); | |
| 26 _secondaryButton = OCMStrictClassMock([MDCFlatButton class]); | |
| 27 OCMStub([_signinPromoView secondaryButton]).andReturn(_secondaryButton); | |
| 28 } | |
| 29 | |
| 30 void TearDown() override { | |
| 31 _mediator = nil; | |
| 32 EXPECT_OCMOCK_VERIFY((id)_signinPromoView); | |
| 33 EXPECT_OCMOCK_VERIFY((id)_primaryButton); | |
| 34 EXPECT_OCMOCK_VERIFY((id)_secondaryButton); | |
| 35 } | |
| 36 | |
| 37 void ExpectColdStartConfiguration() { | |
| 38 OCMExpect([_signinPromoView setMode:SigninPromoViewColdStartMode]); | |
| 39 _imageViewProfileImage = nil; | |
| 40 _primaryButtonTitle = nil; | |
| 41 OCMExpect([_primaryButton setTitle:[OCMArg checkWithBlock:^BOOL(id value) { | |
| 42 _primaryButtonTitle = value; | |
| 43 return YES; | |
| 44 }] | |
| 45 forState:UIControlStateNormal]); | |
| 46 _secondaryButtonTitle = nil; | |
| 47 } | |
| 48 | |
| 49 void CheckColdStartConfiguration() { | |
| 50 EXPECT_EQ(nil, _imageViewProfileImage); | |
| 51 EXPECT_NE(nil, _primaryButtonTitle); | |
| 52 EXPECT_EQ(nil, _secondaryButtonTitle); | |
| 53 } | |
| 54 | |
| 55 void ExpectWarmStartConfiguration() { | |
| 56 OCMExpect([_signinPromoView setMode:SigninPromoViewWarmStartMode]); | |
| 57 OCMExpect([_signinPromoView | |
| 58 setProfileImage:[OCMArg checkWithBlock:^BOOL(id value) { | |
| 59 _imageViewProfileImage = value; | |
| 60 return YES; | |
| 61 }]]); | |
| 62 _primaryButtonTitle = nil; | |
| 63 OCMExpect([_primaryButton setTitle:[OCMArg checkWithBlock:^BOOL(id value) { | |
| 64 _primaryButtonTitle = value; | |
| 65 return YES; | |
| 66 }] | |
| 67 forState:UIControlStateNormal]); | |
| 68 _secondaryButtonTitle = nil; | |
| 69 OCMExpect([_secondaryButton | |
| 70 setTitle:[OCMArg checkWithBlock:^BOOL(id value) { | |
| 71 _secondaryButtonTitle = value; | |
| 72 return YES; | |
| 73 }] | |
| 74 forState:UIControlStateNormal]); | |
| 75 } | |
| 76 | |
| 77 void CheckWarmStartConfiguration() { | |
| 78 EXPECT_NE(nil, _imageViewProfileImage); | |
| 79 NSRange profileNameRange = | |
| 80 [_primaryButtonTitle rangeOfString:_mediator.userFullName]; | |
| 81 EXPECT_NE(profileNameRange.length, 0u); | |
| 82 NSRange profileEmailRange = | |
| 83 [_secondaryButtonTitle rangeOfString:_mediator.userEmail]; | |
| 84 EXPECT_NE(profileEmailRange.length, 0u); | |
| 85 } | |
| 86 | |
| 87 // Mediator used for the tests. | |
| 88 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.
| |
| 89 | |
| 90 // Mocks. | |
| 91 SigninPromoView* _signinPromoView; | |
| 92 MDCFlatButton* _primaryButton; | |
| 93 MDCFlatButton* _secondaryButton; | |
| 94 | |
| 95 // Value set by -[SigninPromoView setProfileImage:]. | |
| 96 UIImage* _imageViewProfileImage; | |
| 97 // Value set by -[_primaryButton setTitle: forState:UIControlStateNormal]. | |
| 98 NSString* _primaryButtonTitle; | |
| 99 // Value set by -[_secondaryButton setTitle: forState:UIControlStateNormal]. | |
| 100 NSString* _secondaryButtonTitle; | |
| 101 }; | |
| 102 | |
| 103 TEST_F(SigninPromoViewMediatorTest, ColdStartConfigureSigninPromoView) { | |
| 104 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.
| |
| 105 EXPECT_EQ(nil, _mediator.userFullName); | |
| 106 EXPECT_EQ(nil, _mediator.userEmail); | |
| 107 EXPECT_EQ(nil, _mediator.userImage); | |
| 108 | |
| 109 ExpectColdStartConfiguration(); | |
| 110 [_mediator configureSigninPromoView:_signinPromoView]; | |
| 111 CheckColdStartConfiguration(); | |
| 112 } | |
| 113 | |
| 114 TEST_F(SigninPromoViewMediatorTest, | |
| 115 WarmStartConfigureSigninPromoViewWithoutImage) { | |
| 116 _mediator.userFullName = @"John Doe"; | |
| 117 _mediator.userEmail = @"johndoe@example.com"; | |
| 118 EXPECT_FALSE(_mediator.coldStart); | |
| 119 | |
| 120 ExpectWarmStartConfiguration(); | |
| 121 [_mediator configureSigninPromoView:_signinPromoView]; | |
| 122 CheckWarmStartConfiguration(); | |
| 123 } | |
| 124 | |
| 125 TEST_F(SigninPromoViewMediatorTest, | |
| 126 WarmStartConfigureSigninPromoViewWithImage) { | |
| 127 _mediator.userFullName = @"John Doe"; | |
| 128 _mediator.userEmail = @"johndoe@example.com"; | |
| 129 _mediator.userImage = [[UIImage alloc] init]; | |
| 130 EXPECT_FALSE(_mediator.coldStart); | |
| 131 | |
| 132 ExpectWarmStartConfiguration(); | |
| 133 [_mediator configureSigninPromoView:_signinPromoView]; | |
| 134 CheckWarmStartConfiguration(); | |
| 135 EXPECT_EQ(_mediator.userImage, _imageViewProfileImage); | |
| 136 } | |
| 137 | |
| 138 // Cold start configuration and then warm start configuration. | |
| 139 TEST_F(SigninPromoViewMediatorTest, TwoConfigureSigninPromoView) { | |
| 140 ExpectColdStartConfiguration(); | |
| 141 [_mediator configureSigninPromoView:_signinPromoView]; | |
| 142 CheckColdStartConfiguration(); | |
| 143 | |
| 144 _mediator.userFullName = @"John Doe"; | |
| 145 _mediator.userEmail = @"johndoe@example.com"; | |
| 146 | |
| 147 ExpectWarmStartConfiguration(); | |
| 148 [_mediator configureSigninPromoView:_signinPromoView]; | |
| 149 CheckWarmStartConfiguration(); | |
| 150 } | |
| 151 | |
| 152 } // namespace | |
| OLD | NEW |