OLD | NEW |
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" | 9 #include "chrome/browser/command_updater.h" |
10 #include "chrome/browser/ui/browser_command_controller.h" | 10 #include "chrome/browser/ui/browser_command_controller.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 class ToolbarControllerTest : public CocoaProfileTest { | 42 class ToolbarControllerTest : public CocoaProfileTest { |
43 public: | 43 public: |
44 | 44 |
45 // Indexes that match the ordering returned by the private ToolbarController | 45 // Indexes that match the ordering returned by the private ToolbarController |
46 // |-toolbarViews| method. | 46 // |-toolbarViews| method. |
47 enum { | 47 enum { |
48 kBackIndex, kForwardIndex, kReloadIndex, kHomeIndex, | 48 kBackIndex, kForwardIndex, kReloadIndex, kHomeIndex, |
49 kWrenchIndex, kLocationIndex, kBrowserActionContainerViewIndex | 49 kWrenchIndex, kLocationIndex, kBrowserActionContainerViewIndex |
50 }; | 50 }; |
51 | 51 |
52 virtual void SetUp() { | 52 virtual void SetUp() OVERRIDE { |
53 CocoaProfileTest::SetUp(); | 53 CocoaProfileTest::SetUp(); |
54 ASSERT_TRUE(browser()); | 54 ASSERT_TRUE(browser()); |
55 | 55 |
56 CommandUpdater* updater = | 56 CommandUpdater* updater = |
57 browser()->command_controller()->command_updater(); | 57 browser()->command_controller()->command_updater(); |
58 // 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 |
59 // ensure they get picked up correct on initialization | 59 // ensure they get picked up correct on initialization |
60 updater->UpdateCommandEnabled(IDC_BACK, false); | 60 updater->UpdateCommandEnabled(IDC_BACK, false); |
61 updater->UpdateCommandEnabled(IDC_FORWARD, false); | 61 updater->UpdateCommandEnabled(IDC_FORWARD, false); |
62 resizeDelegate_.reset([[ViewResizerPong alloc] init]); | 62 resizeDelegate_.reset([[ViewResizerPong alloc] init]); |
63 bar_.reset( | 63 bar_.reset( |
64 [[ToolbarController alloc] initWithModel:browser()->toolbar_model() | 64 [[ToolbarController alloc] initWithModel:browser()->toolbar_model() |
65 commands:browser()->command_controller()
->command_updater() | 65 commands:browser()->command_controller()
->command_updater() |
66 profile:profile() | 66 profile:profile() |
67 browser:browser() | 67 browser:browser() |
68 resizeDelegate:resizeDelegate_.get()]); | 68 resizeDelegate:resizeDelegate_.get()]); |
69 EXPECT_TRUE([bar_ view]); | 69 EXPECT_TRUE([bar_ view]); |
70 NSView* parent = [test_window() contentView]; | 70 NSView* parent = [test_window() contentView]; |
71 [parent addSubview:[bar_ view]]; | 71 [parent addSubview:[bar_ view]]; |
72 } | 72 } |
73 | 73 |
| 74 virtual void TearDown() OVERRIDE { |
| 75 bar_.reset(); // browser() must outlive the ToolbarController. |
| 76 CocoaProfileTest::TearDown(); |
| 77 } |
| 78 |
74 // Make sure the enabled state of the view is the same as the corresponding | 79 // Make sure the enabled state of the view is the same as the corresponding |
75 // command in the updater. The views are in the declaration order of outlets. | 80 // command in the updater. The views are in the declaration order of outlets. |
76 void CompareState(CommandUpdater* updater, NSArray* views) { | 81 void CompareState(CommandUpdater* updater, NSArray* views) { |
77 EXPECT_EQ(updater->IsCommandEnabled(IDC_BACK), | 82 EXPECT_EQ(updater->IsCommandEnabled(IDC_BACK), |
78 [[views objectAtIndex:kBackIndex] isEnabled] ? true : false); | 83 [[views objectAtIndex:kBackIndex] isEnabled] ? true : false); |
79 EXPECT_EQ(updater->IsCommandEnabled(IDC_FORWARD), | 84 EXPECT_EQ(updater->IsCommandEnabled(IDC_FORWARD), |
80 [[views objectAtIndex:kForwardIndex] isEnabled] ? true : false); | 85 [[views objectAtIndex:kForwardIndex] isEnabled] ? true : false); |
81 EXPECT_EQ(updater->IsCommandEnabled(IDC_RELOAD), | 86 EXPECT_EQ(updater->IsCommandEnabled(IDC_RELOAD), |
82 [[views objectAtIndex:kReloadIndex] isEnabled] ? true : false); | 87 [[views objectAtIndex:kReloadIndex] isEnabled] ? true : false); |
83 EXPECT_EQ(updater->IsCommandEnabled(IDC_HOME), | 88 EXPECT_EQ(updater->IsCommandEnabled(IDC_HOME), |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 [view setHitTestReturn:button]; | 237 [view setHitTestReturn:button]; |
233 EXPECT_FALSE([bar_ hoverButtonForEvent:event]); | 238 EXPECT_FALSE([bar_ hoverButtonForEvent:event]); |
234 | 239 |
235 // Now! | 240 // Now! |
236 scoped_nsobject<GradientButtonCell> cell([[GradientButtonCell alloc] init]); | 241 scoped_nsobject<GradientButtonCell> cell([[GradientButtonCell alloc] init]); |
237 [button setCell:cell.get()]; | 242 [button setCell:cell.get()]; |
238 EXPECT_TRUE([bar_ hoverButtonForEvent:nil]); | 243 EXPECT_TRUE([bar_ hoverButtonForEvent:nil]); |
239 } | 244 } |
240 | 245 |
241 } // namespace | 246 } // namespace |
OLD | NEW |