OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "base/mac/scoped_nsobject.h" | 5 #include "base/mac/scoped_nsobject.h" |
6 #include "testing/gtest_mac.h" | 6 #include "testing/gtest_mac.h" |
7 #import "ui/base/cocoa/controls/hyperlink_text_view.h" | 7 #import "ui/base/cocoa/controls/hyperlink_text_view.h" |
8 #import "ui/gfx/test/ui_cocoa_test_helper.h" | 8 #import "ui/gfx/test/ui_cocoa_test_helper.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 TEST_VIEW(HyperlinkTextViewTest, view_); | 58 TEST_VIEW(HyperlinkTextViewTest, view_); |
59 | 59 |
60 TEST_F(HyperlinkTextViewTest, TestViewConfiguration) { | 60 TEST_F(HyperlinkTextViewTest, TestViewConfiguration) { |
61 EXPECT_FALSE([view_ isEditable]); | 61 EXPECT_FALSE([view_ isEditable]); |
62 EXPECT_FALSE([view_ drawsBackground]); | 62 EXPECT_FALSE([view_ drawsBackground]); |
63 EXPECT_FALSE([view_ isHorizontallyResizable]); | 63 EXPECT_FALSE([view_ isHorizontallyResizable]); |
64 EXPECT_FALSE([view_ isVerticallyResizable]); | 64 EXPECT_FALSE([view_ isVerticallyResizable]); |
65 } | 65 } |
66 | 66 |
67 TEST_F(HyperlinkTextViewTest, LinkInsertion) { | |
68 // Test that setMessage:withLink:... inserts the link text. | |
69 [view_ setMessageAndLink:@"This is a short text message" | |
70 withLink:@"alarmingly " | |
71 atOffset:10 | |
72 font:GetDefaultFont() | |
73 messageColor:[NSColor blackColor] | |
74 linkColor:[NSColor blueColor]]; | |
75 EXPECT_NSEQ(@"This is a alarmingly short text message", | |
76 [[view_ textStorage] string]); | |
77 | |
78 // Test insertion at end - most common use case. | |
79 NSString* message=@"This is another test message "; | |
80 [view_ setMessageAndLink:message | |
81 withLink:@"with link" | |
82 atOffset:[message length] | |
83 font:GetDefaultFont() | |
84 messageColor:[NSColor blackColor] | |
85 linkColor:[NSColor blueColor]]; | |
86 EXPECT_NSEQ(@"This is another test message with link", | |
87 [[view_ textStorage] string]); | |
88 } | |
89 | |
90 TEST_F(HyperlinkTextViewTest, AttributesForMessageWithLink) { | |
91 // Verifies text attributes are set as expected for setMessageWithLink:... | |
92 [view_ setMessageAndLink:@"aaabbbbb" | |
93 withLink:@"xxxx" | |
94 atOffset:3 | |
95 font:GetDefaultFont() | |
96 messageColor:[NSColor blackColor] | |
97 linkColor:[NSColor blueColor]]; | |
98 | |
99 NSDictionary* attributes; | |
100 NSRange rangeLimit = NSMakeRange(0, 12); | |
101 NSRange range; | |
102 attributes = [[view_ textStorage] attributesAtIndex:0 | |
103 longestEffectiveRange:&range | |
104 inRange:rangeLimit]; | |
105 EXPECT_EQ(0U, range.location); | |
106 EXPECT_EQ(3U, range.length); | |
107 EXPECT_NSEQ(GetDefaultTextAttributes(), attributes); | |
108 | |
109 attributes = [[view_ textStorage] attributesAtIndex:3 | |
110 longestEffectiveRange:&range | |
111 inRange:rangeLimit]; | |
112 EXPECT_EQ(3U, range.location); | |
113 EXPECT_EQ(4U, range.length); | |
114 EXPECT_NSEQ(GetDefaultLinkAttributes(), attributes); | |
115 | |
116 attributes = [[view_ textStorage] attributesAtIndex:7 | |
117 longestEffectiveRange:&range | |
118 inRange:rangeLimit]; | |
119 EXPECT_EQ(7U, range.location); | |
120 EXPECT_EQ(5U, range.length); | |
121 EXPECT_NSEQ(GetDefaultTextAttributes(), attributes); | |
122 | |
123 } | |
124 | |
125 TEST_F(HyperlinkTextViewTest, TestSetMessage) { | 67 TEST_F(HyperlinkTextViewTest, TestSetMessage) { |
126 // Verifies setMessage sets text and attributes properly. | 68 // Verifies setMessage sets text and attributes properly. |
127 NSString* message = @"Test message"; | 69 NSString* message = @"Test message"; |
128 [view_ setMessage:message | 70 [view_ setMessage:message |
129 withFont:GetDefaultFont() | 71 withFont:GetDefaultFont() |
130 messageColor:[NSColor blackColor]]; | 72 messageColor:[NSColor blackColor]]; |
131 EXPECT_NSEQ(@"Test message", [[view_ textStorage] string]); | 73 EXPECT_NSEQ(@"Test message", [[view_ textStorage] string]); |
132 | 74 |
133 NSDictionary* attributes; | 75 NSDictionary* attributes; |
134 NSRange rangeLimit = NSMakeRange(0, [message length]); | 76 NSRange rangeLimit = NSMakeRange(0, [message length]); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 130 |
189 TEST_F(HyperlinkTextViewTest, FirstResponderBehavior) { | 131 TEST_F(HyperlinkTextViewTest, FirstResponderBehavior) { |
190 // By default, accept. | 132 // By default, accept. |
191 EXPECT_TRUE([view_ acceptsFirstResponder]); | 133 EXPECT_TRUE([view_ acceptsFirstResponder]); |
192 | 134 |
193 [view_ setRefusesFirstResponder:YES]; | 135 [view_ setRefusesFirstResponder:YES]; |
194 EXPECT_FALSE([view_ acceptsFirstResponder]); | 136 EXPECT_FALSE([view_ acceptsFirstResponder]); |
195 } | 137 } |
196 | 138 |
197 } // namespace | 139 } // namespace |
OLD | NEW |