| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_wrapper.h" | 7 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 8 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 8 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" |
| 9 #include "content/public/test/test_browser_thread.h" | 9 #include "content/public/test/test_browser_thread.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 using content::BrowserThread; | 12 using content::BrowserThread; |
| 13 | 13 |
| 14 class ConstrainedWindowTabHelperUnit : public TabContentsWrapperTestHarness { | 14 class ConstrainedWindowTabHelperUnit : public TabContentsTestHarness { |
| 15 public: | 15 public: |
| 16 ConstrainedWindowTabHelperUnit() | 16 ConstrainedWindowTabHelperUnit() |
| 17 : TabContentsWrapperTestHarness(), | 17 : TabContentsTestHarness(), |
| 18 ui_thread_(BrowserThread::UI, &message_loop_) { | 18 ui_thread_(BrowserThread::UI, &message_loop_) { |
| 19 } | 19 } |
| 20 | 20 |
| 21 private: | 21 private: |
| 22 content::TestBrowserThread ui_thread_; | 22 content::TestBrowserThread ui_thread_; |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 class ConstrainedWindowCloseTest : public ConstrainedWindow { | 25 class ConstrainedWindowCloseTest : public ConstrainedWindow { |
| 26 public: | 26 public: |
| 27 explicit ConstrainedWindowCloseTest(TabContentsWrapper* wrapper) | 27 explicit ConstrainedWindowCloseTest(TabContentsWrapper* wrapper) |
| 28 : wrapper_(wrapper) { | 28 : wrapper_(wrapper) { |
| 29 } | 29 } |
| 30 | 30 |
| 31 virtual void ShowConstrainedWindow() {} | 31 virtual void ShowConstrainedWindow() {} |
| 32 virtual void FocusConstrainedWindow() {} | 32 virtual void FocusConstrainedWindow() {} |
| 33 virtual ~ConstrainedWindowCloseTest() {} | 33 virtual ~ConstrainedWindowCloseTest() {} |
| 34 | 34 |
| 35 virtual void CloseConstrainedWindow() { | 35 virtual void CloseConstrainedWindow() { |
| 36 wrapper_->constrained_window_tab_helper()->WillClose(this); | 36 wrapper_->constrained_window_tab_helper()->WillClose(this); |
| 37 close_count++; | 37 close_count++; |
| 38 } | 38 } |
| 39 | 39 |
| 40 int close_count; | 40 int close_count; |
| 41 TabContentsWrapper* wrapper_; | 41 TabContentsWrapper* wrapper_; |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 TEST_F(ConstrainedWindowTabHelperUnit, ConstrainedWindows) { | 44 TEST_F(ConstrainedWindowTabHelperUnit, ConstrainedWindows) { |
| 45 ConstrainedWindowCloseTest window(contents_wrapper()); | 45 ConstrainedWindowCloseTest window(tab_contents()); |
| 46 window.close_count = 0; | 46 window.close_count = 0; |
| 47 | 47 |
| 48 const int kWindowCount = 4; | 48 const int kWindowCount = 4; |
| 49 for (int i = 0; i < kWindowCount; i++) { | 49 for (int i = 0; i < kWindowCount; i++) { |
| 50 contents_wrapper()->constrained_window_tab_helper()->AddConstrainedDialog( | 50 tab_contents()->constrained_window_tab_helper()->AddConstrainedDialog( |
| 51 &window); | 51 &window); |
| 52 } | 52 } |
| 53 EXPECT_EQ(window.close_count, 0); | 53 EXPECT_EQ(window.close_count, 0); |
| 54 contents_wrapper()->constrained_window_tab_helper()-> | 54 tab_contents()->constrained_window_tab_helper()->CloseConstrainedWindows(); |
| 55 CloseConstrainedWindows(); | |
| 56 EXPECT_EQ(window.close_count, kWindowCount); | 55 EXPECT_EQ(window.close_count, kWindowCount); |
| 57 } | 56 } |
| OLD | NEW |