| Index: components/bubble/bubble_manager_unittest.cc
|
| diff --git a/components/bubble/bubble_manager_unittest.cc b/components/bubble/bubble_manager_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6f71c65e027a4cb6b58ec7f424ba080b4d68dd7d
|
| --- /dev/null
|
| +++ b/components/bubble/bubble_manager_unittest.cc
|
| @@ -0,0 +1,76 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "components/bubble/bubble_manager.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "components/bubble/bubble_builder.h"
|
| +#include "components/bubble/bubble_delegate.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace {
|
| +
|
| +class DelegateMock : public BubbleDelegate {
|
| + public:
|
| + MOCK_METHOD0(OnShow, void());
|
| + MOCK_METHOD0(OnHide, void());
|
| + MOCK_METHOD0(OnUpdatePosition, void());
|
| + MOCK_METHOD1(BuildBubble, void(BubbleBuilder*));
|
| +};
|
| +
|
| +class ControllerMock : public BubbleController {
|
| + public:
|
| + ControllerMock(BubbleManager* manager, BubbleDelegate* delegate)
|
| + : BubbleController(manager, delegate) {}
|
| +
|
| + MOCK_METHOD0(Show, void());
|
| + MOCK_METHOD1(Hide, void(BubbleCloseReason));
|
| +
|
| + void SuperHide() { BubbleController::Hide(BUBBLE_CLOSE_IGNORE); }
|
| +
|
| + static scoped_ptr<BubbleController> Create(BubbleManager* manager,
|
| + BubbleDelegate* delegate) {
|
| + auto scoped_controller =
|
| + make_scoped_ptr(new ControllerMock(manager, delegate));
|
| +
|
| + ControllerMock* controller = scoped_controller.get();
|
| +
|
| + EXPECT_CALL(*controller, Show()).Times(1);
|
| +
|
| + EXPECT_CALL(*controller, Hide(testing::_))
|
| + .Times(1)
|
| + .WillOnce(
|
| + testing::InvokeWithoutArgs(controller, &ControllerMock::SuperHide));
|
| +
|
| + return scoped_controller.Pass();
|
| + }
|
| +};
|
| +
|
| +class BubbleManagerUnittest : public testing::Test {};
|
| +
|
| +// Simple test to show and hide a bubble.
|
| +TEST_F(BubbleManagerUnittest, ShowAndHideBubble) {
|
| + BubbleManager manager(base::Bind(&ControllerMock::Create));
|
| +
|
| + DelegateMock delegate;
|
| +
|
| + manager.ShowBubble(&delegate);
|
| + manager.HideBubble(&delegate);
|
| +}
|
| +
|
| +// Simple test to show and hide more than one bubble.
|
| +TEST_F(BubbleManagerUnittest, ShowAndHide2Bubbles) {
|
| + BubbleManager manager(base::Bind(&ControllerMock::Create));
|
| +
|
| + DelegateMock delegate1, delegate2;
|
| +
|
| + manager.ShowBubble(&delegate1);
|
| + manager.ShowBubble(&delegate2);
|
| +
|
| + manager.HideBubble(&delegate1);
|
| + manager.HideBubble(&delegate2);
|
| +}
|
| +
|
| +} // namespace
|
|
|