| 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 #include "chrome/browser/ui/views/global_error_bubble_view.h" |
| 6 |
| 7 #include <memory> |
| 8 #include <vector> |
| 9 |
| 10 #include "chrome/browser/ui/global_error/global_error.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/gfx/codec/png_codec.h" |
| 14 #include "ui/gfx/image/image.h" |
| 15 #include "ui/gfx/image/image_png_rep.h" |
| 16 #include "ui/gfx/image/image_unittest_util.h" |
| 17 #include "ui/views/controls/button/button.h" |
| 18 #include "ui/views/controls/button/label_button.h" |
| 19 |
| 20 using ::testing::_; |
| 21 using ::testing::Return; |
| 22 using ::testing::StrictMock; |
| 23 |
| 24 namespace views { |
| 25 class FakeButtonListener : public views::ButtonListener { |
| 26 public: |
| 27 FakeButtonListener() {} |
| 28 ~FakeButtonListener() override; |
| 29 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 30 |
| 31 private: |
| 32 DISALLOW_COPY_AND_ASSIGN(FakeButtonListener); |
| 33 }; |
| 34 |
| 35 FakeButtonListener::~FakeButtonListener() {} |
| 36 void FakeButtonListener::ButtonPressed(views::Button* sender, |
| 37 const ui::Event& event) {} |
| 38 |
| 39 namespace { |
| 40 |
| 41 class MockGlobalErrorWithStandardBubble : public GlobalErrorWithStandardBubble { |
| 42 public: |
| 43 MockGlobalErrorWithStandardBubble() {} |
| 44 ~MockGlobalErrorWithStandardBubble() override; |
| 45 |
| 46 MOCK_METHOD0(GetBubbleViewIcon, gfx::Image()); |
| 47 MOCK_METHOD0(GetBubbleViewTitle, base::string16()); |
| 48 MOCK_METHOD0(GetBubbleViewMessage, std::vector<base::string16>()); |
| 49 MOCK_METHOD0(GetBubbleViewAcceptButtonLabel, base::string16()); |
| 50 MOCK_CONST_METHOD0(ShouldShowCloseButton, bool()); |
| 51 MOCK_METHOD0(ShouldAddElevationIconToAcceptButton, bool()); |
| 52 MOCK_METHOD0(GetBubbleViewCancelButtonLabel, base::string16()); |
| 53 MOCK_METHOD1(BubbleViewDidClose, void(Browser* browser)); |
| 54 MOCK_METHOD1(OnBubbleViewDidClose, void(Browser* browser)); |
| 55 MOCK_METHOD1(BubbleViewAcceptButtonPressed, void(Browser* browser)); |
| 56 MOCK_METHOD1(BubbleViewCancelButtonPressed, void(Browser* browser)); |
| 57 MOCK_CONST_METHOD0(ShouldCloseOnDeactivate, bool()); |
| 58 MOCK_METHOD0(HasBubbleView, bool()); |
| 59 MOCK_METHOD0(HasShownBubbleView, bool()); |
| 60 MOCK_METHOD1(ShowBubbleView, void(Browser* browser)); |
| 61 MOCK_METHOD0(GetBubbleView, GlobalErrorBubbleViewBase*()); |
| 62 MOCK_METHOD0(HasMenuItem, bool()); |
| 63 MOCK_METHOD0(MenuItemCommandID, int()); |
| 64 MOCK_METHOD0(MenuItemLabel, base::string16()); |
| 65 MOCK_METHOD1(ExecuteMenuItem, void(Browser* browser)); |
| 66 MOCK_METHOD0(GetBubbleViewMessages, std::vector<base::string16>()); |
| 67 |
| 68 private: |
| 69 DISALLOW_COPY_AND_ASSIGN(MockGlobalErrorWithStandardBubble); |
| 70 }; |
| 71 |
| 72 MockGlobalErrorWithStandardBubble::~MockGlobalErrorWithStandardBubble() {} |
| 73 |
| 74 } // namespace |
| 75 |
| 76 class GlobalErrorBubbleViewTest : public testing::Test { |
| 77 public: |
| 78 GlobalErrorBubbleViewTest() |
| 79 : mock_global_error_with_standard_bubble_( |
| 80 base::MakeUnique<StrictMock<MockGlobalErrorWithStandardBubble>>()), |
| 81 button_(&mock_button_listener_, base::string16()), |
| 82 view_(base::MakeUnique<GlobalErrorBubbleView>( |
| 83 &arg_view_, |
| 84 anchor_point_, |
| 85 arrow_, |
| 86 nullptr, |
| 87 mock_global_error_with_standard_bubble_->AsWeakPtr())) {} |
| 88 |
| 89 protected: |
| 90 std::unique_ptr<StrictMock<MockGlobalErrorWithStandardBubble>> |
| 91 mock_global_error_with_standard_bubble_; |
| 92 views::View arg_view_; |
| 93 const gfx::Point anchor_point_; |
| 94 views::BubbleBorder::Arrow arrow_; |
| 95 FakeButtonListener mock_button_listener_; |
| 96 views::LabelButton button_; |
| 97 std::unique_ptr<GlobalErrorBubbleView> view_; |
| 98 |
| 99 private: |
| 100 DISALLOW_COPY_AND_ASSIGN(GlobalErrorBubbleViewTest); |
| 101 }; |
| 102 |
| 103 TEST_F(GlobalErrorBubbleViewTest, Basic) { |
| 104 EXPECT_CALL(*mock_global_error_with_standard_bubble_, GetBubbleViewTitle()); |
| 105 view_->GetWindowTitle(); |
| 106 |
| 107 std::vector<gfx::ImagePNGRep> image_png_reps; |
| 108 image_png_reps.push_back( |
| 109 gfx::ImagePNGRep(gfx::test::CreatePNGBytes(25), 1.0f)); |
| 110 gfx::Image image = gfx::Image(image_png_reps); |
| 111 EXPECT_CALL(*mock_global_error_with_standard_bubble_, GetBubbleViewIcon()) |
| 112 .WillOnce(Return(image)); |
| 113 view_->GetWindowIcon(); |
| 114 |
| 115 EXPECT_TRUE(view_->ShouldShowWindowIcon()); |
| 116 |
| 117 EXPECT_CALL(*mock_global_error_with_standard_bubble_, |
| 118 BubbleViewDidClose(nullptr)); |
| 119 view_->WindowClosing(); |
| 120 |
| 121 EXPECT_CALL(*mock_global_error_with_standard_bubble_, |
| 122 GetBubbleViewAcceptButtonLabel()); |
| 123 EXPECT_CALL(*mock_global_error_with_standard_bubble_, |
| 124 GetBubbleViewCancelButtonLabel()); |
| 125 EXPECT_CALL(*mock_global_error_with_standard_bubble_, |
| 126 ShouldAddElevationIconToAcceptButton()) |
| 127 .WillOnce(Return(false)); |
| 128 view_->UpdateButton(&button_, ui::DIALOG_BUTTON_OK); |
| 129 |
| 130 EXPECT_CALL(*mock_global_error_with_standard_bubble_, |
| 131 ShouldShowCloseButton()); |
| 132 view_->ShouldShowCloseButton(); |
| 133 |
| 134 EXPECT_CALL(*mock_global_error_with_standard_bubble_, |
| 135 GetBubbleViewAcceptButtonLabel()); |
| 136 EXPECT_CALL(*mock_global_error_with_standard_bubble_, |
| 137 GetBubbleViewCancelButtonLabel()); |
| 138 view_->GetDialogButtonLabel(ui::DIALOG_BUTTON_OK); |
| 139 view_->GetDialogButtonLabel(ui::DIALOG_BUTTON_CANCEL); |
| 140 |
| 141 EXPECT_CALL(*mock_global_error_with_standard_bubble_, |
| 142 GetBubbleViewCancelButtonLabel()); |
| 143 view_->GetDialogButtons(); |
| 144 |
| 145 EXPECT_CALL(*mock_global_error_with_standard_bubble_, |
| 146 BubbleViewCancelButtonPressed(nullptr)); |
| 147 view_->Cancel(); |
| 148 |
| 149 EXPECT_CALL(*mock_global_error_with_standard_bubble_, |
| 150 BubbleViewAcceptButtonPressed(nullptr)); |
| 151 view_->Accept(); |
| 152 } |
| 153 |
| 154 TEST_F(GlobalErrorBubbleViewTest, ErrorIsNull) { |
| 155 mock_global_error_with_standard_bubble_.reset(); |
| 156 view_->GetWindowTitle(); |
| 157 view_->WindowClosing(); |
| 158 |
| 159 view_->UpdateButton(&button_, ui::DIALOG_BUTTON_OK); |
| 160 view_->ShouldShowCloseButton(); |
| 161 |
| 162 EXPECT_EQ(base::string16(), |
| 163 view_->GetDialogButtonLabel(ui::DIALOG_BUTTON_OK)); |
| 164 EXPECT_EQ(base::string16(), |
| 165 view_->GetDialogButtonLabel(ui::DIALOG_BUTTON_CANCEL)); |
| 166 EXPECT_EQ(ui::DIALOG_BUTTON_NONE, view_->GetDialogButtons()); |
| 167 |
| 168 view_->Cancel(); |
| 169 view_->Accept(); |
| 170 } |
| 171 |
| 172 } // namespace views |
| OLD | NEW |