| 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/cocoa/constrained_window/constrained_window_mac.h" | 5 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_tabstrip.h" | 9 #include "chrome/browser/ui/browser_tabstrip.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 BrowserWindowController* controller_; | 70 BrowserWindowController* controller_; |
| 71 NSView* tab_view0_; | 71 NSView* tab_view0_; |
| 72 NSView* tab_view1_; | 72 NSView* tab_view1_; |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 // Test that a sheet added to a inactive tab is not shown until the | 75 // Test that a sheet added to a inactive tab is not shown until the |
| 76 // tab is activated. | 76 // tab is activated. |
| 77 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, ShowInInactiveTab) { | 77 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, ShowInInactiveTab) { |
| 78 // Show dialog in non active tab. | 78 // Show dialog in non active tab. |
| 79 NiceMock<ConstrainedWindowDelegateMock> delegate; | 79 NiceMock<ConstrainedWindowDelegateMock> delegate; |
| 80 ConstrainedWindowMac dialog(&delegate, tab0_, sheet_); | 80 ConstrainedWindowMac* dialog = |
| 81 CreateAndShowWebModalDialogMac(&delegate, tab0_, sheet_); |
| 81 EXPECT_EQ(0.0, [sheet_window_ alphaValue]); | 82 EXPECT_EQ(0.0, [sheet_window_ alphaValue]); |
| 82 | 83 |
| 83 // Switch to inactive tab. | 84 // Switch to inactive tab. |
| 84 browser()->tab_strip_model()->ActivateTabAt(0, true); | 85 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 85 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); | 86 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); |
| 86 | 87 |
| 87 dialog.CloseWebContentsModalDialog(); | 88 dialog->CloseWebContentsModalDialog(); |
| 88 } | 89 } |
| 89 | 90 |
| 90 // If a tab has never been shown then the associated tab view for the web | 91 // If a tab has never been shown then the associated tab view for the web |
| 91 // content will not be created. Verify that adding a constrained window to such | 92 // content will not be created. Verify that adding a constrained window to such |
| 92 // a tab works correctly. | 93 // a tab works correctly. |
| 93 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, ShowInUninitializedTab) { | 94 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, ShowInUninitializedTab) { |
| 94 scoped_ptr<content::WebContents> web_contents(content::WebContents::Create( | 95 scoped_ptr<content::WebContents> web_contents(content::WebContents::Create( |
| 95 content::WebContents::CreateParams(browser()->profile()))); | 96 content::WebContents::CreateParams(browser()->profile()))); |
| 96 bool was_blocked = false; | 97 bool was_blocked = false; |
| 97 chrome::AddWebContents(browser(), NULL, web_contents.release(), | 98 chrome::AddWebContents(browser(), NULL, web_contents.release(), |
| 98 NEW_BACKGROUND_TAB, gfx::Rect(), false, &was_blocked); | 99 NEW_BACKGROUND_TAB, gfx::Rect(), false, &was_blocked); |
| 99 content::WebContents* tab2 = | 100 content::WebContents* tab2 = |
| 100 browser()->tab_strip_model()->GetWebContentsAt(2); | 101 browser()->tab_strip_model()->GetWebContentsAt(2); |
| 101 ASSERT_TRUE(tab2); | 102 ASSERT_TRUE(tab2); |
| 102 EXPECT_FALSE([tab2->GetNativeView() superview]); | 103 EXPECT_FALSE([tab2->GetNativeView() superview]); |
| 103 | 104 |
| 104 // Show dialog and verify that it's not visible yet. | 105 // Show dialog and verify that it's not visible yet. |
| 105 NiceMock<ConstrainedWindowDelegateMock> delegate; | 106 NiceMock<ConstrainedWindowDelegateMock> delegate; |
| 106 ConstrainedWindowMac dialog(&delegate, tab2, sheet_); | 107 ConstrainedWindowMac* dialog = |
| 108 CreateAndShowWebModalDialogMac(&delegate, tab2, sheet_); |
| 107 EXPECT_FALSE([sheet_window_ isVisible]); | 109 EXPECT_FALSE([sheet_window_ isVisible]); |
| 108 | 110 |
| 109 // Activate the tab and verify that the constrained window is shown. | 111 // Activate the tab and verify that the constrained window is shown. |
| 110 browser()->tab_strip_model()->ActivateTabAt(2, true); | 112 browser()->tab_strip_model()->ActivateTabAt(2, true); |
| 111 EXPECT_TRUE([tab2->GetNativeView() superview]); | 113 EXPECT_TRUE([tab2->GetNativeView() superview]); |
| 112 EXPECT_TRUE([sheet_window_ isVisible]); | 114 EXPECT_TRUE([sheet_window_ isVisible]); |
| 113 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); | 115 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); |
| 114 | 116 |
| 115 dialog.CloseWebContentsModalDialog(); | 117 dialog->CloseWebContentsModalDialog(); |
| 116 } | 118 } |
| 117 | 119 |
| 118 // Test that adding a sheet disables tab dragging. | 120 // Test that adding a sheet disables tab dragging. |
| 119 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, TabDragging) { | 121 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, TabDragging) { |
| 120 NiceMock<ConstrainedWindowDelegateMock> delegate; | 122 NiceMock<ConstrainedWindowDelegateMock> delegate; |
| 121 ConstrainedWindowMac dialog(&delegate, tab1_, sheet_); | 123 ConstrainedWindowMac* dialog = |
| 124 CreateAndShowWebModalDialogMac(&delegate, tab1_, sheet_); |
| 122 | 125 |
| 123 // Verify that the dialog disables dragging. | 126 // Verify that the dialog disables dragging. |
| 124 EXPECT_TRUE([controller_ isTabDraggable:tab_view0_]); | 127 EXPECT_TRUE([controller_ isTabDraggable:tab_view0_]); |
| 125 EXPECT_FALSE([controller_ isTabDraggable:tab_view1_]); | 128 EXPECT_FALSE([controller_ isTabDraggable:tab_view1_]); |
| 126 | 129 |
| 127 dialog.CloseWebContentsModalDialog(); | 130 dialog->CloseWebContentsModalDialog(); |
| 128 } | 131 } |
| 129 | 132 |
| 130 // Test that closing a browser window with a sheet works. | 133 // Test that closing a browser window with a sheet works. |
| 131 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, BrowserWindowClose) { | 134 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, BrowserWindowClose) { |
| 132 NiceMock<ConstrainedWindowDelegateMock> delegate; | 135 NiceMock<ConstrainedWindowDelegateMock> delegate; |
| 133 ConstrainedWindowMac dialog(&delegate, tab1_, sheet_); | 136 CreateAndShowWebModalDialogMac(&delegate, tab1_, sheet_); |
| 134 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); | 137 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); |
| 135 | 138 |
| 136 // Close the browser window. | 139 // Close the browser window. |
| 137 base::scoped_nsobject<NSWindow> browser_window( | 140 base::scoped_nsobject<NSWindow> browser_window( |
| 138 [browser()->window()->GetNativeWindow() retain]); | 141 [browser()->window()->GetNativeWindow() retain]); |
| 139 EXPECT_TRUE([browser_window isVisible]); | 142 EXPECT_TRUE([browser_window isVisible]); |
| 140 [browser()->window()->GetNativeWindow() performClose:nil]; | 143 [browser()->window()->GetNativeWindow() performClose:nil]; |
| 141 EXPECT_FALSE([browser_window isVisible]); | 144 EXPECT_FALSE([browser_window isVisible]); |
| 142 } | 145 } |
| 143 | 146 |
| 144 // Test that closing a tab with a sheet works. | 147 // Test that closing a tab with a sheet works. |
| 145 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, TabClose) { | 148 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, TabClose) { |
| 146 NiceMock<ConstrainedWindowDelegateMock> delegate; | 149 NiceMock<ConstrainedWindowDelegateMock> delegate; |
| 147 ConstrainedWindowMac dialog(&delegate, tab1_, sheet_); | 150 CreateAndShowWebModalDialogMac(&delegate, tab1_, sheet_); |
| 148 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); | 151 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); |
| 149 | 152 |
| 150 // Close the tab. | 153 // Close the tab. |
| 151 TabStripModel* tab_strip = browser()->tab_strip_model(); | 154 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 152 EXPECT_EQ(2, tab_strip->count()); | 155 EXPECT_EQ(2, tab_strip->count()); |
| 153 EXPECT_TRUE(tab_strip->CloseWebContentsAt(1, | 156 EXPECT_TRUE(tab_strip->CloseWebContentsAt(1, |
| 154 TabStripModel::CLOSE_USER_GESTURE)); | 157 TabStripModel::CLOSE_USER_GESTURE)); |
| 155 EXPECT_EQ(1, tab_strip->count()); | 158 EXPECT_EQ(1, tab_strip->count()); |
| 156 } | 159 } |
| OLD | NEW |