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