OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/i18n/rtl.h" | 5 #include "base/i18n/rtl.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/base/accessibility/accessible_view_state.h" | 8 #include "ui/base/accessibility/accessible_view_state.h" |
9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 213 |
214 // SizeToFit with unlimited width. | 214 // SizeToFit with unlimited width. |
215 label.SizeToFit(0); | 215 label.SizeToFit(0); |
216 int required_width = label.GetLocalBounds().width(); | 216 int required_width = label.GetLocalBounds().width(); |
217 EXPECT_GT(required_width, kMinTextDimension); | 217 EXPECT_GT(required_width, kMinTextDimension); |
218 | 218 |
219 // SizeToFit with limited width. | 219 // SizeToFit with limited width. |
220 label.SizeToFit(required_width - 1); | 220 label.SizeToFit(required_width - 1); |
221 int constrained_width = label.GetLocalBounds().width(); | 221 int constrained_width = label.GetLocalBounds().width(); |
222 #if defined(OS_WIN) | 222 #if defined(OS_WIN) |
223 // Canvas::SizeStringInt (in ui/gfx/canvas_linux.cc) | 223 // Canvas::SizeStringToFit (in ui/gfx/canvas_linux.cc) |
224 // has to be fixed to return the size that fits to given width/height. | 224 // has to be fixed to return the size that fits to given width/height. |
225 EXPECT_LT(constrained_width, required_width); | 225 EXPECT_LT(constrained_width, required_width); |
226 #endif | 226 #endif |
227 EXPECT_GT(constrained_width, kMinTextDimension); | 227 EXPECT_GT(constrained_width, kMinTextDimension); |
228 | 228 |
229 // Change the width back to the desire width. | 229 // Change the width back to the desire width. |
230 label.SizeToFit(required_width); | 230 label.SizeToFit(required_width); |
231 EXPECT_EQ(required_width, label.GetLocalBounds().width()); | 231 EXPECT_EQ(required_width, label.GetLocalBounds().width()); |
232 | 232 |
233 // General tests for GetHeightForWidth. | 233 // General tests for GetHeightForWidth. |
234 int required_height = label.GetHeightForWidth(required_width); | 234 int required_height = label.GetHeightForWidth(required_width); |
235 EXPECT_GT(required_height, kMinTextDimension); | 235 EXPECT_GT(required_height, kMinTextDimension); |
236 int height_for_constrained_width = label.GetHeightForWidth(constrained_width); | 236 int height_for_constrained_width = label.GetHeightForWidth(constrained_width); |
237 #if defined(OS_WIN) | 237 #if defined(OS_WIN) |
238 // Canvas::SizeStringInt (in ui/gfx/canvas_linux.cc) | 238 // Canvas::SizeStringToFit (in ui/gfx/canvas_linux.cc) |
239 // has to be fixed to return the size that fits to given width/height. | 239 // has to be fixed to return the size that fits to given width/height. |
240 EXPECT_GT(height_for_constrained_width, required_height); | 240 EXPECT_GT(height_for_constrained_width, required_height); |
241 #endif | 241 #endif |
242 // Using the constrained width or the required_width - 1 should give the | 242 // Using the constrained width or the required_width - 1 should give the |
243 // same result for the height because the constrainted width is the tight | 243 // same result for the height because the constrainted width is the tight |
244 // width when given "required_width - 1" as the max width. | 244 // width when given "required_width - 1" as the max width. |
245 EXPECT_EQ(height_for_constrained_width, | 245 EXPECT_EQ(height_for_constrained_width, |
246 label.GetHeightForWidth(required_width - 1)); | 246 label.GetHeightForWidth(required_width - 1)); |
247 | 247 |
248 // Test everything with borders. | 248 // Test everything with borders. |
(...skipping 11 matching lines...) Expand all Loading... |
260 // GetHeightForWidth and borders. | 260 // GetHeightForWidth and borders. |
261 int required_height_with_border = | 261 int required_height_with_border = |
262 label.GetHeightForWidth(required_width_with_border); | 262 label.GetHeightForWidth(required_width_with_border); |
263 EXPECT_EQ(required_height_with_border, required_height + border.height()); | 263 EXPECT_EQ(required_height_with_border, required_height + border.height()); |
264 | 264 |
265 // Test that the border width is subtracted before doing the height | 265 // Test that the border width is subtracted before doing the height |
266 // calculation. If it is, then the height will grow when width | 266 // calculation. If it is, then the height will grow when width |
267 // is shrunk. | 267 // is shrunk. |
268 int height1 = label.GetHeightForWidth(required_width_with_border - 1); | 268 int height1 = label.GetHeightForWidth(required_width_with_border - 1); |
269 #if defined(OS_WIN) | 269 #if defined(OS_WIN) |
270 // Canvas::SizeStringInt (in ui/gfx/canvas_linux.cc) | 270 // Canvas::SizeStringToFit (in ui/gfx/canvas_linux.cc) |
271 // has to be fixed to return the size that fits to given width/height. | 271 // has to be fixed to return the size that fits to given width/height. |
272 EXPECT_GT(height1, required_height_with_border); | 272 EXPECT_GT(height1, required_height_with_border); |
273 #endif | 273 #endif |
274 EXPECT_EQ(height1, height_for_constrained_width + border.height()); | 274 EXPECT_EQ(height1, height_for_constrained_width + border.height()); |
275 | 275 |
276 // GetPreferredSize and borders. | 276 // GetPreferredSize and borders. |
277 label.SetBounds(0, 0, 0, 0); | 277 label.SetBounds(0, 0, 0, 0); |
278 gfx::Size required_size_with_border = label.GetPreferredSize(); | 278 gfx::Size required_size_with_border = label.GetPreferredSize(); |
279 EXPECT_EQ(required_size_with_border.height(), | 279 EXPECT_EQ(required_size_with_border.height(), |
280 required_size.height() + border.height()); | 280 required_size.height() + border.height()); |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51))); | 922 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51))); |
923 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20))); | 923 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20))); |
924 | 924 |
925 // GetTooltipHandlerForPoint works should work in child bounds. | 925 // GetTooltipHandlerForPoint works should work in child bounds. |
926 label.SetBounds(2, 2, 10, 10); | 926 label.SetBounds(2, 2, 10, 10); |
927 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5))); | 927 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5))); |
928 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11))); | 928 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11))); |
929 } | 929 } |
930 | 930 |
931 } // namespace views | 931 } // namespace views |
OLD | NEW |