| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 277 |
| 278 // Test that the security icon is at the right side of the cell. | 278 // Test that the security icon is at the right side of the cell. |
| 279 TEST_F(AutocompleteTextFieldCellTest, SecurityImageFrame) { | 279 TEST_F(AutocompleteTextFieldCellTest, SecurityImageFrame) { |
| 280 AutocompleteTextFieldCell* cell = | 280 AutocompleteTextFieldCell* cell = |
| 281 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 281 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
| 282 const NSRect bounds([view_ bounds]); | 282 const NSRect bounds([view_ bounds]); |
| 283 security_image_view_.SetImageShown( | 283 security_image_view_.SetImageShown( |
| 284 LocationBarViewMac::SecurityImageView::LOCK); | 284 LocationBarViewMac::SecurityImageView::LOCK); |
| 285 | 285 |
| 286 security_image_view_.SetVisible(false); | 286 security_image_view_.SetVisible(false); |
| 287 NSRect iconRect = [cell securityImageFrameForFrame:bounds]; | 287 EXPECT_EQ(0u, [[cell layedOutIcons:bounds] count]); |
| 288 EXPECT_TRUE(NSIsEmptyRect(iconRect)); | |
| 289 | |
| 290 // Save the starting frame for after clear. | |
| 291 const NSRect originalIconRect(iconRect); | |
| 292 | 288 |
| 293 security_image_view_.SetVisible(true); | 289 security_image_view_.SetVisible(true); |
| 294 iconRect = [cell securityImageFrameForFrame:bounds]; | 290 NSArray* icons = [cell layedOutIcons:bounds]; |
| 291 ASSERT_EQ(1u, [icons count]); |
| 292 NSRect iconRect = [[icons objectAtIndex:0] rect]; |
| 295 | 293 |
| 296 EXPECT_FALSE(NSIsEmptyRect(iconRect)); | 294 EXPECT_FALSE(NSIsEmptyRect(iconRect)); |
| 297 EXPECT_TRUE(NSContainsRect(bounds, iconRect)); | 295 EXPECT_TRUE(NSContainsRect(bounds, iconRect)); |
| 298 | 296 |
| 299 // Make sure we are right of the |drawingRect|. | 297 // Make sure we are right of the |drawingRect|. |
| 300 NSRect drawingRect = [cell drawingRectForBounds:bounds]; | 298 NSRect drawingRect = [cell drawingRectForBounds:bounds]; |
| 301 EXPECT_LE(NSMaxX(drawingRect), NSMinX(iconRect)); | 299 EXPECT_LE(NSMaxX(drawingRect), NSMinX(iconRect)); |
| 302 | 300 |
| 303 // Make sure we're right of the |textFrame|. | 301 // Make sure we're right of the |textFrame|. |
| 304 NSRect textFrame = [cell textFrameForFrame:bounds]; | 302 NSRect textFrame = [cell textFrameForFrame:bounds]; |
| 305 EXPECT_LE(NSMaxX(textFrame), NSMinX(iconRect)); | 303 EXPECT_LE(NSMaxX(textFrame), NSMinX(iconRect)); |
| 306 | 304 |
| 307 // Now add a label. | 305 // Now add a label. |
| 308 NSFont* font = [NSFont controlContentFontOfSize:12.0]; | 306 NSFont* font = [NSFont controlContentFontOfSize:12.0]; |
| 309 NSColor* color = [NSColor blackColor]; | 307 NSColor* color = [NSColor blackColor]; |
| 310 security_image_view_.SetLabel(@"Label", font, color); | 308 security_image_view_.SetLabel(@"Label", font, color); |
| 311 iconRect = [cell securityImageFrameForFrame:bounds]; | 309 icons = [cell layedOutIcons:bounds]; |
| 310 ASSERT_EQ(1u, [icons count]); |
| 311 iconRect = [[icons objectAtIndex:0] rect]; |
| 312 | 312 |
| 313 EXPECT_FALSE(NSIsEmptyRect(iconRect)); | 313 EXPECT_FALSE(NSIsEmptyRect(iconRect)); |
| 314 EXPECT_TRUE(NSContainsRect(bounds, iconRect)); | 314 EXPECT_TRUE(NSContainsRect(bounds, iconRect)); |
| 315 | 315 |
| 316 // Make sure we are right of the |drawingRect|. | 316 // Make sure we are right of the |drawingRect|. |
| 317 drawingRect = [cell drawingRectForBounds:bounds]; | 317 drawingRect = [cell drawingRectForBounds:bounds]; |
| 318 EXPECT_LE(NSMaxX(drawingRect), NSMinX(iconRect)); | 318 EXPECT_LE(NSMaxX(drawingRect), NSMinX(iconRect)); |
| 319 | 319 |
| 320 // Make sure we're right of the |textFrame|. | 320 // Make sure we're right of the |textFrame|. |
| 321 textFrame = [cell textFrameForFrame:bounds]; | 321 textFrame = [cell textFrameForFrame:bounds]; |
| 322 EXPECT_LE(NSMaxX(textFrame), NSMinX(iconRect)); | 322 EXPECT_LE(NSMaxX(textFrame), NSMinX(iconRect)); |
| 323 | 323 |
| 324 // Make sure we clear correctly. | 324 // Make sure we clear correctly. |
| 325 security_image_view_.SetVisible(false); | 325 security_image_view_.SetVisible(false); |
| 326 iconRect = [cell securityImageFrameForFrame:bounds]; | 326 EXPECT_EQ(0u, [[cell layedOutIcons:bounds] count]); |
| 327 EXPECT_TRUE(NSEqualRects(iconRect, originalIconRect)); | |
| 328 EXPECT_TRUE(NSIsEmptyRect(iconRect)); | |
| 329 } | 327 } |
| 330 | 328 |
| 331 // Test Page Action counts. | 329 // Test Page Action counts. |
| 332 TEST_F(AutocompleteTextFieldCellTest, PageActionCount) { | 330 TEST_F(AutocompleteTextFieldCellTest, PageActionCount) { |
| 333 AutocompleteTextFieldCell* cell = | 331 AutocompleteTextFieldCell* cell = |
| 334 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 332 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
| 335 | 333 |
| 336 TestPageActionImageView page_action_view; | 334 TestPageActionImageView page_action_view; |
| 337 TestPageActionImageView page_action_view2; | 335 TestPageActionImageView page_action_view2; |
| 338 | 336 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 page_action_view2.SetVisible(false); | 373 page_action_view2.SetVisible(false); |
| 376 EXPECT_TRUE(NSIsEmptyRect([cell pageActionFrameForIndex:0 inFrame:bounds])); | 374 EXPECT_TRUE(NSIsEmptyRect([cell pageActionFrameForIndex:0 inFrame:bounds])); |
| 377 EXPECT_TRUE(NSIsEmptyRect([cell pageActionFrameForIndex:1 inFrame:bounds])); | 375 EXPECT_TRUE(NSIsEmptyRect([cell pageActionFrameForIndex:1 inFrame:bounds])); |
| 378 | 376 |
| 379 // Test preview page actions, as used by the extension installed bubble. | 377 // Test preview page actions, as used by the extension installed bubble. |
| 380 TestPageActionImageView preview_view; | 378 TestPageActionImageView preview_view; |
| 381 list.Add(&preview_view); | 379 list.Add(&preview_view); |
| 382 EXPECT_TRUE(NSIsEmptyRect([cell pageActionFrameForIndex:2 inFrame:bounds])); | 380 EXPECT_TRUE(NSIsEmptyRect([cell pageActionFrameForIndex:2 inFrame:bounds])); |
| 383 preview_view.set_preview_enabled(true); | 381 preview_view.set_preview_enabled(true); |
| 384 EXPECT_FALSE(NSIsEmptyRect([cell pageActionFrameForIndex:2 inFrame:bounds])); | 382 EXPECT_FALSE(NSIsEmptyRect([cell pageActionFrameForIndex:2 inFrame:bounds])); |
| 383 preview_view.set_preview_enabled(false); |
| 385 | 384 |
| 386 // One page action, no security icon. | 385 // One page action, no security icon. |
| 387 page_action_view.SetVisible(true); | 386 page_action_view.SetVisible(true); |
| 388 NSRect iconRect0 = [cell pageActionFrameForIndex:0 inFrame:bounds]; | 387 NSRect iconRect0 = [cell pageActionFrameForIndex:0 inFrame:bounds]; |
| 389 | 388 |
| 390 EXPECT_FALSE(NSIsEmptyRect(iconRect0)); | 389 EXPECT_FALSE(NSIsEmptyRect(iconRect0)); |
| 391 EXPECT_TRUE(NSContainsRect(bounds, iconRect0)); | 390 EXPECT_TRUE(NSContainsRect(bounds, iconRect0)); |
| 392 | 391 |
| 393 // Make sure we are right of the |drawingRect|. | 392 // Make sure we are right of the |drawingRect|. |
| 394 NSRect drawingRect = [cell drawingRectForBounds:bounds]; | 393 NSRect drawingRect = [cell drawingRectForBounds:bounds]; |
| 395 EXPECT_LE(NSMaxX(drawingRect), NSMinX(iconRect0)); | 394 EXPECT_LE(NSMaxX(drawingRect), NSMinX(iconRect0)); |
| 396 | 395 |
| 397 // Make sure we're right of the |textFrame|. | 396 // Make sure we're right of the |textFrame|. |
| 398 NSRect textFrame = [cell textFrameForFrame:bounds]; | 397 NSRect textFrame = [cell textFrameForFrame:bounds]; |
| 399 EXPECT_LE(NSMaxX(textFrame), NSMinX(iconRect0)); | 398 EXPECT_LE(NSMaxX(textFrame), NSMinX(iconRect0)); |
| 400 | 399 |
| 401 // Two page actions plus a security icon. | 400 // Two page actions plus a security icon. |
| 402 page_action_view2.SetVisible(true); | 401 page_action_view2.SetVisible(true); |
| 403 security_image_view_.SetVisible(true); | 402 security_image_view_.SetVisible(true); |
| 403 NSArray* icons = [cell layedOutIcons:bounds]; |
| 404 EXPECT_EQ(3u, [icons count]); |
| 404 iconRect0 = [cell pageActionFrameForIndex:0 inFrame:bounds]; | 405 iconRect0 = [cell pageActionFrameForIndex:0 inFrame:bounds]; |
| 405 NSRect iconRect1 = [cell pageActionFrameForIndex:1 inFrame:bounds]; | 406 NSRect iconRect1 = [cell pageActionFrameForIndex:1 inFrame:bounds]; |
| 406 NSRect lockRect = [cell securityImageFrameForFrame:bounds]; | 407 NSRect lockRect = [[icons objectAtIndex:0] rect]; |
| 408 |
| 409 EXPECT_TRUE(NSEqualRects(iconRect0, [[icons objectAtIndex:1] rect])); |
| 410 EXPECT_TRUE(NSEqualRects(iconRect1, [[icons objectAtIndex:2] rect])); |
| 407 | 411 |
| 408 // Make sure they're all in the expected order, and right of the |drawingRect| | 412 // Make sure they're all in the expected order, and right of the |drawingRect| |
| 409 // and |textFrame|. | 413 // and |textFrame|. |
| 410 drawingRect = [cell drawingRectForBounds:bounds]; | 414 drawingRect = [cell drawingRectForBounds:bounds]; |
| 411 textFrame = [cell textFrameForFrame:bounds]; | 415 textFrame = [cell textFrameForFrame:bounds]; |
| 412 | 416 |
| 413 EXPECT_FALSE(NSIsEmptyRect(iconRect0)); | 417 EXPECT_FALSE(NSIsEmptyRect(iconRect0)); |
| 414 EXPECT_TRUE(NSContainsRect(bounds, iconRect0)); | 418 EXPECT_TRUE(NSContainsRect(bounds, iconRect0)); |
| 415 EXPECT_FALSE(NSIsEmptyRect(iconRect1)); | 419 EXPECT_FALSE(NSIsEmptyRect(iconRect1)); |
| 416 EXPECT_TRUE(NSContainsRect(bounds, iconRect1)); | 420 EXPECT_TRUE(NSContainsRect(bounds, iconRect1)); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kHintPrefix]); | 494 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kHintPrefix]); |
| 491 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kHintSuffix]); | 495 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kHintSuffix]); |
| 492 | 496 |
| 493 // Narrow width suppresses everything but the image. | 497 // Narrow width suppresses everything but the image. |
| 494 [cell setKeywordHintPrefix:kHintPrefix image:image suffix:kHintSuffix | 498 [cell setKeywordHintPrefix:kHintPrefix image:image suffix:kHintSuffix |
| 495 availableWidth:kNarrowWidth]; | 499 availableWidth:kNarrowWidth]; |
| 496 EXPECT_EQ([[cell hintString] length], 1U); | 500 EXPECT_EQ([[cell hintString] length], 1U); |
| 497 } | 501 } |
| 498 | 502 |
| 499 } // namespace | 503 } // namespace |
| OLD | NEW |