Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: chrome/browser/ui/cocoa/constrained_window/constrained_window_mac_browsertest.mm

Issue 1446623003: [Reland] Enable AutoResize for Constrained Web Dialogs for Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes per thakis@'s comments. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 CreateAndShowWebModalDialogMac(&delegate, tab1_, sheet_);
136 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); 139 EXPECT_EQ(1.0, [sheet_window_ alphaValue]);
137 140
138 // Close the browser window. 141 // Close the browser window.
139 base::scoped_nsobject<NSWindow> browser_window( 142 base::scoped_nsobject<NSWindow> browser_window(
140 [browser()->window()->GetNativeWindow() retain]); 143 [browser()->window()->GetNativeWindow() retain]);
141 EXPECT_TRUE([browser_window isVisible]); 144 EXPECT_TRUE([browser_window isVisible]);
142 [browser()->window()->GetNativeWindow() performClose:nil]; 145 [browser()->window()->GetNativeWindow() performClose:nil];
143 EXPECT_FALSE([browser_window isVisible]); 146 EXPECT_FALSE([browser_window isVisible]);
144 } 147 }
145 148
146 // Test that closing a tab with a sheet works. 149 // Test that closing a tab with a sheet works.
147 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, TabClose) { 150 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, TabClose) {
148 NiceMock<ConstrainedWindowDelegateMock> delegate; 151 NiceMock<ConstrainedWindowDelegateMock> delegate;
149 ConstrainedWindowMac dialog(&delegate, tab1_, sheet_); 152 CreateAndShowWebModalDialogMac(&delegate, tab1_, sheet_);
150 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); 153 EXPECT_EQ(1.0, [sheet_window_ alphaValue]);
151 154
152 // Close the tab. 155 // Close the tab.
153 TabStripModel* tab_strip = browser()->tab_strip_model(); 156 TabStripModel* tab_strip = browser()->tab_strip_model();
154 EXPECT_EQ(2, tab_strip->count()); 157 EXPECT_EQ(2, tab_strip->count());
155 EXPECT_TRUE(tab_strip->CloseWebContentsAt(1, 158 EXPECT_TRUE(tab_strip->CloseWebContentsAt(1,
156 TabStripModel::CLOSE_USER_GESTURE)); 159 TabStripModel::CLOSE_USER_GESTURE));
157 EXPECT_EQ(1, tab_strip->count()); 160 EXPECT_EQ(1, tab_strip->count());
158 } 161 }
159 162
160 // Test that the sheet is still visible after entering and exiting fullscreen. 163 // Test that the sheet is still visible after entering and exiting fullscreen.
161 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, BrowserWindowFullscreen) { 164 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, BrowserWindowFullscreen) {
162 NiceMock<ConstrainedWindowDelegateMock> delegate; 165 NiceMock<ConstrainedWindowDelegateMock> delegate;
163 ConstrainedWindowMac dialog(&delegate, tab1_, sheet_); 166 std::unique_ptr<ConstrainedWindowMac> dialog(
167 CreateAndShowWebModalDialogMac(&delegate, tab1_, sheet_));
164 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); 168 EXPECT_EQ(1.0, [sheet_window_ alphaValue]);
165 169
166 // Toggle fullscreen twice: one for entering and one for exiting. 170 // Toggle fullscreen twice: one for entering and one for exiting.
167 // Check to see if the sheet is visible. 171 // Check to see if the sheet is visible.
168 for (int i = 0; i < 2; i++) { 172 for (int i = 0; i < 2; i++) {
169 { 173 {
170 // NOTIFICATION_FULLSCREEN_CHANGED is sent asynchronously. Wait for the 174 // NOTIFICATION_FULLSCREEN_CHANGED is sent asynchronously. Wait for the
171 // notification before testing the sheet's visibility. 175 // notification before testing the sheet's visibility.
172 scoped_ptr<FullscreenNotificationObserver> waiter( 176 scoped_ptr<FullscreenNotificationObserver> waiter(
173 new FullscreenNotificationObserver()); 177 new FullscreenNotificationObserver());
174 browser() 178 browser()
175 ->exclusive_access_manager() 179 ->exclusive_access_manager()
176 ->fullscreen_controller() 180 ->fullscreen_controller()
177 ->ToggleBrowserFullscreenMode(); 181 ->ToggleBrowserFullscreenMode();
178 waiter->Wait(); 182 waiter->Wait();
179 } 183 }
180 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); 184 EXPECT_EQ(1.0, [sheet_window_ alphaValue]);
181 } 185 }
182 186
183 dialog.CloseWebContentsModalDialog(); 187 dialog->CloseWebContentsModalDialog();
184 } 188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698