| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 10 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 10 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 257 |
| 258 // Decoration should be right of |drawingRect|. | 258 // Decoration should be right of |drawingRect|. |
| 259 const NSRect drawingRect = [cell drawingRectForBounds:bounds]; | 259 const NSRect drawingRect = [cell drawingRectForBounds:bounds]; |
| 260 EXPECT_LT(NSMinX(drawingRect), NSMinX(decoration1Rect)); | 260 EXPECT_LT(NSMinX(drawingRect), NSMinX(decoration1Rect)); |
| 261 | 261 |
| 262 // Decoration should be right of |textFrame|. | 262 // Decoration should be right of |textFrame|. |
| 263 const NSRect textFrame = [cell textFrameForFrame:bounds]; | 263 const NSRect textFrame = [cell textFrameForFrame:bounds]; |
| 264 EXPECT_LT(NSMinX(textFrame), NSMinX(decoration1Rect)); | 264 EXPECT_LT(NSMinX(textFrame), NSMinX(decoration1Rect)); |
| 265 } | 265 } |
| 266 | 266 |
| 267 // Verify -[AutocompleteTextFieldCell updateToolTipsInRect:ofView:]. | 267 // Verify -[AutocompleteTextFieldCell |
| 268 // updateMouseTrackingAndToolTipsInRect:ofView:]. |
| 268 TEST_F(AutocompleteTextFieldCellTest, UpdateToolTips) { | 269 TEST_F(AutocompleteTextFieldCellTest, UpdateToolTips) { |
| 269 NSString* tooltip = @"tooltip"; | 270 NSString* tooltip = @"tooltip"; |
| 270 | 271 |
| 271 // Left decoration returns a tooltip, make sure it is called at | 272 // Left decoration returns a tooltip, make sure it is called at |
| 272 // least once. | 273 // least once. |
| 273 mock_left_decoration_.SetVisible(true); | 274 mock_left_decoration_.SetVisible(true); |
| 274 EXPECT_CALL(mock_left_decoration_, GetToolTip()) | 275 EXPECT_CALL(mock_left_decoration_, GetToolTip()) |
| 275 .WillOnce(Return(tooltip)) | 276 .WillOnce(Return(tooltip)) |
| 276 .WillRepeatedly(Return(tooltip)); | 277 .WillRepeatedly(Return(tooltip)); |
| 277 | 278 |
| 278 // Right decoration returns no tooltip, make sure it is called at | 279 // Right decoration returns no tooltip, make sure it is called at |
| 279 // least once. | 280 // least once. |
| 280 mock_right_decoration0_.SetVisible(true); | 281 mock_right_decoration0_.SetVisible(true); |
| 281 EXPECT_CALL(mock_right_decoration0_, GetToolTip()) | 282 EXPECT_CALL(mock_right_decoration0_, GetToolTip()) |
| 282 .WillOnce(Return((NSString*)nil)) | 283 .WillOnce(Return((NSString*)nil)) |
| 283 .WillRepeatedly(Return((NSString*)nil)); | 284 .WillRepeatedly(Return((NSString*)nil)); |
| 284 | 285 |
| 285 AutocompleteTextFieldCell* cell = | 286 AutocompleteTextFieldCell* cell = |
| 286 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 287 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
| 287 const NSRect bounds = [view_ bounds]; | 288 const NSRect bounds = [view_ bounds]; |
| 288 const NSRect leftDecorationRect = | 289 const NSRect leftDecorationRect = |
| 289 [cell frameForDecoration:&mock_left_decoration_ inFrame:bounds]; | 290 [cell frameForDecoration:&mock_left_decoration_ inFrame:bounds]; |
| 290 | 291 |
| 291 // |controlView| gets the tooltip for the left decoration. | 292 // |controlView| gets the tooltip for the left decoration. |
| 292 id controlView = [OCMockObject mockForClass:[AutocompleteTextField class]]; | 293 id controlView = [OCMockObject mockForClass:[AutocompleteTextField class]]; |
| 293 [[controlView expect] addToolTip:tooltip forRect:leftDecorationRect]; | 294 [[controlView expect] addToolTip:tooltip forRect:leftDecorationRect]; |
| 294 | 295 |
| 295 [cell updateToolTipsInRect:bounds ofView:controlView]; | 296 [cell updateMouseTrackingAndToolTipsInRect:bounds ofView:controlView]; |
| 296 | 297 |
| 297 EXPECT_OCMOCK_VERIFY(controlView); | 298 EXPECT_OCMOCK_VERIFY(controlView); |
| 298 } | 299 } |
| 299 | 300 |
| 300 } // namespace | 301 } // namespace |
| OLD | NEW |