| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 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/native_app_launcher/native_app_infobar_controller.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/mac/scoped_nsobject.h" |
| 10 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_types
.h" |
| 11 #include "ios/chrome/browser/native_app_launcher/native_app_infobar_delegate.h" |
| 12 #import "ios/chrome/browser/native_app_launcher/native_app_navigation_controller
_protocol.h" |
| 13 #include "testing/platform_test.h" |
| 14 |
| 15 @interface NativeAppInfoBarController (Testing) |
| 16 - (void)infoBarButtonDidPress:(UIButton*)button; |
| 17 - (void)setInfoBarDelegate:(NativeAppInfoBarDelegate*)delegate; |
| 18 @end |
| 19 |
| 20 namespace { |
| 21 |
| 22 class NativeAppInfoBarControllerTest : public PlatformTest { |
| 23 class MockNativeAppInfoBarDelegate : public NativeAppInfoBarDelegate { |
| 24 public: |
| 25 MockNativeAppInfoBarDelegate(NativeAppControllerType type) |
| 26 : NativeAppInfoBarDelegate(nil, GURL(), type), |
| 27 performedActionCount_(0), |
| 28 userAction_(NATIVE_APP_ACTION_COUNT){}; |
| 29 |
| 30 void CheckIfPerformedActionIsCorrectAndResetCounter() { |
| 31 EXPECT_EQ(expectedUserAction_, userAction_); |
| 32 EXPECT_EQ(performedActionCount_, 1); |
| 33 performedActionCount_ = 0; |
| 34 } |
| 35 |
| 36 void UserPerformedAction(NativeAppActionType userAction) override { |
| 37 userAction_ = userAction; |
| 38 performedActionCount_++; |
| 39 }; |
| 40 |
| 41 void SetExpectedUserAction(const NativeAppActionType expectedUserAction) { |
| 42 expectedUserAction_ = expectedUserAction; |
| 43 }; |
| 44 |
| 45 private: |
| 46 int performedActionCount_; |
| 47 NativeAppActionType userAction_; |
| 48 NativeAppActionType expectedUserAction_; |
| 49 }; |
| 50 |
| 51 class MockInfobarViewDelegate : public InfoBarViewDelegate { |
| 52 public: |
| 53 void SetInfoBarTargetHeight(int height) override{}; |
| 54 void InfoBarDidCancel() override{}; |
| 55 void InfoBarButtonDidPress(NSUInteger button_id) override{}; |
| 56 }; |
| 57 |
| 58 protected: |
| 59 void SetUpWithType(NativeAppControllerType type) { |
| 60 mockDelegate_.reset(new MockNativeAppInfoBarDelegate(type)); |
| 61 mockInfoBarViewDelegate_.reset(new MockInfobarViewDelegate()); |
| 62 infobarController_.reset([[NativeAppInfoBarController alloc] |
| 63 initWithDelegate:mockInfoBarViewDelegate_.get()]); |
| 64 [infobarController_ setInfoBarDelegate:mockDelegate_.get()]; |
| 65 }; |
| 66 |
| 67 // Checks -userPerformedAction: for calls to the delegate's |
| 68 // UserPerformedAction member function. |
| 69 void ExpectUserPerformedAction(NativeAppActionType performedAction) { |
| 70 mockDelegate_->SetExpectedUserAction(performedAction); |
| 71 UIButton* mockButton = [UIButton buttonWithType:UIButtonTypeCustom]; |
| 72 mockButton.tag = performedAction; |
| 73 [infobarController_ infoBarButtonDidPress:mockButton]; |
| 74 mockDelegate_->CheckIfPerformedActionIsCorrectAndResetCounter(); |
| 75 }; |
| 76 |
| 77 base::scoped_nsobject<NativeAppInfoBarController> infobarController_; |
| 78 std::unique_ptr<MockNativeAppInfoBarDelegate> mockDelegate_; |
| 79 std::unique_ptr<MockInfobarViewDelegate> mockInfoBarViewDelegate_; |
| 80 }; |
| 81 |
| 82 TEST_F(NativeAppInfoBarControllerTest, TestActionsWithInstallInfoBar) { |
| 83 SetUpWithType(NATIVE_APP_INSTALLER_CONTROLLER); |
| 84 ExpectUserPerformedAction(NATIVE_APP_ACTION_CLICK_INSTALL); |
| 85 ExpectUserPerformedAction(NATIVE_APP_ACTION_DISMISS); |
| 86 } |
| 87 |
| 88 TEST_F(NativeAppInfoBarControllerTest, TestActionsWithLaunchInfoBar) { |
| 89 SetUpWithType(NATIVE_APP_LAUNCHER_CONTROLLER); |
| 90 ExpectUserPerformedAction(NATIVE_APP_ACTION_CLICK_LAUNCH); |
| 91 ExpectUserPerformedAction(NATIVE_APP_ACTION_DISMISS); |
| 92 } |
| 93 |
| 94 TEST_F(NativeAppInfoBarControllerTest, TestActionsWithOpenPolicyInfoBar) { |
| 95 SetUpWithType(NATIVE_APP_OPEN_POLICY_CONTROLLER); |
| 96 ExpectUserPerformedAction(NATIVE_APP_ACTION_CLICK_ONCE); |
| 97 ExpectUserPerformedAction(NATIVE_APP_ACTION_CLICK_ALWAYS); |
| 98 ExpectUserPerformedAction(NATIVE_APP_ACTION_DISMISS); |
| 99 } |
| 100 |
| 101 } // namespace |
| OLD | NEW |