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

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

Issue 2742813003: [Mac] Lay out the browser window when adding the download shelf. (Closed)
Patch Set: Test name and whitespace tweaks. Created 3 years, 9 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 11 matching lines...) Expand all
22 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
23 #include "components/bookmarks/common/bookmark_pref_names.h" 23 #include "components/bookmarks/common/bookmark_pref_names.h"
24 #include "components/prefs/pref_service.h" 24 #include "components/prefs/pref_service.h"
25 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
26 #include "content/public/test/test_utils.h" 26 #include "content/public/test/test_utils.h"
27 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
28 #import "testing/gtest_mac.h" 28 #import "testing/gtest_mac.h"
29 #import "third_party/ocmock/OCMock/OCMock.h" 29 #import "third_party/ocmock/OCMock/OCMock.h"
30 #import "ui/base/test/scoped_fake_nswindow_fullscreen.h" 30 #import "ui/base/test/scoped_fake_nswindow_fullscreen.h"
31 31
32 namespace {
33 const gfx::Size kMinTabbedWindowSize(
tapted 2017/03/13 00:25:36 I'm pretty sure this will add a static initializer
Sidney San Martín 2017/03/14 23:28:39 Hmm, I came very close to making MinWindowSizeForB
34 MinWindowSizeForBrowserType(Browser::TYPE_TABBED));
35 } // namespace
36
32 using ::testing::Return; 37 using ::testing::Return;
33 38
34 @interface BrowserWindowController (JustForTesting) 39 @interface BrowserWindowController (JustForTesting)
35 // Already defined in BWC. 40 // Already defined in BWC.
36 - (void)saveWindowPositionIfNeeded; 41 - (void)saveWindowPositionIfNeeded;
37 - (void)layoutSubviews; 42 - (void)layoutSubviews;
38 @end 43 @end
39 44
40 @interface BrowserWindowController (ExposedForTesting) 45 @interface BrowserWindowController (ExposedForTesting)
41 // Implementations are below. 46 // Implementations are below.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 Browser::CreateParams params(Browser::TYPE_TABBED, profile(), true); 149 Browser::CreateParams params(Browser::TYPE_TABBED, profile(), true);
145 params.initial_bounds = gfx::Rect(0, 0, 50, 50); 150 params.initial_bounds = gfx::Rect(0, 0, 50, 50);
146 Browser* browser = new Browser(params); 151 Browser* browser = new Browser(params);
147 NSWindow* cocoaWindow = browser->window()->GetNativeWindow(); 152 NSWindow* cocoaWindow = browser->window()->GetNativeWindow();
148 BrowserWindowController* controller = 153 BrowserWindowController* controller =
149 static_cast<BrowserWindowController*>([cocoaWindow windowController]); 154 static_cast<BrowserWindowController*>([cocoaWindow windowController]);
150 155
151 ASSERT_TRUE([controller isTabbedWindow]); 156 ASSERT_TRUE([controller isTabbedWindow]);
152 BrowserWindow* browser_window = [controller browserWindow]; 157 BrowserWindow* browser_window = [controller browserWindow];
153 EXPECT_EQ(browser_window, browser->window()); 158 EXPECT_EQ(browser_window, browser->window());
154 gfx::Rect bounds = browser_window->GetBounds(); 159 EXPECT_EQ(browser_window->GetBounds().size(), kMinTabbedWindowSize);
155 EXPECT_EQ(400, bounds.width());
156 EXPECT_EQ(272, bounds.height());
157 160
158 // Try to set the bounds smaller than the minimum. 161 // Try to set the bounds smaller than the minimum.
159 browser_window->SetBounds(gfx::Rect(0, 0, 50, 50)); 162 browser_window->SetBounds(gfx::Rect(0, 0, 50, 50));
160 bounds = browser_window->GetBounds(); 163 EXPECT_EQ(browser_window->GetBounds().size(), kMinTabbedWindowSize);
161 EXPECT_EQ(400, bounds.width());
162 EXPECT_EQ(272, bounds.height());
163 164
164 [controller close]; 165 [controller close];
165 } 166 }
166 167
168 // https://crbug.com/667698 - When Auto Layout is in use, adding the download
169 // shelf without ever showing it shouldn't prevent the window from being
170 // resized to its minimum width.
171 TEST_F(BrowserWindowControllerTest, TestSetBoundsWithDownloadShelf) {
172 Browser::CreateParams params(Browser::TYPE_TABBED, profile(), true);
173 params.initial_bounds = gfx::Rect(0, 0, 1000, 50);
174 Browser* browser = new Browser(params);
175 BrowserWindow* browser_window = browser->window();
176 browser_window->ShowInactive();
177
178 EXPECT_TRUE(browser_window->GetDownloadShelf());
tapted 2017/03/13 00:25:36 nit: comment here. Something like // Requesting t
Sidney San Martín 2017/03/14 23:28:39 Done.
tapted 2017/03/15 00:49:51 My main thought is that testing layout regressions
Sidney San Martín 2017/03/15 03:13:39 Aw, thanks tapted@.
179 EXPECT_FALSE(browser_window->IsDownloadShelfVisible());
180
181 browser_window->SetBounds(gfx::Rect(0, 0, 50, 50));
182
183 // When linking against an SDK >= 10.11, AppKit may lay out the window
184 // asynchronously (CFExecutableLinkedOnOrAfter check in -[NSThemeFrame
185 // handleSetFrameCommonRedisplay]). Do layout now instead.
186 [browser_window->GetNativeWindow() layoutIfNeeded];
187
188 EXPECT_EQ(browser_window->GetBounds().size(), kMinTabbedWindowSize);
189
190 browser_window->Close();
191 }
192
167 TEST_F(BrowserWindowControllerTest, TestSetBoundsPopup) { 193 TEST_F(BrowserWindowControllerTest, TestSetBoundsPopup) {
168 // Create a popup with bounds smaller than the minimum. 194 // Create a popup with bounds smaller than the minimum.
169 Browser::CreateParams params(Browser::TYPE_POPUP, profile(), true); 195 Browser::CreateParams params(Browser::TYPE_POPUP, profile(), true);
170 params.initial_bounds = gfx::Rect(0, 0, 50, 50); 196 params.initial_bounds = gfx::Rect(0, 0, 50, 50);
171 Browser* browser = new Browser(params); 197 Browser* browser = new Browser(params);
172 NSWindow* cocoaWindow = browser->window()->GetNativeWindow(); 198 NSWindow* cocoaWindow = browser->window()->GetNativeWindow();
173 BrowserWindowController* controller = 199 BrowserWindowController* controller =
174 static_cast<BrowserWindowController*>([cocoaWindow windowController]); 200 static_cast<BrowserWindowController*>([cocoaWindow windowController]);
175 201
176 ASSERT_FALSE([controller isTabbedWindow]); 202 ASSERT_FALSE([controller isTabbedWindow]);
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) 842 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400)
817 styleMask:NSBorderlessWindowMask 843 styleMask:NSBorderlessWindowMask
818 backing:NSBackingStoreBuffered 844 backing:NSBackingStoreBuffered
819 defer:NO]); 845 defer:NO]);
820 [[testFullscreenWindow_ contentView] setWantsLayer:YES]; 846 [[testFullscreenWindow_ contentView] setWantsLayer:YES];
821 return testFullscreenWindow_.get(); 847 return testFullscreenWindow_.get();
822 } 848 }
823 @end 849 @end
824 850
825 /* TODO(???): test other methods of BrowserWindowController */ 851 /* TODO(???): test other methods of BrowserWindowController */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698