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

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

Issue 216031: Add EV certificate text to the Mac location bar... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 #include "base/scoped_nsobject.h" 7 #include "base/scoped_nsobject.h"
8 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" 8 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h"
9 #import "chrome/browser/cocoa/cocoa_test_helper.h" 9 #import "chrome/browser/cocoa/cocoa_test_helper.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 137 }
138 138
139 TEST_F(AutocompleteTextFieldCellTest, SecurityIcon) { 139 TEST_F(AutocompleteTextFieldCellTest, SecurityIcon) {
140 AutocompleteTextFieldCell* cell = 140 AutocompleteTextFieldCell* cell =
141 static_cast<AutocompleteTextFieldCell*>([view_ cell]); 141 static_cast<AutocompleteTextFieldCell*>([view_ cell]);
142 142
143 EXPECT_FALSE([cell fieldEditorNeedsReset]); 143 EXPECT_FALSE([cell fieldEditorNeedsReset]);
144 144
145 NSImage* image1 = [NSImage imageNamed:@"NSApplicationIcon"]; 145 NSImage* image1 = [NSImage imageNamed:@"NSApplicationIcon"];
146 // Setting a security icon will need a reset. 146 // Setting a security icon will need a reset.
147 [cell setHintIcon:image1]; 147 [cell setHintIcon:image1 label:nil color:nil];
148 EXPECT_TRUE([cell fieldEditorNeedsReset]); 148 EXPECT_TRUE([cell fieldEditorNeedsReset]);
149 [cell setFieldEditorNeedsReset:NO]; 149 [cell setFieldEditorNeedsReset:NO];
150 EXPECT_FALSE([cell fieldEditorNeedsReset]); 150 EXPECT_FALSE([cell fieldEditorNeedsReset]);
151 151
152 // Changing the security icon needs a reset. 152 // Changing the security icon needs a reset.
153 NSImage* image2 = [NSImage imageNamed:@"NSComputer"]; 153 NSImage* image2 = [NSImage imageNamed:@"NSComputer"];
154 [cell setHintIcon:image2]; 154 [cell setHintIcon:image2 label:nil color:nil];
155 EXPECT_TRUE([cell fieldEditorNeedsReset]); 155 EXPECT_TRUE([cell fieldEditorNeedsReset]);
156 [cell setFieldEditorNeedsReset:NO]; 156 [cell setFieldEditorNeedsReset:NO];
157 EXPECT_FALSE([cell fieldEditorNeedsReset]); 157 EXPECT_FALSE([cell fieldEditorNeedsReset]);
158 158
159 // Changing to an identical security icon doesn't need a reset. 159 // Changing to an identical security icon doesn't need a reset.
160 [cell setHintIcon:image2]; 160 [cell setHintIcon:image2 label:nil color:nil];
161 EXPECT_FALSE([cell fieldEditorNeedsReset]);
162
163 // Adding a label without changing the icon needs a reset.
164 NSColor *color = [NSColor blackColor];
165 [cell setHintIcon:image2 label:@"New Label" color:color];
166 EXPECT_TRUE([cell fieldEditorNeedsReset]);
167
168 // Removing the label without changing the icon needs a reset.
169 [cell setHintIcon:image2 label:nil color:nil];
170 EXPECT_TRUE([cell fieldEditorNeedsReset]);
171 }
172
173 TEST_F(AutocompleteTextFieldCellTest, SecurityIconLabel) {
174 AutocompleteTextFieldCell* cell =
175 static_cast<AutocompleteTextFieldCell*>([view_ cell]);
176 NSColor *color = [NSColor blackColor];
177
178 EXPECT_FALSE([cell fieldEditorNeedsReset]);
179
180 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
181 // Setting a security icon will need a reset.
182 [cell setHintIcon:image label:@"Hello, world" color:color];
183 EXPECT_TRUE([cell fieldEditorNeedsReset]);
184 [cell setFieldEditorNeedsReset:NO];
185 EXPECT_FALSE([cell fieldEditorNeedsReset]);
186
187 // Changing the label needs a reset.
188 [cell setHintIcon:image label:@"Hello, you" color:color];
189 EXPECT_TRUE([cell fieldEditorNeedsReset]);
190 [cell setFieldEditorNeedsReset:NO];
191 EXPECT_FALSE([cell fieldEditorNeedsReset]);
192
193 // Changing to an identical label doesn't need a reset
194 [cell setHintIcon:image label:@"Hello, you" color:color];
161 EXPECT_FALSE([cell fieldEditorNeedsReset]); 195 EXPECT_FALSE([cell fieldEditorNeedsReset]);
162 } 196 }
163 197
164 // Test that transitions between various modes set the reset flag. 198 // Test that transitions between various modes set the reset flag.
165 TEST_F(AutocompleteTextFieldCellTest, Transitions) { 199 TEST_F(AutocompleteTextFieldCellTest, Transitions) {
166 AutocompleteTextFieldCell* cell = 200 AutocompleteTextFieldCell* cell =
167 static_cast<AutocompleteTextFieldCell*>([view_ cell]); 201 static_cast<AutocompleteTextFieldCell*>([view_ cell]);
168 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; 202 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
169 203
170 // Transitions from hint to keyword string, keyword hint, and 204 // Transitions from hint to keyword string, keyword hint, and
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 // Text frame should take everything over again on reset. 316 // Text frame should take everything over again on reset.
283 [cell clearKeywordAndHint]; 317 [cell clearKeywordAndHint];
284 textFrame = [cell textFrameForFrame:bounds]; 318 textFrame = [cell textFrameForFrame:bounds];
285 EXPECT_FALSE(NSIsEmptyRect(textFrame)); 319 EXPECT_FALSE(NSIsEmptyRect(textFrame));
286 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); 320 EXPECT_TRUE(NSContainsRect(bounds, textFrame));
287 EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame)); 321 EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame));
288 EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame)); 322 EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame));
289 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); 323 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame));
290 324
291 // Hint icon takes up space on the right 325 // Hint icon takes up space on the right
292 [cell setHintIcon:[NSImage imageNamed:@"NSComputer"]]; 326 [cell setHintIcon:[NSImage imageNamed:@"NSComputer"] label:nil color:nil];
293 textFrame = [cell textFrameForFrame:bounds]; 327 textFrame = [cell textFrameForFrame:bounds];
294 EXPECT_FALSE(NSIsEmptyRect(textFrame)); 328 EXPECT_FALSE(NSIsEmptyRect(textFrame));
295 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); 329 EXPECT_TRUE(NSContainsRect(bounds, textFrame));
296 EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds)); 330 EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds));
297 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); 331 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame));
298 332
299 // Search hint text takes precedence over the hint icon; the text frame 333 // Search hint text takes precedence over the hint icon; the text frame
300 // should be smaller in order to accomodate the text that is wider than 334 // should be smaller in order to accomodate the text that is wider than
301 // the icon. 335 // the icon.
302 [cell setSearchHintString:@"Search hint"]; 336 [cell setSearchHintString:@"Search hint"];
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); 375 EXPECT_FALSE(NSIsEmptyRect(drawingRect));
342 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect)); 376 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect));
343 377
344 [cell clearKeywordAndHint]; 378 [cell clearKeywordAndHint];
345 textFrame = [cell textFrameForFrame:bounds]; 379 textFrame = [cell textFrameForFrame:bounds];
346 drawingRect = [cell drawingRectForBounds:bounds]; 380 drawingRect = [cell drawingRectForBounds:bounds];
347 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); 381 EXPECT_FALSE(NSIsEmptyRect(drawingRect));
348 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect)); 382 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect));
349 EXPECT_TRUE(NSEqualRects(drawingRect, originalDrawingRect)); 383 EXPECT_TRUE(NSEqualRects(drawingRect, originalDrawingRect));
350 384
351 [cell setHintIcon:[NSImage imageNamed:@"NSComputer"]]; 385 [cell setHintIcon:[NSImage imageNamed:@"NSComputer"] label:nil color:nil];
352 textFrame = [cell textFrameForFrame:bounds]; 386 textFrame = [cell textFrameForFrame:bounds];
353 drawingRect = [cell drawingRectForBounds:bounds]; 387 drawingRect = [cell drawingRectForBounds:bounds];
354 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); 388 EXPECT_FALSE(NSIsEmptyRect(drawingRect));
355 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect)); 389 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect));
356 } 390 }
357 391
358 // Test that the security icon is at the right side of the cell. 392 // Test that the security icon is at the right side of the cell.
359 TEST_F(AutocompleteTextFieldCellTest, HintImageFrame) { 393 TEST_F(AutocompleteTextFieldCellTest, HintImageFrame) {
360 AutocompleteTextFieldCell* cell = 394 AutocompleteTextFieldCell* cell =
361 static_cast<AutocompleteTextFieldCell*>([view_ cell]); 395 static_cast<AutocompleteTextFieldCell*>([view_ cell]);
362 const NSRect bounds([view_ bounds]); 396 const NSRect bounds([view_ bounds]);
363 scoped_nsobject<NSImage> hintIcon( 397 scoped_nsobject<NSImage> hintIcon(
364 [[NSImage alloc] initWithSize:NSMakeSize(20, 20)]); 398 [[NSImage alloc] initWithSize:NSMakeSize(20, 20)]);
365 399
366 NSRect iconRect = [cell hintImageFrameForFrame:bounds]; 400 NSRect iconRect = [cell hintImageFrameForFrame:bounds];
367 EXPECT_TRUE(NSIsEmptyRect(iconRect)); 401 EXPECT_TRUE(NSIsEmptyRect(iconRect));
368 402
369 // Save the starting frame for after clear. 403 // Save the starting frame for after clear.
370 const NSRect originalIconRect(iconRect); 404 const NSRect originalIconRect(iconRect);
371 405
372 [cell setHintIcon:hintIcon]; 406 [cell setHintIcon:hintIcon label:nil color:nil];
373 iconRect = [cell hintImageFrameForFrame:bounds]; 407 iconRect = [cell hintImageFrameForFrame:bounds];
374 EXPECT_FALSE(NSIsEmptyRect(iconRect)); 408 EXPECT_FALSE(NSIsEmptyRect(iconRect));
375 EXPECT_TRUE(NSContainsRect(bounds, iconRect)); 409 EXPECT_TRUE(NSContainsRect(bounds, iconRect));
376 410
377 // Make sure we are right of the |drawingRect|. 411 // Make sure we are right of the |drawingRect|.
378 NSRect drawingRect = [cell drawingRectForBounds:bounds]; 412 NSRect drawingRect = [cell drawingRectForBounds:bounds];
379 EXPECT_LE(NSMaxX(drawingRect), NSMinX(iconRect)); 413 EXPECT_LE(NSMaxX(drawingRect), NSMinX(iconRect));
380 414
381 // Make sure we're right of the |textFrame|. 415 // Make sure we're right of the |textFrame|.
382 NSRect textFrame = [cell textFrameForFrame:bounds]; 416 NSRect textFrame = [cell textFrameForFrame:bounds];
383 EXPECT_LE(NSMaxX(textFrame), NSMinX(iconRect)); 417 EXPECT_LE(NSMaxX(textFrame), NSMinX(iconRect));
384 418
385 // Make sure we clear correctly. 419 // Make sure we clear correctly.
386 [cell setHintIcon:nil]; 420 [cell setHintIcon:nil label:nil color:nil];
387 iconRect = [cell hintImageFrameForFrame:bounds]; 421 iconRect = [cell hintImageFrameForFrame:bounds];
388 EXPECT_TRUE(NSEqualRects(iconRect, originalIconRect)); 422 EXPECT_TRUE(NSEqualRects(iconRect, originalIconRect));
389 EXPECT_TRUE(NSIsEmptyRect(iconRect)); 423 EXPECT_TRUE(NSIsEmptyRect(iconRect));
390 } 424 }
391 425
392 } // namespace 426 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field_cell.mm ('k') | chrome/browser/cocoa/location_bar_view_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698