| 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" |
| 11 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h" | 11 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h" |
| 12 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_editor.h" | 12 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_editor.h" |
| 13 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_unittest_help
er.h" | 13 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_unittest_help
er.h" |
| 14 #import "chrome/browser/cocoa/location_bar/location_bar_decoration.h" | 14 #import "chrome/browser/cocoa/location_bar/location_bar_decoration.h" |
| 15 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 15 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #import "testing/gtest_mac.h" |
| 19 #include "testing/platform_test.h" | 20 #include "testing/platform_test.h" |
| 20 | 21 |
| 21 using ::testing::InSequence; | 22 using ::testing::InSequence; |
| 22 using ::testing::Return; | 23 using ::testing::Return; |
| 23 using ::testing::StrictMock; | 24 using ::testing::StrictMock; |
| 24 using ::testing::_; | 25 using ::testing::_; |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 class MockDecoration : public LocationBarDecoration { | 29 class MockDecoration : public LocationBarDecoration { |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 size:[[field_ font] pointSize] + 2]; | 648 size:[[field_ font] pointSize] + 2]; |
| 648 NSDictionary* attributes = | 649 NSDictionary* attributes = |
| 649 [NSDictionary dictionaryWithObject:font | 650 [NSDictionary dictionaryWithObject:font |
| 650 forKey:NSFontAttributeName]; | 651 forKey:NSFontAttributeName]; |
| 651 NSString* const kString = @"This is a test"; | 652 NSString* const kString = @"This is a test"; |
| 652 scoped_nsobject<NSAttributedString> attributedString( | 653 scoped_nsobject<NSAttributedString> attributedString( |
| 653 [[NSAttributedString alloc] initWithString:kString | 654 [[NSAttributedString alloc] initWithString:kString |
| 654 attributes:attributes]); | 655 attributes:attributes]); |
| 655 | 656 |
| 656 // Check that what we get back looks like what we put in. | 657 // Check that what we get back looks like what we put in. |
| 657 EXPECT_FALSE([[field_ stringValue] isEqualToString:kString]); | 658 EXPECT_NSNE(kString, [field_ stringValue]); |
| 658 [field_ setAttributedStringValue:attributedString]; | 659 [field_ setAttributedStringValue:attributedString]; |
| 659 EXPECT_TRUE([[field_ attributedStringValue] | 660 EXPECT_TRUE([[field_ attributedStringValue] |
| 660 isEqualToAttributedString:attributedString]); | 661 isEqualToAttributedString:attributedString]); |
| 661 EXPECT_TRUE([[field_ stringValue] isEqualToString:kString]); | 662 EXPECT_NSEQ(kString, [field_ stringValue]); |
| 662 | 663 |
| 663 // Try that again with focus. | 664 // Try that again with focus. |
| 664 [test_window() makePretendKeyWindowAndSetFirstResponder:field_]; | 665 [test_window() makePretendKeyWindowAndSetFirstResponder:field_]; |
| 665 | 666 |
| 666 EXPECT_TRUE([field_ currentEditor]); | 667 EXPECT_TRUE([field_ currentEditor]); |
| 667 | 668 |
| 668 // Check that what we get back looks like what we put in. | 669 // Check that what we get back looks like what we put in. |
| 669 [field_ setStringValue:@""]; | 670 [field_ setStringValue:@""]; |
| 670 EXPECT_FALSE([[field_ stringValue] isEqualToString:kString]); | 671 EXPECT_NSNE(kString, [field_ stringValue]); |
| 671 [field_ setAttributedStringValue:attributedString]; | 672 [field_ setAttributedStringValue:attributedString]; |
| 672 EXPECT_TRUE([[field_ attributedStringValue] | 673 EXPECT_TRUE([[field_ attributedStringValue] |
| 673 isEqualToAttributedString:attributedString]); | 674 isEqualToAttributedString:attributedString]); |
| 674 EXPECT_TRUE([[field_ stringValue] isEqualToString:kString]); | 675 EXPECT_NSEQ(kString, [field_ stringValue]); |
| 675 } | 676 } |
| 676 | 677 |
| 677 // -setAttributedStringValue: shouldn't reset the undo state if things | 678 // -setAttributedStringValue: shouldn't reset the undo state if things |
| 678 // are being editted. | 679 // are being editted. |
| 679 TEST_F(AutocompleteTextFieldTest, SetAttributedStringUndo) { | 680 TEST_F(AutocompleteTextFieldTest, SetAttributedStringUndo) { |
| 680 NSColor* redColor = [NSColor redColor]; | 681 NSColor* redColor = [NSColor redColor]; |
| 681 NSDictionary* attributes = | 682 NSDictionary* attributes = |
| 682 [NSDictionary dictionaryWithObject:redColor | 683 [NSDictionary dictionaryWithObject:redColor |
| 683 forKey:NSForegroundColorAttributeName]; | 684 forKey:NSForegroundColorAttributeName]; |
| 684 NSString* const kString = @"This is a test"; | 685 NSString* const kString = @"This is a test"; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 scoped_nsobject<AutocompleteTextField> pin([field_ retain]); | 769 scoped_nsobject<AutocompleteTextField> pin([field_ retain]); |
| 769 [field_ removeFromSuperview]; | 770 [field_ removeFromSuperview]; |
| 770 [test_window() resignKeyWindow]; | 771 [test_window() resignKeyWindow]; |
| 771 | 772 |
| 772 [[test_window() contentView] addSubview:field_]; | 773 [[test_window() contentView] addSubview:field_]; |
| 773 EXPECT_CALL(field_observer_, ClosePopup()); | 774 EXPECT_CALL(field_observer_, ClosePopup()); |
| 774 [test_window() resignKeyWindow]; | 775 [test_window() resignKeyWindow]; |
| 775 } | 776 } |
| 776 | 777 |
| 777 } // namespace | 778 } // namespace |
| OLD | NEW |