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