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

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

Issue 402066: Moved a whole pile of unittests over to CocoaTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 #include "base/scoped_nsautorelease_pool.h" 7 #include "base/scoped_nsautorelease_pool.h"
8 #import "base/scoped_nsobject.h" 8 #import "base/scoped_nsobject.h"
9 #import "chrome/browser/cocoa/tab_controller.h" 9 #import "chrome/browser/cocoa/tab_controller.h"
10 #import "chrome/browser/cocoa/tab_controller_target.h" 10 #import "chrome/browser/cocoa/tab_controller_target.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 56 }
57 - (BOOL)isCommandEnabled:(TabStripModel::ContextMenuCommand)command 57 - (BOOL)isCommandEnabled:(TabStripModel::ContextMenuCommand)command
58 forController:(TabController*)controller { 58 forController:(TabController*)controller {
59 return NO; 59 return NO;
60 } 60 }
61 @end 61 @end
62 62
63 namespace { 63 namespace {
64 64
65 // The dragging code in TabView makes heavy use of autorelease pools so 65 // The dragging code in TabView makes heavy use of autorelease pools so
66 // inherit from Platform test to have one created for us. 66 // inherit from CocoaTest to have one created for us.
67 class TabControllerTest : public PlatformTest { 67 class TabControllerTest : public CocoaTest {
68 public: 68 public:
69 TabControllerTest() { } 69 TabControllerTest() { }
70
71 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc...
72 }; 70 };
73 71
74 // Tests creating the controller, sticking it in a window, and removing it. 72 // Tests creating the controller, sticking it in a window, and removing it.
75 TEST_F(TabControllerTest, Creation) { 73 TEST_F(TabControllerTest, Creation) {
76 NSWindow* window = cocoa_helper_.window(); 74 NSWindow* window = test_window();
77 scoped_nsobject<TabController> controller([[TabController alloc] init]); 75 scoped_nsobject<TabController> controller([[TabController alloc] init]);
78 [[window contentView] addSubview:[controller view]]; 76 [[window contentView] addSubview:[controller view]];
79 EXPECT_TRUE([controller tabView]); 77 EXPECT_TRUE([controller tabView]);
80 EXPECT_EQ([[controller view] window], window); 78 EXPECT_EQ([[controller view] window], window);
81 [[controller view] display]; // Test drawing to ensure nothing leaks/crashes. 79 [[controller view] display]; // Test drawing to ensure nothing leaks/crashes.
82 [[controller view] removeFromSuperview]; 80 [[controller view] removeFromSuperview];
83 } 81 }
84 82
85 // Tests sending it a close message and ensuring that the target/action get 83 // Tests sending it a close message and ensuring that the target/action get
86 // called. Mimics the user clicking on the close button in the tab. 84 // called. Mimics the user clicking on the close button in the tab.
87 TEST_F(TabControllerTest, Close) { 85 TEST_F(TabControllerTest, Close) {
88 NSWindow* window = cocoa_helper_.window(); 86 NSWindow* window = test_window();
89 scoped_nsobject<TabController> controller([[TabController alloc] init]); 87 scoped_nsobject<TabController> controller([[TabController alloc] init]);
90 [[window contentView] addSubview:[controller view]]; 88 [[window contentView] addSubview:[controller view]];
91 89
92 scoped_nsobject<TabControllerTestTarget> target( 90 scoped_nsobject<TabControllerTestTarget> target(
93 [[TabControllerTestTarget alloc] init]); 91 [[TabControllerTestTarget alloc] init]);
94 EXPECT_FALSE([target closed]); 92 EXPECT_FALSE([target closed]);
95 [controller setTarget:target]; 93 [controller setTarget:target];
96 EXPECT_EQ(target.get(), [controller target]); 94 EXPECT_EQ(target.get(), [controller target]);
97 95
98 [controller closeTab:nil]; 96 [controller closeTab:nil];
99 EXPECT_TRUE([target closed]); 97 EXPECT_TRUE([target closed]);
100 98
101 [[controller view] removeFromSuperview]; 99 [[controller view] removeFromSuperview];
102 } 100 }
103 101
104 // Tests setting the |selected| property via code. 102 // Tests setting the |selected| property via code.
105 TEST_F(TabControllerTest, APISelection) { 103 TEST_F(TabControllerTest, APISelection) {
106 NSWindow* window = cocoa_helper_.window(); 104 NSWindow* window = test_window();
107 scoped_nsobject<TabController> controller([[TabController alloc] init]); 105 scoped_nsobject<TabController> controller([[TabController alloc] init]);
108 [[window contentView] addSubview:[controller view]]; 106 [[window contentView] addSubview:[controller view]];
109 107
110 EXPECT_FALSE([controller selected]); 108 EXPECT_FALSE([controller selected]);
111 [controller setSelected:YES]; 109 [controller setSelected:YES];
112 EXPECT_TRUE([controller selected]); 110 EXPECT_TRUE([controller selected]);
113 111
114 [[controller view] removeFromSuperview]; 112 [[controller view] removeFromSuperview];
115 } 113 }
116 114
117 // Tests that setting the title of a tab sets the tooltip as well. 115 // Tests that setting the title of a tab sets the tooltip as well.
118 TEST_F(TabControllerTest, ToolTip) { 116 TEST_F(TabControllerTest, ToolTip) {
119 NSWindow* window = cocoa_helper_.window(); 117 NSWindow* window = test_window();
120 118
121 scoped_nsobject<TabController> controller([[TabController alloc] init]); 119 scoped_nsobject<TabController> controller([[TabController alloc] init]);
122 [[window contentView] addSubview:[controller view]]; 120 [[window contentView] addSubview:[controller view]];
123 121
124 EXPECT_TRUE([[controller toolTip] length] == 0); 122 EXPECT_TRUE([[controller toolTip] length] == 0);
125 NSString *tooltip_string = @"Some text to use as a tab title"; 123 NSString *tooltip_string = @"Some text to use as a tab title";
126 [controller setTitle:tooltip_string]; 124 [controller setTitle:tooltip_string];
127 EXPECT_TRUE([tooltip_string isEqualToString:[controller toolTip]]); 125 EXPECT_TRUE([tooltip_string isEqualToString:[controller toolTip]]);
128 } 126 }
129 127
130 // Tests setting the |loading| property via code. 128 // Tests setting the |loading| property via code.
131 TEST_F(TabControllerTest, Loading) { 129 TEST_F(TabControllerTest, Loading) {
132 NSWindow* window = cocoa_helper_.window(); 130 NSWindow* window = test_window();
133 scoped_nsobject<TabController> controller([[TabController alloc] init]); 131 scoped_nsobject<TabController> controller([[TabController alloc] init]);
134 [[window contentView] addSubview:[controller view]]; 132 [[window contentView] addSubview:[controller view]];
135 133
136 EXPECT_EQ(kTabDone, [controller loadingState]); 134 EXPECT_EQ(kTabDone, [controller loadingState]);
137 [controller setLoadingState:kTabWaiting]; 135 [controller setLoadingState:kTabWaiting];
138 EXPECT_EQ(kTabWaiting, [controller loadingState]); 136 EXPECT_EQ(kTabWaiting, [controller loadingState]);
139 [controller setLoadingState:kTabLoading]; 137 [controller setLoadingState:kTabLoading];
140 EXPECT_EQ(kTabLoading, [controller loadingState]); 138 EXPECT_EQ(kTabLoading, [controller loadingState]);
141 [controller setLoadingState:kTabDone]; 139 [controller setLoadingState:kTabDone];
142 EXPECT_EQ(kTabDone, [controller loadingState]); 140 EXPECT_EQ(kTabDone, [controller loadingState]);
143 141
144 [[controller view] removeFromSuperview]; 142 [[controller view] removeFromSuperview];
145 } 143 }
146 144
147 // Tests selecting the tab with the mouse click and ensuring the target/action 145 // Tests selecting the tab with the mouse click and ensuring the target/action
148 // get called. 146 // get called.
149 // TODO(pinkerton): It's yucky that TabView bakes in the dragging so that we 147 // TODO(pinkerton): It's yucky that TabView bakes in the dragging so that we
150 // can't test this class w/out lots of extra effort. When cole finishes the 148 // can't test this class w/out lots of extra effort. When cole finishes the
151 // rewrite, we should move all that logic out into a separate controller which 149 // rewrite, we should move all that logic out into a separate controller which
152 // we can dependency-inject/mock so it has very simple click behavior for unit 150 // we can dependency-inject/mock so it has very simple click behavior for unit
153 // testing. 151 // testing.
154 TEST_F(TabControllerTest, UserSelection) { 152 TEST_F(TabControllerTest, UserSelection) {
155 NSWindow* window = cocoa_helper_.window(); 153 NSWindow* window = test_window();
156 154
157 // Create a tab at a known location in the window that we can click on 155 // Create a tab at a known location in the window that we can click on
158 // to activate selection. 156 // to activate selection.
159 scoped_nsobject<TabController> controller([[TabController alloc] init]); 157 scoped_nsobject<TabController> controller([[TabController alloc] init]);
160 [[window contentView] addSubview:[controller view]]; 158 [[window contentView] addSubview:[controller view]];
161 NSRect frame = [[controller view] frame]; 159 NSRect frame = [[controller view] frame];
162 frame.size.width = [TabController minTabWidth]; 160 frame.size.width = [TabController minTabWidth];
163 frame.origin = NSMakePoint(0, 0); 161 frame.origin = NSMakePoint(0, 0);
164 [[controller view] setFrame:frame]; 162 [[controller view] setFrame:frame];
165 163
(...skipping 28 matching lines...) Expand all
194 pressure:1.0]; 192 pressure:1.0];
195 [[controller view] mouseDown:down]; 193 [[controller view] mouseDown:down];
196 194
197 // Check our target was told the tab got selected. 195 // Check our target was told the tab got selected.
198 EXPECT_TRUE([target selected]); 196 EXPECT_TRUE([target selected]);
199 197
200 [[controller view] removeFromSuperview]; 198 [[controller view] removeFromSuperview];
201 } 199 }
202 200
203 TEST_F(TabControllerTest, IconCapacity) { 201 TEST_F(TabControllerTest, IconCapacity) {
204 NSWindow* window = cocoa_helper_.window(); 202 NSWindow* window = test_window();
205 scoped_nsobject<TabController> controller([[TabController alloc] init]); 203 scoped_nsobject<TabController> controller([[TabController alloc] init]);
206 [[window contentView] addSubview:[controller view]]; 204 [[window contentView] addSubview:[controller view]];
207 int cap = [controller iconCapacity]; 205 int cap = [controller iconCapacity];
208 EXPECT_GE(cap, 1); 206 EXPECT_GE(cap, 1);
209 207
210 NSRect frame = [[controller view] frame]; 208 NSRect frame = [[controller view] frame];
211 frame.size.width += 500; 209 frame.size.width += 500;
212 [[controller view] setFrame:frame]; 210 [[controller view] setFrame:frame];
213 int newcap = [controller iconCapacity]; 211 int newcap = [controller iconCapacity];
214 EXPECT_GT(newcap, cap); 212 EXPECT_GT(newcap, cap);
215 } 213 }
216 214
217 TEST_F(TabControllerTest, ShouldShowIcon) { 215 TEST_F(TabControllerTest, ShouldShowIcon) {
218 NSWindow* window = cocoa_helper_.window(); 216 NSWindow* window = test_window();
219 scoped_nsobject<TabController> controller([[TabController alloc] init]); 217 scoped_nsobject<TabController> controller([[TabController alloc] init]);
220 [[window contentView] addSubview:[controller view]]; 218 [[window contentView] addSubview:[controller view]];
221 int cap = [controller iconCapacity]; 219 int cap = [controller iconCapacity];
222 EXPECT_GT(cap, 0); 220 EXPECT_GT(cap, 0);
223 221
224 // Tab is minimum width, both icon and close box should be hidden. 222 // Tab is minimum width, both icon and close box should be hidden.
225 NSRect frame = [[controller view] frame]; 223 NSRect frame = [[controller view] frame];
226 frame.size.width = [TabController minTabWidth]; 224 frame.size.width = [TabController minTabWidth];
227 [[controller view] setFrame:frame]; 225 [[controller view] setFrame:frame];
228 EXPECT_FALSE([controller shouldShowIcon]); 226 EXPECT_FALSE([controller shouldShowIcon]);
(...skipping 24 matching lines...) Expand all
253 EXPECT_TRUE([controller shouldShowCloseButton]); 251 EXPECT_TRUE([controller shouldShowCloseButton]);
254 [controller setSelected:NO]; 252 [controller setSelected:NO];
255 EXPECT_TRUE([controller shouldShowIcon]); 253 EXPECT_TRUE([controller shouldShowIcon]);
256 EXPECT_TRUE([controller shouldShowCloseButton]); 254 EXPECT_TRUE([controller shouldShowCloseButton]);
257 255
258 cap = [controller iconCapacity]; 256 cap = [controller iconCapacity];
259 EXPECT_GT(cap, 0); 257 EXPECT_GT(cap, 0);
260 } 258 }
261 259
262 } // namespace 260 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/styled_text_field_cell_unittest.mm ('k') | chrome/browser/cocoa/tab_strip_view_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698