| 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 "ui/views/controls/label.h" | 5 #include "ui/views/controls/label.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/accessibility/ax_view_state.h" | 13 #include "ui/accessibility/ax_node_data.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/compositor/canvas_painter.h" | 15 #include "ui/compositor/canvas_painter.h" |
| 16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 17 #include "ui/gfx/render_text.h" | 17 #include "ui/gfx/render_text.h" |
| 18 #include "ui/views/border.h" | 18 #include "ui/views/border.h" |
| 19 #include "ui/views/test/focus_manager_test.h" | 19 #include "ui/views/test/focus_manager_test.h" |
| 20 #include "ui/views/test/views_test_base.h" | 20 #include "ui/views/test/views_test_base.h" |
| 21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 22 | 22 |
| 23 using base::ASCIIToUTF16; | 23 using base::ASCIIToUTF16; |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); | 332 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 333 EXPECT_EQ(tooltip_text, tooltip); | 333 EXPECT_EQ(tooltip_text, tooltip); |
| 334 // Clear out the tooltip. | 334 // Clear out the tooltip. |
| 335 label.SetTooltipText(base::string16()); | 335 label.SetTooltipText(base::string16()); |
| 336 } | 336 } |
| 337 | 337 |
| 338 TEST_F(LabelTest, Accessibility) { | 338 TEST_F(LabelTest, Accessibility) { |
| 339 Label label; | 339 Label label; |
| 340 label.SetText(ASCIIToUTF16("My special text.")); | 340 label.SetText(ASCIIToUTF16("My special text.")); |
| 341 | 341 |
| 342 ui::AXViewState state; | 342 ui::AXNodeData node_data; |
| 343 label.GetAccessibleState(&state); | 343 label.GetAccessibleNodeData(&node_data); |
| 344 EXPECT_EQ(ui::AX_ROLE_STATIC_TEXT, state.role); | 344 EXPECT_EQ(ui::AX_ROLE_STATIC_TEXT, node_data.role); |
| 345 EXPECT_EQ(label.text(), state.name); | 345 EXPECT_EQ(label.text(), node_data.GetString16Attribute(ui::AX_ATTR_NAME)); |
| 346 EXPECT_TRUE(state.HasStateFlag(ui::AX_STATE_READ_ONLY)); | 346 EXPECT_TRUE(node_data.HasStateFlag(ui::AX_STATE_READ_ONLY)); |
| 347 } | 347 } |
| 348 | 348 |
| 349 TEST_F(LabelTest, TextChangeWithoutLayout) { | 349 TEST_F(LabelTest, TextChangeWithoutLayout) { |
| 350 Label label; | 350 Label label; |
| 351 label.SetText(ASCIIToUTF16("Example")); | 351 label.SetText(ASCIIToUTF16("Example")); |
| 352 label.SetBounds(0, 0, 200, 200); | 352 label.SetBounds(0, 0, 200, 200); |
| 353 | 353 |
| 354 gfx::Canvas canvas(gfx::Size(200, 200), 1.0f, true); | 354 gfx::Canvas canvas(gfx::Size(200, 200), 1.0f, true); |
| 355 label.Paint(ui::CanvasPainter(&canvas, 1.f).context()); | 355 label.Paint(ui::CanvasPainter(&canvas, 1.f).context()); |
| 356 EXPECT_EQ(1u, label.lines_.size()); | 356 EXPECT_EQ(1u, label.lines_.size()); |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 label()->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 724 label()->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
| 725 label()->RequestFocus(); | 725 label()->RequestFocus(); |
| 726 label()->SizeToPreferredSize(); | 726 label()->SizeToPreferredSize(); |
| 727 | 727 |
| 728 gfx::Rect focus_bounds = label()->GetFocusBounds(); | 728 gfx::Rect focus_bounds = label()->GetFocusBounds(); |
| 729 EXPECT_FALSE(focus_bounds.IsEmpty()); | 729 EXPECT_FALSE(focus_bounds.IsEmpty()); |
| 730 EXPECT_LT(label()->font_list().GetHeight(), focus_bounds.height()); | 730 EXPECT_LT(label()->font_list().GetHeight(), focus_bounds.height()); |
| 731 } | 731 } |
| 732 | 732 |
| 733 } // namespace views | 733 } // namespace views |
| OLD | NEW |