Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: ui/views/controls/button/blue_button_unittest.cc

Issue 1216673005: views::LabelButton should not call virtual methods from its constructor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20150703-Views-ButtonBorderRefactor
Patch Set: self review Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/controls/button/blue_button.cc ('k') | ui/views/controls/button/checkbox.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/button/blue_button.h" 5 #include "ui/views/controls/button/blue_button.h"
6 6
7 #include "base/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/skia_util.h" 10 #include "ui/gfx/skia_util.h"
11 #include "ui/views/controls/button/label_button_border.h" 11 #include "ui/views/controls/button/label_button_border.h"
12 #include "ui/views/test/views_test_base.h" 12 #include "ui/views/test/views_test_base.h"
13 13
14 namespace views { 14 namespace views {
15 15
16 namespace {
17
18 class TestBlueButton : public BlueButton {
19 public:
20 TestBlueButton() : BlueButton(NULL, base::ASCIIToUTF16("foo")) {}
21 ~TestBlueButton() override {}
22
23 using BlueButton::OnNativeThemeChanged;
24
25 private:
26 DISALLOW_COPY_AND_ASSIGN(TestBlueButton);
27 };
28
29 } // namespace
30
31 typedef ViewsTestBase BlueButtonTest; 16 typedef ViewsTestBase BlueButtonTest;
32 17
33 TEST_F(BlueButtonTest, Border) { 18 TEST_F(BlueButtonTest, Border) {
34 // Compared to a normal LabelButton... 19 // Compared to a normal LabelButton...
35 LabelButton button(NULL, base::ASCIIToUTF16("foo")); 20 LabelButton button(nullptr);
21 button.InitAsTextbutton(base::ASCIIToUTF16("foo"));
36 button.SetBoundsRect(gfx::Rect(gfx::Point(0, 0), button.GetPreferredSize())); 22 button.SetBoundsRect(gfx::Rect(gfx::Point(0, 0), button.GetPreferredSize()));
37 gfx::Canvas button_canvas(button.bounds().size(), 1.0, true); 23 gfx::Canvas button_canvas(button.bounds().size(), 1.0, true);
38 button.border()->Paint(button, &button_canvas); 24 button.border()->Paint(button, &button_canvas);
39 25
40 // ... a special blue border should be used. 26 // ... a special blue border should be used.
41 TestBlueButton blue_button; 27 BlueButton blue_button(nullptr, base::ASCIIToUTF16("foo"));
42 blue_button.SetBoundsRect(gfx::Rect(gfx::Point(0, 0), 28 blue_button.SetBoundsRect(gfx::Rect(gfx::Point(0, 0),
43 blue_button.GetPreferredSize())); 29 blue_button.GetPreferredSize()));
44 gfx::Canvas canvas(blue_button.bounds().size(), 1.0, true); 30 gfx::Canvas canvas(blue_button.bounds().size(), 1.0, true);
45 blue_button.border()->Paint(blue_button, &canvas); 31 blue_button.border()->Paint(blue_button, &canvas);
46 EXPECT_EQ(button.GetText(), blue_button.GetText()); 32 EXPECT_EQ(button.GetText(), blue_button.GetText());
47 EXPECT_FALSE(gfx::BitmapsAreEqual(button_canvas.ExtractImageRep().sk_bitmap(), 33 EXPECT_FALSE(gfx::BitmapsAreEqual(button_canvas.ExtractImageRep().sk_bitmap(),
48 canvas.ExtractImageRep().sk_bitmap())); 34 canvas.ExtractImageRep().sk_bitmap()));
49 35
50 // Make sure it's still used after the native theme "changes". 36 // Make sure it's still used after the native theme "changes".
51 blue_button.OnNativeThemeChanged(NULL); 37 blue_button.OnNativeThemeChanged(NULL);
52 gfx::Canvas canvas2(blue_button.bounds().size(), 1.0, true); 38 gfx::Canvas canvas2(blue_button.bounds().size(), 1.0, true);
53 blue_button.border()->Paint(blue_button, &canvas2); 39 blue_button.border()->Paint(blue_button, &canvas2);
54 40
55 EXPECT_TRUE(gfx::BitmapsAreEqual(canvas.ExtractImageRep().sk_bitmap(), 41 EXPECT_TRUE(gfx::BitmapsAreEqual(canvas.ExtractImageRep().sk_bitmap(),
56 canvas2.ExtractImageRep().sk_bitmap())); 42 canvas2.ExtractImageRep().sk_bitmap()));
57 } 43 }
58 44
59 } // namespace views 45 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/blue_button.cc ('k') | ui/views/controls/button/checkbox.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698