Chromium Code Reviews| 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 9 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
| 10 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" | 10 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
| 11 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" | 11 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" |
| 12 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" | 12 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" |
| 13 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" | 13 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" |
| 14 #import "chrome/browser/ui/cocoa/location_bar/security_state_bubble_decoration.h " | 14 #import "chrome/browser/ui/cocoa/location_bar/security_state_bubble_decoration.h " |
| 15 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" | 15 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" |
| 16 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" | 16 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
| 17 #import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h" | 17 #import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h" |
| 18 #import "chrome/browser/ui/cocoa/test/scoped_force_rtl_mac.h" | |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #import "testing/gtest_mac.h" | 21 #import "testing/gtest_mac.h" |
| 21 #include "testing/platform_test.h" | 22 #include "testing/platform_test.h" |
| 22 #import "third_party/ocmock/OCMock/OCMock.h" | 23 #import "third_party/ocmock/OCMock/OCMock.h" |
| 23 #include "third_party/ocmock/gtest_support.h" | 24 #include "third_party/ocmock/gtest_support.h" |
| 24 #include "ui/base/material_design/material_design_controller.h" | 25 #include "ui/base/material_design/material_design_controller.h" |
| 25 | 26 |
| 26 using ::testing::Return; | 27 using ::testing::Return; |
| 27 using ::testing::StrictMock; | 28 using ::testing::StrictMock; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 51 base::scoped_nsobject<NSTextField> view( | 52 base::scoped_nsobject<NSTextField> view( |
| 52 [[NSTextField alloc] initWithFrame:frame]); | 53 [[NSTextField alloc] initWithFrame:frame]); |
| 53 view_ = view.get(); | 54 view_ = view.get(); |
| 54 | 55 |
| 55 base::scoped_nsobject<AutocompleteTextFieldCell> cell( | 56 base::scoped_nsobject<AutocompleteTextFieldCell> cell( |
| 56 [[AutocompleteTextFieldCell alloc] initTextCell:@"Testing"]); | 57 [[AutocompleteTextFieldCell alloc] initTextCell:@"Testing"]); |
| 57 [cell setEditable:YES]; | 58 [cell setEditable:YES]; |
| 58 [cell setBordered:YES]; | 59 [cell setBordered:YES]; |
| 59 | 60 |
| 60 [cell clearDecorations]; | 61 [cell clearDecorations]; |
| 61 mock_left_decoration_.SetVisible(false); | 62 mock_leading_decoration_.SetVisible(false); |
| 62 [cell addLeftDecoration:&mock_left_decoration_]; | 63 [cell addLeadingDecoration:&mock_leading_decoration_]; |
| 63 mock_right_decoration0_.SetVisible(false); | 64 mock_trailing_decoration0_.SetVisible(false); |
| 64 mock_right_decoration1_.SetVisible(false); | 65 mock_trailing_decoration1_.SetVisible(false); |
| 65 [cell addRightDecoration:&mock_right_decoration0_]; | 66 [cell addTrailingDecoration:&mock_trailing_decoration0_]; |
| 66 [cell addRightDecoration:&mock_right_decoration1_]; | 67 [cell addTrailingDecoration:&mock_trailing_decoration1_]; |
| 67 | 68 |
| 68 [view_ setCell:cell.get()]; | 69 [view_ setCell:cell.get()]; |
| 69 | 70 |
| 70 [[test_window() contentView] addSubview:view_]; | 71 [[test_window() contentView] addSubview:view_]; |
| 71 } | 72 } |
| 72 | 73 |
| 73 NSTextField* view_; | 74 NSTextField* view_; |
| 74 MockDecoration mock_left_decoration_; | 75 MockDecoration mock_leading_decoration_; |
| 75 MockDecoration mock_right_decoration0_; | 76 MockDecoration mock_trailing_decoration0_; |
| 76 MockDecoration mock_right_decoration1_; | 77 MockDecoration mock_trailing_decoration1_; |
| 77 }; | 78 }; |
| 78 | 79 |
| 79 // Basic view tests (AddRemove, Display). | 80 // Basic view tests (AddRemove, Display). |
| 80 TEST_VIEW(AutocompleteTextFieldCellTest, view_); | 81 TEST_VIEW(AutocompleteTextFieldCellTest, view_); |
| 81 | 82 |
| 82 // Test drawing, mostly to ensure nothing leaks or crashes. | 83 // Test drawing, mostly to ensure nothing leaks or crashes. |
| 83 // Flaky, disabled. Bug http://crbug.com/49522 | 84 // Flaky, disabled. Bug http://crbug.com/49522 |
| 84 TEST_F(AutocompleteTextFieldCellTest, DISABLED_FocusedDisplay) { | 85 TEST_F(AutocompleteTextFieldCellTest, DISABLED_FocusedDisplay) { |
| 85 [view_ display]; | 86 [view_ display]; |
| 86 | 87 |
| 87 // Test focused drawing. | 88 // Test focused drawing. |
| 88 [test_window() makePretendKeyWindowAndSetFirstResponder:view_]; | 89 [test_window() makePretendKeyWindowAndSetFirstResponder:view_]; |
| 89 [view_ display]; | 90 [view_ display]; |
| 90 [test_window() clearPretendKeyWindowAndFirstResponder]; | 91 [test_window() clearPretendKeyWindowAndFirstResponder]; |
| 91 | 92 |
| 92 // Test display of various cell configurations. | 93 // Test display of various cell configurations. |
| 93 AutocompleteTextFieldCell* cell = | 94 AutocompleteTextFieldCell* cell = |
| 94 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 95 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
| 95 | 96 |
| 96 // Load available decorations and try drawing. To make sure that | 97 // Load available decorations and try drawing. To make sure that |
| 97 // they are actually drawn, check that |GetWidthForSpace()| doesn't | 98 // they are actually drawn, check that |GetWidthForSpace()| doesn't |
| 98 // indicate that they should be omitted. | 99 // indicate that they should be omitted. |
| 99 const CGFloat kVeryWide = 1000.0; | 100 const CGFloat kVeryWide = 1000.0; |
| 100 | 101 |
| 101 SelectedKeywordDecoration selected_keyword_decoration; | 102 SelectedKeywordDecoration selected_keyword_decoration; |
| 102 selected_keyword_decoration.SetVisible(true); | 103 selected_keyword_decoration.SetVisible(true); |
| 103 selected_keyword_decoration.SetKeyword(base::ASCIIToUTF16("Google"), false); | 104 selected_keyword_decoration.SetKeyword(base::ASCIIToUTF16("Google"), false); |
| 104 [cell addLeftDecoration:&selected_keyword_decoration]; | 105 [cell addLeadingDecoration:&selected_keyword_decoration]; |
| 105 EXPECT_NE(selected_keyword_decoration.GetWidthForSpace(kVeryWide), | 106 EXPECT_NE(selected_keyword_decoration.GetWidthForSpace(kVeryWide), |
| 106 LocationBarDecoration::kOmittedWidth); | 107 LocationBarDecoration::kOmittedWidth); |
| 107 | 108 |
| 108 // TODO(shess): This really wants a |LocationBarViewMac|, but only a | 109 // TODO(shess): This really wants a |LocationBarViewMac|, but only a |
| 109 // few methods reference it, so this works well enough. But | 110 // few methods reference it, so this works well enough. But |
| 110 // something better would be nice. | 111 // something better would be nice. |
| 111 LocationIconDecoration location_icon_decoration(NULL); | 112 LocationIconDecoration location_icon_decoration(NULL); |
| 112 location_icon_decoration.SetVisible(true); | 113 location_icon_decoration.SetVisible(true); |
| 113 location_icon_decoration.SetImage([NSImage imageNamed:@"NSApplicationIcon"]); | 114 location_icon_decoration.SetImage([NSImage imageNamed:@"NSApplicationIcon"]); |
| 114 [cell addLeftDecoration:&location_icon_decoration]; | 115 [cell addLeadingDecoration:&location_icon_decoration]; |
| 115 EXPECT_NE(location_icon_decoration.GetWidthForSpace(kVeryWide), | 116 EXPECT_NE(location_icon_decoration.GetWidthForSpace(kVeryWide), |
| 116 LocationBarDecoration::kOmittedWidth); | 117 LocationBarDecoration::kOmittedWidth); |
| 117 | 118 |
| 118 SecurityStateBubbleDecoration security_state_bubble_decoration( | 119 SecurityStateBubbleDecoration security_state_bubble_decoration( |
| 119 &location_icon_decoration, nullptr); | 120 &location_icon_decoration, nullptr); |
| 120 security_state_bubble_decoration.SetVisible(true); | 121 security_state_bubble_decoration.SetVisible(true); |
| 121 security_state_bubble_decoration.SetImage( | 122 security_state_bubble_decoration.SetImage( |
| 122 [NSImage imageNamed:@"NSApplicationIcon"]); | 123 [NSImage imageNamed:@"NSApplicationIcon"]); |
| 123 security_state_bubble_decoration.SetLabel(@"Application"); | 124 security_state_bubble_decoration.SetLabel(@"Application"); |
| 124 [cell addLeftDecoration:&security_state_bubble_decoration]; | 125 [cell addLeadingDecoration:&security_state_bubble_decoration]; |
| 125 EXPECT_NE(security_state_bubble_decoration.GetWidthForSpace(kVeryWide), | 126 EXPECT_NE(security_state_bubble_decoration.GetWidthForSpace(kVeryWide), |
| 126 LocationBarDecoration::kOmittedWidth); | 127 LocationBarDecoration::kOmittedWidth); |
| 127 | 128 |
| 128 StarDecoration star_decoration(NULL); | 129 StarDecoration star_decoration(NULL); |
| 129 star_decoration.SetVisible(true); | 130 star_decoration.SetVisible(true); |
| 130 [cell addRightDecoration:&star_decoration]; | 131 [cell addTrailingDecoration:&star_decoration]; |
| 131 EXPECT_NE(star_decoration.GetWidthForSpace(kVeryWide), | 132 EXPECT_NE(star_decoration.GetWidthForSpace(kVeryWide), |
| 132 LocationBarDecoration::kOmittedWidth); | 133 LocationBarDecoration::kOmittedWidth); |
| 133 | 134 |
| 134 KeywordHintDecoration keyword_hint_decoration; | 135 KeywordHintDecoration keyword_hint_decoration; |
| 135 keyword_hint_decoration.SetVisible(true); | 136 keyword_hint_decoration.SetVisible(true); |
| 136 keyword_hint_decoration.SetKeyword(base::ASCIIToUTF16("google"), false); | 137 keyword_hint_decoration.SetKeyword(base::ASCIIToUTF16("google"), false); |
| 137 [cell addRightDecoration:&keyword_hint_decoration]; | 138 [cell addTrailingDecoration:&keyword_hint_decoration]; |
| 138 EXPECT_NE(keyword_hint_decoration.GetWidthForSpace(kVeryWide), | 139 EXPECT_NE(keyword_hint_decoration.GetWidthForSpace(kVeryWide), |
| 139 LocationBarDecoration::kOmittedWidth); | 140 LocationBarDecoration::kOmittedWidth); |
| 140 | 141 |
| 141 // Make sure we're actually calling |DrawInFrame()|. | 142 // Make sure we're actually calling |DrawInFrame()|. |
| 142 StrictMock<MockDecoration> mock_decoration; | 143 StrictMock<MockDecoration> mock_decoration; |
| 143 mock_decoration.SetVisible(true); | 144 mock_decoration.SetVisible(true); |
| 144 [cell addLeftDecoration:&mock_decoration]; | 145 [cell addLeadingDecoration:&mock_decoration]; |
| 145 EXPECT_CALL(mock_decoration, DrawInFrame(_, _)); | 146 EXPECT_CALL(mock_decoration, DrawInFrame(_, _)); |
| 146 EXPECT_NE(mock_decoration.GetWidthForSpace(kVeryWide), | 147 EXPECT_NE(mock_decoration.GetWidthForSpace(kVeryWide), |
| 147 LocationBarDecoration::kOmittedWidth); | 148 LocationBarDecoration::kOmittedWidth); |
| 148 | 149 |
| 149 [view_ display]; | 150 [view_ display]; |
| 150 | 151 |
| 151 [cell clearDecorations]; | 152 [cell clearDecorations]; |
| 152 } | 153 } |
| 153 | 154 |
| 154 TEST_F(AutocompleteTextFieldCellTest, TextFrame) { | 155 TEST_F(AutocompleteTextFieldCellTest, TextFrame) { |
| 155 AutocompleteTextFieldCell* cell = | 156 AutocompleteTextFieldCell* cell = |
| 156 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 157 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
| 157 const NSRect bounds([view_ bounds]); | 158 const NSRect bounds([view_ bounds]); |
| 158 NSRect textFrame; | 159 NSRect textFrame; |
| 159 | 160 |
| 160 // The cursor frame should stay the same throughout. | 161 // The cursor frame should stay the same throughout. |
| 161 const NSRect cursorFrame([cell textCursorFrameForFrame:bounds]); | 162 const NSRect cursorFrame([cell textCursorFrameForFrame:bounds]); |
| 162 EXPECT_NSEQ(cursorFrame, bounds); | 163 EXPECT_NSEQ(cursorFrame, bounds); |
| 163 | 164 |
| 164 // At default settings, everything goes to the text area. | 165 // At default settings, everything goes to the text area. |
| 165 textFrame = [cell textFrameForFrame:bounds]; | 166 textFrame = [cell textFrameForFrame:bounds]; |
| 166 EXPECT_FALSE(NSIsEmptyRect(textFrame)); | 167 EXPECT_FALSE(NSIsEmptyRect(textFrame)); |
| 167 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); | 168 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); |
| 168 EXPECT_EQ(1, NSMinX(textFrame)); | 169 EXPECT_EQ(1, NSMinX(textFrame)); |
| 169 EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame)); | 170 EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame)); |
| 170 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); | 171 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); |
| 171 | 172 |
| 172 // Decoration on the left takes up space. | 173 // Leading decoration takes up space. |
| 173 mock_left_decoration_.SetVisible(true); | 174 mock_leading_decoration_.SetVisible(true); |
| 174 textFrame = [cell textFrameForFrame:bounds]; | 175 textFrame = [cell textFrameForFrame:bounds]; |
| 175 EXPECT_FALSE(NSIsEmptyRect(textFrame)); | 176 EXPECT_FALSE(NSIsEmptyRect(textFrame)); |
| 176 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); | 177 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); |
| 177 EXPECT_GT(NSMinX(textFrame), NSMinX(bounds)); | 178 EXPECT_GT(NSMinX(textFrame), NSMinX(bounds)); |
| 178 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); | 179 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); |
| 179 } | 180 } |
| 180 | 181 |
| 181 // The editor frame should be slightly inset from the text frame. | 182 // The editor frame should be slightly inset from the text frame. |
| 182 TEST_F(AutocompleteTextFieldCellTest, DrawingRectForBounds) { | 183 TEST_F(AutocompleteTextFieldCellTest, DrawingRectForBounds) { |
| 183 AutocompleteTextFieldCell* cell = | 184 AutocompleteTextFieldCell* cell = |
| 184 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 185 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
| 185 const NSRect bounds([view_ bounds]); | 186 const NSRect bounds([view_ bounds]); |
| 186 NSRect textFrame, drawingRect; | 187 NSRect textFrame, drawingRect; |
| 187 | 188 |
| 188 textFrame = [cell textFrameForFrame:bounds]; | 189 textFrame = [cell textFrameForFrame:bounds]; |
| 189 drawingRect = [cell drawingRectForBounds:bounds]; | 190 drawingRect = [cell drawingRectForBounds:bounds]; |
| 190 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); | 191 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); |
| 191 EXPECT_TRUE(NSContainsRect(textFrame, NSInsetRect(drawingRect, 1, 1))); | 192 EXPECT_TRUE(NSContainsRect(textFrame, NSInsetRect(drawingRect, 1, 1))); |
| 192 | 193 |
| 193 // Save the starting frame for after clear. | 194 // Save the starting frame for after clear. |
| 194 const NSRect originalDrawingRect = drawingRect; | 195 const NSRect originalDrawingRect = drawingRect; |
| 195 | 196 |
| 196 mock_left_decoration_.SetVisible(true); | 197 mock_leading_decoration_.SetVisible(true); |
| 197 textFrame = [cell textFrameForFrame:bounds]; | 198 textFrame = [cell textFrameForFrame:bounds]; |
| 198 drawingRect = [cell drawingRectForBounds:bounds]; | 199 drawingRect = [cell drawingRectForBounds:bounds]; |
| 199 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); | 200 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); |
| 200 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect)); | 201 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect)); |
| 201 | 202 |
| 202 mock_right_decoration0_.SetVisible(true); | 203 mock_trailing_decoration0_.SetVisible(true); |
| 203 textFrame = [cell textFrameForFrame:bounds]; | 204 textFrame = [cell textFrameForFrame:bounds]; |
| 204 drawingRect = [cell drawingRectForBounds:bounds]; | 205 drawingRect = [cell drawingRectForBounds:bounds]; |
| 205 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); | 206 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); |
| 206 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect)); | 207 EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect)); |
| 207 | 208 |
| 208 mock_left_decoration_.SetVisible(false); | 209 mock_leading_decoration_.SetVisible(false); |
| 209 mock_right_decoration0_.SetVisible(false); | 210 mock_trailing_decoration0_.SetVisible(false); |
| 210 drawingRect = [cell drawingRectForBounds:bounds]; | 211 drawingRect = [cell drawingRectForBounds:bounds]; |
| 211 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); | 212 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); |
| 212 EXPECT_NSEQ(drawingRect, originalDrawingRect); | 213 EXPECT_NSEQ(drawingRect, originalDrawingRect); |
| 213 } | 214 } |
| 214 | 215 |
| 215 // Test that left decorations are at the correct edge of the cell. | 216 // Test that leading decorations are at the correct edge of the cell. |
| 216 TEST_F(AutocompleteTextFieldCellTest, LeftDecorationFrame) { | 217 TEST_F(AutocompleteTextFieldCellTest, LeadingDecorationFrame) { |
| 217 AutocompleteTextFieldCell* cell = | 218 AutocompleteTextFieldCell* cell = |
| 218 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 219 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
| 219 const NSRect bounds = [view_ bounds]; | 220 const NSRect bounds = [view_ bounds]; |
| 220 | 221 |
| 221 mock_left_decoration_.SetVisible(true); | 222 mock_leading_decoration_.SetVisible(true); |
| 222 const NSRect decorationRect = | 223 const NSRect decorationRect = |
| 223 [cell frameForDecoration:&mock_left_decoration_ inFrame:bounds]; | 224 [cell frameForDecoration:&mock_leading_decoration_ inFrame:bounds]; |
| 224 EXPECT_FALSE(NSIsEmptyRect(decorationRect)); | 225 EXPECT_FALSE(NSIsEmptyRect(decorationRect)); |
| 225 EXPECT_TRUE(NSContainsRect(bounds, decorationRect)); | 226 EXPECT_TRUE(NSContainsRect(bounds, decorationRect)); |
| 226 | 227 |
| 227 // Decoration should be left of |drawingRect|. | 228 // Decoration should be left of |drawingRect|. |
| 228 const NSRect drawingRect = [cell drawingRectForBounds:bounds]; | 229 const NSRect drawingRect = [cell drawingRectForBounds:bounds]; |
| 229 EXPECT_GT(NSMinX(drawingRect), NSMinX(decorationRect)); | 230 EXPECT_GT(NSMinX(drawingRect), NSMinX(decorationRect)); |
| 230 | 231 |
| 231 // Decoration should be left of |textFrame|. | 232 // Decoration should be left of |textFrame|. |
| 232 const NSRect textFrame = [cell textFrameForFrame:bounds]; | 233 const NSRect textFrame = [cell textFrameForFrame:bounds]; |
| 233 EXPECT_GT(NSMinX(textFrame), NSMinX(decorationRect)); | 234 EXPECT_GT(NSMinX(textFrame), NSMinX(decorationRect)); |
| 234 } | 235 } |
| 235 | 236 |
| 236 // Test that right decorations are at the correct edge of the cell. | 237 // Test that trailing decorations are at the correct edge of the cell. |
| 237 TEST_F(AutocompleteTextFieldCellTest, RightDecorationFrame) { | 238 TEST_F(AutocompleteTextFieldCellTest, TrailingDecorationFrame) { |
| 238 AutocompleteTextFieldCell* cell = | 239 AutocompleteTextFieldCell* cell = |
| 239 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 240 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
| 240 const NSRect bounds = [view_ bounds]; | 241 const NSRect bounds = [view_ bounds]; |
| 241 | 242 |
| 242 mock_right_decoration0_.SetVisible(true); | 243 mock_trailing_decoration0_.SetVisible(true); |
| 243 mock_right_decoration1_.SetVisible(true); | 244 mock_trailing_decoration1_.SetVisible(true); |
| 244 | 245 |
| 245 const NSRect decoration0Rect = | 246 const NSRect decoration0Rect = |
| 246 [cell frameForDecoration:&mock_right_decoration0_ inFrame:bounds]; | 247 [cell frameForDecoration:&mock_trailing_decoration0_ inFrame:bounds]; |
| 247 EXPECT_FALSE(NSIsEmptyRect(decoration0Rect)); | 248 EXPECT_FALSE(NSIsEmptyRect(decoration0Rect)); |
| 248 EXPECT_TRUE(NSContainsRect(bounds, decoration0Rect)); | 249 EXPECT_TRUE(NSContainsRect(bounds, decoration0Rect)); |
| 249 | 250 |
| 250 // Right-side decorations are ordered from rightmost to leftmost. | 251 // Trailing decorations are ordered from front to back.. |
|
Sidney San Martín
2016/12/16 00:05:54
Ditto — "outermost to innermost", or whatever you
lgrey
2016/12/20 19:41:04
Done.
| |
| 251 // Outer decoration (0) to right of inner decoration (1). | 252 // Outer decoration (0) to right of inner decoration (1). |
| 252 const NSRect decoration1Rect = | 253 const NSRect decoration1Rect = |
| 253 [cell frameForDecoration:&mock_right_decoration1_ inFrame:bounds]; | 254 [cell frameForDecoration:&mock_trailing_decoration1_ inFrame:bounds]; |
| 254 EXPECT_FALSE(NSIsEmptyRect(decoration1Rect)); | 255 EXPECT_FALSE(NSIsEmptyRect(decoration1Rect)); |
| 255 EXPECT_TRUE(NSContainsRect(bounds, decoration1Rect)); | 256 EXPECT_TRUE(NSContainsRect(bounds, decoration1Rect)); |
| 256 EXPECT_LT(NSMinX(decoration1Rect), NSMinX(decoration0Rect)); | 257 EXPECT_LT(NSMinX(decoration1Rect), NSMinX(decoration0Rect)); |
| 257 | 258 |
| 258 // Decoration should be right of |drawingRect|. | 259 // Decoration should be right of |drawingRect|. |
| 259 const NSRect drawingRect = [cell drawingRectForBounds:bounds]; | 260 const NSRect drawingRect = [cell drawingRectForBounds:bounds]; |
| 260 EXPECT_LT(NSMinX(drawingRect), NSMinX(decoration1Rect)); | 261 EXPECT_LT(NSMinX(drawingRect), NSMinX(decoration1Rect)); |
| 261 | 262 |
| 262 // Decoration should be right of |textFrame|. | 263 // Decoration should be right of |textFrame|. |
| 263 const NSRect textFrame = [cell textFrameForFrame:bounds]; | 264 const NSRect textFrame = [cell textFrameForFrame:bounds]; |
| 264 EXPECT_LT(NSMinX(textFrame), NSMinX(decoration1Rect)); | 265 EXPECT_LT(NSMinX(textFrame), NSMinX(decoration1Rect)); |
| 265 } | 266 } |
| 266 | 267 |
| 267 // Verify -[AutocompleteTextFieldCell | 268 // Verify -[AutocompleteTextFieldCell |
| 268 // updateMouseTrackingAndToolTipsInRect:ofView:]. | 269 // updateMouseTrackingAndToolTipsInRect:ofView:]. |
| 269 TEST_F(AutocompleteTextFieldCellTest, UpdateToolTips) { | 270 TEST_F(AutocompleteTextFieldCellTest, UpdateToolTips) { |
| 270 NSString* tooltip = @"tooltip"; | 271 NSString* tooltip = @"tooltip"; |
| 271 | 272 |
| 272 // Left decoration returns a tooltip, make sure it is called at | 273 // Leading decoration returns a tooltip, make sure it is called at |
| 273 // least once. | 274 // least once. |
| 274 mock_left_decoration_.SetVisible(true); | 275 mock_leading_decoration_.SetVisible(true); |
| 275 EXPECT_CALL(mock_left_decoration_, GetToolTip()) | 276 EXPECT_CALL(mock_leading_decoration_, GetToolTip()) |
| 276 .WillOnce(Return(tooltip)) | 277 .WillOnce(Return(tooltip)) |
| 277 .WillRepeatedly(Return(tooltip)); | 278 .WillRepeatedly(Return(tooltip)); |
| 278 | 279 |
| 279 // Right decoration returns no tooltip, make sure it is called at | 280 // Right decoration returns no tooltip, make sure it is called at |
| 280 // least once. | 281 // least once. |
| 281 mock_right_decoration0_.SetVisible(true); | 282 mock_trailing_decoration0_.SetVisible(true); |
| 282 EXPECT_CALL(mock_right_decoration0_, GetToolTip()) | 283 EXPECT_CALL(mock_trailing_decoration0_, GetToolTip()) |
| 283 .WillOnce(Return((NSString*)nil)) | 284 .WillOnce(Return((NSString*)nil)) |
| 284 .WillRepeatedly(Return((NSString*)nil)); | 285 .WillRepeatedly(Return((NSString*)nil)); |
| 285 | 286 |
| 286 AutocompleteTextFieldCell* cell = | 287 AutocompleteTextFieldCell* cell = |
| 287 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | 288 static_cast<AutocompleteTextFieldCell*>([view_ cell]); |
| 288 const NSRect bounds = [view_ bounds]; | 289 const NSRect bounds = [view_ bounds]; |
| 289 const NSRect leftDecorationRect = | 290 const NSRect leadingDecorationRect = |
| 290 [cell frameForDecoration:&mock_left_decoration_ inFrame:bounds]; | 291 [cell frameForDecoration:&mock_leading_decoration_ inFrame:bounds]; |
| 291 | 292 |
| 292 // |controlView| gets the tooltip for the left decoration. | 293 // |controlView| gets the tooltip for the leading decoration. |
| 293 id controlView = [OCMockObject mockForClass:[AutocompleteTextField class]]; | 294 id controlView = [OCMockObject mockForClass:[AutocompleteTextField class]]; |
| 294 [[controlView expect] addToolTip:tooltip forRect:leftDecorationRect]; | 295 [[controlView expect] addToolTip:tooltip forRect:leadingDecorationRect]; |
| 295 | 296 |
| 296 [cell updateMouseTrackingAndToolTipsInRect:bounds ofView:controlView]; | 297 [cell updateMouseTrackingAndToolTipsInRect:bounds ofView:controlView]; |
| 297 | 298 |
| 298 EXPECT_OCMOCK_VERIFY(controlView); | 299 EXPECT_OCMOCK_VERIFY(controlView); |
| 299 } | 300 } |
| 300 | 301 |
| 302 class AutocompleteTextFieldCellTestRTL : public AutocompleteTextFieldCellTest { | |
|
Sidney San Martín
2016/12/16 00:05:54
Would it be possible to use the same basic test fo
lgrey
2016/12/20 19:41:04
I think this has some practical issues (RTL scopin
| |
| 303 private: | |
| 304 cocoa_l10n_util::ScopedForceRTLMac rtl_; | |
| 305 }; | |
| 306 | |
| 307 // Test that leading decorations are at the correct edge of the cell. | |
| 308 TEST_F(AutocompleteTextFieldCellTestRTL, LeadingDecorationFrame) { | |
| 309 AutocompleteTextFieldCell* cell = | |
| 310 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | |
| 311 const NSRect bounds = [view_ bounds]; | |
| 312 | |
| 313 mock_leading_decoration_.SetVisible(true); | |
| 314 const NSRect decorationRect = | |
| 315 [cell frameForDecoration:&mock_leading_decoration_ inFrame:bounds]; | |
| 316 EXPECT_FALSE(NSIsEmptyRect(decorationRect)); | |
| 317 EXPECT_TRUE(NSContainsRect(bounds, decorationRect)); | |
| 318 // Decoration should be right of |drawingRect|. | |
| 319 const NSRect drawingRect = [cell drawingRectForBounds:bounds]; | |
| 320 EXPECT_LT(NSMinX(drawingRect), NSMinX(decorationRect)); | |
| 321 | |
| 322 // Decoration should be right of |textFrame|. | |
| 323 const NSRect textFrame = [cell textFrameForFrame:bounds]; | |
| 324 EXPECT_LT(NSMinX(textFrame), NSMinX(decorationRect)); | |
| 325 } | |
| 326 | |
| 327 // Test that trailing decorations are at the correct edge of the cell. | |
| 328 TEST_F(AutocompleteTextFieldCellTestRTL, TrailingDecorationFrame) { | |
| 329 AutocompleteTextFieldCell* cell = | |
| 330 static_cast<AutocompleteTextFieldCell*>([view_ cell]); | |
| 331 const NSRect bounds = [view_ bounds]; | |
| 332 | |
| 333 mock_trailing_decoration0_.SetVisible(true); | |
| 334 mock_trailing_decoration1_.SetVisible(true); | |
| 335 | |
| 336 const NSRect decoration0Rect = | |
| 337 [cell frameForDecoration:&mock_trailing_decoration0_ inFrame:bounds]; | |
| 338 EXPECT_FALSE(NSIsEmptyRect(decoration0Rect)); | |
| 339 EXPECT_TRUE(NSContainsRect(bounds, decoration0Rect)); | |
| 340 | |
| 341 // Trailing decorations are ordered from front to back.. | |
| 342 // Outer decoration (0) to the left of inner decoration (1). | |
| 343 const NSRect decoration1Rect = | |
| 344 [cell frameForDecoration:&mock_trailing_decoration1_ inFrame:bounds]; | |
| 345 EXPECT_FALSE(NSIsEmptyRect(decoration1Rect)); | |
| 346 EXPECT_TRUE(NSContainsRect(bounds, decoration1Rect)); | |
| 347 EXPECT_GT(NSMinX(decoration1Rect), NSMinX(decoration0Rect)); | |
| 348 | |
| 349 // Decoration should be left of |drawingRect|. | |
| 350 const NSRect drawingRect = [cell drawingRectForBounds:bounds]; | |
| 351 EXPECT_GT(NSMinX(drawingRect), NSMinX(decoration1Rect)); | |
| 352 | |
| 353 // Decoration should be left of |textFrame|. | |
| 354 const NSRect textFrame = [cell textFrameForFrame:bounds]; | |
| 355 EXPECT_GT(NSMinX(textFrame), NSMinX(decoration1Rect)); | |
| 356 } | |
| 357 | |
| 301 } // namespace | 358 } // namespace |
| OLD | NEW |