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