| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 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/web_contents_modal_dialog.h" |
| 6 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" |
| 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 8 #include "content/public/test/test_browser_thread.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 using content::BrowserThread; |
| 12 |
| 13 class WebContentsModalDialogManagerTest |
| 14 : public ChromeRenderViewHostTestHarness { |
| 15 public: |
| 16 WebContentsModalDialogManagerTest() |
| 17 : ChromeRenderViewHostTestHarness(), |
| 18 ui_thread_(BrowserThread::UI, &message_loop_) { |
| 19 } |
| 20 |
| 21 virtual void SetUp() { |
| 22 ChromeRenderViewHostTestHarness::SetUp(); |
| 23 WebContentsModalDialogManager::CreateForWebContents(web_contents()); |
| 24 } |
| 25 |
| 26 private: |
| 27 content::TestBrowserThread ui_thread_; |
| 28 }; |
| 29 |
| 30 class WebContentsModalDialogCloseTest : public WebContentsModalDialog { |
| 31 public: |
| 32 explicit WebContentsModalDialogCloseTest(content::WebContents* web_contents) |
| 33 : web_contents_(web_contents) { |
| 34 } |
| 35 |
| 36 virtual void ShowWebContentsModalDialog() {} |
| 37 virtual void FocusWebContentsModalDialog() {} |
| 38 virtual ~WebContentsModalDialogCloseTest() {} |
| 39 |
| 40 virtual void CloseWebContentsModalDialog() { |
| 41 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 42 WebContentsModalDialogManager::FromWebContents(web_contents_); |
| 43 web_contents_modal_dialog_manager->WillClose(this); |
| 44 close_count++; |
| 45 } |
| 46 |
| 47 int close_count; |
| 48 content::WebContents* web_contents_; |
| 49 }; |
| 50 |
| 51 TEST_F(WebContentsModalDialogManagerTest, WebContentsModalDialogs) { |
| 52 WebContentsModalDialogCloseTest dialog(web_contents()); |
| 53 dialog.close_count = 0; |
| 54 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 55 WebContentsModalDialogManager::FromWebContents(web_contents()); |
| 56 |
| 57 const int kDialogCount = 4; |
| 58 for (int i = 0; i < kDialogCount; i++) |
| 59 web_contents_modal_dialog_manager->AddDialog(&dialog); |
| 60 EXPECT_EQ(dialog.close_count, 0); |
| 61 |
| 62 web_contents_modal_dialog_manager->CloseAllDialogs(); |
| 63 EXPECT_EQ(dialog.close_count, kDialogCount); |
| 64 } |
| OLD | NEW |