| Index: ui/views/controls/label_unittest.cc
|
| diff --git a/ui/views/controls/label_unittest.cc b/ui/views/controls/label_unittest.cc
|
| index 43f09fb092b06a1968e2432352781ce0bc42ba86..e2ab5080acce68b819cc58bf0bbcd746d16d6d98 100644
|
| --- a/ui/views/controls/label_unittest.cc
|
| +++ b/ui/views/controls/label_unittest.cc
|
| @@ -22,8 +22,12 @@
|
| using base::ASCIIToUTF16;
|
|
|
| namespace views {
|
| +namespace {
|
|
|
| -typedef ViewsTestBase LabelTest;
|
| +// All text sizing measurements (width and height) should be greater than this.
|
| +const int kMinTextDimension = 4;
|
| +
|
| +using LabelTest = ViewsTestBase;
|
|
|
| class LabelFocusTest : public FocusManagerTest {
|
| public:
|
| @@ -31,7 +35,7 @@ class LabelFocusTest : public FocusManagerTest {
|
| ~LabelFocusTest() override {}
|
|
|
| protected:
|
| - views::Label* label() { return label_; }
|
| + Label* label() { return label_; }
|
|
|
| private:
|
| // FocusManagerTest:
|
| @@ -40,11 +44,31 @@ class LabelFocusTest : public FocusManagerTest {
|
| GetContentsView()->AddChildView(label_);
|
| }
|
|
|
| - views::Label* label_;
|
| + Label* label_;
|
| };
|
|
|
| -// All text sizing measurements (width and height) should be greater than this.
|
| -const int kMinTextDimension = 4;
|
| +class TestLabel : public Label {
|
| + public:
|
| + TestLabel() : Label(ASCIIToUTF16("TestLabel")) { SizeToPreferredSize(); }
|
| +
|
| + int schedule_paint_count() const { return schedule_paint_count_; }
|
| +
|
| + void SimulatePaint() {
|
| + gfx::Canvas canvas(bounds().size(), 1.0, false /* is_opaque */);
|
| + Paint(ui::CanvasPainter(&canvas, 1.f).context());
|
| + }
|
| +
|
| + // View:
|
| + void SchedulePaintInRect(const gfx::Rect& r) override {
|
| + ++schedule_paint_count_;
|
| + Label::SchedulePaintInRect(r);
|
| + }
|
| +
|
| + private:
|
| + int schedule_paint_count_ = 0;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestLabel);
|
| +};
|
|
|
| // A test utility function to set the application default text direction.
|
| void SetRTL(bool rtl) {
|
| @@ -53,6 +77,15 @@ void SetRTL(bool rtl) {
|
| EXPECT_EQ(rtl, base::i18n::IsRTL());
|
| }
|
|
|
| +// Returns true if |current| is bigger than |last|. Sets |last| to |current|.
|
| +bool Increased(int current, int* last) {
|
| + bool increased = current > *last;
|
| + *last = current;
|
| + return increased;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| // Crashes on Linux only. http://crbug.com/612406
|
| #if defined(OS_LINUX)
|
| #define MAYBE_FontPropertySymbol DISABLED_FontPropertySymbol
|
| @@ -612,6 +645,36 @@ TEST_F(LabelTest, MultilineSupportedRenderText) {
|
| }
|
| #endif
|
|
|
| +// Ensures SchedulePaint() calls are not made in OnPaint().
|
| +TEST_F(LabelTest, NoSchedulePaintInOnPaint) {
|
| + TestLabel label;
|
| +
|
| + // Initialization should schedule at least one paint, but the precise number
|
| + // doesn't really matter.
|
| + int count = label.schedule_paint_count();
|
| + EXPECT_LT(0, count);
|
| +
|
| + // Painting should never schedule another paint.
|
| + label.SimulatePaint();
|
| + EXPECT_EQ(count, label.schedule_paint_count());
|
| +
|
| + // Test a few things that should schedule paints. Multiple times is OK.
|
| + label.SetEnabled(false);
|
| + EXPECT_TRUE(Increased(label.schedule_paint_count(), &count));
|
| +
|
| + label.SetText(label.text() + ASCIIToUTF16("Changed"));
|
| + EXPECT_TRUE(Increased(label.schedule_paint_count(), &count));
|
| +
|
| + label.SizeToPreferredSize();
|
| + EXPECT_TRUE(Increased(label.schedule_paint_count(), &count));
|
| +
|
| + label.SetEnabledColor(SK_ColorBLUE);
|
| + EXPECT_TRUE(Increased(label.schedule_paint_count(), &count));
|
| +
|
| + label.SimulatePaint();
|
| + EXPECT_EQ(count, label.schedule_paint_count()); // Unchanged.
|
| +}
|
| +
|
| TEST_F(LabelFocusTest, FocusBounds) {
|
| label()->SetText(ASCIIToUTF16("Example"));
|
| gfx::Size normal_size = label()->GetPreferredSize();
|
|
|