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 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, kStarIndex, kGoIndex, | 46 kBackIndex, kForwardIndex, kReloadIndex, kHomeIndex, kGoIndex, |
47 kPageIndex, kWrenchIndex, kLocationIndex, | 47 kPageIndex, kWrenchIndex, kLocationIndex, |
48 kBrowserActionContainerViewIndex | 48 kBrowserActionContainerViewIndex |
49 }; | 49 }; |
50 | 50 |
51 ToolbarControllerTest() { | 51 ToolbarControllerTest() { |
52 Browser* browser = helper_.browser(); | 52 Browser* browser = helper_.browser(); |
53 CommandUpdater* updater = browser->command_updater(); | 53 CommandUpdater* updater = browser->command_updater(); |
54 // The default state for the commands is true, set a couple to false to | 54 // The default state for the commands is true, set a couple to false to |
55 // ensure they get picked up correct on initialization | 55 // ensure they get picked up correct on initialization |
56 updater->UpdateCommandEnabled(IDC_BACK, false); | 56 updater->UpdateCommandEnabled(IDC_BACK, false); |
(...skipping 14 matching lines...) Expand all Loading... |
71 // command in the updater. The views are in the declaration order of outlets. | 71 // command in the updater. The views are in the declaration order of outlets. |
72 void CompareState(CommandUpdater* updater, NSArray* views) { | 72 void CompareState(CommandUpdater* updater, NSArray* views) { |
73 EXPECT_EQ(updater->IsCommandEnabled(IDC_BACK), | 73 EXPECT_EQ(updater->IsCommandEnabled(IDC_BACK), |
74 [[views objectAtIndex:kBackIndex] isEnabled] ? true : false); | 74 [[views objectAtIndex:kBackIndex] isEnabled] ? true : false); |
75 EXPECT_EQ(updater->IsCommandEnabled(IDC_FORWARD), | 75 EXPECT_EQ(updater->IsCommandEnabled(IDC_FORWARD), |
76 [[views objectAtIndex:kForwardIndex] isEnabled] ? true : false); | 76 [[views objectAtIndex:kForwardIndex] isEnabled] ? true : false); |
77 EXPECT_EQ(updater->IsCommandEnabled(IDC_RELOAD), | 77 EXPECT_EQ(updater->IsCommandEnabled(IDC_RELOAD), |
78 [[views objectAtIndex:kReloadIndex] isEnabled] ? true : false); | 78 [[views objectAtIndex:kReloadIndex] isEnabled] ? true : false); |
79 EXPECT_EQ(updater->IsCommandEnabled(IDC_HOME), | 79 EXPECT_EQ(updater->IsCommandEnabled(IDC_HOME), |
80 [[views objectAtIndex:kHomeIndex] isEnabled] ? true : false); | 80 [[views objectAtIndex:kHomeIndex] isEnabled] ? true : false); |
81 EXPECT_EQ(updater->IsCommandEnabled(IDC_BOOKMARK_PAGE), | |
82 [[views objectAtIndex:kStarIndex] isEnabled] ? true : false); | |
83 } | 81 } |
84 | 82 |
85 BrowserTestHelper helper_; | 83 BrowserTestHelper helper_; |
86 scoped_nsobject<ViewResizerPong> resizeDelegate_; | 84 scoped_nsobject<ViewResizerPong> resizeDelegate_; |
87 scoped_nsobject<ToolbarController> bar_; | 85 scoped_nsobject<ToolbarController> bar_; |
88 }; | 86 }; |
89 | 87 |
90 TEST_VIEW(ToolbarControllerTest, [bar_ view]) | 88 TEST_VIEW(ToolbarControllerTest, [bar_ view]) |
91 | 89 |
92 // Test the initial state that everything is sync'd up | 90 // Test the initial state that everything is sync'd up |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 151 } |
154 | 152 |
155 // Check that toggling the state of the home button changes the visible | 153 // Check that toggling the state of the home button changes the visible |
156 // state of the home button and moves the other buttons accordingly. | 154 // state of the home button and moves the other buttons accordingly. |
157 TEST_F(ToolbarControllerTest, ToggleHome) { | 155 TEST_F(ToolbarControllerTest, ToggleHome) { |
158 PrefService* prefs = helper_.profile()->GetPrefs(); | 156 PrefService* prefs = helper_.profile()->GetPrefs(); |
159 bool showHome = prefs->GetBoolean(prefs::kShowHomeButton); | 157 bool showHome = prefs->GetBoolean(prefs::kShowHomeButton); |
160 NSView* homeButton = [[bar_ toolbarViews] objectAtIndex:kHomeIndex]; | 158 NSView* homeButton = [[bar_ toolbarViews] objectAtIndex:kHomeIndex]; |
161 EXPECT_EQ(showHome, ![homeButton isHidden]); | 159 EXPECT_EQ(showHome, ![homeButton isHidden]); |
162 | 160 |
163 NSView* starButton = [[bar_ toolbarViews] objectAtIndex:kStarIndex]; | 161 NSView* reloadButton = [[bar_ toolbarViews] objectAtIndex:kReloadIndex]; |
164 NSView* locationBar = [[bar_ toolbarViews] objectAtIndex:kLocationIndex]; | 162 NSView* locationBar = [[bar_ toolbarViews] objectAtIndex:kLocationIndex]; |
165 NSRect originalStarFrame = [starButton frame]; | 163 NSRect originalReloadFrame = [reloadButton frame]; |
166 NSRect originalLocationBarFrame = [locationBar frame]; | 164 NSRect originalLocationBarFrame = [locationBar frame]; |
167 | 165 |
168 // Toggle the pref and make sure the button changed state and the other | 166 // Toggle the pref and make sure the button changed state and the other |
169 // views moved. | 167 // views moved. |
170 prefs->SetBoolean(prefs::kShowHomeButton, !showHome); | 168 prefs->SetBoolean(prefs::kShowHomeButton, !showHome); |
171 EXPECT_EQ(showHome, [homeButton isHidden]); | 169 EXPECT_EQ(showHome, [homeButton isHidden]); |
172 EXPECT_NE(NSMinX(originalStarFrame), NSMinX([starButton frame])); | 170 EXPECT_NE(NSMinX(originalReloadFrame), NSMinX([reloadButton frame])); |
173 EXPECT_NE(NSMinX(originalLocationBarFrame), NSMinX([locationBar frame])); | 171 EXPECT_NE(NSMinX(originalLocationBarFrame), NSMinX([locationBar frame])); |
174 EXPECT_NE(NSWidth(originalLocationBarFrame), NSWidth([locationBar frame])); | 172 EXPECT_NE(NSWidth(originalLocationBarFrame), NSWidth([locationBar frame])); |
175 } | 173 } |
176 | 174 |
177 TEST_F(ToolbarControllerTest, TogglePageWrench) { | 175 TEST_F(ToolbarControllerTest, TogglePageWrench) { |
178 PrefService* prefs = helper_.profile()->GetPrefs(); | 176 PrefService* prefs = helper_.profile()->GetPrefs(); |
179 bool showButtons = prefs->GetBoolean(prefs::kShowPageOptionsButtons); | 177 bool showButtons = prefs->GetBoolean(prefs::kShowPageOptionsButtons); |
180 NSView* pageButton = [[bar_ toolbarViews] objectAtIndex:kPageIndex]; | 178 NSView* pageButton = [[bar_ toolbarViews] objectAtIndex:kPageIndex]; |
181 NSView* wrenchButton = [[bar_ toolbarViews] objectAtIndex:kWrenchIndex]; | 179 NSView* wrenchButton = [[bar_ toolbarViews] objectAtIndex:kWrenchIndex]; |
182 EXPECT_EQ(showButtons, ![pageButton isHidden]); | 180 EXPECT_EQ(showButtons, ![pageButton isHidden]); |
(...skipping 30 matching lines...) Expand all Loading... |
213 EXPECT_EQ([homeButton isHidden], YES); | 211 EXPECT_EQ([homeButton isHidden], YES); |
214 NSRect newLocationBarFrame = [locationBar frame]; | 212 NSRect newLocationBarFrame = [locationBar frame]; |
215 EXPECT_TRUE(NSEqualRects(locationBarFrame, newLocationBarFrame)); | 213 EXPECT_TRUE(NSEqualRects(locationBarFrame, newLocationBarFrame)); |
216 [bar_ showOptionalPageWrenchButtons]; | 214 [bar_ showOptionalPageWrenchButtons]; |
217 EXPECT_EQ([pageButton isHidden], YES); | 215 EXPECT_EQ([pageButton isHidden], YES); |
218 EXPECT_EQ([wrenchButton isHidden], YES); | 216 EXPECT_EQ([wrenchButton isHidden], YES); |
219 newLocationBarFrame = [locationBar frame]; | 217 newLocationBarFrame = [locationBar frame]; |
220 EXPECT_TRUE(NSEqualRects(locationBarFrame, newLocationBarFrame)); | 218 EXPECT_TRUE(NSEqualRects(locationBarFrame, newLocationBarFrame)); |
221 } | 219 } |
222 | 220 |
223 TEST_F(ToolbarControllerTest, StarButtonInWindowCoordinates) { | 221 TEST_F(ToolbarControllerTest, StarIconInWindowCoordinates) { |
224 NSRect star = [bar_ starButtonInWindowCoordinates]; | 222 NSRect star = [bar_ starIconInWindowCoordinates]; |
225 NSRect all = [[[bar_ view] window] frame]; | 223 NSRect all = [[[bar_ view] window] frame]; |
226 | 224 |
227 // Make sure the star is completely inside the window rect | 225 // Make sure the star is completely inside the window rect |
228 EXPECT_TRUE(NSContainsRect(all, star)); | 226 EXPECT_TRUE(NSContainsRect(all, star)); |
229 } | 227 } |
230 | 228 |
231 TEST_F(ToolbarControllerTest, BubblePosition) { | 229 TEST_F(ToolbarControllerTest, BubblePosition) { |
232 NSView* locationBar = [[bar_ toolbarViews] objectAtIndex:kLocationIndex]; | 230 NSView* locationBar = [[bar_ toolbarViews] objectAtIndex:kLocationIndex]; |
233 | 231 |
234 // The window frame (in window base coordinates). | 232 // The window frame (in window base coordinates). |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 [view setHitTestReturn:button]; | 267 [view setHitTestReturn:button]; |
270 EXPECT_FALSE([bar_ hoverButtonForEvent:event]); | 268 EXPECT_FALSE([bar_ hoverButtonForEvent:event]); |
271 | 269 |
272 // Now! | 270 // Now! |
273 scoped_nsobject<GradientButtonCell> cell([[GradientButtonCell alloc] init]); | 271 scoped_nsobject<GradientButtonCell> cell([[GradientButtonCell alloc] init]); |
274 [button setCell:cell.get()]; | 272 [button setCell:cell.get()]; |
275 EXPECT_TRUE([bar_ hoverButtonForEvent:nil]); | 273 EXPECT_TRUE([bar_ hoverButtonForEvent:nil]); |
276 } | 274 } |
277 | 275 |
278 } // namespace | 276 } // namespace |
OLD | NEW |