| Index: chrome/browser/ui/web_contents_modal_dialog_manager_unittest.cc
|
| diff --git a/chrome/browser/ui/web_contents_modal_dialog_manager_unittest.cc b/chrome/browser/ui/web_contents_modal_dialog_manager_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7746c864306e85d74edb5c000a282f8854dd04e8
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/web_contents_modal_dialog_manager_unittest.cc
|
| @@ -0,0 +1,64 @@
|
| +// Copyright (c) 2012 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 "chrome/browser/ui/web_contents_modal_dialog.h"
|
| +#include "chrome/browser/ui/web_contents_modal_dialog_manager.h"
|
| +#include "chrome/test/base/chrome_render_view_host_test_harness.h"
|
| +#include "content/public/test/test_browser_thread.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +using content::BrowserThread;
|
| +
|
| +class WebContentsModalDialogManagerTest
|
| + : public ChromeRenderViewHostTestHarness {
|
| + public:
|
| + WebContentsModalDialogManagerTest()
|
| + : ChromeRenderViewHostTestHarness(),
|
| + ui_thread_(BrowserThread::UI, &message_loop_) {
|
| + }
|
| +
|
| + virtual void SetUp() {
|
| + ChromeRenderViewHostTestHarness::SetUp();
|
| + WebContentsModalDialogManager::CreateForWebContents(web_contents());
|
| + }
|
| +
|
| + private:
|
| + content::TestBrowserThread ui_thread_;
|
| +};
|
| +
|
| +class WebContentsModalDialogCloseTest : public WebContentsModalDialog {
|
| + public:
|
| + explicit WebContentsModalDialogCloseTest(content::WebContents* web_contents)
|
| + : web_contents_(web_contents) {
|
| + }
|
| +
|
| + virtual void ShowWebContentsModalDialog() {}
|
| + virtual void FocusWebContentsModalDialog() {}
|
| + virtual ~WebContentsModalDialogCloseTest() {}
|
| +
|
| + virtual void CloseWebContentsModalDialog() {
|
| + WebContentsModalDialogManager* web_contents_modal_dialog_manager =
|
| + WebContentsModalDialogManager::FromWebContents(web_contents_);
|
| + web_contents_modal_dialog_manager->WillClose(this);
|
| + close_count++;
|
| + }
|
| +
|
| + int close_count;
|
| + content::WebContents* web_contents_;
|
| +};
|
| +
|
| +TEST_F(WebContentsModalDialogManagerTest, WebContentsModalDialogs) {
|
| + WebContentsModalDialogCloseTest dialog(web_contents());
|
| + dialog.close_count = 0;
|
| + WebContentsModalDialogManager* web_contents_modal_dialog_manager =
|
| + WebContentsModalDialogManager::FromWebContents(web_contents());
|
| +
|
| + const int kDialogCount = 4;
|
| + for (int i = 0; i < kDialogCount; i++)
|
| + web_contents_modal_dialog_manager->AddDialog(&dialog);
|
| + EXPECT_EQ(dialog.close_count, 0);
|
| +
|
| + web_contents_modal_dialog_manager->CloseAllDialogs();
|
| + EXPECT_EQ(dialog.close_count, kDialogCount);
|
| +}
|
|
|