| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 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 "components/bubble/bubble_manager.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "components/bubble/bubble_builder.h" |
| 9 #include "components/bubble/bubble_delegate.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace { |
| 14 |
| 15 class DelegateMock : public BubbleDelegate { |
| 16 public: |
| 17 MOCK_METHOD0(OnShow, void()); |
| 18 MOCK_METHOD0(OnHide, void()); |
| 19 MOCK_METHOD0(OnUpdatePosition, void()); |
| 20 MOCK_METHOD1(BuildBubble, void(BubbleBuilder*)); |
| 21 }; |
| 22 |
| 23 class ControllerMock : public BubbleController { |
| 24 public: |
| 25 ControllerMock(BubbleManager* manager, BubbleDelegate* delegate) |
| 26 : BubbleController(manager, delegate) {} |
| 27 |
| 28 MOCK_METHOD0(Show, void()); |
| 29 MOCK_METHOD1(Hide, void(BubbleCloseReason)); |
| 30 |
| 31 void SuperHide() { BubbleController::Hide(BUBBLE_CLOSE_IGNORE); } |
| 32 |
| 33 static scoped_ptr<BubbleController> Create(BubbleManager* manager, |
| 34 BubbleDelegate* delegate) { |
| 35 auto scoped_controller = |
| 36 make_scoped_ptr(new ControllerMock(manager, delegate)); |
| 37 |
| 38 ControllerMock* controller = scoped_controller.get(); |
| 39 |
| 40 EXPECT_CALL(*controller, Show()).Times(1); |
| 41 |
| 42 EXPECT_CALL(*controller, Hide(testing::_)) |
| 43 .Times(1) |
| 44 .WillOnce( |
| 45 testing::InvokeWithoutArgs(controller, &ControllerMock::SuperHide)); |
| 46 |
| 47 return scoped_controller.Pass(); |
| 48 } |
| 49 }; |
| 50 |
| 51 class BubbleManagerUnittest : public testing::Test {}; |
| 52 |
| 53 // Simple test to show and hide a bubble. |
| 54 TEST_F(BubbleManagerUnittest, ShowAndHideBubble) { |
| 55 BubbleManager manager(base::Bind(&ControllerMock::Create)); |
| 56 |
| 57 DelegateMock delegate; |
| 58 |
| 59 manager.ShowBubble(&delegate); |
| 60 manager.HideBubble(&delegate); |
| 61 } |
| 62 |
| 63 // Simple test to show and hide more than one bubble. |
| 64 TEST_F(BubbleManagerUnittest, ShowAndHide2Bubbles) { |
| 65 BubbleManager manager(base::Bind(&ControllerMock::Create)); |
| 66 |
| 67 DelegateMock delegate1, delegate2; |
| 68 |
| 69 manager.ShowBubble(&delegate1); |
| 70 manager.ShowBubble(&delegate2); |
| 71 |
| 72 manager.HideBubble(&delegate1); |
| 73 manager.HideBubble(&delegate2); |
| 74 } |
| 75 |
| 76 } // namespace |
| OLD | NEW |