| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #import "base/scoped_nsobject.h" | 7 #import "base/scoped_nsobject.h" |
| 8 #include "chrome/app/chrome_dll_resource.h" | 8 #include "chrome/app/chrome_dll_resource.h" |
| 9 #include "chrome/browser/cocoa/browser_test_helper.h" | 9 #include "chrome/browser/cocoa/browser_test_helper.h" |
| 10 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 10 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 class ToolbarControllerTest : public CocoaTest { | 40 class ToolbarControllerTest : public CocoaTest { |
| 41 public: | 41 public: |
| 42 | 42 |
| 43 // Indexes that match the ordering returned by the private ToolbarController | 43 // Indexes that match the ordering returned by the private ToolbarController |
| 44 // |-toolbarViews| method. | 44 // |-toolbarViews| method. |
| 45 enum { | 45 enum { |
| 46 kBackIndex, kForwardIndex, kReloadIndex, kHomeIndex, kPageIndex, | 46 kBackIndex, kForwardIndex, kReloadIndex, kHomeIndex, |
| 47 kWrenchIndex, kLocationIndex, kBrowserActionContainerViewIndex | 47 kWrenchIndex, kLocationIndex, kBrowserActionContainerViewIndex |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 ToolbarControllerTest() { | 50 ToolbarControllerTest() { |
| 51 Browser* browser = helper_.browser(); | 51 Browser* browser = helper_.browser(); |
| 52 CommandUpdater* updater = browser->command_updater(); | 52 CommandUpdater* updater = browser->command_updater(); |
| 53 // The default state for the commands is true, set a couple to false to | 53 // The default state for the commands is true, set a couple to false to |
| 54 // ensure they get picked up correct on initialization | 54 // ensure they get picked up correct on initialization |
| 55 updater->UpdateCommandEnabled(IDC_BACK, false); | 55 updater->UpdateCommandEnabled(IDC_BACK, false); |
| 56 updater->UpdateCommandEnabled(IDC_FORWARD, false); | 56 updater->UpdateCommandEnabled(IDC_FORWARD, false); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 175 |
| 176 // Toggle the pref and make sure the button changed state and the other | 176 // Toggle the pref and make sure the button changed state and the other |
| 177 // views moved. | 177 // views moved. |
| 178 prefs->SetBoolean(prefs::kShowHomeButton, !showHome); | 178 prefs->SetBoolean(prefs::kShowHomeButton, !showHome); |
| 179 EXPECT_EQ(showHome, [homeButton isHidden]); | 179 EXPECT_EQ(showHome, [homeButton isHidden]); |
| 180 EXPECT_NE(NSMinX(originalReloadFrame), NSMinX([reloadButton frame])); | 180 EXPECT_NE(NSMinX(originalReloadFrame), NSMinX([reloadButton frame])); |
| 181 EXPECT_NE(NSMinX(originalLocationBarFrame), NSMinX([locationBar frame])); | 181 EXPECT_NE(NSMinX(originalLocationBarFrame), NSMinX([locationBar frame])); |
| 182 EXPECT_NE(NSWidth(originalLocationBarFrame), NSWidth([locationBar frame])); | 182 EXPECT_NE(NSWidth(originalLocationBarFrame), NSWidth([locationBar frame])); |
| 183 } | 183 } |
| 184 | 184 |
| 185 TEST_F(ToolbarControllerTest, TogglePageWrench) { | |
| 186 PrefService* prefs = helper_.profile()->GetPrefs(); | |
| 187 bool showButtons = prefs->GetBoolean(prefs::kShowPageOptionsButtons); | |
| 188 NSView* pageButton = [[bar_ toolbarViews] objectAtIndex:kPageIndex]; | |
| 189 NSView* wrenchButton = [[bar_ toolbarViews] objectAtIndex:kWrenchIndex]; | |
| 190 EXPECT_EQ(showButtons, ![pageButton isHidden]); | |
| 191 EXPECT_EQ(showButtons, ![wrenchButton isHidden]); | |
| 192 | |
| 193 NSView* locationBar = [[bar_ toolbarViews] objectAtIndex:kLocationIndex]; | |
| 194 NSRect originalLocationBarFrame = [locationBar frame]; | |
| 195 | |
| 196 // Toggle the pref and make sure the buttons changed state and the other | |
| 197 // views moved (or in the case of the location bar, it changed width). | |
| 198 prefs->SetBoolean(prefs::kShowPageOptionsButtons, !showButtons); | |
| 199 EXPECT_EQ(showButtons, [pageButton isHidden]); | |
| 200 EXPECT_EQ(showButtons, [wrenchButton isHidden]); | |
| 201 EXPECT_NE(NSWidth(originalLocationBarFrame), NSWidth([locationBar frame])); | |
| 202 } | |
| 203 | |
| 204 // Ensure that we don't toggle the buttons when we have a strip marked as not | 185 // Ensure that we don't toggle the buttons when we have a strip marked as not |
| 205 // having the full toolbar. Also ensure that the location bar doesn't change | 186 // having the full toolbar. Also ensure that the location bar doesn't change |
| 206 // size. | 187 // size. |
| 207 TEST_F(ToolbarControllerTest, DontToggleWhenNoToolbar) { | 188 TEST_F(ToolbarControllerTest, DontToggleWhenNoToolbar) { |
| 208 [bar_ setHasToolbar:NO hasLocationBar:YES]; | 189 [bar_ setHasToolbar:NO hasLocationBar:YES]; |
| 209 NSView* homeButton = [[bar_ toolbarViews] objectAtIndex:kHomeIndex]; | 190 NSView* homeButton = [[bar_ toolbarViews] objectAtIndex:kHomeIndex]; |
| 210 NSView* pageButton = [[bar_ toolbarViews] objectAtIndex:kPageIndex]; | |
| 211 NSView* wrenchButton = [[bar_ toolbarViews] objectAtIndex:kWrenchIndex]; | |
| 212 NSView* locationBar = [[bar_ toolbarViews] objectAtIndex:kLocationIndex]; | 191 NSView* locationBar = [[bar_ toolbarViews] objectAtIndex:kLocationIndex]; |
| 213 NSRect locationBarFrame = [locationBar frame]; | 192 NSRect locationBarFrame = [locationBar frame]; |
| 214 EXPECT_EQ([homeButton isHidden], YES); | 193 EXPECT_EQ([homeButton isHidden], YES); |
| 215 EXPECT_EQ([pageButton isHidden], YES); | |
| 216 EXPECT_EQ([wrenchButton isHidden], YES); | |
| 217 [bar_ showOptionalHomeButton]; | 194 [bar_ showOptionalHomeButton]; |
| 218 EXPECT_EQ([homeButton isHidden], YES); | 195 EXPECT_EQ([homeButton isHidden], YES); |
| 219 NSRect newLocationBarFrame = [locationBar frame]; | 196 NSRect newLocationBarFrame = [locationBar frame]; |
| 220 EXPECT_TRUE(NSEqualRects(locationBarFrame, newLocationBarFrame)); | 197 EXPECT_TRUE(NSEqualRects(locationBarFrame, newLocationBarFrame)); |
| 221 [bar_ showOptionalPageWrenchButtons]; | |
| 222 EXPECT_EQ([pageButton isHidden], YES); | |
| 223 EXPECT_EQ([wrenchButton isHidden], YES); | |
| 224 newLocationBarFrame = [locationBar frame]; | 198 newLocationBarFrame = [locationBar frame]; |
| 225 EXPECT_TRUE(NSEqualRects(locationBarFrame, newLocationBarFrame)); | 199 EXPECT_TRUE(NSEqualRects(locationBarFrame, newLocationBarFrame)); |
| 226 } | 200 } |
| 227 | 201 |
| 228 TEST_F(ToolbarControllerTest, StarIconInWindowCoordinates) { | 202 TEST_F(ToolbarControllerTest, StarIconInWindowCoordinates) { |
| 229 NSRect star = [bar_ starIconInWindowCoordinates]; | 203 NSRect star = [bar_ starIconInWindowCoordinates]; |
| 230 NSRect all = [[[bar_ view] window] frame]; | 204 NSRect all = [[[bar_ view] window] frame]; |
| 231 | 205 |
| 232 // Make sure the star is completely inside the window rect | 206 // Make sure the star is completely inside the window rect |
| 233 EXPECT_TRUE(NSContainsRect(all, star)); | 207 EXPECT_TRUE(NSContainsRect(all, star)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 256 [view setHitTestReturn:button]; | 230 [view setHitTestReturn:button]; |
| 257 EXPECT_FALSE([bar_ hoverButtonForEvent:event]); | 231 EXPECT_FALSE([bar_ hoverButtonForEvent:event]); |
| 258 | 232 |
| 259 // Now! | 233 // Now! |
| 260 scoped_nsobject<GradientButtonCell> cell([[GradientButtonCell alloc] init]); | 234 scoped_nsobject<GradientButtonCell> cell([[GradientButtonCell alloc] init]); |
| 261 [button setCell:cell.get()]; | 235 [button setCell:cell.get()]; |
| 262 EXPECT_TRUE([bar_ hoverButtonForEvent:nil]); | 236 EXPECT_TRUE([bar_ hoverButtonForEvent:nil]); |
| 263 } | 237 } |
| 264 | 238 |
| 265 } // namespace | 239 } // namespace |
| OLD | NEW |