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

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

Issue 10692195: Consolidate Browser Creation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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) 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 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
6 6
7 #include "base/mac/mac_util.h" 7 #include "base/mac/mac_util.h"
8 #import "base/memory/scoped_nsobject.h" 8 #import "base/memory/scoped_nsobject.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 [controller_ updateBookmarkBarVisibilityWithAnimation:NO]; 114 [controller_ updateBookmarkBarVisibilityWithAnimation:NO];
115 115
116 // Make sure a normal BrowserWindowController is, uh, normal. 116 // Make sure a normal BrowserWindowController is, uh, normal.
117 EXPECT_TRUE([controller_ isTabbedWindow]); 117 EXPECT_TRUE([controller_ isTabbedWindow]);
118 EXPECT_TRUE([controller_ hasTabStrip]); 118 EXPECT_TRUE([controller_ hasTabStrip]);
119 EXPECT_FALSE([controller_ hasTitleBar]); 119 EXPECT_FALSE([controller_ hasTitleBar]);
120 EXPECT_TRUE([controller_ isBookmarkBarVisible]); 120 EXPECT_TRUE([controller_ isBookmarkBarVisible]);
121 121
122 // And make sure a controller for a pop-up window is not normal. 122 // And make sure a controller for a pop-up window is not normal.
123 // popup_browser will be owned by its window. 123 // popup_browser will be owned by its window.
124 Browser* popup_browser(Browser::CreateWithParams( 124 Browser* popup_browser(new Browser(
125 Browser::CreateParams(Browser::TYPE_POPUP, profile()))); 125 Browser::CreateParams(Browser::TYPE_POPUP, profile())));
126 NSWindow *cocoaWindow = popup_browser->window()->GetNativeWindow(); 126 NSWindow *cocoaWindow = popup_browser->window()->GetNativeWindow();
127 BrowserWindowController* controller = 127 BrowserWindowController* controller =
128 static_cast<BrowserWindowController*>([cocoaWindow windowController]); 128 static_cast<BrowserWindowController*>([cocoaWindow windowController]);
129 ASSERT_TRUE([controller isKindOfClass:[BrowserWindowController class]]); 129 ASSERT_TRUE([controller isKindOfClass:[BrowserWindowController class]]);
130 EXPECT_FALSE([controller isTabbedWindow]); 130 EXPECT_FALSE([controller isTabbedWindow]);
131 EXPECT_FALSE([controller hasTabStrip]); 131 EXPECT_FALSE([controller hasTabStrip]);
132 EXPECT_TRUE([controller hasTitleBar]); 132 EXPECT_TRUE([controller hasTitleBar]);
133 EXPECT_FALSE([controller isBookmarkBarVisible]); 133 EXPECT_FALSE([controller isBookmarkBarVisible]);
134 [controller close]; 134 [controller close];
135 } 135 }
136 136
137 TEST_F(BrowserWindowControllerTest, TestSetBounds) { 137 TEST_F(BrowserWindowControllerTest, TestSetBounds) {
138 // Create a normal browser with bounds smaller than the minimum. 138 // Create a normal browser with bounds smaller than the minimum.
139 Browser::CreateParams params(Browser::TYPE_TABBED, profile()); 139 Browser::CreateParams params(Browser::TYPE_TABBED, profile());
140 params.initial_bounds = gfx::Rect(0, 0, 50, 50); 140 params.initial_bounds = gfx::Rect(0, 0, 50, 50);
141 Browser* browser = Browser::CreateWithParams(params); 141 Browser* browser = new Browser(params);
142 NSWindow *cocoaWindow = browser->window()->GetNativeWindow(); 142 NSWindow *cocoaWindow = browser->window()->GetNativeWindow();
143 BrowserWindowController* controller = 143 BrowserWindowController* controller =
144 static_cast<BrowserWindowController*>([cocoaWindow windowController]); 144 static_cast<BrowserWindowController*>([cocoaWindow windowController]);
145 145
146 ASSERT_TRUE([controller isTabbedWindow]); 146 ASSERT_TRUE([controller isTabbedWindow]);
147 BrowserWindow* browser_window = [controller browserWindow]; 147 BrowserWindow* browser_window = [controller browserWindow];
148 EXPECT_EQ(browser_window, browser->window()); 148 EXPECT_EQ(browser_window, browser->window());
149 gfx::Rect bounds = browser_window->GetBounds(); 149 gfx::Rect bounds = browser_window->GetBounds();
150 EXPECT_EQ(400, bounds.width()); 150 EXPECT_EQ(400, bounds.width());
151 EXPECT_EQ(272, bounds.height()); 151 EXPECT_EQ(272, bounds.height());
152 152
153 // Try to set the bounds smaller than the minimum. 153 // Try to set the bounds smaller than the minimum.
154 browser_window->SetBounds(gfx::Rect(0, 0, 50, 50)); 154 browser_window->SetBounds(gfx::Rect(0, 0, 50, 50));
155 bounds = browser_window->GetBounds(); 155 bounds = browser_window->GetBounds();
156 EXPECT_EQ(400, bounds.width()); 156 EXPECT_EQ(400, bounds.width());
157 EXPECT_EQ(272, bounds.height()); 157 EXPECT_EQ(272, bounds.height());
158 158
159 [controller close]; 159 [controller close];
160 } 160 }
161 161
162 TEST_F(BrowserWindowControllerTest, TestSetBoundsPopup) { 162 TEST_F(BrowserWindowControllerTest, TestSetBoundsPopup) {
163 // Create a popup with bounds smaller than the minimum. 163 // Create a popup with bounds smaller than the minimum.
164 Browser::CreateParams params(Browser::TYPE_POPUP, profile()); 164 Browser::CreateParams params(Browser::TYPE_POPUP, profile());
165 params.initial_bounds = gfx::Rect(0, 0, 50, 50); 165 params.initial_bounds = gfx::Rect(0, 0, 50, 50);
166 Browser* browser = Browser::CreateWithParams(params); 166 Browser* browser = new Browser(params);
167 NSWindow *cocoaWindow = browser->window()->GetNativeWindow(); 167 NSWindow *cocoaWindow = browser->window()->GetNativeWindow();
168 BrowserWindowController* controller = 168 BrowserWindowController* controller =
169 static_cast<BrowserWindowController*>([cocoaWindow windowController]); 169 static_cast<BrowserWindowController*>([cocoaWindow windowController]);
170 170
171 ASSERT_FALSE([controller isTabbedWindow]); 171 ASSERT_FALSE([controller isTabbedWindow]);
172 BrowserWindow* browser_window = [controller browserWindow]; 172 BrowserWindow* browser_window = [controller browserWindow];
173 EXPECT_EQ(browser_window, browser->window()); 173 EXPECT_EQ(browser_window, browser->window());
174 gfx::Rect bounds = browser_window->GetBounds(); 174 gfx::Rect bounds = browser_window->GetBounds();
175 EXPECT_EQ(100, bounds.width()); 175 EXPECT_EQ(100, bounds.width());
176 EXPECT_EQ(122, bounds.height()); 176 EXPECT_EQ(122, bounds.height());
(...skipping 22 matching lines...) Expand all
199 [controller_ updateBookmarkBarVisibilityWithAnimation:NO]; 199 [controller_ updateBookmarkBarVisibilityWithAnimation:NO];
200 EXPECT_TRUE([controller_ isBookmarkBarVisible]); 200 EXPECT_TRUE([controller_ isBookmarkBarVisible]);
201 } 201 }
202 202
203 #if 0 203 #if 0
204 // TODO(jrg): This crashes trying to create the BookmarkBarController, adding 204 // TODO(jrg): This crashes trying to create the BookmarkBarController, adding
205 // an observer to the BookmarkModel. 205 // an observer to the BookmarkModel.
206 TEST_F(BrowserWindowControllerTest, TestIncognitoWidthSpace) { 206 TEST_F(BrowserWindowControllerTest, TestIncognitoWidthSpace) {
207 scoped_ptr<TestingProfile> incognito_profile(new TestingProfile()); 207 scoped_ptr<TestingProfile> incognito_profile(new TestingProfile());
208 incognito_profile->set_off_the_record(true); 208 incognito_profile->set_off_the_record(true);
209 scoped_ptr<Browser> browser(new Browser(Browser::TYPE_TABBED, 209 scoped_ptr<Browser> browser(
210 incognito_profile.get())); 210 new Browser(Browser::CreateParams(incognito_profile.get()));
211 controller_.reset([[BrowserWindowController alloc] 211 controller_.reset([[BrowserWindowController alloc]
212 initWithBrowser:browser.get() 212 initWithBrowser:browser.get()
213 takeOwnership:NO]); 213 takeOwnership:NO]);
214 214
215 NSRect tabFrame = [[controller_ tabStripView] frame]; 215 NSRect tabFrame = [[controller_ tabStripView] frame];
216 [controller_ installIncognitoBadge]; 216 [controller_ installIncognitoBadge];
217 NSRect newTabFrame = [[controller_ tabStripView] frame]; 217 NSRect newTabFrame = [[controller_ tabStripView] frame];
218 EXPECT_GT(tabFrame.size.width, newTabFrame.size.width); 218 EXPECT_GT(tabFrame.size.width, newTabFrame.size.width);
219 219
220 controller_.release(); 220 controller_.release();
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 } 668 }
669 669
670 void WaitForFullScreenTransition() { 670 void WaitForFullScreenTransition() {
671 content::WindowedNotificationObserver observer( 671 content::WindowedNotificationObserver observer(
672 chrome::NOTIFICATION_FULLSCREEN_CHANGED, 672 chrome::NOTIFICATION_FULLSCREEN_CHANGED,
673 content::NotificationService::AllSources()); 673 content::NotificationService::AllSources());
674 observer.Wait(); 674 observer.Wait();
675 } 675 }
676 676
677 TEST_F(BrowserWindowFullScreenControllerTest, TestFullscreen) { 677 TEST_F(BrowserWindowFullScreenControllerTest, TestFullscreen) {
678 CreateBrowserWindow();
679 [controller_ showWindow:nil]; 678 [controller_ showWindow:nil];
680 EXPECT_FALSE([controller_ isFullscreen]); 679 EXPECT_FALSE([controller_ isFullscreen]);
681 680
682 [controller_ enterFullscreenForURL:GURL() 681 [controller_ enterFullscreenForURL:GURL()
683 bubbleType:FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION]; 682 bubbleType:FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION];
684 WaitForFullScreenTransition(); 683 WaitForFullScreenTransition();
685 EXPECT_TRUE([controller_ isFullscreen]); 684 EXPECT_TRUE([controller_ isFullscreen]);
686 685
687 [controller_ exitFullscreen]; 686 [controller_ exitFullscreen];
688 WaitForFullScreenTransition(); 687 WaitForFullScreenTransition();
689 EXPECT_FALSE([controller_ isFullscreen]); 688 EXPECT_FALSE([controller_ isFullscreen]);
690 } 689 }
691 690
692 // If this test fails, it is usually a sign that the bots have some sort of 691 // If this test fails, it is usually a sign that the bots have some sort of
693 // problem (such as a modal dialog up). This tests is a very useful canary, so 692 // problem (such as a modal dialog up). This tests is a very useful canary, so
694 // please do not mark it as flaky without first verifying that there are no bot 693 // please do not mark it as flaky without first verifying that there are no bot
695 // problems. 694 // problems.
696 TEST_F(BrowserWindowFullScreenControllerTest, TestActivate) { 695 TEST_F(BrowserWindowFullScreenControllerTest, TestActivate) {
697 CreateBrowserWindow();
698 [controller_ showWindow:nil]; 696 [controller_ showWindow:nil];
699 697
700 EXPECT_FALSE([controller_ isFullscreen]); 698 EXPECT_FALSE([controller_ isFullscreen]);
701 699
702 [controller_ activate]; 700 [controller_ activate];
703 EXPECT_TRUE(IsFrontWindow([controller_ window])); 701 EXPECT_TRUE(IsFrontWindow([controller_ window]));
704 702
705 [controller_ enterFullscreenForURL:GURL() 703 [controller_ enterFullscreenForURL:GURL()
706 bubbleType:FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION]; 704 bubbleType:FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION];
707 WaitForFullScreenTransition(); 705 WaitForFullScreenTransition();
(...skipping 21 matching lines...) Expand all
729 testFullscreenWindow_.reset( 727 testFullscreenWindow_.reset(
730 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) 728 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400)
731 styleMask:NSBorderlessWindowMask 729 styleMask:NSBorderlessWindowMask
732 backing:NSBackingStoreBuffered 730 backing:NSBackingStoreBuffered
733 defer:NO]); 731 defer:NO]);
734 return testFullscreenWindow_.get(); 732 return testFullscreenWindow_.get();
735 } 733 }
736 @end 734 @end
737 735
738 /* TODO(???): test other methods of BrowserWindowController */ 736 /* TODO(???): test other methods of BrowserWindowController */
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser/avatar_button_controller_unittest.mm ('k') | chrome/browser/ui/cocoa/cocoa_profile_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698