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 #import "base/cocoa_protocols_mac.h" | 7 #import "base/cocoa_protocols_mac.h" |
8 #include "base/scoped_nsobject.h" | 8 #include "base/scoped_nsobject.h" |
9 #import "chrome/browser/cocoa/autocomplete_text_field.h" | 9 #import "chrome/browser/cocoa/autocomplete_text_field.h" |
10 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" | 10 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" |
11 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" | 11 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" |
12 #import "chrome/browser/cocoa/autocomplete_text_field_unittest_helper.h" | 12 #import "chrome/browser/cocoa/autocomplete_text_field_unittest_helper.h" |
13 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 13 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "testing/platform_test.h" | 16 #include "testing/platform_test.h" |
16 #import "third_party/ocmock/OCMock/OCMock.h" | 17 #import "third_party/ocmock/OCMock/OCMock.h" |
17 | 18 |
18 using ::testing::InSequence; | 19 using ::testing::InSequence; |
19 | 20 |
20 // OCMock wants to mock a concrete class or protocol. This should | 21 // OCMock wants to mock a concrete class or protocol. This should |
21 // provide a correct protocol for newer versions of the SDK, while | 22 // provide a correct protocol for newer versions of the SDK, while |
22 // providing something mockable for older versions. | 23 // providing something mockable for older versions. |
23 | 24 |
24 @protocol MockTextEditingDelegate<NSControlTextEditingDelegate> | 25 @protocol MockTextEditingDelegate<NSControlTextEditingDelegate> |
25 - (void)controlTextDidBeginEditing:(NSNotification*)aNotification; | 26 - (void)controlTextDidBeginEditing:(NSNotification*)aNotification; |
26 - (BOOL)control:(NSControl*)control textShouldEndEditing:(NSText*)fieldEditor; | 27 - (BOOL)control:(NSControl*)control textShouldEndEditing:(NSText*)fieldEditor; |
27 @end | 28 @end |
28 | 29 |
29 namespace { | 30 namespace { |
| 31 // Mock a SecurityImageView. |
| 32 class MockSecurityImageView : public LocationBarViewMac::SecurityImageView { |
| 33 public: |
| 34 MockSecurityImageView(Profile* profile, ToolbarModel* model) |
| 35 : LocationBarViewMac::SecurityImageView(profile, model) {} |
| 36 |
| 37 MOCK_METHOD0(OnMousePressed, bool()); |
| 38 }; |
30 | 39 |
31 // Mock up an incrementing event number. | 40 // Mock up an incrementing event number. |
32 NSUInteger eventNumber = 0; | 41 NSUInteger eventNumber = 0; |
33 | 42 |
34 // Create an event of the indicated |type| at |point| within |view|. | 43 // Create an event of the indicated |type| at |point| within |view|. |
35 // TODO(shess): Would be nice to have a MockApplication which provided | 44 // TODO(shess): Would be nice to have a MockApplication which provided |
36 // nifty accessors to create these things and inject them. It could | 45 // nifty accessors to create these things and inject them. It could |
37 // even provide functions for "Click and drag mouse from point A to | 46 // even provide functions for "Click and drag mouse from point A to |
38 // point B". | 47 // point B". |
39 NSEvent* Event(NSView* view, const NSPoint point, const NSEventType type, | 48 NSEvent* Event(NSView* view, const NSPoint point, const NSEventType type, |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 EXPECT_TRUE([field_ currentEditor]); | 570 EXPECT_TRUE([field_ currentEditor]); |
562 | 571 |
563 // Selected the first word. | 572 // Selected the first word. |
564 const NSRange selectedRange([[field_ currentEditor] selectedRange]); | 573 const NSRange selectedRange([[field_ currentEditor] selectedRange]); |
565 EXPECT_EQ(selectedRange.location, 0U); | 574 EXPECT_EQ(selectedRange.location, 0U); |
566 EXPECT_EQ(selectedRange.length, [[field_ stringValue] length]); | 575 EXPECT_EQ(selectedRange.length, [[field_ stringValue] length]); |
567 } | 576 } |
568 | 577 |
569 TEST_F(AutocompleteTextFieldTest, SecurityIconMouseDown) { | 578 TEST_F(AutocompleteTextFieldTest, SecurityIconMouseDown) { |
570 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; | 579 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; |
571 scoped_nsobject<NSImage> hintIcon( | 580 |
572 [[NSImage alloc] initWithSize:NSMakeSize(20, 20)]); | 581 MockSecurityImageView security_image_view(NULL, NULL); |
573 [cell setHintIcon:hintIcon.get() label:nil color:nil]; | 582 [cell setSecurityImageView:&security_image_view]; |
574 NSRect iconFrame([cell hintImageFrameForFrame:[field_ bounds]]); | 583 security_image_view.SetImageShown( |
| 584 LocationBarViewMac::SecurityImageView::LOCK); |
| 585 security_image_view.SetVisible(true); |
| 586 |
| 587 NSRect iconFrame([cell securityImageFrameForFrame:[field_ bounds]]); |
575 NSPoint location(NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame))); | 588 NSPoint location(NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame))); |
576 NSEvent* event(Event(field_, location, NSLeftMouseDown, 1)); | 589 NSEvent* event(Event(field_, location, NSLeftMouseDown, 1)); |
577 EXPECT_CALL(field_observer_, OnSecurityIconClicked()); | 590 |
| 591 EXPECT_CALL(security_image_view, OnMousePressed()); |
578 [field_ mouseDown:event]; | 592 [field_ mouseDown:event]; |
579 } | 593 } |
580 | 594 |
581 } // namespace | 595 } // namespace |
OLD | NEW |