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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 EXPECT_NSEQ(GetDefaultTextAttributes(), attributes); | 83 EXPECT_NSEQ(GetDefaultTextAttributes(), attributes); |
84 } | 84 } |
85 | 85 |
86 TEST_F(HyperlinkTextViewTest, TestAddLinkRange) { | 86 TEST_F(HyperlinkTextViewTest, TestAddLinkRange) { |
87 NSString* message = @"One Two Three Four"; | 87 NSString* message = @"One Two Three Four"; |
88 [view_ setMessage:message | 88 [view_ setMessage:message |
89 withFont:GetDefaultFont() | 89 withFont:GetDefaultFont() |
90 messageColor:[NSColor blackColor]]; | 90 messageColor:[NSColor blackColor]]; |
91 | 91 |
92 NSColor* blue = [NSColor blueColor]; | 92 NSColor* blue = [NSColor blueColor]; |
93 [view_ addLinkRange:NSMakeRange(4,3) withName:@"Name:Two" linkColor:blue]; | 93 [view_ addLinkRange:NSMakeRange(4,3) withURL:@"http://2" linkColor:blue]; |
94 [view_ addLinkRange:NSMakeRange(14,4) withName:@"Name:Four" linkColor:blue]; | 94 [view_ addLinkRange:NSMakeRange(14,4) withURL:@"http://4" linkColor:blue]; |
95 | 95 |
96 NSDictionary* attributes; | 96 NSDictionary* attributes; |
97 NSRange rangeLimit = NSMakeRange(0, [message length]); | 97 NSRange rangeLimit = NSMakeRange(0, [message length]); |
98 NSRange range; | 98 NSRange range; |
99 attributes = [[view_ textStorage] attributesAtIndex:0 | 99 attributes = [[view_ textStorage] attributesAtIndex:0 |
100 longestEffectiveRange:&range | 100 longestEffectiveRange:&range |
101 inRange:rangeLimit]; | 101 inRange:rangeLimit]; |
102 EXPECT_EQ(0U, range.location); | 102 EXPECT_EQ(0U, range.location); |
103 EXPECT_EQ(4U, range.length); | 103 EXPECT_EQ(4U, range.length); |
104 EXPECT_NSEQ(GetDefaultTextAttributes(), attributes); | 104 EXPECT_NSEQ(GetDefaultTextAttributes(), attributes); |
105 | 105 |
106 NSMutableDictionary* linkAttributes = GetDefaultLinkAttributes(); | 106 NSMutableDictionary* linkAttributes = GetDefaultLinkAttributes(); |
107 [linkAttributes setObject:@"Name:Two" forKey:NSLinkAttributeName]; | 107 [linkAttributes setObject:@"http://2" forKey:NSLinkAttributeName]; |
108 attributes = [[view_ textStorage] attributesAtIndex:4 | 108 attributes = [[view_ textStorage] attributesAtIndex:4 |
109 longestEffectiveRange:&range | 109 longestEffectiveRange:&range |
110 inRange:rangeLimit]; | 110 inRange:rangeLimit]; |
111 EXPECT_EQ(4U, range.location); | 111 EXPECT_EQ(4U, range.location); |
112 EXPECT_EQ(3U, range.length); | 112 EXPECT_EQ(3U, range.length); |
113 EXPECT_NSEQ(linkAttributes, attributes); | 113 EXPECT_NSEQ(linkAttributes, attributes); |
114 | 114 |
115 attributes = [[view_ textStorage] attributesAtIndex:7 | 115 attributes = [[view_ textStorage] attributesAtIndex:7 |
116 longestEffectiveRange:&range | 116 longestEffectiveRange:&range |
117 inRange:rangeLimit]; | 117 inRange:rangeLimit]; |
118 EXPECT_EQ(7U, range.location); | 118 EXPECT_EQ(7U, range.location); |
119 EXPECT_EQ(7U, range.length); | 119 EXPECT_EQ(7U, range.length); |
120 EXPECT_NSEQ(GetDefaultTextAttributes(), attributes); | 120 EXPECT_NSEQ(GetDefaultTextAttributes(), attributes); |
121 | 121 |
122 [linkAttributes setObject:@"Name:Four" forKey:NSLinkAttributeName]; | 122 [linkAttributes setObject:@"http://4" forKey:NSLinkAttributeName]; |
123 attributes = [[view_ textStorage] attributesAtIndex:14 | 123 attributes = [[view_ textStorage] attributesAtIndex:14 |
124 longestEffectiveRange:&range | 124 longestEffectiveRange:&range |
125 inRange:rangeLimit]; | 125 inRange:rangeLimit]; |
126 EXPECT_EQ(14U, range.location); | 126 EXPECT_EQ(14U, range.location); |
127 EXPECT_EQ(4U, range.length); | 127 EXPECT_EQ(4U, range.length); |
128 EXPECT_NSEQ(linkAttributes, attributes); | 128 EXPECT_NSEQ(linkAttributes, attributes); |
129 } | 129 } |
130 | 130 |
131 TEST_F(HyperlinkTextViewTest, FirstResponderBehavior) { | 131 TEST_F(HyperlinkTextViewTest, FirstResponderBehavior) { |
132 // By default, accept. | 132 // By default, accept. |
133 EXPECT_TRUE([view_ acceptsFirstResponder]); | 133 EXPECT_TRUE([view_ acceptsFirstResponder]); |
134 | 134 |
135 [view_ setRefusesFirstResponder:YES]; | 135 [view_ setRefusesFirstResponder:YES]; |
136 EXPECT_FALSE([view_ acceptsFirstResponder]); | 136 EXPECT_FALSE([view_ acceptsFirstResponder]); |
137 } | 137 } |
138 | 138 |
139 } // namespace | 139 } // namespace |
OLD | NEW |