OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/launcher/launcher_button.h" | |
6 #include "ash/launcher/launcher_model.h" | |
7 #include "ash/launcher/launcher_view.h" | |
sky
2012/04/23 20:47:25
launcher_view should be the first include (test fi
xiyuan
2012/04/23 21:01:21
Done.
| |
8 #include "ash/test/launcher_view_test_api.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "ui/aura/test/aura_test_base.h" | |
11 | |
12 namespace ash { | |
13 namespace test { | |
14 | |
15 class LauncherViewTest : public aura::test::AuraTestBase { | |
16 public: | |
17 LauncherViewTest() {} | |
18 virtual ~LauncherViewTest() {} | |
19 | |
20 virtual void SetUp() OVERRIDE { | |
21 aura::test::AuraTestBase::SetUp(); | |
22 | |
23 model_.reset(new LauncherModel); | |
24 | |
25 launcher_view_.reset(new internal::LauncherView(model_.get(), NULL)); | |
26 launcher_view_->Init(); | |
27 // The bounds should be big enough for 4 buttons + overflow chevron. | |
28 launcher_view_->SetBounds(0, 0, 500, 50); | |
29 | |
30 test_api_.reset(new LauncherViewTestAPI(launcher_view_.get())); | |
31 test_api_->SetAnimationDuration(1); // Speeds up animation for test. | |
32 } | |
33 | |
34 protected: | |
35 LauncherID AddAppShortcut() { | |
36 LauncherItem item; | |
37 item.type = TYPE_APP_SHORTCUT; | |
38 item.status = STATUS_CLOSED; | |
39 | |
40 int id = model_->next_id(); | |
41 model_->Add(item); | |
42 test_api_->RunMessageLoopUntilAnimationsDone(); | |
43 return id; | |
44 } | |
45 | |
46 LauncherID AddTabbedBrowser() { | |
47 LauncherItem item; | |
48 item.type = TYPE_TABBED; | |
49 item.status = STATUS_RUNNING; | |
50 | |
51 int id = model_->next_id(); | |
52 model_->Add(item); | |
53 test_api_->RunMessageLoopUntilAnimationsDone(); | |
54 return id; | |
55 } | |
56 | |
57 void RemoveByID(LauncherID id) { | |
58 model_->RemoveItemAt(model_->ItemIndexByID(id)); | |
59 test_api_->RunMessageLoopUntilAnimationsDone(); | |
60 } | |
61 | |
62 internal::LauncherButton* GetButtonByID(LauncherID id) { | |
63 int index = model_->ItemIndexByID(id); | |
64 return test_api_->GetButton(index); | |
65 } | |
66 | |
67 scoped_ptr<LauncherModel> model_; | |
68 scoped_ptr<internal::LauncherView> launcher_view_; | |
69 scoped_ptr<LauncherViewTestAPI> test_api_; | |
70 | |
71 private: | |
72 DISALLOW_COPY_AND_ASSIGN(LauncherViewTest); | |
73 }; | |
74 | |
75 // Adds browser button until overflow and verifies that the last added browser | |
76 // button is hidden. | |
77 TEST_F(LauncherViewTest, AddBrowserUntilOverflow) { | |
78 // All buttons should be visible. | |
79 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | |
80 test_api_->GetButtonCount()); | |
81 | |
82 // Add tabbed browser until overflow. | |
83 LauncherID last_added = AddTabbedBrowser(); | |
84 while (!test_api_->IsOverflowButtonVisible()) { | |
85 // Added button is visible after animation while in this loop. | |
86 EXPECT_TRUE(GetButtonByID(last_added)->visible()); | |
87 | |
88 last_added = AddTabbedBrowser(); | |
89 } | |
90 | |
91 // The last added button should be invisible. | |
92 EXPECT_FALSE(GetButtonByID(last_added)->visible()); | |
93 } | |
94 | |
95 // Adds one browser button then adds app shortcut until overflow. Verifies that | |
96 // the browser button gets hidden on overflow and last added app shortcut is | |
97 // still visible. | |
98 TEST_F(LauncherViewTest, AddAppShortcutWithBrowserButtonUntilOverflow) { | |
99 // All buttons should be visible. | |
100 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | |
101 test_api_->GetButtonCount()); | |
102 | |
103 LauncherID browser_button_id = AddTabbedBrowser(); | |
104 | |
105 // Add app shortcut until overflow. | |
106 LauncherID last_added = AddAppShortcut(); | |
107 while (!test_api_->IsOverflowButtonVisible()) { | |
108 // Added button is visible after animation while in this loop. | |
109 EXPECT_TRUE(GetButtonByID(last_added)->visible()); | |
110 | |
111 last_added = AddAppShortcut(); | |
112 } | |
113 | |
114 // The last added app short button should be visible. | |
115 EXPECT_TRUE(GetButtonByID(last_added)->visible()); | |
116 // And the browser button is invisible. | |
117 EXPECT_FALSE(GetButtonByID(browser_button_id)->visible()); | |
118 } | |
119 | |
120 // Adds button until overflow then removes first added one. Verifies that | |
121 // the last added one changes from invisible to visible and overflow | |
122 // chevron is gone. | |
123 TEST_F(LauncherViewTest, RemoveButtonRevealsOverflowed) { | |
124 // All buttons should be visible. | |
125 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | |
126 test_api_->GetButtonCount()); | |
127 | |
128 // Add tabbed browser until overflow. | |
129 LauncherID first_added= AddTabbedBrowser(); | |
130 LauncherID last_added = first_added; | |
131 while (!test_api_->IsOverflowButtonVisible()) | |
132 last_added = AddTabbedBrowser(); | |
133 | |
134 // Expect add more than 1 button. First added is visible and last is not. | |
135 EXPECT_NE(first_added, last_added); | |
136 EXPECT_TRUE(GetButtonByID(first_added)->visible()); | |
137 EXPECT_FALSE(GetButtonByID(last_added)->visible()); | |
138 | |
139 // Remove first added. | |
140 RemoveByID(first_added); | |
141 | |
142 // Last added button becomes visible and overflow chevron is gone. | |
143 EXPECT_TRUE(GetButtonByID(last_added)->visible()); | |
144 EXPECT_FALSE(test_api_->IsOverflowButtonVisible()); | |
145 } | |
146 | |
147 // Verifies that remove last overflowed button should hide overflow chevron. | |
148 TEST_F(LauncherViewTest, RemoveLastOverflowed) { | |
149 // All buttons should be visible. | |
150 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | |
151 test_api_->GetButtonCount()); | |
152 | |
153 // Add tabbed browser until overflow. | |
154 LauncherID last_added= AddTabbedBrowser(); | |
155 while (!test_api_->IsOverflowButtonVisible()) | |
156 last_added = AddTabbedBrowser(); | |
157 | |
158 RemoveByID(last_added); | |
159 EXPECT_FALSE(test_api_->IsOverflowButtonVisible()); | |
160 } | |
161 | |
162 } // namespace test | |
163 } // namespace ash | |
OLD | NEW |