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

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

Issue 165014: Reverting 22541. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/scoped_nsobject.h" 5 #include "base/scoped_nsobject.h"
6 #include "base/scoped_nsautorelease_pool.h" 6 #include "base/scoped_nsautorelease_pool.h"
7 #include "base/scoped_ptr.h" 7 #include "base/scoped_ptr.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/cocoa/browser_test_helper.h" 9 #include "chrome/browser/cocoa/browser_test_helper.h"
10 #include "chrome/browser/cocoa/browser_window_controller.h" 10 #include "chrome/browser/cocoa/browser_window_controller.h"
11 #include "chrome/browser/cocoa/cocoa_test_helper.h" 11 #include "chrome/browser/cocoa/cocoa_test_helper.h"
12 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 #include "chrome/common/pref_service.h" 13 #include "chrome/common/pref_service.h"
14 #include "chrome/test/testing_browser_process.h" 14 #include "chrome/test/testing_browser_process.h"
15 #include "chrome/test/testing_profile.h" 15 #include "chrome/test/testing_profile.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 @interface BrowserWindowController (JustForTesting)
19 // Already defined in BWC.
20 - (void)saveWindowPositionToPrefs:(PrefService*)prefs;
21 - (void)layoutSubviews;
22 @end
23
18 @interface BrowserWindowController (ExposedForTesting) 24 @interface BrowserWindowController (ExposedForTesting)
19 - (void)saveWindowPositionToPrefs:(PrefService*)prefs; 25 // Implementations are below.
26 - (NSView*)infoBarContainerView;
27 - (NSView*)toolbarView;
28 @end
29
30 @implementation BrowserWindowController (ExposedForTesting)
31 - (NSView*)infoBarContainerView {
32 return [infoBarContainerController_ view];
33 }
34
35 - (NSView*)toolbarView {
36 return [toolbarController_ view];
37 }
20 @end 38 @end
21 39
22 class BrowserWindowControllerTest : public testing::Test { 40 class BrowserWindowControllerTest : public testing::Test {
23 virtual void SetUp() { 41 virtual void SetUp() {
24 controller_.reset([[BrowserWindowController alloc] 42 controller_.reset([[BrowserWindowController alloc]
25 initWithBrowser:browser_helper_.browser() 43 initWithBrowser:browser_helper_.browser()
26 takeOwnership:NO]); 44 takeOwnership:NO]);
27 } 45 }
28 46
29 public: 47 public:
(...skipping 15 matching lines...) Expand all
45 63
46 // Ask the window to save its position, then check that a preference 64 // Ask the window to save its position, then check that a preference
47 // exists. We're technically passing in a pointer to the user prefs 65 // exists. We're technically passing in a pointer to the user prefs
48 // and not the local state prefs, but a PrefService* is a 66 // and not the local state prefs, but a PrefService* is a
49 // PrefService*, and this is a unittest. 67 // PrefService*, and this is a unittest.
50 [controller_ saveWindowPositionToPrefs:prefs]; 68 [controller_ saveWindowPositionToPrefs:prefs];
51 EXPECT_TRUE(prefs->GetDictionary(prefs::kBrowserWindowPlacement) != NULL); 69 EXPECT_TRUE(prefs->GetDictionary(prefs::kBrowserWindowPlacement) != NULL);
52 } 70 }
53 71
54 @interface BrowserWindowControllerFakeFullscreen : BrowserWindowController { 72 @interface BrowserWindowControllerFakeFullscreen : BrowserWindowController {
73 @private
74 // We release the window ourselves, so we don't have to rely on the unittest
75 // doing it for us.
76 scoped_nsobject<NSWindow> fullscreenWindow_;
55 } 77 }
56 @end 78 @end
57 @implementation BrowserWindowControllerFakeFullscreen 79 @implementation BrowserWindowControllerFakeFullscreen
58 // This isn't needed to pass the test, but does prevent an actual 80 // Override fullscreenWindow to return a dummy window. This isn't needed to
59 // fullscreen from happening. 81 // pass the test, but does prevent an actual fullscreen from happening. We have
82 // to return an actual window because layoutSubviews: looks at the window's
83 // frame.
60 - (NSWindow*)fullscreenWindow { 84 - (NSWindow*)fullscreenWindow {
61 return nil; 85 if (fullscreenWindow_.get())
86 return fullscreenWindow_.get();
87
88 fullscreenWindow_.reset(
89 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400)
90 styleMask:NSBorderlessWindowMask
91 backing:NSBackingStoreBuffered
92 defer:NO]);
93 [fullscreenWindow_ setReleasedWhenClosed:NO];
94 return fullscreenWindow_.get();
62 } 95 }
63 @end 96 @end
64 97
65 TEST_F(BrowserWindowControllerTest, TestFullscreen) { 98 TEST_F(BrowserWindowControllerTest, TestFullscreen) {
66 // Note use of "controller", not "controller_" 99 // Note use of "controller", not "controller_"
67 scoped_nsobject<BrowserWindowController> controller; 100 scoped_nsobject<BrowserWindowController> controller;
68 controller.reset([[BrowserWindowControllerFakeFullscreen alloc] 101 controller.reset([[BrowserWindowControllerFakeFullscreen alloc]
69 initWithBrowser:browser_helper_.browser() 102 initWithBrowser:browser_helper_.browser()
70 takeOwnership:NO]); 103 takeOwnership:NO]);
71 EXPECT_FALSE([controller isFullscreen]); 104 EXPECT_FALSE([controller isFullscreen]);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 158
126 NSRect tabFrame = [[controller_ tabStripView] frame]; 159 NSRect tabFrame = [[controller_ tabStripView] frame];
127 [controller_ installIncognitoBadge]; 160 [controller_ installIncognitoBadge];
128 NSRect newTabFrame = [[controller_ tabStripView] frame]; 161 NSRect newTabFrame = [[controller_ tabStripView] frame];
129 EXPECT_GT(tabFrame.size.width, newTabFrame.size.width); 162 EXPECT_GT(tabFrame.size.width, newTabFrame.size.width);
130 163
131 controller_.release(); 164 controller_.release();
132 } 165 }
133 #endif 166 #endif
134 167
168 @interface BrowserWindowControllerResizePong : BrowserWindowController {
169 }
170 @end
171
172 @implementation BrowserWindowControllerResizePong
173 @end
174
175 // Test to make sure resizing and relaying-out subviews works correctly.
176 TEST_F(BrowserWindowControllerTest, TestResizeViews) {
177 TabStripView* tabstrip = [controller_ tabStripView];
178 NSView* contentView = [[tabstrip window] contentView];
179 NSView* toolbar = [controller_ toolbarView];
180 NSView* infobar = [controller_ infoBarContainerView];
181 NSView* contentArea = [controller_ tabContentArea];
182
183 // We need to muck with the views a bit to put us in a consistent state before
184 // we start resizing. In particular, we need to move the tab strip to be
185 // immediately above the content area, since we layout views to be directly
186 // under the tab strip. We also explicitly set the contentView's frame to be
187 // 800x600.
188 [contentView setFrame:NSMakeRect(0, 0, 800, 600)];
189 NSRect tabstripFrame = [tabstrip frame];
190 tabstripFrame.origin.y = NSMaxY([contentView frame]);
191 [tabstrip setFrame:tabstripFrame];
192
193 // Make sure each view is as tall as we expect.
194 ASSERT_EQ(39, NSHeight([toolbar frame]));
195 ASSERT_EQ(0, NSHeight([infobar frame]));
196
197 // Force a layout and check each view's frame.
198 // contentView should be at 0,0 800x600
199 // contentArea should be at 0,0 800x561
200 // infobar should be at 0,561 800x0
201 // toolbar should be at 0,561 800x39
202 [controller_ layoutSubviews];
203 EXPECT_TRUE(NSEqualRects([contentView frame], NSMakeRect(0, 0, 800, 600)));
204 EXPECT_TRUE(NSEqualRects([contentArea frame], NSMakeRect(0, 0, 800, 561)));
205 EXPECT_TRUE(NSEqualRects([infobar frame], NSMakeRect(0, 561, 800, 0)));
206 EXPECT_TRUE(NSEqualRects([toolbar frame], NSMakeRect(0, 561, 800, 39)));
207
208 // Expand the infobar to 60px and recheck
209 // contentView should be at 0,0 800x600
210 // contentArea should be at 0,0 800x501
211 // infobar should be at 0,501 800x60
212 // toolbar should be at 0,561 800x39
213 [controller_ resizeView:infobar newHeight:60];
214 EXPECT_TRUE(NSEqualRects([contentView frame], NSMakeRect(0, 0, 800, 600)));
215 EXPECT_TRUE(NSEqualRects([contentArea frame], NSMakeRect(0, 0, 800, 501)));
216 EXPECT_TRUE(NSEqualRects([infobar frame], NSMakeRect(0, 501, 800, 60)));
217 EXPECT_TRUE(NSEqualRects([toolbar frame], NSMakeRect(0, 561, 800, 39)));
218
219 // Expand the toolbar to 64px and recheck
220 // contentView should be at 0,0 800x600
221 // contentArea should be at 0,0 800x476
222 // infobar should be at 0,476 800x60
223 // toolbar should be at 0,536 800x64
224 [controller_ resizeView:toolbar newHeight:64];
225 EXPECT_TRUE(NSEqualRects([contentView frame], NSMakeRect(0, 0, 800, 600)));
226 EXPECT_TRUE(NSEqualRects([contentArea frame], NSMakeRect(0, 0, 800, 476)));
227 EXPECT_TRUE(NSEqualRects([infobar frame], NSMakeRect(0, 476, 800, 60)));
228 EXPECT_TRUE(NSEqualRects([toolbar frame], NSMakeRect(0, 536, 800, 64)));
229
230 // Add a 30px download shelf and recheck
231 // contentView should be at 0,0 800x600
232 // download should be at 0,0 800x30
233 // contentArea should be at 0,30 800x446
234 // infobar should be at 0,476 800x60
235 // toolbar should be at 0,536 800x64
236 NSView* download = [[controller_ downloadShelf] view];
237 [controller_ resizeView:download newHeight:30];
238 EXPECT_TRUE(NSEqualRects([contentView frame], NSMakeRect(0, 0, 800, 600)));
239 EXPECT_TRUE(NSEqualRects([download frame], NSMakeRect(0, 0, 800, 30)));
240 EXPECT_TRUE(NSEqualRects([contentArea frame], NSMakeRect(0, 30, 800, 446)));
241 EXPECT_TRUE(NSEqualRects([infobar frame], NSMakeRect(0, 476, 800, 60)));
242 EXPECT_TRUE(NSEqualRects([toolbar frame], NSMakeRect(0, 536, 800, 64)));
243
244 // Shrink the infobar to 0px and toolbar to 39px and recheck
245 // contentView should be at 0,0 800x600
246 // download should be at 0,0 800x30
247 // contentArea should be at 0,30 800x531
248 // infobar should be at 0,561 800x0
249 // toolbar should be at 0,561 800x39
250 [controller_ resizeView:infobar newHeight:0];
251 [controller_ resizeView:toolbar newHeight:39];
252 EXPECT_TRUE(NSEqualRects([contentView frame], NSMakeRect(0, 0, 800, 600)));
253 EXPECT_TRUE(NSEqualRects([download frame], NSMakeRect(0, 0, 800, 30)));
254 EXPECT_TRUE(NSEqualRects([contentArea frame], NSMakeRect(0, 30, 800, 531)));
255 EXPECT_TRUE(NSEqualRects([infobar frame], NSMakeRect(0, 561, 800, 0)));
256 EXPECT_TRUE(NSEqualRects([toolbar frame], NSMakeRect(0, 561, 800, 39)));
257 }
258
135 /* TODO(???): test other methods of BrowserWindowController */ 259 /* TODO(???): test other methods of BrowserWindowController */
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/browser_window_controller.mm ('k') | chrome/browser/cocoa/download_shelf_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698