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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 BrowserWindowController* controller_; | 72 BrowserWindowController* controller_; |
73 NSView* tab_view0_; | 73 NSView* tab_view0_; |
74 NSView* tab_view1_; | 74 NSView* tab_view1_; |
75 }; | 75 }; |
76 | 76 |
77 // Test that a sheet added to a inactive tab is not shown until the | 77 // Test that a sheet added to a inactive tab is not shown until the |
78 // tab is activated. | 78 // tab is activated. |
79 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, ShowInInactiveTab) { | 79 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, ShowInInactiveTab) { |
80 // Show dialog in non active tab. | 80 // Show dialog in non active tab. |
81 NiceMock<ConstrainedWindowDelegateMock> delegate; | 81 NiceMock<ConstrainedWindowDelegateMock> delegate; |
82 ConstrainedWindowMac dialog(&delegate, tab0_, sheet_); | 82 std::unique_ptr<ConstrainedWindowMac> dialog( |
| 83 CreateAndShowWebModalDialogMac(&delegate, tab0_, sheet_)); |
83 EXPECT_EQ(0.0, [sheet_window_ alphaValue]); | 84 EXPECT_EQ(0.0, [sheet_window_ alphaValue]); |
84 | 85 |
85 // Switch to inactive tab. | 86 // Switch to inactive tab. |
86 browser()->tab_strip_model()->ActivateTabAt(0, true); | 87 browser()->tab_strip_model()->ActivateTabAt(0, true); |
87 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); | 88 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); |
88 | 89 |
89 dialog.CloseWebContentsModalDialog(); | 90 dialog->CloseWebContentsModalDialog(); |
90 } | 91 } |
91 | 92 |
92 // If a tab has never been shown then the associated tab view for the web | 93 // If a tab has never been shown then the associated tab view for the web |
93 // content will not be created. Verify that adding a constrained window to such | 94 // content will not be created. Verify that adding a constrained window to such |
94 // a tab works correctly. | 95 // a tab works correctly. |
95 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, ShowInUninitializedTab) { | 96 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, ShowInUninitializedTab) { |
96 scoped_ptr<content::WebContents> web_contents(content::WebContents::Create( | 97 scoped_ptr<content::WebContents> web_contents(content::WebContents::Create( |
97 content::WebContents::CreateParams(browser()->profile()))); | 98 content::WebContents::CreateParams(browser()->profile()))); |
98 bool was_blocked = false; | 99 bool was_blocked = false; |
99 chrome::AddWebContents(browser(), NULL, web_contents.release(), | 100 chrome::AddWebContents(browser(), NULL, web_contents.release(), |
100 NEW_BACKGROUND_TAB, gfx::Rect(), false, &was_blocked); | 101 NEW_BACKGROUND_TAB, gfx::Rect(), false, &was_blocked); |
101 content::WebContents* tab2 = | 102 content::WebContents* tab2 = |
102 browser()->tab_strip_model()->GetWebContentsAt(2); | 103 browser()->tab_strip_model()->GetWebContentsAt(2); |
103 ASSERT_TRUE(tab2); | 104 ASSERT_TRUE(tab2); |
104 EXPECT_FALSE([tab2->GetNativeView() superview]); | 105 EXPECT_FALSE([tab2->GetNativeView() superview]); |
105 | 106 |
106 // Show dialog and verify that it's not visible yet. | 107 // Show dialog and verify that it's not visible yet. |
107 NiceMock<ConstrainedWindowDelegateMock> delegate; | 108 NiceMock<ConstrainedWindowDelegateMock> delegate; |
108 ConstrainedWindowMac dialog(&delegate, tab2, sheet_); | 109 std::unique_ptr<ConstrainedWindowMac> dialog( |
| 110 CreateAndShowWebModalDialogMac(&delegate, tab2, sheet_)); |
109 EXPECT_FALSE([sheet_window_ isVisible]); | 111 EXPECT_FALSE([sheet_window_ isVisible]); |
110 | 112 |
111 // Activate the tab and verify that the constrained window is shown. | 113 // Activate the tab and verify that the constrained window is shown. |
112 browser()->tab_strip_model()->ActivateTabAt(2, true); | 114 browser()->tab_strip_model()->ActivateTabAt(2, true); |
113 EXPECT_TRUE([tab2->GetNativeView() superview]); | 115 EXPECT_TRUE([tab2->GetNativeView() superview]); |
114 EXPECT_TRUE([sheet_window_ isVisible]); | 116 EXPECT_TRUE([sheet_window_ isVisible]); |
115 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); | 117 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); |
116 | 118 |
117 dialog.CloseWebContentsModalDialog(); | 119 dialog->CloseWebContentsModalDialog(); |
118 } | 120 } |
119 | 121 |
120 // Test that adding a sheet disables tab dragging. | 122 // Test that adding a sheet disables tab dragging. |
121 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, TabDragging) { | 123 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, TabDragging) { |
122 NiceMock<ConstrainedWindowDelegateMock> delegate; | 124 NiceMock<ConstrainedWindowDelegateMock> delegate; |
123 ConstrainedWindowMac dialog(&delegate, tab1_, sheet_); | 125 std::unique_ptr<ConstrainedWindowMac> dialog( |
| 126 CreateAndShowWebModalDialogMac(&delegate, tab1_, sheet_)); |
124 | 127 |
125 // Verify that the dialog disables dragging. | 128 // Verify that the dialog disables dragging. |
126 EXPECT_TRUE([controller_ isTabDraggable:tab_view0_]); | 129 EXPECT_TRUE([controller_ isTabDraggable:tab_view0_]); |
127 EXPECT_FALSE([controller_ isTabDraggable:tab_view1_]); | 130 EXPECT_FALSE([controller_ isTabDraggable:tab_view1_]); |
128 | 131 |
129 dialog.CloseWebContentsModalDialog(); | 132 dialog->CloseWebContentsModalDialog(); |
130 } | 133 } |
131 | 134 |
132 // Test that closing a browser window with a sheet works. | 135 // Test that closing a browser window with a sheet works. |
133 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, BrowserWindowClose) { | 136 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, BrowserWindowClose) { |
134 NiceMock<ConstrainedWindowDelegateMock> delegate; | 137 NiceMock<ConstrainedWindowDelegateMock> delegate; |
135 ConstrainedWindowMac dialog(&delegate, tab1_, sheet_); | 138 std::unique_ptr<ConstrainedWindowMac> dialog( |
| 139 CreateAndShowWebModalDialogMac(&delegate, tab1_, sheet_)); |
136 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); | 140 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); |
137 | 141 |
138 // Close the browser window. | 142 // Close the browser window. |
139 base::scoped_nsobject<NSWindow> browser_window( | 143 base::scoped_nsobject<NSWindow> browser_window( |
140 [browser()->window()->GetNativeWindow() retain]); | 144 [browser()->window()->GetNativeWindow() retain]); |
141 EXPECT_TRUE([browser_window isVisible]); | 145 EXPECT_TRUE([browser_window isVisible]); |
142 [browser()->window()->GetNativeWindow() performClose:nil]; | 146 [browser()->window()->GetNativeWindow() performClose:nil]; |
143 EXPECT_FALSE([browser_window isVisible]); | 147 EXPECT_FALSE([browser_window isVisible]); |
144 } | 148 } |
145 | 149 |
146 // Test that closing a tab with a sheet works. | 150 // Test that closing a tab with a sheet works. |
147 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, TabClose) { | 151 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, TabClose) { |
148 NiceMock<ConstrainedWindowDelegateMock> delegate; | 152 NiceMock<ConstrainedWindowDelegateMock> delegate; |
149 ConstrainedWindowMac dialog(&delegate, tab1_, sheet_); | 153 std::unique_ptr<ConstrainedWindowMac> dialog( |
| 154 CreateAndShowWebModalDialogMac(&delegate, tab1_, sheet_)); |
150 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); | 155 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); |
151 | 156 |
152 // Close the tab. | 157 // Close the tab. |
153 TabStripModel* tab_strip = browser()->tab_strip_model(); | 158 TabStripModel* tab_strip = browser()->tab_strip_model(); |
154 EXPECT_EQ(2, tab_strip->count()); | 159 EXPECT_EQ(2, tab_strip->count()); |
155 EXPECT_TRUE(tab_strip->CloseWebContentsAt(1, | 160 EXPECT_TRUE(tab_strip->CloseWebContentsAt(1, |
156 TabStripModel::CLOSE_USER_GESTURE)); | 161 TabStripModel::CLOSE_USER_GESTURE)); |
157 EXPECT_EQ(1, tab_strip->count()); | 162 EXPECT_EQ(1, tab_strip->count()); |
158 } | 163 } |
159 | 164 |
160 // Test that the sheet is still visible after entering and exiting fullscreen. | 165 // Test that the sheet is still visible after entering and exiting fullscreen. |
161 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, BrowserWindowFullscreen) { | 166 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, BrowserWindowFullscreen) { |
162 NiceMock<ConstrainedWindowDelegateMock> delegate; | 167 NiceMock<ConstrainedWindowDelegateMock> delegate; |
163 ConstrainedWindowMac dialog(&delegate, tab1_, sheet_); | 168 std::unique_ptr<ConstrainedWindowMac> dialog( |
| 169 CreateAndShowWebModalDialogMac(&delegate, tab1_, sheet_)); |
164 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); | 170 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); |
165 | 171 |
166 // Toggle fullscreen twice: one for entering and one for exiting. | 172 // Toggle fullscreen twice: one for entering and one for exiting. |
167 // Check to see if the sheet is visible. | 173 // Check to see if the sheet is visible. |
168 for (int i = 0; i < 2; i++) { | 174 for (int i = 0; i < 2; i++) { |
169 { | 175 { |
170 // NOTIFICATION_FULLSCREEN_CHANGED is sent asynchronously. Wait for the | 176 // NOTIFICATION_FULLSCREEN_CHANGED is sent asynchronously. Wait for the |
171 // notification before testing the sheet's visibility. | 177 // notification before testing the sheet's visibility. |
172 scoped_ptr<FullscreenNotificationObserver> waiter( | 178 scoped_ptr<FullscreenNotificationObserver> waiter( |
173 new FullscreenNotificationObserver()); | 179 new FullscreenNotificationObserver()); |
174 browser() | 180 browser() |
175 ->exclusive_access_manager() | 181 ->exclusive_access_manager() |
176 ->fullscreen_controller() | 182 ->fullscreen_controller() |
177 ->ToggleBrowserFullscreenMode(); | 183 ->ToggleBrowserFullscreenMode(); |
178 waiter->Wait(); | 184 waiter->Wait(); |
179 } | 185 } |
180 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); | 186 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); |
181 } | 187 } |
182 | 188 |
183 dialog.CloseWebContentsModalDialog(); | 189 dialog->CloseWebContentsModalDialog(); |
184 } | 190 } |
OLD | NEW |