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

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

Issue 2868058: [Mac] Re-enable decoration tooltips in omnibox. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: Created 10 years, 5 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
« no previous file with comments | « chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "base/scoped_nsobject.h" 8 #include "base/scoped_nsobject.h"
9 #import "chrome/browser/cocoa/cocoa_test_helper.h" 9 #import "chrome/browser/cocoa/cocoa_test_helper.h"
10 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h" 10 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h"
11 #import "chrome/browser/cocoa/location_bar/ev_bubble_decoration.h" 11 #import "chrome/browser/cocoa/location_bar/ev_bubble_decoration.h"
12 #import "chrome/browser/cocoa/location_bar/location_bar_decoration.h" 12 #import "chrome/browser/cocoa/location_bar/location_bar_decoration.h"
13 #import "chrome/browser/cocoa/location_bar/location_icon_decoration.h" 13 #import "chrome/browser/cocoa/location_bar/location_icon_decoration.h"
14 #import "chrome/browser/cocoa/location_bar/selected_keyword_decoration.h" 14 #import "chrome/browser/cocoa/location_bar/selected_keyword_decoration.h"
15 #import "chrome/browser/cocoa/location_bar/star_decoration.h" 15 #import "chrome/browser/cocoa/location_bar/star_decoration.h"
16 #include "grit/theme_resources.h" 16 #include "grit/theme_resources.h"
17 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "testing/platform_test.h" 19 #include "testing/platform_test.h"
20 #import "third_party/ocmock/OCMock/OCMock.h"
20 21
22 using ::testing::Return;
21 using ::testing::StrictMock; 23 using ::testing::StrictMock;
22 using ::testing::_; 24 using ::testing::_;
23 25
24 namespace { 26 namespace {
25 27
26 // Width of the field so that we don't have to ask |field_| for it all 28 // Width of the field so that we don't have to ask |field_| for it all
27 // the time. 29 // the time.
28 const CGFloat kWidth(300.0); 30 const CGFloat kWidth(300.0);
29 31
30 // A narrow width for tests which test things that don't fit. 32 // A narrow width for tests which test things that don't fit.
31 const CGFloat kNarrowWidth(5.0); 33 const CGFloat kNarrowWidth(5.0);
32 34
33 class MockDecoration : public LocationBarDecoration { 35 class MockDecoration : public LocationBarDecoration {
34 public: 36 public:
35 virtual CGFloat GetWidthForSpace(CGFloat width) { return 20.0; } 37 virtual CGFloat GetWidthForSpace(CGFloat width) { return 20.0; }
36 virtual bool IsVisible() const { return visible_; }
37 void SetVisible(bool visible) { visible_ = visible; }
38 38
39 MOCK_METHOD2(DrawInFrame, void(NSRect frame, NSView* control_view)); 39 MOCK_METHOD2(DrawInFrame, void(NSRect frame, NSView* control_view));
40 40 MOCK_METHOD0(GetToolTip, NSString*());
41 bool visible_;
42 }; 41 };
43 42
44 class AutocompleteTextFieldCellTest : public CocoaTest { 43 class AutocompleteTextFieldCellTest : public CocoaTest {
45 public: 44 public:
46 AutocompleteTextFieldCellTest() { 45 AutocompleteTextFieldCellTest() {
47 // Make sure this is wide enough to play games with the cell 46 // Make sure this is wide enough to play games with the cell
48 // decorations. 47 // decorations.
49 const NSRect frame = NSMakeRect(0, 0, kWidth, 30); 48 const NSRect frame = NSMakeRect(0, 0, kWidth, 30);
50 49
51 scoped_nsobject<NSTextField> view( 50 scoped_nsobject<NSTextField> view(
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 335
337 // Decoration should be right of |drawingRect|. 336 // Decoration should be right of |drawingRect|.
338 const NSRect drawingRect = [cell drawingRectForBounds:bounds]; 337 const NSRect drawingRect = [cell drawingRectForBounds:bounds];
339 EXPECT_LT(NSMinX(drawingRect), NSMinX(decoration1Rect)); 338 EXPECT_LT(NSMinX(drawingRect), NSMinX(decoration1Rect));
340 339
341 // Decoration should be right of |textFrame|. 340 // Decoration should be right of |textFrame|.
342 const NSRect textFrame = [cell textFrameForFrame:bounds]; 341 const NSRect textFrame = [cell textFrameForFrame:bounds];
343 EXPECT_LT(NSMinX(textFrame), NSMinX(decoration1Rect)); 342 EXPECT_LT(NSMinX(textFrame), NSMinX(decoration1Rect));
344 } 343 }
345 344
346 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
Scott Hess - ex-Googler 2010/07/17 00:35:10 I, too, am confused by this. I'll try to figure o
347
348 // Test that the cell drops the search hint if there is no room for 345 // Test that the cell drops the search hint if there is no room for
349 // it. 346 // it.
350 TEST_F(AutocompleteTextFieldCellTest, OmitsSearchHintIfNarrow) { 347 TEST_F(AutocompleteTextFieldCellTest, OmitsSearchHintIfNarrow) {
351 AutocompleteTextFieldCell* cell = 348 AutocompleteTextFieldCell* cell =
352 static_cast<AutocompleteTextFieldCell*>([view_ cell]); 349 static_cast<AutocompleteTextFieldCell*>([view_ cell]);
353 350
354 NSString* const kSearchHint = @"Type to search"; 351 NSString* const kSearchHint = @"Type to search";
355 352
356 // Wide width chooses the full string. 353 // Wide width chooses the full string.
357 [cell setSearchHintString:kSearchHint availableWidth:kWidth]; 354 [cell setSearchHintString:kSearchHint availableWidth:kWidth];
(...skipping 22 matching lines...) Expand all
380 EXPECT_TRUE([cell hintString]); 377 EXPECT_TRUE([cell hintString]);
381 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kHintPrefix]); 378 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kHintPrefix]);
382 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kHintSuffix]); 379 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kHintSuffix]);
383 380
384 // Narrow width suppresses everything but the image. 381 // Narrow width suppresses everything but the image.
385 [cell setKeywordHintPrefix:kHintPrefix image:image suffix:kHintSuffix 382 [cell setKeywordHintPrefix:kHintPrefix image:image suffix:kHintSuffix
386 availableWidth:kNarrowWidth]; 383 availableWidth:kNarrowWidth];
387 EXPECT_EQ([[cell hintString] length], 1U); 384 EXPECT_EQ([[cell hintString] length], 1U);
388 } 385 }
389 386
387 // Verify -[AutocompleteTextFieldCell updateToolTipsInRect:ofView:].
388 TEST_F(AutocompleteTextFieldCellTest, UpdateToolTips) {
389 NSString* tooltip = @"tooltip";
390
391 // Left decoration returns a tooltip, make sure it is called at
392 // least once.
393 mock_left_decoration_.SetVisible(true);
394 EXPECT_CALL(mock_left_decoration_, GetToolTip())
395 .WillOnce(Return(tooltip))
396 .WillRepeatedly(Return(tooltip));
397
398 // Right decoration returns no tooltip, make sure it is called at
399 // least once.
400 mock_right_decoration0_.SetVisible(true);
401 EXPECT_CALL(mock_right_decoration0_, GetToolTip())
402 .WillOnce(Return((NSString*)nil))
403 .WillRepeatedly(Return((NSString*)nil));
404
405 AutocompleteTextFieldCell* cell =
406 static_cast<AutocompleteTextFieldCell*>([view_ cell]);
407 const NSRect bounds = [view_ bounds];
408 const NSRect leftDecorationRect =
409 [cell frameForDecoration:&mock_left_decoration_ inFrame:bounds];
410
411 // |controlView| gets the tooltip for the left decoration.
412 id controlView = [OCMockObject mockForClass:[AutocompleteTextField class]];
413 [[controlView expect] addToolTip:tooltip forRect:leftDecorationRect];
414
415 [cell updateToolTipsInRect:bounds ofView:controlView];
416
417 [controlView verify];
418 }
419
390 } // namespace 420 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698