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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_controller_unittest.mm

Issue 2685333005: ash: fix regression where ctrl+n put new window on wrong desktop (Closed)
Patch Set: We have both kinds of compile fixes: mac and windows Created 3 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/mac/mac_util.h" 9 #include "base/mac/mac_util.h"
10 #import "base/mac/scoped_nsobject.h" 10 #import "base/mac/scoped_nsobject.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 // Make sure a normal BrowserWindowController is, uh, normal. 121 // Make sure a normal BrowserWindowController is, uh, normal.
122 EXPECT_TRUE([controller_ isTabbedWindow]); 122 EXPECT_TRUE([controller_ isTabbedWindow]);
123 EXPECT_TRUE([controller_ hasTabStrip]); 123 EXPECT_TRUE([controller_ hasTabStrip]);
124 EXPECT_FALSE([controller_ hasTitleBar]); 124 EXPECT_FALSE([controller_ hasTitleBar]);
125 EXPECT_TRUE([controller_ isBookmarkBarVisible]); 125 EXPECT_TRUE([controller_ isBookmarkBarVisible]);
126 126
127 // And make sure a controller for a pop-up window is not normal. 127 // And make sure a controller for a pop-up window is not normal.
128 // popup_browser will be owned by its window. 128 // popup_browser will be owned by its window.
129 Browser* popup_browser( 129 Browser* popup_browser(
130 new Browser(Browser::CreateParams(Browser::TYPE_POPUP, profile()))); 130 new Browser(Browser::CreateParams(Browser::TYPE_POPUP, profile(), true)));
131 NSWindow* cocoaWindow = popup_browser->window()->GetNativeWindow(); 131 NSWindow* cocoaWindow = popup_browser->window()->GetNativeWindow();
132 BrowserWindowController* controller = 132 BrowserWindowController* controller =
133 static_cast<BrowserWindowController*>([cocoaWindow windowController]); 133 static_cast<BrowserWindowController*>([cocoaWindow windowController]);
134 ASSERT_TRUE([controller isKindOfClass:[BrowserWindowController class]]); 134 ASSERT_TRUE([controller isKindOfClass:[BrowserWindowController class]]);
135 EXPECT_FALSE([controller isTabbedWindow]); 135 EXPECT_FALSE([controller isTabbedWindow]);
136 EXPECT_FALSE([controller hasTabStrip]); 136 EXPECT_FALSE([controller hasTabStrip]);
137 EXPECT_TRUE([controller hasTitleBar]); 137 EXPECT_TRUE([controller hasTitleBar]);
138 EXPECT_FALSE([controller isBookmarkBarVisible]); 138 EXPECT_FALSE([controller isBookmarkBarVisible]);
139 [controller close]; 139 [controller close];
140 } 140 }
141 141
142 TEST_F(BrowserWindowControllerTest, TestSetBounds) { 142 TEST_F(BrowserWindowControllerTest, TestSetBounds) {
143 // Create a normal browser with bounds smaller than the minimum. 143 // Create a normal browser with bounds smaller than the minimum.
144 Browser::CreateParams params(Browser::TYPE_TABBED, profile()); 144 Browser::CreateParams params(Browser::TYPE_TABBED, profile(), true);
145 params.initial_bounds = gfx::Rect(0, 0, 50, 50); 145 params.initial_bounds = gfx::Rect(0, 0, 50, 50);
146 Browser* browser = new Browser(params); 146 Browser* browser = new Browser(params);
147 NSWindow* cocoaWindow = browser->window()->GetNativeWindow(); 147 NSWindow* cocoaWindow = browser->window()->GetNativeWindow();
148 BrowserWindowController* controller = 148 BrowserWindowController* controller =
149 static_cast<BrowserWindowController*>([cocoaWindow windowController]); 149 static_cast<BrowserWindowController*>([cocoaWindow windowController]);
150 150
151 ASSERT_TRUE([controller isTabbedWindow]); 151 ASSERT_TRUE([controller isTabbedWindow]);
152 BrowserWindow* browser_window = [controller browserWindow]; 152 BrowserWindow* browser_window = [controller browserWindow];
153 EXPECT_EQ(browser_window, browser->window()); 153 EXPECT_EQ(browser_window, browser->window());
154 gfx::Rect bounds = browser_window->GetBounds(); 154 gfx::Rect bounds = browser_window->GetBounds();
155 EXPECT_EQ(400, bounds.width()); 155 EXPECT_EQ(400, bounds.width());
156 EXPECT_EQ(272, bounds.height()); 156 EXPECT_EQ(272, bounds.height());
157 157
158 // Try to set the bounds smaller than the minimum. 158 // Try to set the bounds smaller than the minimum.
159 browser_window->SetBounds(gfx::Rect(0, 0, 50, 50)); 159 browser_window->SetBounds(gfx::Rect(0, 0, 50, 50));
160 bounds = browser_window->GetBounds(); 160 bounds = browser_window->GetBounds();
161 EXPECT_EQ(400, bounds.width()); 161 EXPECT_EQ(400, bounds.width());
162 EXPECT_EQ(272, bounds.height()); 162 EXPECT_EQ(272, bounds.height());
163 163
164 [controller close]; 164 [controller close];
165 } 165 }
166 166
167 TEST_F(BrowserWindowControllerTest, TestSetBoundsPopup) { 167 TEST_F(BrowserWindowControllerTest, TestSetBoundsPopup) {
168 // Create a popup with bounds smaller than the minimum. 168 // Create a popup with bounds smaller than the minimum.
169 Browser::CreateParams params(Browser::TYPE_POPUP, profile()); 169 Browser::CreateParams params(Browser::TYPE_POPUP, profile(), true);
170 params.initial_bounds = gfx::Rect(0, 0, 50, 50); 170 params.initial_bounds = gfx::Rect(0, 0, 50, 50);
171 Browser* browser = new Browser(params); 171 Browser* browser = new Browser(params);
172 NSWindow* cocoaWindow = browser->window()->GetNativeWindow(); 172 NSWindow* cocoaWindow = browser->window()->GetNativeWindow();
173 BrowserWindowController* controller = 173 BrowserWindowController* controller =
174 static_cast<BrowserWindowController*>([cocoaWindow windowController]); 174 static_cast<BrowserWindowController*>([cocoaWindow windowController]);
175 175
176 ASSERT_FALSE([controller isTabbedWindow]); 176 ASSERT_FALSE([controller isTabbedWindow]);
177 BrowserWindow* browser_window = [controller browserWindow]; 177 BrowserWindow* browser_window = [controller browserWindow];
178 EXPECT_EQ(browser_window, browser->window()); 178 EXPECT_EQ(browser_window, browser->window());
179 gfx::Rect bounds = browser_window->GetBounds(); 179 gfx::Rect bounds = browser_window->GetBounds();
(...skipping 19 matching lines...) Expand all
199 // Explicitly show the bar. Can't use chrome::ToggleBookmarkBarWhenVisible() 199 // Explicitly show the bar. Can't use chrome::ToggleBookmarkBarWhenVisible()
200 // because of the notification issues. 200 // because of the notification issues.
201 profile()->GetPrefs()->SetBoolean(bookmarks::prefs::kShowBookmarkBar, true); 201 profile()->GetPrefs()->SetBoolean(bookmarks::prefs::kShowBookmarkBar, true);
202 202
203 [controller_ browserWindow]->BookmarkBarStateChanged( 203 [controller_ browserWindow]->BookmarkBarStateChanged(
204 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); 204 BookmarkBar::DONT_ANIMATE_STATE_CHANGE);
205 EXPECT_TRUE([controller_ isBookmarkBarVisible]); 205 EXPECT_TRUE([controller_ isBookmarkBarVisible]);
206 } 206 }
207 207
208 TEST_F(BrowserWindowControllerTest, BookmarkBarToggleRespectMinWindowHeight) { 208 TEST_F(BrowserWindowControllerTest, BookmarkBarToggleRespectMinWindowHeight) {
209 Browser::CreateParams params(Browser::TYPE_TABBED, profile()); 209 Browser::CreateParams params(Browser::TYPE_TABBED, profile(), true);
210 params.initial_bounds = gfx::Rect(0, 0, 50, 280); 210 params.initial_bounds = gfx::Rect(0, 0, 50, 280);
211 Browser* browser = new Browser(params); 211 Browser* browser = new Browser(params);
212 NSWindow* cocoaWindow = browser->window()->GetNativeWindow(); 212 NSWindow* cocoaWindow = browser->window()->GetNativeWindow();
213 BrowserWindowController* controller = 213 BrowserWindowController* controller =
214 static_cast<BrowserWindowController*>([cocoaWindow windowController]); 214 static_cast<BrowserWindowController*>([cocoaWindow windowController]);
215 BrowserWindow* browser_window = [controller browserWindow]; 215 BrowserWindow* browser_window = [controller browserWindow];
216 gfx::Rect bounds = browser_window->GetBounds(); 216 gfx::Rect bounds = browser_window->GetBounds();
217 EXPECT_EQ(280, bounds.height()); 217 EXPECT_EQ(280, bounds.height());
218 218
219 // Try to set the bounds smaller than the minimum. 219 // Try to set the bounds smaller than the minimum.
220 // Explicitly show the bar. Can't use chrome::ToggleBookmarkBarWhenVisible() 220 // Explicitly show the bar. Can't use chrome::ToggleBookmarkBarWhenVisible()
221 // because of the notification issues. 221 // because of the notification issues.
222 [controller adjustWindowHeightBy:-20]; 222 [controller adjustWindowHeightBy:-20];
223 bounds = browser_window->GetBounds(); 223 bounds = browser_window->GetBounds();
224 EXPECT_EQ(272, bounds.height()); 224 EXPECT_EQ(272, bounds.height());
225 225
226 [controller close]; 226 [controller close];
227 } 227 }
228 228
229 #if 0 229 #if 0
230 // TODO(jrg): This crashes trying to create the BookmarkBarController, adding 230 // TODO(jrg): This crashes trying to create the BookmarkBarController, adding
231 // an observer to the BookmarkModel. 231 // an observer to the BookmarkModel.
232 TEST_F(BrowserWindowControllerTest, TestIncognitoWidthSpace) { 232 TEST_F(BrowserWindowControllerTest, TestIncognitoWidthSpace) {
233 std::unique_ptr<TestingProfile> incognito_profile(new TestingProfile()); 233 std::unique_ptr<TestingProfile> incognito_profile(new TestingProfile());
234 incognito_profile->set_off_the_record(true); 234 incognito_profile->set_off_the_record(true);
235 std::unique_ptr<Browser> browser( 235 std::unique_ptr<Browser> browser(
236 new Browser(Browser::CreateParams(incognito_profile.get()))); 236 new Browser(Browser::CreateParams(incognito_profile.get(), true)));
237 controller_.reset([[BrowserWindowController alloc] 237 controller_.reset([[BrowserWindowController alloc]
238 initWithBrowser:browser.get() 238 initWithBrowser:browser.get()
239 takeOwnership:NO]); 239 takeOwnership:NO]);
240 240
241 NSRect tabFrame = [[controller_ tabStripView] frame]; 241 NSRect tabFrame = [[controller_ tabStripView] frame];
242 [controller_ installIncognitoBadge]; 242 [controller_ installIncognitoBadge];
243 NSRect newTabFrame = [[controller_ tabStripView] frame]; 243 NSRect newTabFrame = [[controller_ tabStripView] frame];
244 EXPECT_GT(tabFrame.size.width, newTabFrame.size.width); 244 EXPECT_GT(tabFrame.size.width, newTabFrame.size.width);
245 245
246 controller_.release(); 246 controller_.release();
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) 816 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400)
817 styleMask:NSBorderlessWindowMask 817 styleMask:NSBorderlessWindowMask
818 backing:NSBackingStoreBuffered 818 backing:NSBackingStoreBuffered
819 defer:NO]); 819 defer:NO]);
820 [[testFullscreenWindow_ contentView] setWantsLayer:YES]; 820 [[testFullscreenWindow_ contentView] setWantsLayer:YES];
821 return testFullscreenWindow_.get(); 821 return testFullscreenWindow_.get();
822 } 822 }
823 @end 823 @end
824 824
825 /* TODO(???): test other methods of BrowserWindowController */ 825 /* TODO(???): test other methods of BrowserWindowController */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698