| 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" |
| 11 #import "chrome/browser/cocoa/gradient_button_cell.h" | 11 #import "chrome/browser/cocoa/gradient_button_cell.h" |
| 12 #import "chrome/browser/cocoa/reload_button.h" |
| 12 #import "chrome/browser/cocoa/toolbar_controller.h" | 13 #import "chrome/browser/cocoa/toolbar_controller.h" |
| 13 #import "chrome/browser/cocoa/view_resizer_pong.h" | 14 #import "chrome/browser/cocoa/view_resizer_pong.h" |
| 14 #include "chrome/browser/pref_service.h" | 15 #include "chrome/browser/pref_service.h" |
| 15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "testing/platform_test.h" | 18 #include "testing/platform_test.h" |
| 18 | 19 |
| 19 // An NSView that fakes out hitTest:. | 20 // An NSView that fakes out hitTest:. |
| 20 @interface HitView : NSView { | 21 @interface HitView : NSView { |
| 21 id hitTestReturn_; | 22 id hitTestReturn_; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 NSWindow* window = test_window(); | 144 NSWindow* window = test_window(); |
| 144 [window makeFirstResponder:[window contentView]]; | 145 [window makeFirstResponder:[window contentView]]; |
| 145 EXPECT_EQ([window firstResponder], [window contentView]); | 146 EXPECT_EQ([window firstResponder], [window contentView]); |
| 146 [bar_ focusLocationBar:YES]; | 147 [bar_ focusLocationBar:YES]; |
| 147 EXPECT_NE([window firstResponder], [window contentView]); | 148 EXPECT_NE([window firstResponder], [window contentView]); |
| 148 NSView* locationBar = [[bar_ toolbarViews] objectAtIndex:kLocationIndex]; | 149 NSView* locationBar = [[bar_ toolbarViews] objectAtIndex:kLocationIndex]; |
| 149 EXPECT_EQ([window firstResponder], [(id)locationBar currentEditor]); | 150 EXPECT_EQ([window firstResponder], [(id)locationBar currentEditor]); |
| 150 } | 151 } |
| 151 | 152 |
| 152 TEST_F(ToolbarControllerTest, LoadingState) { | 153 TEST_F(ToolbarControllerTest, LoadingState) { |
| 153 // In its initial state, the reload button has a tag of | 154 // In its initial state, the reload button has a command of |
| 154 // IDC_RELOAD. When loading, it should be IDC_STOP. | 155 // IDC_RELOAD. When loading, it should be IDC_STOP. |
| 155 NSButton* reload = [[bar_ toolbarViews] objectAtIndex:kReloadIndex]; | 156 ReloadButton* reload = [[bar_ toolbarViews] objectAtIndex:kReloadIndex]; |
| 156 EXPECT_EQ([reload tag], IDC_RELOAD); | 157 EXPECT_EQ([reload command], IDC_RELOAD); |
| 157 [bar_ setIsLoading:YES force:YES]; | 158 [bar_ setIsLoading:YES force:YES]; |
| 158 EXPECT_EQ([reload tag], IDC_STOP); | 159 EXPECT_EQ([reload command], IDC_STOP); |
| 159 [bar_ setIsLoading:NO force:YES]; | 160 [bar_ setIsLoading:NO force:YES]; |
| 160 EXPECT_EQ([reload tag], IDC_RELOAD); | 161 EXPECT_EQ([reload command], IDC_RELOAD); |
| 161 } | 162 } |
| 162 | 163 |
| 163 // Check that toggling the state of the home button changes the visible | 164 // Check that toggling the state of the home button changes the visible |
| 164 // state of the home button and moves the other buttons accordingly. | 165 // state of the home button and moves the other buttons accordingly. |
| 165 TEST_F(ToolbarControllerTest, ToggleHome) { | 166 TEST_F(ToolbarControllerTest, ToggleHome) { |
| 166 PrefService* prefs = helper_.profile()->GetPrefs(); | 167 PrefService* prefs = helper_.profile()->GetPrefs(); |
| 167 bool showHome = prefs->GetBoolean(prefs::kShowHomeButton); | 168 bool showHome = prefs->GetBoolean(prefs::kShowHomeButton); |
| 168 NSView* homeButton = [[bar_ toolbarViews] objectAtIndex:kHomeIndex]; | 169 NSView* homeButton = [[bar_ toolbarViews] objectAtIndex:kHomeIndex]; |
| 169 EXPECT_EQ(showHome, ![homeButton isHidden]); | 170 EXPECT_EQ(showHome, ![homeButton isHidden]); |
| 170 | 171 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 [view setHitTestReturn:button]; | 232 [view setHitTestReturn:button]; |
| 232 EXPECT_FALSE([bar_ hoverButtonForEvent:event]); | 233 EXPECT_FALSE([bar_ hoverButtonForEvent:event]); |
| 233 | 234 |
| 234 // Now! | 235 // Now! |
| 235 scoped_nsobject<GradientButtonCell> cell([[GradientButtonCell alloc] init]); | 236 scoped_nsobject<GradientButtonCell> cell([[GradientButtonCell alloc] init]); |
| 236 [button setCell:cell.get()]; | 237 [button setCell:cell.get()]; |
| 237 EXPECT_TRUE([bar_ hoverButtonForEvent:nil]); | 238 EXPECT_TRUE([bar_ hoverButtonForEvent:nil]); |
| 238 } | 239 } |
| 239 | 240 |
| 240 } // namespace | 241 } // namespace |
| OLD | NEW |