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 ASSERT_TRUE(launcher); | 25 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); |
26 views::View* launcher_view = launcher->widget()->GetContentsView(); | |
27 ASSERT_EQ(1, launcher_view->child_count()); | |
28 launcher_view = launcher_view->child_at(0); | |
29 | 26 |
30 int total_width = launcher->widget()->GetWindowScreenBounds().width(); | 27 int total_width = launcher->widget()->GetWindowScreenBounds().width(); |
31 ASSERT_GT(total_width, 0); | 28 ASSERT_GT(total_width, 0); |
32 launcher->SetStatusWidth(total_width / 2); | 29 launcher->SetStatusWidth(total_width / 2); |
33 EXPECT_EQ(total_width - total_width / 2, launcher_view->width()); | 30 EXPECT_EQ(total_width - total_width / 2, launcher_view->width()); |
34 } | 31 } |
35 | 32 |
| 33 // Confirm that launching an app gets the appropriate state reflected in |
| 34 // its button. |
36 TEST_F(LauncherTest, LaunchApp) { | 35 TEST_F(LauncherTest, LaunchApp) { |
37 Launcher* launcher = Shell::GetInstance()->launcher(); | 36 Launcher* launcher = Shell::GetInstance()->launcher(); |
38 ASSERT_TRUE(launcher); | 37 ASSERT_TRUE(launcher); |
39 views::View* contents_view = launcher->widget()->GetContentsView(); | 38 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); |
40 ASSERT_EQ(1, contents_view->child_count()); | |
41 LauncherView* launcher_view = | |
42 static_cast<LauncherView*>(contents_view->child_at(0)); | |
43 LauncherView::TestAPI test(launcher_view); | 39 LauncherView::TestAPI test(launcher_view); |
44 LauncherModel* model = launcher->model(); | 40 LauncherModel* model = launcher->model(); |
45 | 41 |
46 // Initially we have the app list and chrome icon. | 42 // Initially we have the app list and chrome icon. |
47 int button_count = test.GetButtonCount(); | 43 int button_count = test.GetButtonCount(); |
48 int item_count = model->item_count(); | 44 int item_count = model->item_count(); |
49 | 45 |
50 // Add closed app. | 46 // Add closed app. |
51 LauncherItem item; | 47 LauncherItem item; |
52 item.type = TYPE_APP; | 48 item.type = TYPE_APP; |
(...skipping 12 matching lines...) Expand all Loading... |
65 item = model->items()[item_count]; | 61 item = model->items()[item_count]; |
66 item.status = STATUS_CLOSED; | 62 item.status = STATUS_CLOSED; |
67 model->Set(item_count, item); | 63 model->Set(item_count, item); |
68 EXPECT_EQ(LauncherButton::STATE_NORMAL, button->state()); | 64 EXPECT_EQ(LauncherButton::STATE_NORMAL, button->state()); |
69 | 65 |
70 // Remove it. | 66 // Remove it. |
71 model->RemoveItemAt(item_count); | 67 model->RemoveItemAt(item_count); |
72 ASSERT_EQ(--button_count, test.GetButtonCount()); | 68 ASSERT_EQ(--button_count, test.GetButtonCount()); |
73 } | 69 } |
74 | 70 |
| 71 // Confirm that launching a browser gets the appropriate state reflected in |
| 72 // its button. |
75 TEST_F(LauncherTest, OpenBrowser) { | 73 TEST_F(LauncherTest, OpenBrowser) { |
76 Launcher* launcher = Shell::GetInstance()->launcher(); | 74 Launcher* launcher = Shell::GetInstance()->launcher(); |
77 ASSERT_TRUE(launcher); | 75 ASSERT_TRUE(launcher); |
78 views::View* contents_view = launcher->widget()->GetContentsView(); | 76 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); |
79 ASSERT_EQ(1, contents_view->child_count()); | |
80 LauncherView* launcher_view = | |
81 static_cast<LauncherView*>(contents_view->child_at(0)); | |
82 LauncherView::TestAPI test(launcher_view); | 77 LauncherView::TestAPI test(launcher_view); |
83 LauncherModel* model = launcher->model(); | 78 LauncherModel* model = launcher->model(); |
84 | 79 |
85 // Initially we have the app list and chrome icon. | 80 // Initially we have the app list and chrome icon. |
86 int button_count = test.GetButtonCount(); | 81 int button_count = test.GetButtonCount(); |
87 int item_count = model->item_count(); | 82 int item_count = model->item_count(); |
88 | 83 |
89 // Add running tab. | 84 // Add running tab. |
90 LauncherItem item; | 85 LauncherItem item; |
91 item.type = TYPE_TABBED; | 86 item.type = TYPE_TABBED; |
92 item.status = STATUS_RUNNING; | 87 item.status = STATUS_RUNNING; |
93 model->Add(item_count, item); | 88 model->Add(item_count, item); |
94 ASSERT_EQ(++button_count, test.GetButtonCount()); | 89 ASSERT_EQ(++button_count, test.GetButtonCount()); |
95 LauncherButton* button = test.GetButton(button_count - 1); | 90 LauncherButton* button = test.GetButton(button_count - 1); |
96 EXPECT_EQ(LauncherButton::STATE_RUNNING, button->state()); | 91 EXPECT_EQ(LauncherButton::STATE_RUNNING, button->state()); |
97 | 92 |
98 // Remove it. | 93 // Remove it. |
99 model->RemoveItemAt(item_count); | 94 model->RemoveItemAt(item_count); |
100 ASSERT_EQ(--button_count, test.GetButtonCount()); | 95 ASSERT_EQ(--button_count, test.GetButtonCount()); |
101 } | 96 } |
102 | 97 |
| 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 |
103 } // namespace ash | 138 } // namespace ash |
OLD | NEW |