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

Side by Side Diff: ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc

Issue 1868363002: Replace scoped_ptr with std::unique_ptr in //ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scopedptrcc
Patch Set: scopedptrui: rebase-make_scoped_ptr Created 4 years, 8 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/styled_label_unittest.cc ('k') | ui/views/controls/table/table_header.h » ('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 (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/tabbed_pane/tabbed_pane.h"
6
7 #include <memory>
8
5 #include "base/macros.h" 9 #include "base/macros.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
8 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/views/controls/tabbed_pane/tabbed_pane.h"
11 #include "ui/views/test/views_test_base.h" 13 #include "ui/views/test/views_test_base.h"
12 14
13 using base::ASCIIToUTF16; 15 using base::ASCIIToUTF16;
14 16
15 namespace views { 17 namespace views {
16 18
17 namespace { 19 namespace {
18 20
19 // A view for testing that takes a fixed preferred size upon construction. 21 // A view for testing that takes a fixed preferred size upon construction.
20 class FixedSizeView : public View { 22 class FixedSizeView : public View {
21 public: 23 public:
22 explicit FixedSizeView(const gfx::Size& size) 24 explicit FixedSizeView(const gfx::Size& size)
23 : size_(size) {} 25 : size_(size) {}
24 26
25 // Overridden from View: 27 // Overridden from View:
26 gfx::Size GetPreferredSize() const override { return size_; } 28 gfx::Size GetPreferredSize() const override { return size_; }
27 29
28 private: 30 private:
29 const gfx::Size size_; 31 const gfx::Size size_;
30 32
31 DISALLOW_COPY_AND_ASSIGN(FixedSizeView); 33 DISALLOW_COPY_AND_ASSIGN(FixedSizeView);
32 }; 34 };
33 35
34 typedef ViewsTestBase TabbedPaneTest; 36 typedef ViewsTestBase TabbedPaneTest;
35 37
36 // Tests TabbedPane::GetPreferredSize() and TabbedPane::Layout(). 38 // Tests TabbedPane::GetPreferredSize() and TabbedPane::Layout().
37 TEST_F(TabbedPaneTest, SizeAndLayout) { 39 TEST_F(TabbedPaneTest, SizeAndLayout) {
38 scoped_ptr<TabbedPane> tabbed_pane(new TabbedPane()); 40 std::unique_ptr<TabbedPane> tabbed_pane(new TabbedPane());
39 View* child1 = new FixedSizeView(gfx::Size(20, 10)); 41 View* child1 = new FixedSizeView(gfx::Size(20, 10));
40 tabbed_pane->AddTab(ASCIIToUTF16("tab1"), child1); 42 tabbed_pane->AddTab(ASCIIToUTF16("tab1"), child1);
41 View* child2 = new FixedSizeView(gfx::Size(5, 5)); 43 View* child2 = new FixedSizeView(gfx::Size(5, 5));
42 tabbed_pane->AddTab(ASCIIToUTF16("tab2"), child2); 44 tabbed_pane->AddTab(ASCIIToUTF16("tab2"), child2);
43 tabbed_pane->SelectTabAt(0); 45 tabbed_pane->SelectTabAt(0);
44 46
45 // The |tabbed_pane| implementation of Views has no border by default. 47 // The |tabbed_pane| implementation of Views has no border by default.
46 // Therefore it should be as wide as the widest tab. The native Windows 48 // Therefore it should be as wide as the widest tab. The native Windows
47 // tabbed pane has a border that used up extra space. Therefore the preferred 49 // tabbed pane has a border that used up extra space. Therefore the preferred
48 // width is larger than the largest child. 50 // width is larger than the largest child.
(...skipping 11 matching lines...) Expand all
60 EXPECT_LE(bounds.width(), 100); 62 EXPECT_LE(bounds.width(), 100);
61 EXPECT_GT(bounds.height(), 0); 63 EXPECT_GT(bounds.height(), 0);
62 EXPECT_LT(bounds.height(), 200); 64 EXPECT_LT(bounds.height(), 200);
63 65
64 // If we switch to the other tab, it should get assigned the same bounds. 66 // If we switch to the other tab, it should get assigned the same bounds.
65 tabbed_pane->SelectTabAt(1); 67 tabbed_pane->SelectTabAt(1);
66 EXPECT_EQ(bounds, child2->bounds()); 68 EXPECT_EQ(bounds, child2->bounds());
67 } 69 }
68 70
69 TEST_F(TabbedPaneTest, AddAndSelect) { 71 TEST_F(TabbedPaneTest, AddAndSelect) {
70 scoped_ptr<TabbedPane> tabbed_pane(new TabbedPane()); 72 std::unique_ptr<TabbedPane> tabbed_pane(new TabbedPane());
71 // Add several tabs; only the first should be a selected automatically. 73 // Add several tabs; only the first should be a selected automatically.
72 for (int i = 0; i < 3; ++i) { 74 for (int i = 0; i < 3; ++i) {
73 View* tab = new View(); 75 View* tab = new View();
74 tabbed_pane->AddTab(ASCIIToUTF16("tab"), tab); 76 tabbed_pane->AddTab(ASCIIToUTF16("tab"), tab);
75 EXPECT_EQ(i + 1, tabbed_pane->GetTabCount()); 77 EXPECT_EQ(i + 1, tabbed_pane->GetTabCount());
76 EXPECT_EQ(0, tabbed_pane->selected_tab_index()); 78 EXPECT_EQ(0, tabbed_pane->selected_tab_index());
77 } 79 }
78 80
79 // Select each tab. 81 // Select each tab.
80 for (int i = 0; i < tabbed_pane->GetTabCount(); ++i) { 82 for (int i = 0; i < tabbed_pane->GetTabCount(); ++i) {
81 tabbed_pane->SelectTabAt(i); 83 tabbed_pane->SelectTabAt(i);
82 EXPECT_EQ(i, tabbed_pane->selected_tab_index()); 84 EXPECT_EQ(i, tabbed_pane->selected_tab_index());
83 } 85 }
84 86
85 // Add a tab at index 0, it should not be selected automatically. 87 // Add a tab at index 0, it should not be selected automatically.
86 View* tab0 = new View(); 88 View* tab0 = new View();
87 tabbed_pane->AddTabAtIndex(0, ASCIIToUTF16("tab0"), tab0); 89 tabbed_pane->AddTabAtIndex(0, ASCIIToUTF16("tab0"), tab0);
88 EXPECT_NE(tab0, tabbed_pane->GetSelectedTab()); 90 EXPECT_NE(tab0, tabbed_pane->GetSelectedTab());
89 EXPECT_NE(0, tabbed_pane->selected_tab_index()); 91 EXPECT_NE(0, tabbed_pane->selected_tab_index());
90 } 92 }
91 93
92 } // namespace 94 } // namespace
93 95
94 } // namespace views 96 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/styled_label_unittest.cc ('k') | ui/views/controls/table/table_header.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698