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

Unified Diff: ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc

Issue 12225042: Remove NativeTabbedPane[Win|Wrapper]; promote Views impl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments; cleanup. Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/tabbed_pane/tabbed_pane.cc ('k') | ui/views/examples/tabbed_pane_example.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc
diff --git a/ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc b/ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc
index 1649402f16e52ab8f3d3a0b90a005a3476af02bf..ce7525bef869fd23dfb2109a679e933298b63170 100644
--- a/ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc
+++ b/ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc
@@ -8,11 +8,11 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/controls/tabbed_pane/tabbed_pane.h"
#include "ui/views/test/views_test_base.h"
-#include "ui/views/widget/widget.h"
-#include "ui/views/widget/widget_delegate.h"
namespace views {
+namespace {
+
// A view for testing that takes a fixed preferred size upon construction.
class FixedSizeView : public View {
public:
@@ -30,55 +30,18 @@ class FixedSizeView : public View {
DISALLOW_COPY_AND_ASSIGN(FixedSizeView);
};
-class TabbedPaneTest : public ViewsTestBase {
- public:
- TabbedPaneTest() {}
-
- void TestSizeAndLayout(TabbedPane* tabbed_pane);
-
- void TestAddRemove(TabbedPane* tabbed_pane);
-
- TabbedPane* tabbed_pane_; // Owned by the |widget_|'s root View.
-
-#if defined(OS_WIN) && !defined(USE_AURA)
- TabbedPane* tabbed_pane_win_; // Owned by the |widget_|'s root View.
-#endif
-
- private:
- virtual void SetUp() OVERRIDE;
+typedef ViewsTestBase TabbedPaneTest;
- scoped_ptr<Widget> widget_;
-
- DISALLOW_COPY_AND_ASSIGN(TabbedPaneTest);
-};
-
-void TabbedPaneTest::SetUp() {
- ViewsTestBase::SetUp();
- widget_.reset(new Widget());
- Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
- params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
- params.bounds = gfx::Rect(0, 0, 100, 100);
- widget_->Init(params);
- tabbed_pane_ = new TabbedPane();
- // In order to properly initialize the |TabbedPane| it must be added to a
- // parent view (see the ViewHierarchyChanged method of the |TabbedPane|).
- widget_->GetRootView()->AddChildView(tabbed_pane_);
-
-#if defined(OS_WIN) && !defined(USE_AURA)
- tabbed_pane_win_ = new TabbedPane();
- tabbed_pane_win_->set_use_native_win_control(true);
- widget_->GetRootView()->AddChildView(tabbed_pane_win_);
-#endif
-}
-
-void TabbedPaneTest::TestSizeAndLayout(TabbedPane* tabbed_pane) {
+// Tests TabbedPane::GetPreferredSize() and TabbedPane::Layout().
+TEST_F(TabbedPaneTest, SizeAndLayout) {
+ scoped_ptr<TabbedPane> tabbed_pane(new TabbedPane());
View* child1 = new FixedSizeView(gfx::Size(20, 10));
tabbed_pane->AddTab(ASCIIToUTF16("tab1"), child1);
View* child2 = new FixedSizeView(gfx::Size(5, 5));
tabbed_pane->AddTab(ASCIIToUTF16("tab2"), child2);
tabbed_pane->SelectTabAt(0);
- // The |tabbed_pane_| implementation of Views has no border by default.
+ // The |tabbed_pane| implementation of Views has no border by default.
// Therefore it should be as wide as the widest tab. The native Windows
// tabbed pane has a border that used up extra space. Therefore the preferred
// width is larger than the largest child.
@@ -91,8 +54,8 @@ void TabbedPaneTest::TestSizeAndLayout(TabbedPane* tabbed_pane) {
RunPendingMessages();
gfx::Rect bounds(child1->bounds());
EXPECT_GT(bounds.width(), 0);
- // The |tabbed_pane_| has no border. Therefore the children should be as wide
- // as the |tabbed_pane_|.
+ // The |tabbed_pane| has no border. Therefore the children should be as wide
+ // as the |tabbed_pane|.
EXPECT_LE(bounds.width(), 100);
EXPECT_GT(bounds.height(), 0);
EXPECT_LT(bounds.height(), 200);
@@ -100,84 +63,31 @@ void TabbedPaneTest::TestSizeAndLayout(TabbedPane* tabbed_pane) {
// If we switch to the other tab, it should get assigned the same bounds.
tabbed_pane->SelectTabAt(1);
EXPECT_EQ(bounds, child2->bounds());
-
- // Clean up.
- delete tabbed_pane->RemoveTabAtIndex(0);
- EXPECT_EQ(1, tabbed_pane->GetTabCount());
- delete tabbed_pane->RemoveTabAtIndex(0);
- EXPECT_EQ(0, tabbed_pane->GetTabCount());
}
-void TabbedPaneTest::TestAddRemove(TabbedPane* tabbed_pane) {
- View* tab0 = new View;
- tabbed_pane->AddTab(ASCIIToUTF16("tab0"), tab0);
- EXPECT_EQ(tab0, tabbed_pane->GetSelectedTab());
- EXPECT_EQ(0, tabbed_pane->GetSelectedTabIndex());
-
- // Add more 3 tabs.
- tabbed_pane->AddTab(ASCIIToUTF16("tab1"), new View);
- tabbed_pane->AddTab(ASCIIToUTF16("tab2"), new View);
- tabbed_pane->AddTab(ASCIIToUTF16("tab3"), new View);
- EXPECT_EQ(4, tabbed_pane->GetTabCount());
-
- // Note: AddTab() doesn't select a tab if the tabbed pane isn't empty.
-
- // Select the last one.
- tabbed_pane->SelectTabAt(tabbed_pane->GetTabCount() - 1);
- EXPECT_EQ(3, tabbed_pane->GetSelectedTabIndex());
-
- // Remove the last one.
- delete tabbed_pane->RemoveTabAtIndex(3);
- EXPECT_EQ(3, tabbed_pane->GetTabCount());
-
- // After removing the last tab, check if the tabbed pane selected the previous
- // tab.
- EXPECT_EQ(2, tabbed_pane->GetSelectedTabIndex());
-
- tabbed_pane->AddTabAtIndex(0, ASCIIToUTF16("tab4"), new View, true);
-
- // Assert that even adding a new tab, the tabbed pane doesn't change the
- // selection, i.e., it doesn't select the new one.
- // The last tab should remains selected, instead of the tab added at index 0.
- EXPECT_EQ(3, tabbed_pane->GetSelectedTabIndex());
+TEST_F(TabbedPaneTest, AddAndSelect) {
+ scoped_ptr<TabbedPane> tabbed_pane(new TabbedPane());
+ // Add several tabs; only the first should be a selected automatically.
+ for (int i = 0; i < 3; ++i) {
+ View* tab = new View();
+ tabbed_pane->AddTab(ASCIIToUTF16("tab"), tab);
+ EXPECT_EQ(i + 1, tabbed_pane->GetTabCount());
+ EXPECT_EQ(0, tabbed_pane->selected_tab_index());
+ }
- // Now change the selected tab.
- tabbed_pane->SelectTabAt(1);
- EXPECT_EQ(1, tabbed_pane->GetSelectedTabIndex());
-
- // Remove the first one.
- delete tabbed_pane->RemoveTabAtIndex(0);
- EXPECT_EQ(0, tabbed_pane->GetSelectedTabIndex());
-
- // Clean up the other panes.
- EXPECT_EQ(3, tabbed_pane->GetTabCount());
- delete tabbed_pane->RemoveTabAtIndex(0);
- delete tabbed_pane->RemoveTabAtIndex(0);
- delete tabbed_pane->RemoveTabAtIndex(0);
- EXPECT_EQ(0, tabbed_pane->GetTabCount());
-}
+ // Select each tab.
+ for (int i = 0; i < tabbed_pane->GetTabCount(); ++i) {
+ tabbed_pane->SelectTabAt(i);
+ EXPECT_EQ(i, tabbed_pane->selected_tab_index());
+ }
-// Tests TabbedPane::GetPreferredSize() and TabbedPane::Layout().
-TEST_F(TabbedPaneTest, SizeAndLayout) {
- TestSizeAndLayout(tabbed_pane_);
- // TODO(markusheintz): Once replacing NativeTabbedPaneWin with
- // NativeTabbedPaneView is completed (http://crbug.com/138059), then the
- // TestSizeAndLayout method should be inlined here again and the "ifdef" part
- // should be deleted.
-#if defined(OS_WIN) && !defined(USE_AURA)
- TestSizeAndLayout(tabbed_pane_win_);
-#endif
+ // Add a tab at index 0, it should not be selected automatically.
+ View* tab0 = new View();
+ tabbed_pane->AddTabAtIndex(0, ASCIIToUTF16("tab0"), tab0);
+ EXPECT_NE(tab0, tabbed_pane->GetSelectedTab());
+ EXPECT_NE(0, tabbed_pane->selected_tab_index());
}
-TEST_F(TabbedPaneTest, AddRemove) {
- TestAddRemove(tabbed_pane_);
- // TODO(markusheintz): Once replacing NativeTabbedPaneWin with
- // NativeTabbedPaneView is completed (http://crbug.com/138059), then the
- // TestAddRemove method should be inlined here again and the "ifdef" part
- // should be deleted.
-#if defined(OS_WIN) && !defined(USE_AURA)
- TestAddRemove(tabbed_pane_win_);
-#endif
-}
+} // namespace
} // namespace views
« no previous file with comments | « ui/views/controls/tabbed_pane/tabbed_pane.cc ('k') | ui/views/examples/tabbed_pane_example.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698