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