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 #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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 }; | 88 }; |
89 | 89 |
90 TEST_VIEW(ToolbarControllerTest, [bar_ view]) | 90 TEST_VIEW(ToolbarControllerTest, [bar_ view]) |
91 | 91 |
92 // Test the initial state that everything is sync'd up | 92 // Test the initial state that everything is sync'd up |
93 TEST_F(ToolbarControllerTest, InitialState) { | 93 TEST_F(ToolbarControllerTest, InitialState) { |
94 CommandUpdater* updater = helper_.browser()->command_updater(); | 94 CommandUpdater* updater = helper_.browser()->command_updater(); |
95 CompareState(updater, [bar_ toolbarViews]); | 95 CompareState(updater, [bar_ toolbarViews]); |
96 } | 96 } |
97 | 97 |
98 // Make sure a "titlebar only" toolbar works | 98 // Make sure a "titlebar only" toolbar with location bar works. |
99 TEST_F(ToolbarControllerTest, TitlebarOnly) { | 99 TEST_F(ToolbarControllerTest, TitlebarOnly) { |
100 NSView* view = [bar_ view]; | 100 NSView* view = [bar_ view]; |
101 | 101 |
102 [bar_ setHasToolbar:NO]; | 102 [bar_ setHasToolbar:NO hasLocationBar:YES]; |
103 EXPECT_NE(view, [bar_ view]); | 103 EXPECT_NE(view, [bar_ view]); |
104 | 104 |
105 // Simulate a popup going fullscreen and back. | 105 // Simulate a popup going fullscreen and back. |
106 NSView* superview = [view superview]; | 106 NSView* superview = [view superview]; |
107 // TODO(jrg): find a way to add an [NSAutoreleasePool drain] in | 107 // TODO(jrg): find a way to add an [NSAutoreleasePool drain] in |
108 // here. I don't have access to the current | 108 // here. I don't have access to the current |
109 // scoped_nsautorelease_pool to do it properly :-( | 109 // scoped_nsautorelease_pool to do it properly :-( |
110 [view removeFromSuperview]; | 110 [view removeFromSuperview]; |
111 [superview addSubview:view]; | 111 [superview addSubview:view]; |
112 | 112 |
113 [bar_ setHasToolbar:YES]; | 113 [bar_ setHasToolbar:YES hasLocationBar:YES]; |
114 EXPECT_EQ(view, [bar_ view]); | 114 EXPECT_EQ(view, [bar_ view]); |
115 | 115 |
116 // Leave it off to make sure that's fine | 116 // Leave it off to make sure that's fine |
117 [bar_ setHasToolbar:NO]; | 117 [bar_ setHasToolbar:NO hasLocationBar:YES]; |
118 } | 118 } |
119 | 119 |
| 120 // TODO(viettrungluu): make a version of above without location bar. |
120 | 121 |
121 // Make some changes to the enabled state of a few of the buttons and ensure | 122 // Make some changes to the enabled state of a few of the buttons and ensure |
122 // that we're still in sync. | 123 // that we're still in sync. |
123 TEST_F(ToolbarControllerTest, UpdateEnabledState) { | 124 TEST_F(ToolbarControllerTest, UpdateEnabledState) { |
124 CommandUpdater* updater = helper_.browser()->command_updater(); | 125 CommandUpdater* updater = helper_.browser()->command_updater(); |
125 EXPECT_FALSE(updater->IsCommandEnabled(IDC_BACK)); | 126 EXPECT_FALSE(updater->IsCommandEnabled(IDC_BACK)); |
126 EXPECT_FALSE(updater->IsCommandEnabled(IDC_FORWARD)); | 127 EXPECT_FALSE(updater->IsCommandEnabled(IDC_FORWARD)); |
127 updater->UpdateCommandEnabled(IDC_BACK, true); | 128 updater->UpdateCommandEnabled(IDC_BACK, true); |
128 updater->UpdateCommandEnabled(IDC_FORWARD, true); | 129 updater->UpdateCommandEnabled(IDC_FORWARD, true); |
129 CompareState(updater, [bar_ toolbarViews]); | 130 CompareState(updater, [bar_ toolbarViews]); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 EXPECT_EQ(showButtons, [pageButton isHidden]); | 202 EXPECT_EQ(showButtons, [pageButton isHidden]); |
202 EXPECT_EQ(showButtons, [wrenchButton isHidden]); | 203 EXPECT_EQ(showButtons, [wrenchButton isHidden]); |
203 EXPECT_NE(NSMinX(originalGoFrame), NSMinX([goButton frame])); | 204 EXPECT_NE(NSMinX(originalGoFrame), NSMinX([goButton frame])); |
204 EXPECT_NE(NSWidth(originalLocationBarFrame), NSWidth([locationBar frame])); | 205 EXPECT_NE(NSWidth(originalLocationBarFrame), NSWidth([locationBar frame])); |
205 } | 206 } |
206 | 207 |
207 // Ensure that we don't toggle the buttons when we have a strip marked as not | 208 // Ensure that we don't toggle the buttons when we have a strip marked as not |
208 // having the full toolbar. Also ensure that the location bar doesn't change | 209 // having the full toolbar. Also ensure that the location bar doesn't change |
209 // size. | 210 // size. |
210 TEST_F(ToolbarControllerTest, DontToggleWhenNoToolbar) { | 211 TEST_F(ToolbarControllerTest, DontToggleWhenNoToolbar) { |
211 [bar_ setHasToolbar:NO]; | 212 [bar_ setHasToolbar:NO hasLocationBar:YES]; |
212 NSView* homeButton = [[bar_ toolbarViews] objectAtIndex:kHomeIndex]; | 213 NSView* homeButton = [[bar_ toolbarViews] objectAtIndex:kHomeIndex]; |
213 NSView* pageButton = [[bar_ toolbarViews] objectAtIndex:kPageIndex]; | 214 NSView* pageButton = [[bar_ toolbarViews] objectAtIndex:kPageIndex]; |
214 NSView* wrenchButton = [[bar_ toolbarViews] objectAtIndex:kWrenchIndex]; | 215 NSView* wrenchButton = [[bar_ toolbarViews] objectAtIndex:kWrenchIndex]; |
215 NSView* locationBar = [[bar_ toolbarViews] objectAtIndex:kLocationIndex]; | 216 NSView* locationBar = [[bar_ toolbarViews] objectAtIndex:kLocationIndex]; |
216 NSRect locationBarFrame = [locationBar frame]; | 217 NSRect locationBarFrame = [locationBar frame]; |
217 EXPECT_EQ([homeButton isHidden], YES); | 218 EXPECT_EQ([homeButton isHidden], YES); |
218 EXPECT_EQ([pageButton isHidden], YES); | 219 EXPECT_EQ([pageButton isHidden], YES); |
219 EXPECT_EQ([wrenchButton isHidden], YES); | 220 EXPECT_EQ([wrenchButton isHidden], YES); |
220 [bar_ showOptionalHomeButton]; | 221 [bar_ showOptionalHomeButton]; |
221 EXPECT_EQ([homeButton isHidden], YES); | 222 EXPECT_EQ([homeButton isHidden], YES); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 [view setHitTestReturn:button]; | 278 [view setHitTestReturn:button]; |
278 EXPECT_FALSE([bar_ hoverButtonForEvent:event]); | 279 EXPECT_FALSE([bar_ hoverButtonForEvent:event]); |
279 | 280 |
280 // Now! | 281 // Now! |
281 scoped_nsobject<GradientButtonCell> cell([[GradientButtonCell alloc] init]); | 282 scoped_nsobject<GradientButtonCell> cell([[GradientButtonCell alloc] init]); |
282 [button setCell:cell.get()]; | 283 [button setCell:cell.get()]; |
283 EXPECT_TRUE([bar_ hoverButtonForEvent:nil]); | 284 EXPECT_TRUE([bar_ hoverButtonForEvent:nil]); |
284 } | 285 } |
285 | 286 |
286 } // namespace | 287 } // namespace |
OLD | NEW |