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

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

Issue 149308: a bunch of bookmark bar changes (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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) 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 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 #include "chrome/common/pref_service.h" 13 #include "chrome/common/pref_service.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace { 16 namespace {
17 17
18 class ToolbarControllerTest : public testing::Test { 18 class ToolbarControllerTest : public testing::Test {
19 public: 19 public:
20 20
21 // Indexes that match the ordering returned by the private ToolbarController 21 // Indexes that match the ordering returned by the private ToolbarController
22 // |-toolbarViews| method. 22 // |-toolbarViews| method.
23 enum { 23 enum {
24 kBackIndex, kForwardIndex, kReloadIndex, kHomeIndex, kStarIndex, kGoIndex, 24 kBackIndex, kForwardIndex, kReloadIndex, kHomeIndex, kStarIndex, kGoIndex,
25 kPageIndex, kWrenchIndex, kLocationIndex, 25 kPageIndex, kWrenchIndex, kLocationIndex, kBookmarkIndex,
26 }; 26 };
27 27
28 ToolbarControllerTest() { 28 ToolbarControllerTest() {
29 Browser* browser = helper_.browser(); 29 Browser* browser = helper_.browser();
30 CommandUpdater* updater = browser->command_updater(); 30 CommandUpdater* updater = browser->command_updater();
31 // The default state for the commands is true, set a couple to false to 31 // The default state for the commands is true, set a couple to false to
32 // ensure they get picked up correct on initialization 32 // ensure they get picked up correct on initialization
33 updater->UpdateCommandEnabled(IDC_BACK, false); 33 updater->UpdateCommandEnabled(IDC_BACK, false);
34 updater->UpdateCommandEnabled(IDC_FORWARD, false); 34 updater->UpdateCommandEnabled(IDC_FORWARD, false);
35 bar_.reset( 35 bar_.reset(
36 [[ToolbarController alloc] initWithModel:browser->toolbar_model() 36 [[ToolbarController alloc] initWithModel:browser->toolbar_model()
37 commands:browser->command_updater() 37 commands:browser->command_updater()
38 profile:helper_.profile()]); 38 profile:helper_.profile()
39 webContentView:nil
40 bookmarkDelegate:nil]);
39 EXPECT_TRUE([bar_ view]); 41 EXPECT_TRUE([bar_ view]);
40 NSView* parent = [cocoa_helper_.window() contentView]; 42 NSView* parent = [cocoa_helper_.window() contentView];
41 [parent addSubview:[bar_ view]]; 43 [parent addSubview:[bar_ view]];
42 } 44 }
43 45
44 // Make sure the enabled state of the view is the same as the corresponding 46 // Make sure the enabled state of the view is the same as the corresponding
45 // command in the updater. The views are in the declaration order of outlets. 47 // command in the updater. The views are in the declaration order of outlets.
46 void CompareState(CommandUpdater* updater, NSArray* views) { 48 void CompareState(CommandUpdater* updater, NSArray* views) {
47 EXPECT_EQ(updater->IsCommandEnabled(IDC_BACK), 49 EXPECT_EQ(updater->IsCommandEnabled(IDC_BACK),
48 [[views objectAtIndex:kBackIndex] isEnabled] ? true : false); 50 [[views objectAtIndex:kBackIndex] isEnabled] ? true : false);
(...skipping 11 matching lines...) Expand all
60 BrowserTestHelper helper_; 62 BrowserTestHelper helper_;
61 scoped_nsobject<ToolbarController> bar_; 63 scoped_nsobject<ToolbarController> bar_;
62 }; 64 };
63 65
64 // Test the initial state that everything is sync'd up 66 // Test the initial state that everything is sync'd up
65 TEST_F(ToolbarControllerTest, InitialState) { 67 TEST_F(ToolbarControllerTest, InitialState) {
66 CommandUpdater* updater = helper_.browser()->command_updater(); 68 CommandUpdater* updater = helper_.browser()->command_updater();
67 CompareState(updater, [bar_ toolbarViews]); 69 CompareState(updater, [bar_ toolbarViews]);
68 } 70 }
69 71
72 // Make sure awakeFromNib created a bookmarkBarController
73 TEST_F(ToolbarControllerTest, AwakeFromNibCreatesBMBController) {
74 EXPECT_TRUE([bar_ bookmarkBarController]);
75 }
76
77
70 // Make some changes to the enabled state of a few of the buttons and ensure 78 // Make some changes to the enabled state of a few of the buttons and ensure
71 // that we're still in sync. 79 // that we're still in sync.
72 TEST_F(ToolbarControllerTest, UpdateEnabledState) { 80 TEST_F(ToolbarControllerTest, UpdateEnabledState) {
73 CommandUpdater* updater = helper_.browser()->command_updater(); 81 CommandUpdater* updater = helper_.browser()->command_updater();
74 EXPECT_FALSE(updater->IsCommandEnabled(IDC_BACK)); 82 EXPECT_FALSE(updater->IsCommandEnabled(IDC_BACK));
75 EXPECT_FALSE(updater->IsCommandEnabled(IDC_FORWARD)); 83 EXPECT_FALSE(updater->IsCommandEnabled(IDC_FORWARD));
76 updater->UpdateCommandEnabled(IDC_BACK, true); 84 updater->UpdateCommandEnabled(IDC_BACK, true);
77 updater->UpdateCommandEnabled(IDC_FORWARD, true); 85 updater->UpdateCommandEnabled(IDC_FORWARD, true);
78 CompareState(updater, [bar_ toolbarViews]); 86 CompareState(updater, [bar_ toolbarViews]);
79 } 87 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 // Toggle the pref and make sure the buttons changed state and the other 160 // Toggle the pref and make sure the buttons changed state and the other
153 // views moved (or in the case of the location bar, it changed width). 161 // views moved (or in the case of the location bar, it changed width).
154 prefs->SetBoolean(prefs::kShowPageOptionsButtons, !showButtons); 162 prefs->SetBoolean(prefs::kShowPageOptionsButtons, !showButtons);
155 EXPECT_EQ(showButtons, [pageButton isHidden]); 163 EXPECT_EQ(showButtons, [pageButton isHidden]);
156 EXPECT_EQ(showButtons, [wrenchButton isHidden]); 164 EXPECT_EQ(showButtons, [wrenchButton isHidden]);
157 EXPECT_NE(NSMinX(originalGoFrame), NSMinX([goButton frame])); 165 EXPECT_NE(NSMinX(originalGoFrame), NSMinX([goButton frame]));
158 EXPECT_NE(NSWidth(originalLocationBarFrame), NSWidth([locationBar frame])); 166 EXPECT_NE(NSWidth(originalLocationBarFrame), NSWidth([locationBar frame]));
159 } 167 }
160 168
161 } // namespace 169 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698