| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/scoped_nsobject.h" | |
| 6 #include "chrome/browser/character_encoding.h" | |
| 7 #include "chrome/browser/profiles/profile.h" | |
| 8 #include "chrome/browser/ui/cocoa/browser_test_helper.h" | |
| 9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
| 10 #import "chrome/browser/ui/cocoa/options/font_language_settings_controller.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 #import "testing/gtest_mac.h" | |
| 13 #include "testing/platform_test.h" | |
| 14 | |
| 15 // The FontLanguageSettingsControllerForTest overrides the getFontFieldOrigin | |
| 16 // method to provide a dummy point, so we don't have to actually display the | |
| 17 // window to test the controller. | |
| 18 @interface FontLanguageSettingsControllerForTest : | |
| 19 FontLanguageSettingsController { | |
| 20 } | |
| 21 | |
| 22 - (NSPoint)getFontFieldOrigin:(NSTextField*)field | |
| 23 forLabel:(NSTextField*)label; | |
| 24 | |
| 25 @end | |
| 26 | |
| 27 @implementation FontLanguageSettingsControllerForTest | |
| 28 | |
| 29 - (NSPoint)getFontFieldOrigin:(NSTextField*)field | |
| 30 forLabel:(NSTextField*)label { | |
| 31 return NSMakePoint(10, 10); | |
| 32 } | |
| 33 | |
| 34 @end | |
| 35 | |
| 36 @interface FontLanguageSettingsController (Testing) | |
| 37 - (void)updateDisplayField:(NSTextField*)field | |
| 38 withFont:(NSFont*)font | |
| 39 withLabel:(NSTextField*)label; | |
| 40 @end | |
| 41 | |
| 42 class FontLanguageSettingsControllerTest : public CocoaTest { | |
| 43 public: | |
| 44 FontLanguageSettingsControllerTest() { | |
| 45 Profile* profile = helper_.profile(); | |
| 46 font_controller_.reset([[FontLanguageSettingsControllerForTest alloc] | |
| 47 initWithProfile:profile]); | |
| 48 } | |
| 49 ~FontLanguageSettingsControllerTest() {} | |
| 50 | |
| 51 BrowserTestHelper helper_; | |
| 52 scoped_nsobject<FontLanguageSettingsController> font_controller_; | |
| 53 }; | |
| 54 | |
| 55 TEST_F(FontLanguageSettingsControllerTest, Init) { | |
| 56 ASSERT_EQ(CharacterEncoding::GetSupportCanonicalEncodingCount(), | |
| 57 static_cast<int>([[font_controller_ encodings] count])); | |
| 58 } | |
| 59 | |
| 60 TEST_F(FontLanguageSettingsControllerTest, UpdateDisplayField) { | |
| 61 NSFont* font = [NSFont fontWithName:@"Times-Roman" size:12.0]; | |
| 62 scoped_nsobject<NSTextField> field( | |
| 63 [[NSTextField alloc] initWithFrame:NSMakeRect(100, 100, 100, 100)]); | |
| 64 scoped_nsobject<NSTextField> label( | |
| 65 [[NSTextField alloc] initWithFrame:NSMakeRect(100, 100, 100, 100)]); | |
| 66 [font_controller_ updateDisplayField:field.get() | |
| 67 withFont:font | |
| 68 withLabel:label]; | |
| 69 | |
| 70 ASSERT_NSEQ([font fontName], [[field font] fontName]); | |
| 71 ASSERT_NSEQ(@"Times-Roman, 12", [field stringValue]); | |
| 72 } | |
| 73 | |
| 74 TEST_F(FontLanguageSettingsControllerTest, UpdateDisplayFieldNilFont) { | |
| 75 scoped_nsobject<NSTextField> field( | |
| 76 [[NSTextField alloc] initWithFrame:NSMakeRect(100, 100, 100, 100)]); | |
| 77 scoped_nsobject<NSTextField> label( | |
| 78 [[NSTextField alloc] initWithFrame:NSMakeRect(100, 100, 100, 100)]); | |
| 79 [field setStringValue:@"foo"]; | |
| 80 [font_controller_ updateDisplayField:field.get() | |
| 81 withFont:nil | |
| 82 withLabel:label]; | |
| 83 | |
| 84 ASSERT_NSEQ(@"foo", [field stringValue]); | |
| 85 } | |
| 86 | |
| 87 TEST_F(FontLanguageSettingsControllerTest, UpdateDisplayFieldNilField) { | |
| 88 // Don't crash. | |
| 89 NSFont* font = [NSFont fontWithName:@"Times-Roman" size:12.0]; | |
| 90 [font_controller_ updateDisplayField:nil withFont:font withLabel:nil]; | |
| 91 } | |
| OLD | NEW |