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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "components/bubble/bubble_controller.h" | 10 #include "components/bubble/bubble_controller.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 MockBubbleManagerObserver() {} | 75 MockBubbleManagerObserver() {} |
76 ~MockBubbleManagerObserver() override {} | 76 ~MockBubbleManagerObserver() override {} |
77 | 77 |
78 MOCK_METHOD1(OnBubbleNeverShown, void(BubbleReference)); | 78 MOCK_METHOD1(OnBubbleNeverShown, void(BubbleReference)); |
79 MOCK_METHOD2(OnBubbleClosed, void(BubbleReference, BubbleCloseReason)); | 79 MOCK_METHOD2(OnBubbleClosed, void(BubbleReference, BubbleCloseReason)); |
80 | 80 |
81 private: | 81 private: |
82 DISALLOW_COPY_AND_ASSIGN(MockBubbleManagerObserver); | 82 DISALLOW_COPY_AND_ASSIGN(MockBubbleManagerObserver); |
83 }; | 83 }; |
84 | 84 |
| 85 class BubbleManagerSubclass : public BubbleManager { |
| 86 public: |
| 87 using BubbleManager::CloseBubblesOwnedBy; |
| 88 }; |
| 89 |
85 class BubbleManagerTest : public testing::Test { | 90 class BubbleManagerTest : public testing::Test { |
86 public: | 91 public: |
87 BubbleManagerTest(); | 92 BubbleManagerTest(); |
88 ~BubbleManagerTest() override {} | 93 ~BubbleManagerTest() override {} |
89 | 94 |
90 void SetUp() override; | 95 void SetUp() override; |
91 void TearDown() override; | 96 void TearDown() override; |
92 | 97 |
93 protected: | 98 protected: |
94 scoped_ptr<BubbleManager> manager_; | 99 scoped_ptr<BubbleManagerSubclass> manager_; |
95 | 100 |
96 private: | 101 private: |
97 DISALLOW_COPY_AND_ASSIGN(BubbleManagerTest); | 102 DISALLOW_COPY_AND_ASSIGN(BubbleManagerTest); |
98 }; | 103 }; |
99 | 104 |
100 BubbleManagerTest::BubbleManagerTest() {} | 105 BubbleManagerTest::BubbleManagerTest() {} |
101 | 106 |
102 void BubbleManagerTest::SetUp() { | 107 void BubbleManagerTest::SetUp() { |
103 testing::Test::SetUp(); | 108 testing::Test::SetUp(); |
104 manager_.reset(new BubbleManager); | 109 manager_.reset(new BubbleManagerSubclass); |
105 } | 110 } |
106 | 111 |
107 void BubbleManagerTest::TearDown() { | 112 void BubbleManagerTest::TearDown() { |
108 manager_.reset(); | 113 manager_.reset(); |
109 testing::Test::TearDown(); | 114 testing::Test::TearDown(); |
110 } | 115 } |
111 | 116 |
112 TEST_F(BubbleManagerTest, ManagerShowsBubbleUi) { | 117 TEST_F(BubbleManagerTest, ManagerShowsBubbleUi) { |
113 scoped_ptr<MockBubbleDelegate> delegate = MockBubbleDelegate::Default(); | 118 scoped_ptr<MockBubbleDelegate> delegate = MockBubbleDelegate::Default(); |
114 | 119 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 EXPECT_TRUE(ref2); | 252 EXPECT_TRUE(ref2); |
248 EXPECT_TRUE(ref3); | 253 EXPECT_TRUE(ref3); |
249 | 254 |
250 ref2->CloseBubble(BUBBLE_CLOSE_FOCUS_LOST); | 255 ref2->CloseBubble(BUBBLE_CLOSE_FOCUS_LOST); |
251 | 256 |
252 EXPECT_TRUE(ref1); | 257 EXPECT_TRUE(ref1); |
253 EXPECT_FALSE(ref2); | 258 EXPECT_FALSE(ref2); |
254 EXPECT_TRUE(ref3); | 259 EXPECT_TRUE(ref3); |
255 } | 260 } |
256 | 261 |
| 262 TEST_F(BubbleManagerTest, CloseOwnedByShouldLeaveUnowned) { |
| 263 scoped_ptr<MockBubbleDelegate> delegate1 = MockBubbleDelegate::Default(); |
| 264 scoped_ptr<MockBubbleDelegate> delegate2 = MockBubbleDelegate::Default(); |
| 265 scoped_ptr<MockBubbleDelegate> delegate3 = MockBubbleDelegate::Default(); |
| 266 MockBubbleDelegate& delegate1_ref = *delegate1; |
| 267 MockBubbleDelegate& delegate2_ref = *delegate2; |
| 268 MockBubbleDelegate& delegate3_ref = *delegate3; |
| 269 BubbleReference ref1 = manager_->ShowBubble(std::move(delegate1)); |
| 270 BubbleReference ref2 = manager_->ShowBubble(std::move(delegate2)); |
| 271 BubbleReference ref3 = manager_->ShowBubble(std::move(delegate3)); |
| 272 |
| 273 // These pointers are only compared for equality, not dereferenced. |
| 274 const content::RenderFrameHost* const frame1 = |
| 275 reinterpret_cast<const content::RenderFrameHost*>(&ref1); |
| 276 const content::RenderFrameHost* const frame2 = |
| 277 reinterpret_cast<const content::RenderFrameHost*>(&ref2); |
| 278 |
| 279 EXPECT_CALL(delegate1_ref, OwningFrame()) |
| 280 .WillRepeatedly(testing::Return(frame1)); |
| 281 EXPECT_CALL(delegate2_ref, OwningFrame()) |
| 282 .WillRepeatedly(testing::Return(frame2)); |
| 283 EXPECT_CALL(delegate3_ref, OwningFrame()) |
| 284 .WillRepeatedly(testing::Return(nullptr)); |
| 285 EXPECT_CALL(delegate1_ref, ShouldClose(BUBBLE_CLOSE_FRAME_DESTROYED)) |
| 286 .WillOnce(testing::Return(true)); |
| 287 |
| 288 manager_->CloseBubblesOwnedBy(frame1); |
| 289 EXPECT_FALSE(ref1); |
| 290 EXPECT_TRUE(ref2); |
| 291 EXPECT_TRUE(ref3); |
| 292 } |
| 293 |
257 TEST_F(BubbleManagerTest, UpdateAllShouldWorkWithoutBubbles) { | 294 TEST_F(BubbleManagerTest, UpdateAllShouldWorkWithoutBubbles) { |
258 // Manager shouldn't crash if bubbles have never been added. | 295 // Manager shouldn't crash if bubbles have never been added. |
259 manager_->UpdateAllBubbleAnchors(); | 296 manager_->UpdateAllBubbleAnchors(); |
260 | 297 |
261 // Add a bubble and close it. | 298 // Add a bubble and close it. |
262 BubbleReference ref = manager_->ShowBubble(MockBubbleDelegate::Default()); | 299 BubbleReference ref = manager_->ShowBubble(MockBubbleDelegate::Default()); |
263 ASSERT_TRUE(manager_->CloseBubble(ref, BUBBLE_CLOSE_FORCED)); | 300 ASSERT_TRUE(manager_->CloseBubble(ref, BUBBLE_CLOSE_FORCED)); |
264 | 301 |
265 // Bubble should NOT get an update event because it's already closed. | 302 // Bubble should NOT get an update event because it's already closed. |
266 manager_->UpdateAllBubbleAnchors(); | 303 manager_->UpdateAllBubbleAnchors(); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 EXPECT_TRUE(other_bubble_ref); | 437 EXPECT_TRUE(other_bubble_ref); |
401 EXPECT_TRUE(closing_bubble_ref); | 438 EXPECT_TRUE(closing_bubble_ref); |
402 | 439 |
403 closing_bubble_ref->CloseBubble(BUBBLE_CLOSE_ACCEPTED); | 440 closing_bubble_ref->CloseBubble(BUBBLE_CLOSE_ACCEPTED); |
404 | 441 |
405 EXPECT_TRUE(other_bubble_ref); | 442 EXPECT_TRUE(other_bubble_ref); |
406 EXPECT_TRUE(closing_bubble_ref); | 443 EXPECT_TRUE(closing_bubble_ref); |
407 } | 444 } |
408 | 445 |
409 } // namespace | 446 } // namespace |
OLD | NEW |