| 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/test/ui/ui_test.h" | 5 #include "chrome/test/ui/ui_test.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_tabstrip.h" | 10 #include "chrome/browser/ui/browser_tabstrip.h" |
| 11 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 11 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" |
| 12 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" | 12 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" |
| 13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
| 18 #include "ui/web_dialogs/test/test_web_dialog_delegate.h" | 18 #include "ui/web_dialogs/test/test_web_dialog_delegate.h" |
| 19 | 19 |
| 20 using content::WebContents; | 20 using content::WebContents; |
| 21 using ui::WebDialogDelegate; | 21 using ui::WebDialogDelegate; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 } // namespace | 44 } // namespace |
| 45 | 45 |
| 46 class ConstrainedWebDialogBrowserTest : public InProcessBrowserTest { | 46 class ConstrainedWebDialogBrowserTest : public InProcessBrowserTest { |
| 47 public: | 47 public: |
| 48 ConstrainedWebDialogBrowserTest() {} | 48 ConstrainedWebDialogBrowserTest() {} |
| 49 | 49 |
| 50 protected: | 50 protected: |
| 51 size_t GetConstrainedWindowCount(WebContents* web_contents) const { | 51 size_t GetConstrainedWindowCount(WebContents* web_contents) const { |
| 52 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 52 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 53 ConstrainedWindowTabHelper::FromWebContents(web_contents); | 53 WebContentsModalDialogManager::FromWebContents(web_contents); |
| 54 return constrained_window_tab_helper->constrained_window_count(); | 54 return web_contents_modal_dialog_manager->dialog_count(); |
| 55 } | 55 } |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // Tests that opening/closing the constrained window won't crash it. | 58 // Tests that opening/closing the constrained window won't crash it. |
| 59 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, BasicTest) { | 59 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, BasicTest) { |
| 60 // The delegate deletes itself. | 60 // The delegate deletes itself. |
| 61 WebDialogDelegate* delegate = new ui::test::TestWebDialogDelegate( | 61 WebDialogDelegate* delegate = new ui::test::TestWebDialogDelegate( |
| 62 GURL(chrome::kChromeUIConstrainedHTMLTestURL)); | 62 GURL(chrome::kChromeUIConstrainedHTMLTestURL)); |
| 63 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 63 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
| 64 ASSERT_TRUE(web_contents); | 64 ASSERT_TRUE(web_contents); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 94 | 94 |
| 95 ConstrainedWebDialogBrowserTestObserver observer(new_tab.get()); | 95 ConstrainedWebDialogBrowserTestObserver observer(new_tab.get()); |
| 96 dialog_delegate->ReleaseWebContentsOnDialogClose(); | 96 dialog_delegate->ReleaseWebContentsOnDialogClose(); |
| 97 dialog_delegate->OnDialogCloseFromWebUI(); | 97 dialog_delegate->OnDialogCloseFromWebUI(); |
| 98 | 98 |
| 99 ASSERT_FALSE(observer.contents_destroyed()); | 99 ASSERT_FALSE(observer.contents_destroyed()); |
| 100 EXPECT_EQ(0U, GetConstrainedWindowCount(web_contents)); | 100 EXPECT_EQ(0U, GetConstrainedWindowCount(web_contents)); |
| 101 new_tab.reset(); | 101 new_tab.reset(); |
| 102 EXPECT_TRUE(observer.contents_destroyed()); | 102 EXPECT_TRUE(observer.contents_destroyed()); |
| 103 } | 103 } |
| OLD | NEW |