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