| 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 [cell clearKeywordAndHint]; | 194 [cell clearKeywordAndHint]; |
| 195 EXPECT_TRUE([cell fieldEditorNeedsReset]); | 195 EXPECT_TRUE([cell fieldEditorNeedsReset]); |
| 196 } | 196 } |
| 197 | 197 |
| 198 TEST_F(AutocompleteTextFieldCellTest, TextFrame) { | 198 TEST_F(AutocompleteTextFieldCellTest, TextFrame) { |
| 199 AutocompleteTextFieldCell* cell = | 199 AutocompleteTextFieldCell* cell = |
| 200 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 200 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
| 201 const NSRect bounds([view_ bounds]); | 201 const NSRect bounds([view_ bounds]); |
| 202 NSRect textFrame; | 202 NSRect textFrame; |
| 203 | 203 |
| 204 // The cursor frame should stay the same throughout. |
| 205 const NSRect cursorFrame([cell textCursorFrameForFrame:bounds]); |
| 206 |
| 204 // At default settings, everything goes to the text area. | 207 // At default settings, everything goes to the text area. |
| 205 textFrame = [cell textFrameForFrame:bounds]; | 208 textFrame = [cell textFrameForFrame:bounds]; |
| 206 EXPECT_FALSE(NSIsEmptyRect(textFrame)); | 209 EXPECT_FALSE(NSIsEmptyRect(textFrame)); |
| 207 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); | 210 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); |
| 208 EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame)); | 211 EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame)); |
| 209 EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame)); | 212 EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame)); |
| 213 EXPECT_TRUE(NSEqualRects(cursorFrame, textFrame)); |
| 210 | 214 |
| 211 // Small search hint leaves text frame to left. | 215 // Small search hint leaves text frame to left. |
| 212 [cell setSearchHintString:@"Search hint"]; | 216 [cell setSearchHintString:@"Search hint"]; |
| 213 textFrame = [cell textFrameForFrame:bounds]; | 217 textFrame = [cell textFrameForFrame:bounds]; |
| 214 EXPECT_FALSE(NSIsEmptyRect(textFrame)); | 218 EXPECT_FALSE(NSIsEmptyRect(textFrame)); |
| 215 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); | 219 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); |
| 216 EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds)); | 220 EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds)); |
| 221 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); |
| 217 | 222 |
| 218 // Save search-hint's frame for future reference. | 223 // Save search-hint's frame for future reference. |
| 219 const CGFloat searchHintMaxX(NSMaxX(textFrame)); | 224 const CGFloat searchHintMaxX(NSMaxX(textFrame)); |
| 220 | 225 |
| 221 // Keyword hint also leaves text to left. Arrange for it to be | 226 // Keyword hint also leaves text to left. Arrange for it to be |
| 222 // larger than the search hint just to make sure that things have | 227 // larger than the search hint just to make sure that things have |
| 223 // changed (keyword hint overrode search hint), and that they aren't | 228 // changed (keyword hint overrode search hint), and that they aren't |
| 224 // handled identically w/out reference to the actual button cell. | 229 // handled identically w/out reference to the actual button cell. |
| 225 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; | 230 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; |
| 226 [cell setKeywordHintPrefix:@"Keyword " image:image suffix:@" hint"]; | 231 [cell setKeywordHintPrefix:@"Keyword " image:image suffix:@" hint"]; |
| 227 textFrame = [cell textFrameForFrame:bounds]; | 232 textFrame = [cell textFrameForFrame:bounds]; |
| 228 EXPECT_FALSE(NSIsEmptyRect(textFrame)); | 233 EXPECT_FALSE(NSIsEmptyRect(textFrame)); |
| 229 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); | 234 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); |
| 230 EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds)); | 235 EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds)); |
| 231 EXPECT_LT(NSMaxX(textFrame), searchHintMaxX); | 236 EXPECT_LT(NSMaxX(textFrame), searchHintMaxX); |
| 237 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); |
| 232 | 238 |
| 233 // Keyword search leaves text area to right. | 239 // Keyword search leaves text area to right. |
| 234 [cell setKeywordString:@"Search Engine:"]; | 240 [cell setKeywordString:@"Search Engine:"]; |
| 235 textFrame = [cell textFrameForFrame:bounds]; | 241 textFrame = [cell textFrameForFrame:bounds]; |
| 236 EXPECT_FALSE(NSIsEmptyRect(textFrame)); | 242 EXPECT_FALSE(NSIsEmptyRect(textFrame)); |
| 237 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); | 243 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); |
| 238 EXPECT_GT(NSMinX(textFrame), NSMinX(bounds)); | 244 EXPECT_GT(NSMinX(textFrame), NSMinX(bounds)); |
| 239 EXPECT_LT(NSMinX(textFrame), searchHintMaxX); | 245 EXPECT_LT(NSMinX(textFrame), searchHintMaxX); |
| 240 EXPECT_GT(NSMaxX(textFrame), searchHintMaxX); | 246 EXPECT_GT(NSMaxX(textFrame), searchHintMaxX); |
| 247 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); |
| 241 | 248 |
| 242 // Text frame should take everything over again on reset. | 249 // Text frame should take everything over again on reset. |
| 243 [cell clearKeywordAndHint]; | 250 [cell clearKeywordAndHint]; |
| 244 textFrame = [cell textFrameForFrame:bounds]; | 251 textFrame = [cell textFrameForFrame:bounds]; |
| 245 EXPECT_FALSE(NSIsEmptyRect(textFrame)); | 252 EXPECT_FALSE(NSIsEmptyRect(textFrame)); |
| 246 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); | 253 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); |
| 247 EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame)); | 254 EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame)); |
| 248 EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame)); | 255 EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame)); |
| 256 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); |
| 249 } | 257 } |
| 250 | 258 |
| 251 } // namespace | 259 } // namespace |
| OLD | NEW |