| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 [cell setKeywordString:@"Search on Engine:"]; | 128 [cell setKeywordString:@"Search on Engine:"]; |
| 129 EXPECT_TRUE([cell fieldEditorNeedsReset]); | 129 EXPECT_TRUE([cell fieldEditorNeedsReset]); |
| 130 [cell setFieldEditorNeedsReset:NO]; | 130 [cell setFieldEditorNeedsReset:NO]; |
| 131 EXPECT_FALSE([cell fieldEditorNeedsReset]); | 131 EXPECT_FALSE([cell fieldEditorNeedsReset]); |
| 132 | 132 |
| 133 // Changing to an identical string doesn't need a reset. | 133 // Changing to an identical string doesn't need a reset. |
| 134 [cell setKeywordString:@"Search on Engine:"]; | 134 [cell setKeywordString:@"Search on Engine:"]; |
| 135 EXPECT_FALSE([cell fieldEditorNeedsReset]); | 135 EXPECT_FALSE([cell fieldEditorNeedsReset]); |
| 136 } | 136 } |
| 137 | 137 |
| 138 TEST_F(AutocompleteTextFieldCellTest, SecurityIcon) { |
| 139 AutocompleteTextFieldCell* cell = |
| 140 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
| 141 |
| 142 EXPECT_FALSE([cell fieldEditorNeedsReset]); |
| 143 |
| 144 NSImage* image1 = [NSImage imageNamed:@"NSApplicationIcon"]; |
| 145 // Setting a security icon will need a reset. |
| 146 [cell setHintIcon:image1]; |
| 147 EXPECT_TRUE([cell fieldEditorNeedsReset]); |
| 148 [cell setFieldEditorNeedsReset:NO]; |
| 149 EXPECT_FALSE([cell fieldEditorNeedsReset]); |
| 150 |
| 151 // Changing the security icon needs a reset. |
| 152 NSImage* image2 = [NSImage imageNamed:@"NSComputer"]; |
| 153 [cell setHintIcon:image2]; |
| 154 EXPECT_TRUE([cell fieldEditorNeedsReset]); |
| 155 [cell setFieldEditorNeedsReset:NO]; |
| 156 EXPECT_FALSE([cell fieldEditorNeedsReset]); |
| 157 |
| 158 // Changing to an identical security icon doesn't need a reset. |
| 159 [cell setHintIcon:image2]; |
| 160 EXPECT_FALSE([cell fieldEditorNeedsReset]); |
| 161 } |
| 162 |
| 138 // Test that transitions between various modes set the reset flag. | 163 // Test that transitions between various modes set the reset flag. |
| 139 TEST_F(AutocompleteTextFieldCellTest, Transitions) { | 164 TEST_F(AutocompleteTextFieldCellTest, Transitions) { |
| 140 AutocompleteTextFieldCell* cell = | 165 AutocompleteTextFieldCell* cell = |
| 141 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 166 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
| 142 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; | 167 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; |
| 143 | 168 |
| 144 // Transitions from hint to keyword string, keyword hint, and | 169 // Transitions from hint to keyword string, keyword hint, and |
| 145 // cleared. | 170 // cleared. |
| 146 [cell setSearchHintString:@"Type to search"]; | 171 [cell setSearchHintString:@"Type to search"]; |
| 147 [cell setFieldEditorNeedsReset:NO]; | 172 [cell setFieldEditorNeedsReset:NO]; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); | 279 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); |
| 255 | 280 |
| 256 // Text frame should take everything over again on reset. | 281 // Text frame should take everything over again on reset. |
| 257 [cell clearKeywordAndHint]; | 282 [cell clearKeywordAndHint]; |
| 258 textFrame = [cell textFrameForFrame:bounds]; | 283 textFrame = [cell textFrameForFrame:bounds]; |
| 259 EXPECT_FALSE(NSIsEmptyRect(textFrame)); | 284 EXPECT_FALSE(NSIsEmptyRect(textFrame)); |
| 260 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); | 285 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); |
| 261 EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame)); | 286 EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame)); |
| 262 EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame)); | 287 EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame)); |
| 263 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); | 288 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); |
| 289 |
| 290 // Hint icon takes up space on the right |
| 291 [cell setHintIcon:[NSImage imageNamed:@"NSComputer"]]; |
| 292 textFrame = [cell textFrameForFrame:bounds]; |
| 293 EXPECT_FALSE(NSIsEmptyRect(textFrame)); |
| 294 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); |
| 295 EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds)); |
| 296 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); |
| 297 |
| 298 // Search hint text takes precedence over the hint icon; the text frame |
| 299 // should be smaller in order to accomodate the text that is wider than |
| 300 // the icon. |
| 301 [cell setSearchHintString:@"Search hint"]; |
| 302 NSRect textFrameWithHintText = [cell textFrameForFrame:bounds]; |
| 303 EXPECT_TRUE(NSContainsRect(textFrame, textFrameWithHintText)); |
| 304 EXPECT_LT(NSWidth(textFrameWithHintText), NSWidth(textFrame)); |
| 264 } | 305 } |
| 265 | 306 |
| 266 } // namespace | 307 } // namespace |
| OLD | NEW |