| 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 #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/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "testing/platform_test.h" | 16 #include "testing/platform_test.h" |
| 17 | 17 |
| 18 using ::testing::InSequence; | 18 using ::testing::InSequence; |
| 19 using ::testing::Return; | 19 using ::testing::Return; |
| 20 using ::testing::StrictMock; | 20 using ::testing::StrictMock; |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 class MockSecurityImageView : public LocationBarViewMac::SecurityImageView { | 23 class MockSecurityImageView : public LocationBarViewMac::SecurityImageView { |
| 24 public: | 24 public: |
| 25 MockSecurityImageView(LocationBarViewMac* owner, | 25 MockSecurityImageView(LocationBarViewMac* owner, |
| 26 Profile* profile, | 26 Profile* profile, |
| 27 ToolbarModel* model) | 27 ToolbarModel* model) |
| 28 : LocationBarViewMac::SecurityImageView(owner, profile, model) {} | 28 : LocationBarViewMac::SecurityImageView(owner, profile, model) {} |
| 29 | 29 |
| 30 MOCK_METHOD0(OnMousePressed, bool()); | 30 // We can't use gmock's MOCK_METHOD macro, because it doesn't like the |
| 31 // NSRect argument to OnMousePressed. |
| 32 virtual void OnMousePressed(NSRect bounds) { |
| 33 mouse_was_pressed_ = true; |
| 34 } |
| 35 bool mouse_was_pressed_; |
| 31 }; | 36 }; |
| 32 | 37 |
| 33 class MockPageActionImageView : public LocationBarViewMac::PageActionImageView { | 38 class MockPageActionImageView : public LocationBarViewMac::PageActionImageView { |
| 34 public: | 39 public: |
| 35 MockPageActionImageView() {} | 40 MockPageActionImageView() {} |
| 36 virtual ~MockPageActionImageView() {} | 41 virtual ~MockPageActionImageView() {} |
| 37 | 42 |
| 38 // We can't use gmock's MOCK_METHOD macro, because it doesn't like the | 43 // We can't use gmock's MOCK_METHOD macro, because it doesn't like the |
| 39 // NSRect argument to OnMousePressed. | 44 // NSRect argument to OnMousePressed. |
| 40 virtual bool OnMousePressed(NSRect bounds) { | 45 virtual void OnMousePressed(NSRect bounds) { |
| 41 mouse_was_pressed_ = true; | 46 mouse_was_pressed_ = true; |
| 42 return true; | |
| 43 } | 47 } |
| 44 | 48 |
| 45 bool MouseWasPressed() { return mouse_was_pressed_; } | 49 bool MouseWasPressed() { return mouse_was_pressed_; } |
| 46 | 50 |
| 47 private: | 51 private: |
| 48 bool mouse_was_pressed_; | 52 bool mouse_was_pressed_; |
| 49 }; | 53 }; |
| 50 | 54 |
| 51 // TODO(shess): Consider lifting this to | 55 // TODO(shess): Consider lifting this to |
| 52 // autocomplete_text_field_unittest_helper.h to share this with the | 56 // autocomplete_text_field_unittest_helper.h to share this with the |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 MockSecurityImageView security_image_view(NULL, NULL, NULL); | 582 MockSecurityImageView security_image_view(NULL, NULL, NULL); |
| 579 [cell setSecurityImageView:&security_image_view]; | 583 [cell setSecurityImageView:&security_image_view]; |
| 580 security_image_view.SetImageShown( | 584 security_image_view.SetImageShown( |
| 581 LocationBarViewMac::SecurityImageView::LOCK); | 585 LocationBarViewMac::SecurityImageView::LOCK); |
| 582 security_image_view.SetVisible(true); | 586 security_image_view.SetVisible(true); |
| 583 | 587 |
| 584 NSRect iconFrame([cell securityImageFrameForFrame:[field_ bounds]]); | 588 NSRect iconFrame([cell securityImageFrameForFrame:[field_ bounds]]); |
| 585 NSPoint location(NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame))); | 589 NSPoint location(NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame))); |
| 586 NSEvent* event(Event(field_, location, NSLeftMouseDown, 1)); | 590 NSEvent* event(Event(field_, location, NSLeftMouseDown, 1)); |
| 587 | 591 |
| 588 EXPECT_CALL(security_image_view, OnMousePressed()); | |
| 589 [field_ mouseDown:event]; | 592 [field_ mouseDown:event]; |
| 593 EXPECT_TRUE(security_image_view.mouse_was_pressed_); |
| 590 } | 594 } |
| 591 | 595 |
| 592 // Clicking a Page Action icon should call its OnMousePressed. | 596 // Clicking a Page Action icon should call its OnMousePressed. |
| 593 TEST_F(AutocompleteTextFieldObserverTest, PageActionMouseDown) { | 597 TEST_F(AutocompleteTextFieldObserverTest, PageActionMouseDown) { |
| 594 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; | 598 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; |
| 595 | 599 |
| 596 MockSecurityImageView security_image_view(NULL, NULL, NULL); | 600 MockSecurityImageView security_image_view(NULL, NULL, NULL); |
| 597 security_image_view.SetImageShown( | 601 security_image_view.SetImageShown( |
| 598 LocationBarViewMac::SecurityImageView::LOCK); | 602 LocationBarViewMac::SecurityImageView::LOCK); |
| 599 [cell setSecurityImageView:&security_image_view]; | 603 [cell setSecurityImageView:&security_image_view]; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame)); | 654 location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame)); |
| 651 event = Event(field_, location, NSLeftMouseDown, 1); | 655 event = Event(field_, location, NSLeftMouseDown, 1); |
| 652 | 656 |
| 653 [field_ mouseDown:event]; | 657 [field_ mouseDown:event]; |
| 654 EXPECT_TRUE(page_action_view.MouseWasPressed()); | 658 EXPECT_TRUE(page_action_view.MouseWasPressed()); |
| 655 | 659 |
| 656 iconFrame = [cell securityImageFrameForFrame:[field_ bounds]]; | 660 iconFrame = [cell securityImageFrameForFrame:[field_ bounds]]; |
| 657 location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame)); | 661 location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame)); |
| 658 event = Event(field_, location, NSLeftMouseDown, 1); | 662 event = Event(field_, location, NSLeftMouseDown, 1); |
| 659 | 663 |
| 660 EXPECT_CALL(security_image_view, OnMousePressed()); | |
| 661 [field_ mouseDown:event]; | 664 [field_ mouseDown:event]; |
| 665 EXPECT_TRUE(security_image_view.mouse_was_pressed_); |
| 662 } | 666 } |
| 663 | 667 |
| 664 // Verify that -setAttributedStringValue: works as expected when | 668 // Verify that -setAttributedStringValue: works as expected when |
| 665 // focussed or when not focussed. Our code mostly depends on about | 669 // focussed or when not focussed. Our code mostly depends on about |
| 666 // whether -stringValue works right. | 670 // whether -stringValue works right. |
| 667 TEST_F(AutocompleteTextFieldTest, SetAttributedStringBaseline) { | 671 TEST_F(AutocompleteTextFieldTest, SetAttributedStringBaseline) { |
| 668 EXPECT_EQ(nil, [field_ currentEditor]); | 672 EXPECT_EQ(nil, [field_ currentEditor]); |
| 669 | 673 |
| 670 // So that we can set rich text. | 674 // So that we can set rich text. |
| 671 [field_ setAllowsEditingTextAttributes:YES]; | 675 [field_ setAllowsEditingTextAttributes:YES]; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 scoped_nsobject<AutocompleteTextField> pin([field_ retain]); | 799 scoped_nsobject<AutocompleteTextField> pin([field_ retain]); |
| 796 [field_ removeFromSuperview]; | 800 [field_ removeFromSuperview]; |
| 797 [test_window() resignKeyWindow]; | 801 [test_window() resignKeyWindow]; |
| 798 | 802 |
| 799 [[test_window() contentView] addSubview:field_]; | 803 [[test_window() contentView] addSubview:field_]; |
| 800 EXPECT_CALL(field_observer_, OnDidResignKey()); | 804 EXPECT_CALL(field_observer_, OnDidResignKey()); |
| 801 [test_window() resignKeyWindow]; | 805 [test_window() resignKeyWindow]; |
| 802 } | 806 } |
| 803 | 807 |
| 804 } // namespace | 808 } // namespace |
| OLD | NEW |