Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: chrome/browser/ui/cocoa/toolbar/toolbar_controller_unittest.mm

Issue 10677009: Move command handling and updating off Browser and onto a helper object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/scoped_nsobject.h" 7 #import "base/memory/scoped_nsobject.h"
8 #include "chrome/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/command_updater.h"
10 #include "chrome/browser/ui/browser_command_controller.h"
11 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" 12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
10 #import "chrome/browser/ui/cocoa/gradient_button_cell.h" 13 #import "chrome/browser/ui/cocoa/gradient_button_cell.h"
11 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 14 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
12 #import "chrome/browser/ui/cocoa/view_resizer_pong.h" 15 #import "chrome/browser/ui/cocoa/view_resizer_pong.h"
13 #include "chrome/browser/prefs/pref_service.h" 16 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
15 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/platform_test.h" 19 #include "testing/platform_test.h"
17 20
18 // An NSView that fakes out hitTest:. 21 // An NSView that fakes out hitTest:.
(...skipping 24 matching lines...) Expand all
43 // |-toolbarViews| method. 46 // |-toolbarViews| method.
44 enum { 47 enum {
45 kBackIndex, kForwardIndex, kReloadIndex, kHomeIndex, 48 kBackIndex, kForwardIndex, kReloadIndex, kHomeIndex,
46 kWrenchIndex, kLocationIndex, kBrowserActionContainerViewIndex 49 kWrenchIndex, kLocationIndex, kBrowserActionContainerViewIndex
47 }; 50 };
48 51
49 virtual void SetUp() { 52 virtual void SetUp() {
50 CocoaProfileTest::SetUp(); 53 CocoaProfileTest::SetUp();
51 ASSERT_TRUE(browser()); 54 ASSERT_TRUE(browser());
52 55
53 CommandUpdater* updater = browser()->command_updater(); 56 CommandUpdater* updater =
57 browser()->command_controller()->command_updater();
54 // The default state for the commands is true, set a couple to false to 58 // The default state for the commands is true, set a couple to false to
55 // ensure they get picked up correct on initialization 59 // ensure they get picked up correct on initialization
56 updater->UpdateCommandEnabled(IDC_BACK, false); 60 updater->UpdateCommandEnabled(IDC_BACK, false);
57 updater->UpdateCommandEnabled(IDC_FORWARD, false); 61 updater->UpdateCommandEnabled(IDC_FORWARD, false);
58 resizeDelegate_.reset([[ViewResizerPong alloc] init]); 62 resizeDelegate_.reset([[ViewResizerPong alloc] init]);
59 bar_.reset( 63 bar_.reset(
60 [[ToolbarController alloc] initWithModel:browser()->toolbar_model() 64 [[ToolbarController alloc] initWithModel:browser()->toolbar_model()
61 commands:browser()->command_updater() 65 commands:browser()->command_controller() ->command_updater()
62 profile:profile() 66 profile:profile()
63 browser:browser() 67 browser:browser()
64 resizeDelegate:resizeDelegate_.get()]); 68 resizeDelegate:resizeDelegate_.get()]);
65 EXPECT_TRUE([bar_ view]); 69 EXPECT_TRUE([bar_ view]);
66 NSView* parent = [test_window() contentView]; 70 NSView* parent = [test_window() contentView];
67 [parent addSubview:[bar_ view]]; 71 [parent addSubview:[bar_ view]];
68 } 72 }
69 73
70 // Make sure the enabled state of the view is the same as the corresponding 74 // Make sure the enabled state of the view is the same as the corresponding
71 // command in the updater. The views are in the declaration order of outlets. 75 // command in the updater. The views are in the declaration order of outlets.
72 void CompareState(CommandUpdater* updater, NSArray* views) { 76 void CompareState(CommandUpdater* updater, NSArray* views) {
73 EXPECT_EQ(updater->IsCommandEnabled(IDC_BACK), 77 EXPECT_EQ(updater->IsCommandEnabled(IDC_BACK),
74 [[views objectAtIndex:kBackIndex] isEnabled] ? true : false); 78 [[views objectAtIndex:kBackIndex] isEnabled] ? true : false);
75 EXPECT_EQ(updater->IsCommandEnabled(IDC_FORWARD), 79 EXPECT_EQ(updater->IsCommandEnabled(IDC_FORWARD),
76 [[views objectAtIndex:kForwardIndex] isEnabled] ? true : false); 80 [[views objectAtIndex:kForwardIndex] isEnabled] ? true : false);
77 EXPECT_EQ(updater->IsCommandEnabled(IDC_RELOAD), 81 EXPECT_EQ(updater->IsCommandEnabled(IDC_RELOAD),
78 [[views objectAtIndex:kReloadIndex] isEnabled] ? true : false); 82 [[views objectAtIndex:kReloadIndex] isEnabled] ? true : false);
79 EXPECT_EQ(updater->IsCommandEnabled(IDC_HOME), 83 EXPECT_EQ(updater->IsCommandEnabled(IDC_HOME),
80 [[views objectAtIndex:kHomeIndex] isEnabled] ? true : false); 84 [[views objectAtIndex:kHomeIndex] isEnabled] ? true : false);
81 } 85 }
82 86
83 scoped_nsobject<ViewResizerPong> resizeDelegate_; 87 scoped_nsobject<ViewResizerPong> resizeDelegate_;
84 scoped_nsobject<ToolbarController> bar_; 88 scoped_nsobject<ToolbarController> bar_;
85 }; 89 };
86 90
87 TEST_VIEW(ToolbarControllerTest, [bar_ view]) 91 TEST_VIEW(ToolbarControllerTest, [bar_ view])
88 92
89 // Test the initial state that everything is sync'd up 93 // Test the initial state that everything is sync'd up
90 TEST_F(ToolbarControllerTest, InitialState) { 94 TEST_F(ToolbarControllerTest, InitialState) {
91 CommandUpdater* updater = browser()->command_updater(); 95 CommandUpdater* updater = browser()->command_controller()->command_updater();
92 CompareState(updater, [bar_ toolbarViews]); 96 CompareState(updater, [bar_ toolbarViews]);
93 } 97 }
94 98
95 // Make sure a "titlebar only" toolbar with location bar works. 99 // Make sure a "titlebar only" toolbar with location bar works.
96 // Crashy, http://crbug.com/122836 100 // Crashy, http://crbug.com/122836
97 TEST_F(ToolbarControllerTest, DISABLED_TitlebarOnly) { 101 TEST_F(ToolbarControllerTest, DISABLED_TitlebarOnly) {
98 NSView* view = [bar_ view]; 102 NSView* view = [bar_ view];
99 103
100 [bar_ setHasToolbar:NO hasLocationBar:YES]; 104 [bar_ setHasToolbar:NO hasLocationBar:YES];
101 EXPECT_NE(view, [bar_ view]); 105 EXPECT_NE(view, [bar_ view]);
(...skipping 22 matching lines...) Expand all
124 // Simulate a popup going fullscreen and back by performing the reparenting 128 // Simulate a popup going fullscreen and back by performing the reparenting
125 // that happens during fullscreen transitions 129 // that happens during fullscreen transitions
126 NSView* superview = [view superview]; 130 NSView* superview = [view superview];
127 [view removeFromSuperview]; 131 [view removeFromSuperview];
128 [superview addSubview:view]; 132 [superview addSubview:view];
129 } 133 }
130 134
131 // Make some changes to the enabled state of a few of the buttons and ensure 135 // Make some changes to the enabled state of a few of the buttons and ensure
132 // that we're still in sync. 136 // that we're still in sync.
133 TEST_F(ToolbarControllerTest, UpdateEnabledState) { 137 TEST_F(ToolbarControllerTest, UpdateEnabledState) {
134 CommandUpdater* updater = browser()->command_updater(); 138 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_BACK));
135 EXPECT_FALSE(updater->IsCommandEnabled(IDC_BACK)); 139 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FORWARD));
136 EXPECT_FALSE(updater->IsCommandEnabled(IDC_FORWARD)); 140 chrome::UpdateCommandEnabled(browser(), IDC_BACK, true);
137 updater->UpdateCommandEnabled(IDC_BACK, true); 141 chrome::UpdateCommandEnabled(browser(), IDC_FORWARD, true);
138 updater->UpdateCommandEnabled(IDC_FORWARD, true); 142 CommandUpdater* updater = browser()->command_controller()->command_updater();
139 CompareState(updater, [bar_ toolbarViews]); 143 CompareState(updater, [bar_ toolbarViews]);
140 } 144 }
141 145
142 // Focus the location bar and make sure that it's the first responder. 146 // Focus the location bar and make sure that it's the first responder.
143 TEST_F(ToolbarControllerTest, FocusLocation) { 147 TEST_F(ToolbarControllerTest, FocusLocation) {
144 NSWindow* window = test_window(); 148 NSWindow* window = test_window();
145 [window makeFirstResponder:[window contentView]]; 149 [window makeFirstResponder:[window contentView]];
146 EXPECT_EQ([window firstResponder], [window contentView]); 150 EXPECT_EQ([window firstResponder], [window contentView]);
147 [bar_ focusLocationBar:YES]; 151 [bar_ focusLocationBar:YES];
148 EXPECT_NE([window firstResponder], [window contentView]); 152 EXPECT_NE([window firstResponder], [window contentView]);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 [view setHitTestReturn:button]; 233 [view setHitTestReturn:button];
230 EXPECT_FALSE([bar_ hoverButtonForEvent:event]); 234 EXPECT_FALSE([bar_ hoverButtonForEvent:event]);
231 235
232 // Now! 236 // Now!
233 scoped_nsobject<GradientButtonCell> cell([[GradientButtonCell alloc] init]); 237 scoped_nsobject<GradientButtonCell> cell([[GradientButtonCell alloc] init]);
234 [button setCell:cell.get()]; 238 [button setCell:cell.get()];
235 EXPECT_TRUE([bar_ hoverButtonForEvent:nil]); 239 EXPECT_TRUE([bar_ hoverButtonForEvent:nil]);
236 } 240 }
237 241
238 } // namespace 242 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm ('k') | chrome/browser/ui/fullscreen_exit_bubble.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698