| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/constrained_window.h" | 5 #include "chrome/browser/ui/web_contents_modal_dialog.h" |
| 6 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 6 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" |
| 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 8 #include "content/public/test/test_browser_thread.h" | 8 #include "content/public/test/test_browser_thread.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 using content::BrowserThread; | 11 using content::BrowserThread; |
| 12 | 12 |
| 13 class ConstrainedWindowTabHelperTest : public ChromeRenderViewHostTestHarness { | 13 class WebContentsModalDialogManagerTest |
| 14 : public ChromeRenderViewHostTestHarness { |
| 14 public: | 15 public: |
| 15 ConstrainedWindowTabHelperTest() | 16 WebContentsModalDialogManagerTest() |
| 16 : ChromeRenderViewHostTestHarness(), | 17 : ChromeRenderViewHostTestHarness(), |
| 17 ui_thread_(BrowserThread::UI, &message_loop_) { | 18 ui_thread_(BrowserThread::UI, &message_loop_) { |
| 18 } | 19 } |
| 19 | 20 |
| 20 virtual void SetUp() { | 21 virtual void SetUp() { |
| 21 ChromeRenderViewHostTestHarness::SetUp(); | 22 ChromeRenderViewHostTestHarness::SetUp(); |
| 22 ConstrainedWindowTabHelper::CreateForWebContents(web_contents()); | 23 WebContentsModalDialogManager::CreateForWebContents(web_contents()); |
| 23 } | 24 } |
| 24 | 25 |
| 25 private: | 26 private: |
| 26 content::TestBrowserThread ui_thread_; | 27 content::TestBrowserThread ui_thread_; |
| 27 }; | 28 }; |
| 28 | 29 |
| 29 class WebContentsModalDialogCloseTest : public ConstrainedWindow { | 30 class WebContentsModalDialogCloseTest : public WebContentsModalDialog { |
| 30 public: | 31 public: |
| 31 explicit WebContentsModalDialogCloseTest(content::WebContents* web_contents) | 32 explicit WebContentsModalDialogCloseTest(content::WebContents* web_contents) |
| 32 : web_contents_(web_contents) { | 33 : web_contents_(web_contents) { |
| 33 } | 34 } |
| 34 | 35 |
| 35 virtual void ShowWebContentsModalDialog() {} | 36 virtual void ShowWebContentsModalDialog() {} |
| 36 virtual void FocusWebContentsModalDialog() {} | |
| 37 virtual ~WebContentsModalDialogCloseTest() {} | |
| 38 | |
| 39 virtual void CloseWebContentsModalDialog() { | 37 virtual void CloseWebContentsModalDialog() { |
| 40 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 38 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 41 ConstrainedWindowTabHelper::FromWebContents(web_contents_); | 39 WebContentsModalDialogManager::FromWebContents(web_contents_); |
| 42 constrained_window_tab_helper->WillClose(this); | 40 web_contents_modal_dialog_manager->WillClose(this); |
| 43 close_count++; | 41 close_count++; |
| 44 } | 42 } |
| 43 virtual void FocusWebContentsModalDialog() {} |
| 44 virtual void PulseWebContentsModalDialog() {} |
| 45 virtual bool CanShowWebContentsModalDialog() { |
| 46 return true; |
| 47 } |
| 48 virtual gfx::NativeWindow GetNativeWindow() { |
| 49 NOTREACHED(); |
| 50 return NULL; |
| 51 } |
| 52 virtual ~WebContentsModalDialogCloseTest() {} |
| 45 | 53 |
| 46 int close_count; | 54 int close_count; |
| 47 content::WebContents* web_contents_; | 55 content::WebContents* web_contents_; |
| 48 }; | 56 }; |
| 49 | 57 |
| 50 TEST_F(ConstrainedWindowTabHelperTest, ConstrainedWindows) { | 58 TEST_F(WebContentsModalDialogManagerTest, ConstrainedWindows) { |
| 51 WebContentsModalDialogCloseTest window(web_contents()); | 59 WebContentsModalDialogCloseTest window(web_contents()); |
| 52 window.close_count = 0; | 60 window.close_count = 0; |
| 53 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 61 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 54 ConstrainedWindowTabHelper::FromWebContents(web_contents()); | 62 WebContentsModalDialogManager::FromWebContents(web_contents()); |
| 55 | 63 |
| 56 const int kWindowCount = 4; | 64 const int kWindowCount = 4; |
| 57 for (int i = 0; i < kWindowCount; i++) | 65 for (int i = 0; i < kWindowCount; i++) |
| 58 constrained_window_tab_helper->AddDialog(&window); | 66 web_contents_modal_dialog_manager->AddDialog(&window); |
| 59 EXPECT_EQ(window.close_count, 0); | 67 EXPECT_EQ(window.close_count, 0); |
| 60 | 68 |
| 61 constrained_window_tab_helper->CloseAllDialogs(); | 69 web_contents_modal_dialog_manager->CloseAllDialogs(); |
| 62 EXPECT_EQ(window.close_count, kWindowCount); | 70 EXPECT_EQ(window.close_count, kWindowCount); |
| 63 } | 71 } |
| OLD | NEW |