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 "grit/theme_resources.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "testing/platform_test.h" | 12 #include "testing/platform_test.h" |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 // Width of the field so that we don't have to ask |field_| for it all | 16 // Width of the field so that we don't have to ask |field_| for it all |
16 // the time. | 17 // the time. |
17 const CGFloat kWidth(300.0); | 18 const CGFloat kWidth(300.0); |
18 | 19 |
19 // A narrow width for tests which test things that don't fit. | 20 // A narrow width for tests which test things that don't fit. |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 // Text frame should take everything over again on reset. | 194 // Text frame should take everything over again on reset. |
194 [cell clearKeywordAndHint]; | 195 [cell clearKeywordAndHint]; |
195 textFrame = [cell textFrameForFrame:bounds]; | 196 textFrame = [cell textFrameForFrame:bounds]; |
196 EXPECT_FALSE(NSIsEmptyRect(textFrame)); | 197 EXPECT_FALSE(NSIsEmptyRect(textFrame)); |
197 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); | 198 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); |
198 EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame)); | 199 EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame)); |
199 EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame)); | 200 EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame)); |
200 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); | 201 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); |
201 | 202 |
202 // Security icon takes up space on the right | 203 // Security icon takes up space on the right |
203 security_image_view_.SetImageShown( | 204 security_image_view_.SetImageShown(IDR_SECURE); |
204 LocationBarViewMac::SecurityImageView::LOCK); | |
205 security_image_view_.SetVisible(true); | 205 security_image_view_.SetVisible(true); |
206 | 206 |
207 textFrame = [cell textFrameForFrame:bounds]; | 207 textFrame = [cell textFrameForFrame:bounds]; |
208 EXPECT_FALSE(NSIsEmptyRect(textFrame)); | 208 EXPECT_FALSE(NSIsEmptyRect(textFrame)); |
209 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); | 209 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); |
210 EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds)); | 210 EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds)); |
211 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); | 211 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); |
212 | 212 |
213 // Search hint text takes precedence over the hint icon; the text frame | 213 // Search hint text takes precedence over the hint icon; the text frame |
214 // should be smaller in order to accomodate the text that is wider than | 214 // should be smaller in order to accomodate the text that is wider than |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); | 258 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); |
259 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect)); | 259 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect)); |
260 | 260 |
261 [cell clearKeywordAndHint]; | 261 [cell clearKeywordAndHint]; |
262 textFrame = [cell textFrameForFrame:bounds]; | 262 textFrame = [cell textFrameForFrame:bounds]; |
263 drawingRect = [cell drawingRectForBounds:bounds]; | 263 drawingRect = [cell drawingRectForBounds:bounds]; |
264 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); | 264 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); |
265 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect)); | 265 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect)); |
266 EXPECT_TRUE(NSEqualRects(drawingRect, originalDrawingRect)); | 266 EXPECT_TRUE(NSEqualRects(drawingRect, originalDrawingRect)); |
267 | 267 |
268 security_image_view_.SetImageShown( | 268 security_image_view_.SetImageShown(IDR_SECURE); |
269 LocationBarViewMac::SecurityImageView::LOCK); | |
270 security_image_view_.SetVisible(true); | 269 security_image_view_.SetVisible(true); |
271 | 270 |
272 textFrame = [cell textFrameForFrame:bounds]; | 271 textFrame = [cell textFrameForFrame:bounds]; |
273 drawingRect = [cell drawingRectForBounds:bounds]; | 272 drawingRect = [cell drawingRectForBounds:bounds]; |
274 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); | 273 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); |
275 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect)); | 274 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect)); |
276 } | 275 } |
277 | 276 |
278 // Test that the security icon is at the right side of the cell. | 277 // Test that the security icon is at the right side of the cell. |
279 TEST_F(AutocompleteTextFieldCellTest, SecurityImageFrame) { | 278 TEST_F(AutocompleteTextFieldCellTest, SecurityImageFrame) { |
280 AutocompleteTextFieldCell* cell = | 279 AutocompleteTextFieldCell* cell = |
281 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 280 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
282 const NSRect bounds([view_ bounds]); | 281 const NSRect bounds([view_ bounds]); |
283 security_image_view_.SetImageShown( | 282 security_image_view_.SetImageShown(IDR_SECURE); |
284 LocationBarViewMac::SecurityImageView::LOCK); | |
285 | 283 |
286 security_image_view_.SetVisible(false); | 284 security_image_view_.SetVisible(false); |
287 EXPECT_EQ(0u, [[cell layedOutIcons:bounds] count]); | 285 EXPECT_EQ(0u, [[cell layedOutIcons:bounds] count]); |
288 | 286 |
289 security_image_view_.SetVisible(true); | 287 security_image_view_.SetVisible(true); |
290 NSArray* icons = [cell layedOutIcons:bounds]; | 288 NSArray* icons = [cell layedOutIcons:bounds]; |
291 ASSERT_EQ(1u, [icons count]); | 289 ASSERT_EQ(1u, [icons count]); |
292 NSRect iconRect = [[icons objectAtIndex:0] rect]; | 290 NSRect iconRect = [[icons objectAtIndex:0] rect]; |
293 | 291 |
294 EXPECT_FALSE(NSIsEmptyRect(iconRect)); | 292 EXPECT_FALSE(NSIsEmptyRect(iconRect)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 EXPECT_EQ(1u, [cell pageActionCount]); | 340 EXPECT_EQ(1u, [cell pageActionCount]); |
343 list.Add(&page_action_view2); | 341 list.Add(&page_action_view2); |
344 EXPECT_EQ(2u, [cell pageActionCount]); | 342 EXPECT_EQ(2u, [cell pageActionCount]); |
345 } | 343 } |
346 | 344 |
347 // Test that Page Action icons are properly placed. | 345 // Test that Page Action icons are properly placed. |
348 TEST_F(AutocompleteTextFieldCellTest, PageActionImageFrame) { | 346 TEST_F(AutocompleteTextFieldCellTest, PageActionImageFrame) { |
349 AutocompleteTextFieldCell* cell = | 347 AutocompleteTextFieldCell* cell = |
350 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 348 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
351 const NSRect bounds([view_ bounds]); | 349 const NSRect bounds([view_ bounds]); |
352 security_image_view_.SetImageShown( | 350 security_image_view_.SetImageShown(IDR_SECURE); |
353 LocationBarViewMac::SecurityImageView::LOCK); | |
354 | 351 |
355 TestPageActionImageView page_action_view; | 352 TestPageActionImageView page_action_view; |
356 // We'll assume that the extensions code enforces icons smaller than the | 353 // We'll assume that the extensions code enforces icons smaller than the |
357 // location bar. | 354 // location bar. |
358 NSImage* image = [[[NSImage alloc] | 355 NSImage* image = [[[NSImage alloc] |
359 initWithSize:NSMakeSize(NSHeight(bounds) - 4, NSHeight(bounds) - 4)] | 356 initWithSize:NSMakeSize(NSHeight(bounds) - 4, NSHeight(bounds) - 4)] |
360 autorelease]; | 357 autorelease]; |
361 page_action_view.SetImage(image); | 358 page_action_view.SetImage(image); |
362 | 359 |
363 TestPageActionImageView page_action_view2; | 360 TestPageActionImageView page_action_view2; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kHintPrefix]); | 491 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kHintPrefix]); |
495 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kHintSuffix]); | 492 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kHintSuffix]); |
496 | 493 |
497 // Narrow width suppresses everything but the image. | 494 // Narrow width suppresses everything but the image. |
498 [cell setKeywordHintPrefix:kHintPrefix image:image suffix:kHintSuffix | 495 [cell setKeywordHintPrefix:kHintPrefix image:image suffix:kHintSuffix |
499 availableWidth:kNarrowWidth]; | 496 availableWidth:kNarrowWidth]; |
500 EXPECT_EQ([[cell hintString] length], 1U); | 497 EXPECT_EQ([[cell hintString] length], 1U); |
501 } | 498 } |
502 | 499 |
503 } // namespace | 500 } // namespace |
OLD | NEW |