1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "base/message_loop.h"
#include "chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.h"
#include "chrome/browser/ui/views/tabs/tab_strip_controller.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "testing/gtest/include/gtest/gtest.h"
class TabStripTest : public testing::Test {
public:
TabStripTest()
: controller_(new FakeBaseTabStripController),
tab_strip_(new TabStrip(controller_)) {
controller_->set_tab_strip(tab_strip_);
// Do this to force TabStrip to create the buttons.
parent_.AddChildView(tab_strip_);
}
protected:
MessageLoopForUI ui_loop_;
// Owned by TabStrip.
FakeBaseTabStripController* controller_;
// Owns |tab_strip_|.
views::View parent_;
TabStrip* tab_strip_;
private:
DISALLOW_COPY_AND_ASSIGN(TabStripTest);
};
TEST_F(TabStripTest, GetModelCount) {
EXPECT_EQ(0, tab_strip_->GetModelCount());
}
TEST_F(TabStripTest, IsValidModelIndex) {
EXPECT_FALSE(tab_strip_->IsValidModelIndex(0));
}
TEST_F(TabStripTest, tab_count) {
EXPECT_EQ(0, tab_strip_->tab_count());
}
TEST_F(TabStripTest, CreateTabForDragging) {
// Any result is good, as long as it doesn't crash.
scoped_ptr<BaseTab> tab(tab_strip_->CreateTabForDragging());
}
TEST_F(TabStripTest, AddTabAt) {
tab_strip_->AddTabAt(0, TabRendererData(), false);
ASSERT_EQ(1, tab_strip_->tab_count());
Tab* tab = tab_strip_->tab_at(0);
EXPECT_FALSE(tab == NULL);
}
// Verifies child views are deleted after an animation completes.
TEST_F(TabStripTest, RemoveTab) {
controller_->AddTab(0);
controller_->AddTab(1);
const int child_view_count = tab_strip_->child_count();
EXPECT_EQ(2, tab_strip_->tab_count());
controller_->RemoveTab(0);
// When removing a tab the tabcount should immediately decrement.
EXPECT_EQ(1, tab_strip_->tab_count());
// But the number of views should remain the same (it's animatining closed).
EXPECT_EQ(child_view_count, tab_strip_->child_count());
tab_strip_->SetBounds(0, 0, 200, 20);
// Layout at a different size should force the animation to end and delete
// the tab that was removed.
tab_strip_->Layout();
EXPECT_EQ(child_view_count - 1, tab_strip_->child_count());
// Remove the last tab to make sure things are cleaned up correctly when
// the TabStrip is destroyed and an animation is ongoing.
controller_->RemoveTab(0);
}
|