| 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 #import "base/cocoa_protocols_mac.h" | 8 #import "base/cocoa_protocols_mac.h" |
| 9 #include "base/scoped_nsobject.h" | 9 #include "base/scoped_nsobject.h" |
| 10 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h" | 10 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h" |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 | 259 |
| 260 [cell setSearchHintString:@"Type to search" availableWidth:kWidth]; | 260 [cell setSearchHintString:@"Type to search" availableWidth:kWidth]; |
| 261 [field_ display]; | 261 [field_ display]; |
| 262 | 262 |
| 263 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; | 263 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; |
| 264 [cell setKeywordHintPrefix:@"prefix" image:image suffix:@"suffix" | 264 [cell setKeywordHintPrefix:@"prefix" image:image suffix:@"suffix" |
| 265 availableWidth:kWidth]; | 265 availableWidth:kWidth]; |
| 266 [field_ display]; | 266 [field_ display]; |
| 267 | 267 |
| 268 [cell clearHint]; | 268 [cell clearHint]; |
| 269 |
| 269 [field_ display]; | 270 [field_ display]; |
| 270 } | 271 } |
| 271 | 272 |
| 272 TEST_F(AutocompleteTextFieldObserverTest, FlagsChanged) { | 273 TEST_F(AutocompleteTextFieldObserverTest, FlagsChanged) { |
| 273 InSequence dummy; // Call mock in exactly the order specified. | 274 InSequence dummy; // Call mock in exactly the order specified. |
| 274 | 275 |
| 275 // Test without Control key down, but some other modifier down. | 276 // Test without Control key down, but some other modifier down. |
| 276 EXPECT_CALL(field_observer_, OnControlKeyChanged(false)); | 277 EXPECT_CALL(field_observer_, OnControlKeyChanged(false)); |
| 277 [field_ flagsChanged:KeyDownEventWithFlags(NSShiftKeyMask)]; | 278 [field_ flagsChanged:KeyDownEventWithFlags(NSShiftKeyMask)]; |
| 278 | 279 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 | 376 |
| 376 // Make sure decoration isn't already visible, then make it visible. | 377 // Make sure decoration isn't already visible, then make it visible. |
| 377 EXPECT_TRUE(NSIsEmptyRect([cell frameForDecoration:&mock_left_decoration_ | 378 EXPECT_TRUE(NSIsEmptyRect([cell frameForDecoration:&mock_left_decoration_ |
| 378 inFrame:[field_ bounds]])); | 379 inFrame:[field_ bounds]])); |
| 379 mock_left_decoration_.SetVisible(true); | 380 mock_left_decoration_.SetVisible(true); |
| 380 EXPECT_FALSE(NSIsEmptyRect([cell frameForDecoration:&mock_left_decoration_ | 381 EXPECT_FALSE(NSIsEmptyRect([cell frameForDecoration:&mock_left_decoration_ |
| 381 inFrame:[field_ bounds]])); | 382 inFrame:[field_ bounds]])); |
| 382 | 383 |
| 383 // Capture the editor frame resulting from the standard focus | 384 // Capture the editor frame resulting from the standard focus |
| 384 // machinery. | 385 // machinery. |
| 386 |
| 385 [test_window() makePretendKeyWindowAndSetFirstResponder:field_]; | 387 [test_window() makePretendKeyWindowAndSetFirstResponder:field_]; |
| 386 const NSRect baseEditorFrame(EditorFrame()); | 388 const NSRect baseEditorFrame(EditorFrame()); |
| 387 | 389 |
| 388 // When the decoration is not visible the frame should be strictly larger. | 390 // When the decoration is not visible the frame should be strictly larger. |
| 389 mock_left_decoration_.SetVisible(false); | 391 mock_left_decoration_.SetVisible(false); |
| 390 EXPECT_TRUE(NSIsEmptyRect([cell frameForDecoration:&mock_left_decoration_ | 392 EXPECT_TRUE(NSIsEmptyRect([cell frameForDecoration:&mock_left_decoration_ |
| 391 inFrame:[field_ bounds]])); | 393 inFrame:[field_ bounds]])); |
| 392 [field_ resetFieldEditorFrameIfNeeded]; | 394 [field_ resetFieldEditorFrameIfNeeded]; |
| 393 EXPECT_FALSE(NSEqualRects(baseEditorFrame, EditorFrame())); | 395 EXPECT_FALSE(NSEqualRects(baseEditorFrame, EditorFrame())); |
| 394 EXPECT_TRUE(NSContainsRect(EditorFrame(), baseEditorFrame)); | 396 EXPECT_TRUE(NSContainsRect(EditorFrame(), baseEditorFrame)); |
| 395 | 397 |
| 396 // When the decoration is visible, -resetFieldEditorFrameIfNeeded | 398 // When the decoration is visible, -resetFieldEditorFrameIfNeeded |
| 397 // should result in the same frame as the standard focus machinery. | 399 // should result in the same frame as the standard focus machinery. |
| 398 mock_left_decoration_.SetVisible(true); | 400 mock_left_decoration_.SetVisible(true); |
| 399 EXPECT_FALSE(NSIsEmptyRect([cell frameForDecoration:&mock_left_decoration_ | 401 EXPECT_FALSE(NSIsEmptyRect([cell frameForDecoration:&mock_left_decoration_ |
| 400 inFrame:[field_ bounds]])); | 402 inFrame:[field_ bounds]])); |
| 403 |
| 401 [field_ resetFieldEditorFrameIfNeeded]; | 404 [field_ resetFieldEditorFrameIfNeeded]; |
| 402 EXPECT_TRUE(NSEqualRects(baseEditorFrame, EditorFrame())); | 405 EXPECT_TRUE(NSEqualRects(baseEditorFrame, EditorFrame())); |
| 403 } | 406 } |
| 404 | 407 |
| 405 // Test that resetting the field editor bounds does not cause untoward | 408 // Test that resetting the field editor bounds does not cause untoward |
| 406 // messages to the field's observer. | 409 // messages to the field's observer. |
| 407 TEST_F(AutocompleteTextFieldObserverTest, ResetFieldEditorContinuesEditing) { | 410 TEST_F(AutocompleteTextFieldObserverTest, ResetFieldEditorContinuesEditing) { |
| 408 EXPECT_CALL(field_observer_, OnSetFocus(false)); | 411 EXPECT_CALL(field_observer_, OnSetFocus(false)); |
| 409 // Becoming first responder doesn't begin editing. | 412 // Becoming first responder doesn't begin editing. |
| 410 [test_window() makePretendKeyWindowAndSetFirstResponder:field_]; | 413 [test_window() makePretendKeyWindowAndSetFirstResponder:field_]; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 // puts the selection in the leftmost position. | 453 // puts the selection in the leftmost position. |
| 451 TEST_F(AutocompleteTextFieldTest, ClickLeftDecorationPutsCaretLeftmost) { | 454 TEST_F(AutocompleteTextFieldTest, ClickLeftDecorationPutsCaretLeftmost) { |
| 452 // Decoration does not handle the mouse event, so the cell should | 455 // Decoration does not handle the mouse event, so the cell should |
| 453 // process it. | 456 // process it. |
| 454 EXPECT_CALL(mock_left_decoration_, OnMousePressed(_)) | 457 EXPECT_CALL(mock_left_decoration_, OnMousePressed(_)) |
| 455 .WillRepeatedly(Return(false)); | 458 .WillRepeatedly(Return(false)); |
| 456 | 459 |
| 457 // Set the decoration before becoming responder. | 460 // Set the decoration before becoming responder. |
| 458 EXPECT_FALSE([field_ currentEditor]); | 461 EXPECT_FALSE([field_ currentEditor]); |
| 459 mock_left_decoration_.SetVisible(true); | 462 mock_left_decoration_.SetVisible(true); |
| 463 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; |
| 460 | 464 |
| 461 // Make first responder should select all. | 465 // Make first responder should select all. |
| 462 [test_window() makePretendKeyWindowAndSetFirstResponder:field_]; | 466 [test_window() makePretendKeyWindowAndSetFirstResponder:field_]; |
| 463 EXPECT_TRUE([field_ currentEditor]); | 467 EXPECT_TRUE([field_ currentEditor]); |
| 464 const NSRange allRange = NSMakeRange(0, [[field_ stringValue] length]); | 468 const NSRange allRange = NSMakeRange(0, [[field_ stringValue] length]); |
| 465 EXPECT_TRUE(NSEqualRanges(allRange, [[field_ currentEditor] selectedRange])); | 469 EXPECT_TRUE(NSEqualRanges(allRange, [[field_ currentEditor] selectedRange])); |
| 466 | 470 |
| 467 // Generate a click on the decoration. | 471 // Generate a click on the decoration. |
| 468 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; | 472 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; |
| 469 const NSRect iconFrame = | 473 const NSRect iconFrame = |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 scoped_nsobject<AutocompleteTextField> pin([field_ retain]); | 883 scoped_nsobject<AutocompleteTextField> pin([field_ retain]); |
| 880 [field_ removeFromSuperview]; | 884 [field_ removeFromSuperview]; |
| 881 [test_window() resignKeyWindow]; | 885 [test_window() resignKeyWindow]; |
| 882 | 886 |
| 883 [[test_window() contentView] addSubview:field_]; | 887 [[test_window() contentView] addSubview:field_]; |
| 884 EXPECT_CALL(field_observer_, ClosePopup()); | 888 EXPECT_CALL(field_observer_, ClosePopup()); |
| 885 [test_window() resignKeyWindow]; | 889 [test_window() resignKeyWindow]; |
| 886 } | 890 } |
| 887 | 891 |
| 888 } // namespace | 892 } // namespace |
| OLD | NEW |