This source file includes following definitions.
- GetPreferredSize
- TEST_F
- TEST_F
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/controls/tabbed_pane/tabbed_pane.h"
#include "ui/views/test/views_test_base.h"
using base::ASCIIToUTF16;
namespace views {
namespace {
class FixedSizeView : public View {
public:
explicit FixedSizeView(const gfx::Size& size)
: size_(size) {}
virtual gfx::Size GetPreferredSize() OVERRIDE {
return size_;
}
private:
const gfx::Size size_;
DISALLOW_COPY_AND_ASSIGN(FixedSizeView);
};
typedef ViewsTestBase TabbedPaneTest;
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);
gfx::Size pref(tabbed_pane->GetPreferredSize());
EXPECT_GE(pref.width(), 20);
EXPECT_GT(pref.height(), 10);
tabbed_pane->SetBounds(0, 0, 100, 200);
RunPendingMessages();
gfx::Rect bounds(child1->bounds());
EXPECT_GT(bounds.width(), 0);
EXPECT_LE(bounds.width(), 100);
EXPECT_GT(bounds.height(), 0);
EXPECT_LT(bounds.height(), 200);
tabbed_pane->SelectTabAt(1);
EXPECT_EQ(bounds, child2->bounds());
}
TEST_F(TabbedPaneTest, AddAndSelect) {
scoped_ptr<TabbedPane> tabbed_pane(new TabbedPane());
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());
}
for (int i = 0; i < tabbed_pane->GetTabCount(); ++i) {
tabbed_pane->SelectTabAt(i);
EXPECT_EQ(i, tabbed_pane->selected_tab_index());
}
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());
}
}
}