| 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/constrained_window.h" |
| 6 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 6 #include "chrome/browser/ui/constrained_window_tab_helper.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 ConstrainedWindowTabHelperTest : public ChromeRenderViewHostTestHarness { |
| 14 public: | 14 public: |
| 15 ConstrainedWindowTabHelperTest() | 15 ConstrainedWindowTabHelperTest() |
| 16 : ChromeRenderViewHostTestHarness(), | 16 : ChromeRenderViewHostTestHarness(), |
| 17 ui_thread_(BrowserThread::UI, &message_loop_) { | 17 ui_thread_(BrowserThread::UI, &message_loop_) { |
| 18 } | 18 } |
| 19 | 19 |
| 20 virtual void SetUp() { | 20 virtual void SetUp() { |
| 21 ChromeRenderViewHostTestHarness::SetUp(); | 21 ChromeRenderViewHostTestHarness::SetUp(); |
| 22 ConstrainedWindowTabHelper::CreateForWebContents(web_contents()); | 22 ConstrainedWindowTabHelper::CreateForWebContents(web_contents()); |
| 23 } | 23 } |
| 24 | 24 |
| 25 private: | 25 private: |
| 26 content::TestBrowserThread ui_thread_; | 26 content::TestBrowserThread ui_thread_; |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 class ConstrainedWindowCloseTest : public ConstrainedWindow { | 29 class WebContentsModalDialogCloseTest : public ConstrainedWindow { |
| 30 public: | 30 public: |
| 31 explicit ConstrainedWindowCloseTest(content::WebContents* web_contents) | 31 explicit WebContentsModalDialogCloseTest(content::WebContents* web_contents) |
| 32 : web_contents_(web_contents) { | 32 : web_contents_(web_contents) { |
| 33 } | 33 } |
| 34 | 34 |
| 35 virtual void ShowConstrainedWindow() {} | 35 virtual void ShowWebContentsModalDialog() {} |
| 36 virtual void FocusConstrainedWindow() {} | 36 virtual void FocusWebContentsModalDialog() {} |
| 37 virtual ~ConstrainedWindowCloseTest() {} | 37 virtual ~WebContentsModalDialogCloseTest() {} |
| 38 | 38 |
| 39 virtual void CloseConstrainedWindow() { | 39 virtual void CloseWebContentsModalDialog() { |
| 40 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 40 ConstrainedWindowTabHelper* constrained_window_tab_helper = |
| 41 ConstrainedWindowTabHelper::FromWebContents(web_contents_); | 41 ConstrainedWindowTabHelper::FromWebContents(web_contents_); |
| 42 constrained_window_tab_helper->WillClose(this); | 42 constrained_window_tab_helper->WillClose(this); |
| 43 close_count++; | 43 close_count++; |
| 44 } | 44 } |
| 45 | 45 |
| 46 int close_count; | 46 int close_count; |
| 47 content::WebContents* web_contents_; | 47 content::WebContents* web_contents_; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 TEST_F(ConstrainedWindowTabHelperTest, ConstrainedWindows) { | 50 TEST_F(ConstrainedWindowTabHelperTest, ConstrainedWindows) { |
| 51 ConstrainedWindowCloseTest window(web_contents()); | 51 WebContentsModalDialogCloseTest window(web_contents()); |
| 52 window.close_count = 0; | 52 window.close_count = 0; |
| 53 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 53 ConstrainedWindowTabHelper* constrained_window_tab_helper = |
| 54 ConstrainedWindowTabHelper::FromWebContents(web_contents()); | 54 ConstrainedWindowTabHelper::FromWebContents(web_contents()); |
| 55 | 55 |
| 56 const int kWindowCount = 4; | 56 const int kWindowCount = 4; |
| 57 for (int i = 0; i < kWindowCount; i++) | 57 for (int i = 0; i < kWindowCount; i++) |
| 58 constrained_window_tab_helper->AddConstrainedDialog(&window); | 58 constrained_window_tab_helper->AddDialog(&window); |
| 59 EXPECT_EQ(window.close_count, 0); | 59 EXPECT_EQ(window.close_count, 0); |
| 60 | 60 |
| 61 constrained_window_tab_helper->CloseConstrainedWindows(); | 61 constrained_window_tab_helper->CloseAllDialogs(); |
| 62 EXPECT_EQ(window.close_count, kWindowCount); | 62 EXPECT_EQ(window.close_count, kWindowCount); |
| 63 } | 63 } |
| OLD | NEW |