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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 const NSRange selectedRange([[field_ currentEditor] selectedRange]); | 420 const NSRange selectedRange([[field_ currentEditor] selectedRange]); |
421 EXPECT_EQ(selectedRange.location, 0U); | 421 EXPECT_EQ(selectedRange.location, 0U); |
422 EXPECT_EQ(selectedRange.length, [[field_ stringValue] length]); | 422 EXPECT_EQ(selectedRange.length, [[field_ stringValue] length]); |
423 } | 423 } |
424 | 424 |
425 // Single-click with no drag should setup a field editor and | 425 // Single-click with no drag should setup a field editor and |
426 // select all. | 426 // select all. |
427 TEST_F(AutocompleteTextFieldTest, ClickSelectsAll) { | 427 TEST_F(AutocompleteTextFieldTest, ClickSelectsAll) { |
428 EXPECT_FALSE([field_ currentEditor]); | 428 EXPECT_FALSE([field_ currentEditor]); |
429 | 429 |
430 const NSPoint point(NSMakePoint(20.0, 5.0)); | 430 const NSPoint point = NSMakePoint(20.0, NSMidY([field_ bounds])); |
431 NSEvent* downEvent(Event(field_, point, NSLeftMouseDown)); | 431 NSEvent* downEvent(Event(field_, point, NSLeftMouseDown)); |
432 NSEvent* upEvent(Event(field_, point, NSLeftMouseUp)); | 432 NSEvent* upEvent(Event(field_, point, NSLeftMouseUp)); |
433 [NSApp postEvent:upEvent atStart:YES]; | 433 [NSApp postEvent:upEvent atStart:YES]; |
434 [field_ mouseDown:downEvent]; | 434 [field_ mouseDown:downEvent]; |
435 EXPECT_TRUE([field_ currentEditor]); | 435 EXPECT_TRUE([field_ currentEditor]); |
436 const NSRange selectedRange([[field_ currentEditor] selectedRange]); | 436 const NSRange selectedRange([[field_ currentEditor] selectedRange]); |
437 EXPECT_EQ(selectedRange.location, 0U); | 437 EXPECT_EQ(selectedRange.location, 0U); |
438 EXPECT_EQ(selectedRange.length, [[field_ stringValue] length]); | 438 EXPECT_EQ(selectedRange.length, [[field_ stringValue] length]); |
439 } | 439 } |
440 | 440 |
(...skipping 20 matching lines...) Expand all Loading... |
461 // can't work. What really needs to happen is to push through the | 461 // can't work. What really needs to happen is to push through the |
462 // NSWindow event machinery so that we can say "two independent clicks | 462 // NSWindow event machinery so that we can say "two independent clicks |
463 // at the same location have the right effect". Once that is done, it | 463 // at the same location have the right effect". Once that is done, it |
464 // might make sense to revise the other tests to use the same | 464 // might make sense to revise the other tests to use the same |
465 // machinery. | 465 // machinery. |
466 | 466 |
467 // Double-click selects word, not select all. | 467 // Double-click selects word, not select all. |
468 TEST_F(AutocompleteTextFieldTest, DoubleClickSelectsWord) { | 468 TEST_F(AutocompleteTextFieldTest, DoubleClickSelectsWord) { |
469 EXPECT_FALSE([field_ currentEditor]); | 469 EXPECT_FALSE([field_ currentEditor]); |
470 | 470 |
471 const NSPoint point(NSMakePoint(20.0, 5.0)); | 471 const NSPoint point = NSMakePoint(20.0, NSMidY([field_ bounds])); |
472 NSEvent* downEvent(Event(field_, point, NSLeftMouseDown, 1)); | 472 NSEvent* downEvent(Event(field_, point, NSLeftMouseDown, 1)); |
473 NSEvent* upEvent(Event(field_, point, NSLeftMouseUp, 1)); | 473 NSEvent* upEvent(Event(field_, point, NSLeftMouseUp, 1)); |
474 NSEvent* downEvent2(Event(field_, point, NSLeftMouseDown, 2)); | 474 NSEvent* downEvent2(Event(field_, point, NSLeftMouseDown, 2)); |
475 NSEvent* upEvent2(Event(field_, point, NSLeftMouseUp, 2)); | 475 NSEvent* upEvent2(Event(field_, point, NSLeftMouseUp, 2)); |
476 [NSApp postEvent:upEvent atStart:YES]; | 476 [NSApp postEvent:upEvent atStart:YES]; |
477 [field_ mouseDown:downEvent]; | 477 [field_ mouseDown:downEvent]; |
478 [NSApp postEvent:upEvent2 atStart:YES]; | 478 [NSApp postEvent:upEvent2 atStart:YES]; |
479 [field_ mouseDown:downEvent2]; | 479 [field_ mouseDown:downEvent2]; |
480 EXPECT_TRUE([field_ currentEditor]); | 480 EXPECT_TRUE([field_ currentEditor]); |
481 | 481 |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 scoped_nsobject<AutocompleteTextField> pin([field_ retain]); | 768 scoped_nsobject<AutocompleteTextField> pin([field_ retain]); |
769 [field_ removeFromSuperview]; | 769 [field_ removeFromSuperview]; |
770 [test_window() resignKeyWindow]; | 770 [test_window() resignKeyWindow]; |
771 | 771 |
772 [[test_window() contentView] addSubview:field_]; | 772 [[test_window() contentView] addSubview:field_]; |
773 EXPECT_CALL(field_observer_, ClosePopup()); | 773 EXPECT_CALL(field_observer_, ClosePopup()); |
774 [test_window() resignKeyWindow]; | 774 [test_window() resignKeyWindow]; |
775 } | 775 } |
776 | 776 |
777 } // namespace | 777 } // namespace |
OLD | NEW |