| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/bubble/bubble_manager.h" | 5 #include "components/bubble/bubble_manager.h" |
| 6 | 6 |
| 7 #include "components/bubble/bubble_controller.h" | 7 #include "components/bubble/bubble_controller.h" |
| 8 #include "components/bubble/bubble_delegate.h" | 8 #include "components/bubble/bubble_delegate.h" |
| 9 #include "components/bubble/bubble_ui.h" | 9 #include "components/bubble/bubble_ui.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 class MockBubbleUI : public BubbleUI { | 15 class MockBubbleUI : public BubbleUI { |
| 16 public: | 16 public: |
| 17 MockBubbleUI() {} | 17 MockBubbleUI() {} |
| 18 ~MockBubbleUI() override { Destroyed(); } | 18 ~MockBubbleUI() override { Destroyed(); } |
| 19 | 19 |
| 20 MOCK_METHOD0(Show, void()); | 20 MOCK_METHOD1(Show, void(BubbleReference)); |
| 21 MOCK_METHOD0(Close, void()); | 21 MOCK_METHOD0(Close, void()); |
| 22 MOCK_METHOD0(UpdateAnchorPosition, void()); | 22 MOCK_METHOD0(UpdateAnchorPosition, void()); |
| 23 | 23 |
| 24 // To verify destructor call. | 24 // To verify destructor call. |
| 25 MOCK_METHOD0(Destroyed, void()); | 25 MOCK_METHOD0(Destroyed, void()); |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 class MockBubbleDelegate : public BubbleDelegate { | 28 class MockBubbleDelegate : public BubbleDelegate { |
| 29 public: | 29 public: |
| 30 MockBubbleDelegate() {} | 30 MockBubbleDelegate() {} |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 void BubbleManagerTest::TearDown() { | 112 void BubbleManagerTest::TearDown() { |
| 113 manager_.reset(); | 113 manager_.reset(); |
| 114 testing::Test::TearDown(); | 114 testing::Test::TearDown(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 TEST_F(BubbleManagerTest, ManagerShowsBubbleUI) { | 117 TEST_F(BubbleManagerTest, ManagerShowsBubbleUI) { |
| 118 // Manager will delete bubble_ui. | 118 // Manager will delete bubble_ui. |
| 119 MockBubbleUI* bubble_ui = new MockBubbleUI; | 119 MockBubbleUI* bubble_ui = new MockBubbleUI; |
| 120 EXPECT_CALL(*bubble_ui, Destroyed()); | 120 EXPECT_CALL(*bubble_ui, Destroyed()); |
| 121 EXPECT_CALL(*bubble_ui, Show()); | 121 EXPECT_CALL(*bubble_ui, Show(testing::_)); |
| 122 EXPECT_CALL(*bubble_ui, Close()); | 122 EXPECT_CALL(*bubble_ui, Close()); |
| 123 EXPECT_CALL(*bubble_ui, UpdateAnchorPosition()).Times(0); | 123 EXPECT_CALL(*bubble_ui, UpdateAnchorPosition()).Times(0); |
| 124 | 124 |
| 125 // Manager will delete delegate. | 125 // Manager will delete delegate. |
| 126 MockBubbleDelegate* delegate = new MockBubbleDelegate; | 126 MockBubbleDelegate* delegate = new MockBubbleDelegate; |
| 127 EXPECT_CALL(*delegate, Destroyed()); | 127 EXPECT_CALL(*delegate, Destroyed()); |
| 128 EXPECT_CALL(*delegate, BuildBubbleUIMock()) | 128 EXPECT_CALL(*delegate, BuildBubbleUIMock()) |
| 129 .WillOnce(testing::Return(bubble_ui)); | 129 .WillOnce(testing::Return(bubble_ui)); |
| 130 EXPECT_CALL(*delegate, ShouldClose(testing::_)) | 130 EXPECT_CALL(*delegate, ShouldClose(testing::_)) |
| 131 .WillOnce(testing::Return(true)); | 131 .WillOnce(testing::Return(true)); |
| 132 | 132 |
| 133 manager_->ShowBubble(make_scoped_ptr(delegate)); | 133 manager_->ShowBubble(make_scoped_ptr(delegate)); |
| 134 } | 134 } |
| 135 | 135 |
| 136 TEST_F(BubbleManagerTest, ManagerUpdatesBubbleUI) { | 136 TEST_F(BubbleManagerTest, ManagerUpdatesBubbleUI) { |
| 137 // Manager will delete bubble_ui. | 137 // Manager will delete bubble_ui. |
| 138 MockBubbleUI* bubble_ui = new MockBubbleUI; | 138 MockBubbleUI* bubble_ui = new MockBubbleUI; |
| 139 EXPECT_CALL(*bubble_ui, Destroyed()); | 139 EXPECT_CALL(*bubble_ui, Destroyed()); |
| 140 EXPECT_CALL(*bubble_ui, Show()); | 140 EXPECT_CALL(*bubble_ui, Show(testing::_)); |
| 141 EXPECT_CALL(*bubble_ui, Close()); | 141 EXPECT_CALL(*bubble_ui, Close()); |
| 142 EXPECT_CALL(*bubble_ui, UpdateAnchorPosition()); | 142 EXPECT_CALL(*bubble_ui, UpdateAnchorPosition()); |
| 143 | 143 |
| 144 // Manager will delete delegate. | 144 // Manager will delete delegate. |
| 145 MockBubbleDelegate* delegate = new MockBubbleDelegate; | 145 MockBubbleDelegate* delegate = new MockBubbleDelegate; |
| 146 EXPECT_CALL(*delegate, Destroyed()); | 146 EXPECT_CALL(*delegate, Destroyed()); |
| 147 EXPECT_CALL(*delegate, BuildBubbleUIMock()) | 147 EXPECT_CALL(*delegate, BuildBubbleUIMock()) |
| 148 .WillOnce(testing::Return(bubble_ui)); | 148 .WillOnce(testing::Return(bubble_ui)); |
| 149 EXPECT_CALL(*delegate, ShouldClose(testing::_)) | 149 EXPECT_CALL(*delegate, ShouldClose(testing::_)) |
| 150 .WillOnce(testing::Return(true)); | 150 .WillOnce(testing::Return(true)); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 testing::Return(true))); | 338 testing::Return(true))); |
| 339 | 339 |
| 340 manager_->ShowBubble(make_scoped_ptr(delegate)); | 340 manager_->ShowBubble(make_scoped_ptr(delegate)); |
| 341 manager_.reset(); | 341 manager_.reset(); |
| 342 | 342 |
| 343 // The manager will take the bubble, but not show it. | 343 // The manager will take the bubble, but not show it. |
| 344 ASSERT_TRUE(chain_helper.BubbleWasTaken()); | 344 ASSERT_TRUE(chain_helper.BubbleWasTaken()); |
| 345 } | 345 } |
| 346 | 346 |
| 347 } // namespace | 347 } // namespace |
| OLD | NEW |