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

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

Issue 159776: Rewrites the Mac view resizing logic to have the BrowserWindowController... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 4 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
« no previous file with comments | « chrome/browser/cocoa/toolbar_controller.mm ('k') | chrome/browser/cocoa/view_resizer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #import "chrome/browser/cocoa/toolbar_controller.h" 11 #import "chrome/browser/cocoa/toolbar_controller.h"
12 #import "chrome/browser/cocoa/view_resizer_pong.h"
12 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
13 #include "chrome/common/pref_service.h" 14 #include "chrome/common/pref_service.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 namespace { 17 namespace {
17 18
18 class ToolbarControllerTest : public testing::Test { 19 class ToolbarControllerTest : public testing::Test {
19 public: 20 public:
20 21
21 // Indexes that match the ordering returned by the private ToolbarController 22 // Indexes that match the ordering returned by the private ToolbarController
22 // |-toolbarViews| method. 23 // |-toolbarViews| method.
23 enum { 24 enum {
24 kBackIndex, kForwardIndex, kReloadIndex, kHomeIndex, kStarIndex, kGoIndex, 25 kBackIndex, kForwardIndex, kReloadIndex, kHomeIndex, kStarIndex, kGoIndex,
25 kPageIndex, kWrenchIndex, kLocationIndex, 26 kPageIndex, kWrenchIndex, kLocationIndex,
26 }; 27 };
27 28
28 ToolbarControllerTest() { 29 ToolbarControllerTest() {
29 Browser* browser = helper_.browser(); 30 Browser* browser = helper_.browser();
30 CommandUpdater* updater = browser->command_updater(); 31 CommandUpdater* updater = browser->command_updater();
31 // The default state for the commands is true, set a couple to false to 32 // The default state for the commands is true, set a couple to false to
32 // ensure they get picked up correct on initialization 33 // ensure they get picked up correct on initialization
33 updater->UpdateCommandEnabled(IDC_BACK, false); 34 updater->UpdateCommandEnabled(IDC_BACK, false);
34 updater->UpdateCommandEnabled(IDC_FORWARD, false); 35 updater->UpdateCommandEnabled(IDC_FORWARD, false);
36 resizeDelegate_.reset([[ViewResizerPong alloc] init]);
35 bar_.reset( 37 bar_.reset(
36 [[ToolbarController alloc] initWithModel:browser->toolbar_model() 38 [[ToolbarController alloc] initWithModel:browser->toolbar_model()
37 commands:browser->command_updater() 39 commands:browser->command_updater()
38 profile:helper_.profile() 40 profile:helper_.profile()
39 webContentView:nil 41 resizeDelegate:resizeDelegate_.get()
40 infoBarsView:nil
41 bookmarkDelegate:nil]); 42 bookmarkDelegate:nil]);
42 EXPECT_TRUE([bar_ view]); 43 EXPECT_TRUE([bar_ view]);
43 NSView* parent = [cocoa_helper_.window() contentView]; 44 NSView* parent = [cocoa_helper_.window() contentView];
44 [parent addSubview:[bar_ view]]; 45 [parent addSubview:[bar_ view]];
45 } 46 }
46 47
47 // Make sure the enabled state of the view is the same as the corresponding 48 // Make sure the enabled state of the view is the same as the corresponding
48 // command in the updater. The views are in the declaration order of outlets. 49 // command in the updater. The views are in the declaration order of outlets.
49 void CompareState(CommandUpdater* updater, NSArray* views) { 50 void CompareState(CommandUpdater* updater, NSArray* views) {
50 EXPECT_EQ(updater->IsCommandEnabled(IDC_BACK), 51 EXPECT_EQ(updater->IsCommandEnabled(IDC_BACK),
51 [[views objectAtIndex:kBackIndex] isEnabled] ? true : false); 52 [[views objectAtIndex:kBackIndex] isEnabled] ? true : false);
52 EXPECT_EQ(updater->IsCommandEnabled(IDC_FORWARD), 53 EXPECT_EQ(updater->IsCommandEnabled(IDC_FORWARD),
53 [[views objectAtIndex:kForwardIndex] isEnabled] ? true : false); 54 [[views objectAtIndex:kForwardIndex] isEnabled] ? true : false);
54 EXPECT_EQ(updater->IsCommandEnabled(IDC_RELOAD), 55 EXPECT_EQ(updater->IsCommandEnabled(IDC_RELOAD),
55 [[views objectAtIndex:kReloadIndex] isEnabled] ? true : false); 56 [[views objectAtIndex:kReloadIndex] isEnabled] ? true : false);
56 EXPECT_EQ(updater->IsCommandEnabled(IDC_HOME), 57 EXPECT_EQ(updater->IsCommandEnabled(IDC_HOME),
57 [[views objectAtIndex:kHomeIndex] isEnabled] ? true : false); 58 [[views objectAtIndex:kHomeIndex] isEnabled] ? true : false);
58 EXPECT_EQ(updater->IsCommandEnabled(IDC_STAR), 59 EXPECT_EQ(updater->IsCommandEnabled(IDC_STAR),
59 [[views objectAtIndex:kStarIndex] isEnabled] ? true : false); 60 [[views objectAtIndex:kStarIndex] isEnabled] ? true : false);
60 } 61 }
61 62
62 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... 63 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc...
63 BrowserTestHelper helper_; 64 BrowserTestHelper helper_;
65 scoped_nsobject<ViewResizerPong> resizeDelegate_;
64 scoped_nsobject<ToolbarController> bar_; 66 scoped_nsobject<ToolbarController> bar_;
65 }; 67 };
66 68
67 // Test the initial state that everything is sync'd up 69 // Test the initial state that everything is sync'd up
68 TEST_F(ToolbarControllerTest, InitialState) { 70 TEST_F(ToolbarControllerTest, InitialState) {
69 CommandUpdater* updater = helper_.browser()->command_updater(); 71 CommandUpdater* updater = helper_.browser()->command_updater();
70 CompareState(updater, [bar_ toolbarViews]); 72 CompareState(updater, [bar_ toolbarViews]);
71 } 73 }
72 74
73 // Make sure awakeFromNib created a bookmarkBarController 75 // Make sure awakeFromNib created a bookmarkBarController
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 179
178 // Toggle the pref and make sure the buttons changed state and the other 180 // Toggle the pref and make sure the buttons changed state and the other
179 // views moved (or in the case of the location bar, it changed width). 181 // views moved (or in the case of the location bar, it changed width).
180 prefs->SetBoolean(prefs::kShowPageOptionsButtons, !showButtons); 182 prefs->SetBoolean(prefs::kShowPageOptionsButtons, !showButtons);
181 EXPECT_EQ(showButtons, [pageButton isHidden]); 183 EXPECT_EQ(showButtons, [pageButton isHidden]);
182 EXPECT_EQ(showButtons, [wrenchButton isHidden]); 184 EXPECT_EQ(showButtons, [wrenchButton isHidden]);
183 EXPECT_NE(NSMinX(originalGoFrame), NSMinX([goButton frame])); 185 EXPECT_NE(NSMinX(originalGoFrame), NSMinX([goButton frame]));
184 EXPECT_NE(NSWidth(originalLocationBarFrame), NSWidth([locationBar frame])); 186 EXPECT_NE(NSWidth(originalLocationBarFrame), NSWidth([locationBar frame]));
185 } 187 }
186 188
189 TEST_F(ToolbarControllerTest, BookmarkBarResizes) {
190 NSView* bookmarkBarView = [[bar_ bookmarkBarController] view];
191 ASSERT_EQ(0, NSHeight([bookmarkBarView frame]));
192 [resizeDelegate_ setHeight:-1];
193
194 // Resize the bookmarkbar to 30px. The toolbar should ask the delegate to
195 // resize to 64px.
196 [bar_ resizeView:bookmarkBarView newHeight:30];
197 EXPECT_EQ(64, [resizeDelegate_ height]);
198 EXPECT_EQ(30, NSHeight([bookmarkBarView frame]));
199
200 // Resize the bookmarkbar back to 0px. Toolbar should be at 39px.
201 [bar_ resizeView:bookmarkBarView newHeight:0];
202 EXPECT_EQ(39, [resizeDelegate_ height]);
203 EXPECT_EQ(0, NSHeight([bookmarkBarView frame]));
204
205 // Resize the bookmarkbar to 5px. Toolbar should stay at 39px.
206 [resizeDelegate_ setHeight:-1];
207 [bar_ resizeView:bookmarkBarView newHeight:5];
208 EXPECT_EQ(39, [resizeDelegate_ height]);
209 EXPECT_EQ(5, NSHeight([bookmarkBarView frame]));
210
211 // Resize the bookmarkbar to 6px. Toolbar should grow to 40px.
212 [bar_ resizeView:bookmarkBarView newHeight:6];
213 EXPECT_EQ(40, [resizeDelegate_ height]);
214 EXPECT_EQ(6, NSHeight([bookmarkBarView frame]));
215 }
216
187 } // namespace 217 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/toolbar_controller.mm ('k') | chrome/browser/cocoa/view_resizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698