| OLD | NEW | 
|---|
| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 125 | 143 | 
| 126   NSRect tabFrame = [[controller_ tabStripView] frame]; | 144   NSRect tabFrame = [[controller_ tabStripView] frame]; | 
| 127   [controller_ installIncognitoBadge]; | 145   [controller_ installIncognitoBadge]; | 
| 128   NSRect newTabFrame = [[controller_ tabStripView] frame]; | 146   NSRect newTabFrame = [[controller_ tabStripView] frame]; | 
| 129   EXPECT_GT(tabFrame.size.width, newTabFrame.size.width); | 147   EXPECT_GT(tabFrame.size.width, newTabFrame.size.width); | 
| 130 | 148 | 
| 131   controller_.release(); | 149   controller_.release(); | 
| 132 } | 150 } | 
| 133 #endif | 151 #endif | 
| 134 | 152 | 
|  | 153 @interface BrowserWindowControllerResizePong : BrowserWindowController { | 
|  | 154 } | 
|  | 155 @end | 
|  | 156 | 
|  | 157 @implementation BrowserWindowControllerResizePong | 
|  | 158 @end | 
|  | 159 | 
|  | 160 // Test to make sure resizing and relaying-out subviews works correctly. | 
|  | 161 TEST_F(BrowserWindowControllerTest, TestResizeViews) { | 
|  | 162   TabStripView* tabstrip = [controller_ tabStripView]; | 
|  | 163   NSView* contentView = [[tabstrip window] contentView]; | 
|  | 164   NSView* toolbar = [controller_ toolbarView]; | 
|  | 165   NSView* infobar = [controller_ infoBarContainerView]; | 
|  | 166   NSView* contentArea = [controller_ tabContentArea]; | 
|  | 167 | 
|  | 168   // We need to muck with the views a bit to put us in a consistent state before | 
|  | 169   // we start resizing.  In particular, we need to move the tab strip to be | 
|  | 170   // immediately above the content area, since we layout views to be directly | 
|  | 171   // under the tab strip.  We also explicitly set the contentView's frame to be | 
|  | 172   // 800x600. | 
|  | 173   [contentView setFrame:NSMakeRect(0, 0, 800, 600)]; | 
|  | 174   NSRect tabstripFrame = [tabstrip frame]; | 
|  | 175   tabstripFrame.origin.y = NSMaxY([contentView frame]); | 
|  | 176   [tabstrip setFrame:tabstripFrame]; | 
|  | 177 | 
|  | 178   // Make sure each view is as tall as we expect. | 
|  | 179   ASSERT_EQ(39, NSHeight([toolbar frame])); | 
|  | 180   ASSERT_EQ(0, NSHeight([infobar frame])); | 
|  | 181 | 
|  | 182   // Force a layout and check each view's frame. | 
|  | 183   // contentView should be at 0,0 800x600 | 
|  | 184   // contentArea should be at 0,0 800x561 | 
|  | 185   // infobar should be at 0,561 800x0 | 
|  | 186   // toolbar should be at 0,561 800x39 | 
|  | 187   [controller_ layoutSubviews]; | 
|  | 188   EXPECT_TRUE(NSEqualRects([contentView frame], NSMakeRect(0, 0, 800, 600))); | 
|  | 189   EXPECT_TRUE(NSEqualRects([contentArea frame], NSMakeRect(0, 0, 800, 561))); | 
|  | 190   EXPECT_TRUE(NSEqualRects([infobar frame], NSMakeRect(0, 561, 800, 0))); | 
|  | 191   EXPECT_TRUE(NSEqualRects([toolbar frame], NSMakeRect(0, 561, 800, 39))); | 
|  | 192 | 
|  | 193   // Expand the infobar to 60px and recheck | 
|  | 194   // contentView should be at 0,0 800x600 | 
|  | 195   // contentArea should be at 0,0 800x501 | 
|  | 196   // infobar should be at 0,501 800x60 | 
|  | 197   // toolbar should be at 0,561 800x39 | 
|  | 198   [controller_ resizeView:infobar newHeight:60]; | 
|  | 199   EXPECT_TRUE(NSEqualRects([contentView frame], NSMakeRect(0, 0, 800, 600))); | 
|  | 200   EXPECT_TRUE(NSEqualRects([contentArea frame], NSMakeRect(0, 0, 800, 501))); | 
|  | 201   EXPECT_TRUE(NSEqualRects([infobar frame], NSMakeRect(0, 501, 800, 60))); | 
|  | 202   EXPECT_TRUE(NSEqualRects([toolbar frame], NSMakeRect(0, 561, 800, 39))); | 
|  | 203 | 
|  | 204   // Expand the toolbar to 64px and recheck | 
|  | 205   // contentView should be at 0,0 800x600 | 
|  | 206   // contentArea should be at 0,0 800x476 | 
|  | 207   // infobar should be at 0,476 800x60 | 
|  | 208   // toolbar should be at 0,536 800x64 | 
|  | 209   [controller_ resizeView:toolbar newHeight:64]; | 
|  | 210   EXPECT_TRUE(NSEqualRects([contentView frame], NSMakeRect(0, 0, 800, 600))); | 
|  | 211   EXPECT_TRUE(NSEqualRects([contentArea frame], NSMakeRect(0, 0, 800, 476))); | 
|  | 212   EXPECT_TRUE(NSEqualRects([infobar frame], NSMakeRect(0, 476, 800, 60))); | 
|  | 213   EXPECT_TRUE(NSEqualRects([toolbar frame], NSMakeRect(0, 536, 800, 64))); | 
|  | 214 | 
|  | 215   // Add a 30px download shelf and recheck | 
|  | 216   // contentView should be at 0,0 800x600 | 
|  | 217   // download should be at 0,0 800x30 | 
|  | 218   // contentArea should be at 0,30 800x446 | 
|  | 219   // infobar should be at 0,476 800x60 | 
|  | 220   // toolbar should be at 0,536 800x64 | 
|  | 221   NSView* download = [[controller_ downloadShelf] view]; | 
|  | 222   [controller_ resizeView:download newHeight:30]; | 
|  | 223   EXPECT_TRUE(NSEqualRects([contentView frame], NSMakeRect(0, 0, 800, 600))); | 
|  | 224   EXPECT_TRUE(NSEqualRects([download frame], NSMakeRect(0, 0, 800, 30))); | 
|  | 225   EXPECT_TRUE(NSEqualRects([contentArea frame], NSMakeRect(0, 30, 800, 446))); | 
|  | 226   EXPECT_TRUE(NSEqualRects([infobar frame], NSMakeRect(0, 476, 800, 60))); | 
|  | 227   EXPECT_TRUE(NSEqualRects([toolbar frame], NSMakeRect(0, 536, 800, 64))); | 
|  | 228 | 
|  | 229   // Shrink the infobar to 0px and toolbar to 39px and recheck | 
|  | 230   // contentView should be at 0,0 800x600 | 
|  | 231   // download should be at 0,0 800x30 | 
|  | 232   // contentArea should be at 0,30 800x531 | 
|  | 233   // infobar should be at 0,561 800x0 | 
|  | 234   // toolbar should be at 0,561 800x39 | 
|  | 235   [controller_ resizeView:infobar newHeight:0]; | 
|  | 236   [controller_ resizeView:toolbar newHeight:39]; | 
|  | 237   EXPECT_TRUE(NSEqualRects([contentView frame], NSMakeRect(0, 0, 800, 600))); | 
|  | 238   EXPECT_TRUE(NSEqualRects([download frame], NSMakeRect(0, 0, 800, 30))); | 
|  | 239   EXPECT_TRUE(NSEqualRects([contentArea frame], NSMakeRect(0, 30, 800, 531))); | 
|  | 240   EXPECT_TRUE(NSEqualRects([infobar frame], NSMakeRect(0, 561, 800, 0))); | 
|  | 241   EXPECT_TRUE(NSEqualRects([toolbar frame], NSMakeRect(0, 561, 800, 39))); | 
|  | 242 } | 
|  | 243 | 
| 135 /* TODO(???): test other methods of BrowserWindowController */ | 244 /* TODO(???): test other methods of BrowserWindowController */ | 
| OLD | NEW | 
|---|