OLD | NEW |
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 "ash/launcher/launcher.h" | 5 #include "ash/launcher/launcher.h" |
6 #include "ash/launcher/launcher_button.h" | 6 #include "ash/launcher/launcher_button.h" |
7 #include "ash/launcher/launcher_model.h" | 7 #include "ash/launcher/launcher_model.h" |
8 #include "ash/launcher/launcher_view.h" | 8 #include "ash/launcher/launcher_view.h" |
9 | 9 |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
12 #include "ui/views/view.h" | 12 #include "ui/views/view.h" |
13 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
14 | 14 |
15 typedef ash::test::AshTestBase LauncherTest; | 15 typedef ash::test::AshTestBase LauncherTest; |
16 using ash::internal::LauncherView; | 16 using ash::internal::LauncherView; |
17 using ash::internal::LauncherButton; | 17 using ash::internal::LauncherButton; |
18 | 18 |
19 namespace ash { | 19 namespace ash { |
20 | 20 |
21 // Makes sure invoking SetStatusWidth on the launcher changes the size of the | 21 // Makes sure invoking SetStatusWidth on the launcher changes the size of the |
22 // LauncherView. | 22 // LauncherView. |
23 TEST_F(LauncherTest, SetStatusWidth) { | 23 TEST_F(LauncherTest, SetStatusWidth) { |
24 Launcher* launcher = Shell::GetInstance()->launcher(); | 24 Launcher* launcher = Shell::GetInstance()->launcher(); |
25 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); | 25 ASSERT_TRUE(launcher); |
| 26 views::View* launcher_view = launcher->widget()->GetContentsView(); |
| 27 ASSERT_EQ(1, launcher_view->child_count()); |
| 28 launcher_view = launcher_view->child_at(0); |
26 | 29 |
27 int total_width = launcher->widget()->GetWindowScreenBounds().width(); | 30 int total_width = launcher->widget()->GetWindowScreenBounds().width(); |
28 ASSERT_GT(total_width, 0); | 31 ASSERT_GT(total_width, 0); |
29 launcher->SetStatusWidth(total_width / 2); | 32 launcher->SetStatusWidth(total_width / 2); |
30 EXPECT_EQ(total_width - total_width / 2, launcher_view->width()); | 33 EXPECT_EQ(total_width - total_width / 2, launcher_view->width()); |
31 } | 34 } |
32 | 35 |
33 // Confirm that launching an app gets the appropriate state reflected in | |
34 // its button. | |
35 TEST_F(LauncherTest, LaunchApp) { | 36 TEST_F(LauncherTest, LaunchApp) { |
36 Launcher* launcher = Shell::GetInstance()->launcher(); | 37 Launcher* launcher = Shell::GetInstance()->launcher(); |
37 ASSERT_TRUE(launcher); | 38 ASSERT_TRUE(launcher); |
38 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); | 39 views::View* contents_view = launcher->widget()->GetContentsView(); |
| 40 ASSERT_EQ(1, contents_view->child_count()); |
| 41 LauncherView* launcher_view = |
| 42 static_cast<LauncherView*>(contents_view->child_at(0)); |
39 LauncherView::TestAPI test(launcher_view); | 43 LauncherView::TestAPI test(launcher_view); |
40 LauncherModel* model = launcher->model(); | 44 LauncherModel* model = launcher->model(); |
41 | 45 |
42 // Initially we have the app list and chrome icon. | 46 // Initially we have the app list and chrome icon. |
43 int button_count = test.GetButtonCount(); | 47 int button_count = test.GetButtonCount(); |
44 int item_count = model->item_count(); | 48 int item_count = model->item_count(); |
45 | 49 |
46 // Add closed app. | 50 // Add closed app. |
47 LauncherItem item; | 51 LauncherItem item; |
48 item.type = TYPE_APP; | 52 item.type = TYPE_APP; |
(...skipping 12 matching lines...) Expand all Loading... |
61 item = model->items()[item_count]; | 65 item = model->items()[item_count]; |
62 item.status = STATUS_CLOSED; | 66 item.status = STATUS_CLOSED; |
63 model->Set(item_count, item); | 67 model->Set(item_count, item); |
64 EXPECT_EQ(LauncherButton::STATE_NORMAL, button->state()); | 68 EXPECT_EQ(LauncherButton::STATE_NORMAL, button->state()); |
65 | 69 |
66 // Remove it. | 70 // Remove it. |
67 model->RemoveItemAt(item_count); | 71 model->RemoveItemAt(item_count); |
68 ASSERT_EQ(--button_count, test.GetButtonCount()); | 72 ASSERT_EQ(--button_count, test.GetButtonCount()); |
69 } | 73 } |
70 | 74 |
71 // Confirm that launching a browser gets the appropriate state reflected in | |
72 // its button. | |
73 TEST_F(LauncherTest, OpenBrowser) { | 75 TEST_F(LauncherTest, OpenBrowser) { |
74 Launcher* launcher = Shell::GetInstance()->launcher(); | 76 Launcher* launcher = Shell::GetInstance()->launcher(); |
75 ASSERT_TRUE(launcher); | 77 ASSERT_TRUE(launcher); |
76 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); | 78 views::View* contents_view = launcher->widget()->GetContentsView(); |
| 79 ASSERT_EQ(1, contents_view->child_count()); |
| 80 LauncherView* launcher_view = |
| 81 static_cast<LauncherView*>(contents_view->child_at(0)); |
77 LauncherView::TestAPI test(launcher_view); | 82 LauncherView::TestAPI test(launcher_view); |
78 LauncherModel* model = launcher->model(); | 83 LauncherModel* model = launcher->model(); |
79 | 84 |
80 // Initially we have the app list and chrome icon. | 85 // Initially we have the app list and chrome icon. |
81 int button_count = test.GetButtonCount(); | 86 int button_count = test.GetButtonCount(); |
82 int item_count = model->item_count(); | 87 int item_count = model->item_count(); |
83 | 88 |
84 // Add running tab. | 89 // Add running tab. |
85 LauncherItem item; | 90 LauncherItem item; |
86 item.type = TYPE_TABBED; | 91 item.type = TYPE_TABBED; |
87 item.status = STATUS_RUNNING; | 92 item.status = STATUS_RUNNING; |
88 model->Add(item_count, item); | 93 model->Add(item_count, item); |
89 ASSERT_EQ(++button_count, test.GetButtonCount()); | 94 ASSERT_EQ(++button_count, test.GetButtonCount()); |
90 LauncherButton* button = test.GetButton(button_count - 1); | 95 LauncherButton* button = test.GetButton(button_count - 1); |
91 EXPECT_EQ(LauncherButton::STATE_RUNNING, button->state()); | 96 EXPECT_EQ(LauncherButton::STATE_RUNNING, button->state()); |
92 | 97 |
93 // Remove it. | 98 // Remove it. |
94 model->RemoveItemAt(item_count); | 99 model->RemoveItemAt(item_count); |
95 ASSERT_EQ(--button_count, test.GetButtonCount()); | 100 ASSERT_EQ(--button_count, test.GetButtonCount()); |
96 } | 101 } |
97 | 102 |
98 // Confirm that opening two different browsers and changing their activation | |
99 // causes the appropriate state changes in the launcher buttons. | |
100 TEST_F(LauncherTest, OpenTwoBrowsers) { | |
101 Launcher* launcher = Shell::GetInstance()->launcher(); | |
102 ASSERT_TRUE(launcher); | |
103 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); | |
104 LauncherView::TestAPI test(launcher_view); | |
105 LauncherModel* model = launcher->model(); | |
106 | |
107 // Initially we have the app list and chrome icon. | |
108 int button_count = test.GetButtonCount(); | |
109 int item_count = model->item_count(); | |
110 int button1 = button_count, button2 = button_count + 1; | |
111 int item1 = item_count; | |
112 | |
113 // Add active tab. | |
114 { | |
115 LauncherItem item; | |
116 item.type = TYPE_TABBED; | |
117 item.status = STATUS_ACTIVE; | |
118 model->Add(item_count, item); | |
119 } | |
120 ASSERT_EQ(++button_count, test.GetButtonCount()); | |
121 EXPECT_EQ(LauncherButton::STATE_ACTIVE, test.GetButton(button1)->state()); | |
122 | |
123 // Add new active tab and deactivate other. | |
124 { | |
125 LauncherItem item; | |
126 item.type = TYPE_TABBED; | |
127 model->Add(item_count, item); | |
128 LauncherItem last_item = model->items()[item1]; | |
129 last_item.status = STATUS_RUNNING; | |
130 model->Set(item1, last_item); | |
131 } | |
132 | |
133 ASSERT_EQ(++button_count, test.GetButtonCount()); | |
134 EXPECT_EQ(LauncherButton::STATE_RUNNING, test.GetButton(button1)->state()); | |
135 EXPECT_EQ(LauncherButton::STATE_ACTIVE, test.GetButton(button2)->state()); | |
136 } | |
137 | |
138 } // namespace ash | 103 } // namespace ash |
OLD | NEW |