OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 "chrome/browser/ui/views/browser_modal_dialog.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/memory/ptr_util.h" |
| 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 using ::testing::_; |
| 15 using ::testing::Return; |
| 16 |
| 17 class MockBrowserModalDialog : public BrowserModalDialog { |
| 18 public: |
| 19 MockBrowserModalDialog() { |
| 20 BrowserModalDialogList::GetInstance()->AddDialog(this); |
| 21 } |
| 22 ~MockBrowserModalDialog() override { |
| 23 BrowserModalDialogList::GetInstance()->RemoveDialog(this); |
| 24 } |
| 25 MOCK_METHOD1(ActivateModalDialog, void(Browser*)); |
| 26 MOCK_METHOD0(IsShowing, bool()); |
| 27 }; |
| 28 |
| 29 class BrowserModalDialogTest : public ::testing::Test { |
| 30 public: |
| 31 BrowserModalDialogTest() {} |
| 32 |
| 33 private: |
| 34 DISALLOW_COPY_AND_ASSIGN(BrowserModalDialogTest); |
| 35 }; |
| 36 |
| 37 TEST_F(BrowserModalDialogTest, ShowDialog) { |
| 38 BrowserModalDialogList* dialog_list = BrowserModalDialogList::GetInstance(); |
| 39 ASSERT_FALSE(dialog_list->IsShowing()); |
| 40 MockBrowserModalDialog dialog; |
| 41 EXPECT_CALL(dialog, IsShowing()).Times(2).WillRepeatedly(Return(true)); |
| 42 EXPECT_CALL(dialog, ActivateModalDialog(_)).Times(1); |
| 43 ASSERT_TRUE(dialog_list->IsShowing()); |
| 44 dialog_list->ActivateModalDialog(nullptr); |
| 45 } |
| 46 |
| 47 TEST_F(BrowserModalDialogTest, RemoveDialog) { |
| 48 BrowserModalDialogList* dialog_list = BrowserModalDialogList::GetInstance(); |
| 49 std::unique_ptr<MockBrowserModalDialog> dialog = |
| 50 base::MakeUnique<MockBrowserModalDialog>(); |
| 51 EXPECT_CALL(*dialog, IsShowing()).Times(1).WillRepeatedly(Return(true)); |
| 52 ASSERT_TRUE(dialog_list->IsShowing()); |
| 53 dialog.reset(); |
| 54 ASSERT_FALSE(dialog_list->IsShowing()); |
| 55 } |
OLD | NEW |