| 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 "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 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "testing/platform_test.h" | 19 #include "testing/platform_test.h" |
| 19 | 20 |
| 20 using ::testing::StrictMock; | 21 using ::testing::StrictMock; |
| 21 using ::testing::_; | 22 using ::testing::_; |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 111 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
| 111 | 112 |
| 112 [cell setSearchHintString:@"Type to search" availableWidth:kWidth]; | 113 [cell setSearchHintString:@"Type to search" availableWidth:kWidth]; |
| 113 [view_ display]; | 114 [view_ display]; |
| 114 | 115 |
| 115 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; | 116 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; |
| 116 [cell setKeywordHintPrefix:@"prefix" image:image suffix:@"suffix" | 117 [cell setKeywordHintPrefix:@"prefix" image:image suffix:@"suffix" |
| 117 availableWidth:kWidth]; | 118 availableWidth:kWidth]; |
| 118 [view_ display]; | 119 [view_ display]; |
| 119 | 120 |
| 120 // Load available decorations and try drawing. | 121 // Load available decorations and try drawing. To make sure that |
| 122 // they are actually drawn, check that |GetWidthForSpace()| doesn't |
| 123 // indicate that they should be omitted. |
| 124 const CGFloat kVeryWide = 1000.0; |
| 125 |
| 121 SelectedKeywordDecoration selected_keyword_decoration([view_ font]); | 126 SelectedKeywordDecoration selected_keyword_decoration([view_ font]); |
| 122 selected_keyword_decoration.SetVisible(true); | 127 selected_keyword_decoration.SetVisible(true); |
| 123 selected_keyword_decoration.SetKeyword(std::wstring(L"Google"), false); | 128 selected_keyword_decoration.SetKeyword(std::wstring(L"Google"), false); |
| 124 [cell addLeftDecoration:&selected_keyword_decoration]; | 129 [cell addLeftDecoration:&selected_keyword_decoration]; |
| 130 EXPECT_NE(selected_keyword_decoration.GetWidthForSpace(kVeryWide), |
| 131 LocationBarDecoration::kOmittedWidth); |
| 125 | 132 |
| 126 // TODO(shess): This really wants a |LocationBarViewMac|, but only a | 133 // TODO(shess): This really wants a |LocationBarViewMac|, but only a |
| 127 // few methods reference it, so this works well enough. But | 134 // few methods reference it, so this works well enough. But |
| 128 // something better would be nice. | 135 // something better would be nice. |
| 129 LocationIconDecoration location_icon_decoration(NULL); | 136 LocationIconDecoration location_icon_decoration(NULL); |
| 130 location_icon_decoration.SetVisible(true); | 137 location_icon_decoration.SetVisible(true); |
| 131 location_icon_decoration.SetImage([NSImage imageNamed:@"NSApplicationIcon"]); | 138 location_icon_decoration.SetImage([NSImage imageNamed:@"NSApplicationIcon"]); |
| 132 [cell addLeftDecoration:&location_icon_decoration]; | 139 [cell addLeftDecoration:&location_icon_decoration]; |
| 140 EXPECT_NE(location_icon_decoration.GetWidthForSpace(kVeryWide), |
| 141 LocationBarDecoration::kOmittedWidth); |
| 133 | 142 |
| 134 EVBubbleDecoration ev_bubble_decoration(&location_icon_decoration, | 143 EVBubbleDecoration ev_bubble_decoration(&location_icon_decoration, |
| 135 [view_ font]); | 144 [view_ font]); |
| 136 ev_bubble_decoration.SetVisible(true); | 145 ev_bubble_decoration.SetVisible(true); |
| 137 ev_bubble_decoration.SetImage([NSImage imageNamed:@"NSApplicationIcon"]); | 146 ev_bubble_decoration.SetImage([NSImage imageNamed:@"NSApplicationIcon"]); |
| 138 ev_bubble_decoration.SetLabel(@"Application"); | 147 ev_bubble_decoration.SetLabel(@"Application"); |
| 139 [cell addLeftDecoration:&ev_bubble_decoration]; | 148 [cell addLeftDecoration:&ev_bubble_decoration]; |
| 149 EXPECT_NE(ev_bubble_decoration.GetWidthForSpace(kVeryWide), |
| 150 LocationBarDecoration::kOmittedWidth); |
| 151 |
| 152 StarDecoration star_decoration(NULL); |
| 153 star_decoration.SetVisible(true); |
| 154 [cell addRightDecoration:&star_decoration]; |
| 155 EXPECT_NE(star_decoration.GetWidthForSpace(kVeryWide), |
| 156 LocationBarDecoration::kOmittedWidth); |
| 140 | 157 |
| 141 // Make sure we're actually calling |DrawInFrame()|. | 158 // Make sure we're actually calling |DrawInFrame()|. |
| 142 StrictMock<MockDecoration> mock_decoration; | 159 StrictMock<MockDecoration> mock_decoration; |
| 143 mock_decoration.SetVisible(true); | 160 mock_decoration.SetVisible(true); |
| 144 [cell addLeftDecoration:&mock_decoration]; | 161 [cell addLeftDecoration:&mock_decoration]; |
| 145 EXPECT_CALL(mock_decoration, DrawInFrame(_, _)); | 162 EXPECT_CALL(mock_decoration, DrawInFrame(_, _)); |
| 163 EXPECT_NE(mock_decoration.GetWidthForSpace(kVeryWide), |
| 164 LocationBarDecoration::kOmittedWidth); |
| 146 | 165 |
| 147 [view_ display]; | 166 [view_ display]; |
| 148 | 167 |
| 149 [cell clearDecorations]; | 168 [cell clearDecorations]; |
| 150 } | 169 } |
| 151 | 170 |
| 152 TEST_F(AutocompleteTextFieldCellTest, ClearKeywordAndHint) { | 171 TEST_F(AutocompleteTextFieldCellTest, ClearKeywordAndHint) { |
| 153 AutocompleteTextFieldCell* cell = | 172 AutocompleteTextFieldCell* cell = |
| 154 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 173 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
| 155 EXPECT_FALSE([cell hintString]); | 174 EXPECT_FALSE([cell hintString]); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kHintPrefix]); | 450 EXPECT_TRUE([[[cell hintString] string] hasPrefix:kHintPrefix]); |
| 432 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kHintSuffix]); | 451 EXPECT_TRUE([[[cell hintString] string] hasSuffix:kHintSuffix]); |
| 433 | 452 |
| 434 // Narrow width suppresses everything but the image. | 453 // Narrow width suppresses everything but the image. |
| 435 [cell setKeywordHintPrefix:kHintPrefix image:image suffix:kHintSuffix | 454 [cell setKeywordHintPrefix:kHintPrefix image:image suffix:kHintSuffix |
| 436 availableWidth:kNarrowWidth]; | 455 availableWidth:kNarrowWidth]; |
| 437 EXPECT_EQ([[cell hintString] length], 1U); | 456 EXPECT_EQ([[cell hintString] length], 1U); |
| 438 } | 457 } |
| 439 | 458 |
| 440 } // namespace | 459 } // namespace |
| OLD | NEW |