Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: components/bubble/bubble_manager_unittest.cc

Issue 1310483003: Add ability for a BubbleReference to update the BubbleUI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bm-reference-own-file.gitbr
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_reference.h"
9 #include "components/bubble/bubble_ui.h" 10 #include "components/bubble/bubble_ui.h"
10 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace { 14 namespace {
14 15
15 class MockBubbleUI : public BubbleUI { 16 class MockBubbleUI : public BubbleUI {
16 public: 17 public:
17 MockBubbleUI() {} 18 MockBubbleUI() {}
18 ~MockBubbleUI() override { Destroyed(); } 19 ~MockBubbleUI() override { Destroyed(); }
(...skipping 18 matching lines...) Expand all
37 static scoped_ptr<MockBubbleDelegate> Stubborn(); 38 static scoped_ptr<MockBubbleDelegate> Stubborn();
38 39
39 MOCK_METHOD1(ShouldClose, bool(BubbleCloseReason reason)); 40 MOCK_METHOD1(ShouldClose, bool(BubbleCloseReason reason));
40 41
41 // A scoped_ptr can't be returned in MOCK_METHOD. 42 // A scoped_ptr can't be returned in MOCK_METHOD.
42 MOCK_METHOD0(BuildBubbleUIMock, BubbleUI*()); 43 MOCK_METHOD0(BuildBubbleUIMock, BubbleUI*());
43 scoped_ptr<BubbleUI> BuildBubbleUI() override { 44 scoped_ptr<BubbleUI> BuildBubbleUI() override {
44 return make_scoped_ptr(BuildBubbleUIMock()); 45 return make_scoped_ptr(BuildBubbleUIMock());
45 } 46 }
46 47
48 MOCK_METHOD1(UpdateBubbleUI, bool(BubbleUI*));
49
47 // To verify destructor call. 50 // To verify destructor call.
48 MOCK_METHOD0(Destroyed, void()); 51 MOCK_METHOD0(Destroyed, void());
49 }; 52 };
50 53
51 // static 54 // static
52 scoped_ptr<MockBubbleDelegate> MockBubbleDelegate::Default() { 55 scoped_ptr<MockBubbleDelegate> MockBubbleDelegate::Default() {
53 MockBubbleDelegate* delegate = new MockBubbleDelegate; 56 MockBubbleDelegate* delegate = new MockBubbleDelegate;
54 EXPECT_CALL(*delegate, BuildBubbleUIMock()) 57 EXPECT_CALL(*delegate, BuildBubbleUIMock())
55 .WillOnce(testing::Return(new MockBubbleUI)); 58 .WillOnce(testing::Return(new MockBubbleUI));
56 EXPECT_CALL(*delegate, ShouldClose(testing::_)) 59 EXPECT_CALL(*delegate, ShouldClose(testing::_))
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 &chain_helper, &DelegateChainHelper::Chain), 340 &chain_helper, &DelegateChainHelper::Chain),
338 testing::Return(true))); 341 testing::Return(true)));
339 342
340 manager_->ShowBubble(make_scoped_ptr(delegate)); 343 manager_->ShowBubble(make_scoped_ptr(delegate));
341 manager_.reset(); 344 manager_.reset();
342 345
343 // The manager will take the bubble, but not show it. 346 // The manager will take the bubble, but not show it.
344 ASSERT_TRUE(chain_helper.BubbleWasTaken()); 347 ASSERT_TRUE(chain_helper.BubbleWasTaken());
345 } 348 }
346 349
350 TEST_F(BubbleManagerTest, BubbleUpdatesTrue) {
351 MockBubbleUI* bubble_ui = new MockBubbleUI;
352 MockBubbleDelegate* delegate = new MockBubbleDelegate;
353 EXPECT_CALL(*delegate, BuildBubbleUIMock())
354 .WillOnce(testing::Return(bubble_ui));
355 EXPECT_CALL(*delegate, ShouldClose(testing::_))
356 .WillOnce(testing::Return(true));
357 EXPECT_CALL(*delegate, UpdateBubbleUI(bubble_ui))
358 .WillOnce(testing::Return(true));
359
360 BubbleReference ref = manager_->ShowBubble(make_scoped_ptr(delegate));
361 ASSERT_TRUE(ref->UpdateBubbleUI());
362 }
363
364 TEST_F(BubbleManagerTest, BubbleUpdatesFalse) {
365 MockBubbleUI* bubble_ui = new MockBubbleUI;
366 MockBubbleDelegate* delegate = new MockBubbleDelegate;
367 EXPECT_CALL(*delegate, BuildBubbleUIMock())
368 .WillOnce(testing::Return(bubble_ui));
369 EXPECT_CALL(*delegate, ShouldClose(testing::_))
370 .WillOnce(testing::Return(true));
371 EXPECT_CALL(*delegate, UpdateBubbleUI(bubble_ui))
372 .WillOnce(testing::Return(false));
373
374 BubbleReference ref = manager_->ShowBubble(make_scoped_ptr(delegate));
375 ASSERT_FALSE(ref->UpdateBubbleUI());
376 }
377
347 } // namespace 378 } // namespace
OLDNEW
« components/bubble/bubble_controller.cc ('K') | « components/bubble/bubble_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698