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(TYPE_APP); | 47 LauncherItem item(TYPE_APP); |
52 model->Add(item_count, item); | 48 model->Add(item_count, item); |
(...skipping 11 matching lines...) Expand all Loading... |
64 item = model->items()[item_count]; | 60 item = model->items()[item_count]; |
65 item.status = STATUS_CLOSED; | 61 item.status = STATUS_CLOSED; |
66 model->Set(item_count, item); | 62 model->Set(item_count, item); |
67 EXPECT_EQ(LauncherButton::STATE_NORMAL, button->state()); | 63 EXPECT_EQ(LauncherButton::STATE_NORMAL, button->state()); |
68 | 64 |
69 // Remove it. | 65 // Remove it. |
70 model->RemoveItemAt(item_count); | 66 model->RemoveItemAt(item_count); |
71 ASSERT_EQ(--button_count, test.GetButtonCount()); | 67 ASSERT_EQ(--button_count, test.GetButtonCount()); |
72 } | 68 } |
73 | 69 |
| 70 // Confirm that launching a browser gets the appropriate state reflected in |
| 71 // its button. |
74 TEST_F(LauncherTest, OpenBrowser) { | 72 TEST_F(LauncherTest, OpenBrowser) { |
75 Launcher* launcher = Shell::GetInstance()->launcher(); | 73 Launcher* launcher = Shell::GetInstance()->launcher(); |
76 ASSERT_TRUE(launcher); | 74 ASSERT_TRUE(launcher); |
77 views::View* contents_view = launcher->widget()->GetContentsView(); | 75 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); |
78 ASSERT_EQ(1, contents_view->child_count()); | |
79 LauncherView* launcher_view = | |
80 static_cast<LauncherView*>(contents_view->child_at(0)); | |
81 LauncherView::TestAPI test(launcher_view); | 76 LauncherView::TestAPI test(launcher_view); |
82 LauncherModel* model = launcher->model(); | 77 LauncherModel* model = launcher->model(); |
83 | 78 |
84 // Initially we have the app list and chrome icon. | 79 // Initially we have the app list and chrome icon. |
85 int button_count = test.GetButtonCount(); | 80 int button_count = test.GetButtonCount(); |
86 int item_count = model->item_count(); | 81 int item_count = model->item_count(); |
87 | 82 |
88 // Add running tab. | 83 // Add running tab. |
89 LauncherItem item(TYPE_TABBED); | 84 LauncherItem item(TYPE_TABBED); |
90 item.status = STATUS_RUNNING; | 85 item.status = STATUS_RUNNING; |
91 model->Add(item_count, item); | 86 model->Add(item_count, item); |
92 ASSERT_EQ(++button_count, test.GetButtonCount()); | 87 ASSERT_EQ(++button_count, test.GetButtonCount()); |
93 LauncherButton* button = test.GetButton(button_count - 1); | 88 LauncherButton* button = test.GetButton(button_count - 1); |
94 EXPECT_EQ(LauncherButton::STATE_RUNNING, button->state()); | 89 EXPECT_EQ(LauncherButton::STATE_RUNNING, button->state()); |
95 | 90 |
96 // Remove it. | 91 // Remove it. |
97 model->RemoveItemAt(item_count); | 92 model->RemoveItemAt(item_count); |
98 ASSERT_EQ(--button_count, test.GetButtonCount()); | 93 ASSERT_EQ(--button_count, test.GetButtonCount()); |
99 } | 94 } |
100 | 95 |
| 96 // Confirm that opening two different browsers and changing their activation |
| 97 // causes the appropriate state changes in the launcher buttons. |
| 98 TEST_F(LauncherTest, OpenTwoBrowsers) { |
| 99 Launcher* launcher = Shell::GetInstance()->launcher(); |
| 100 ASSERT_TRUE(launcher); |
| 101 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); |
| 102 LauncherView::TestAPI test(launcher_view); |
| 103 LauncherModel* model = launcher->model(); |
| 104 |
| 105 // Initially we have the app list and chrome icon. |
| 106 int button_count = test.GetButtonCount(); |
| 107 int item_count = model->item_count(); |
| 108 int button1 = button_count, button2 = button_count + 1; |
| 109 int item1 = item_count; |
| 110 |
| 111 // Add active tab. |
| 112 { |
| 113 LauncherItem item(TYPE_TABBED); |
| 114 item.status = STATUS_ACTIVE; |
| 115 model->Add(item_count, item); |
| 116 } |
| 117 ASSERT_EQ(++button_count, test.GetButtonCount()); |
| 118 EXPECT_EQ(LauncherButton::STATE_ACTIVE, test.GetButton(button1)->state()); |
| 119 |
| 120 // Add new active tab and deactivate other. |
| 121 { |
| 122 LauncherItem item(TYPE_TABBED); |
| 123 item.status = STATUS_ACTIVE; |
| 124 model->Add(item_count, item); |
| 125 LauncherItem last_item = model->items()[item1]; |
| 126 last_item.status = STATUS_RUNNING; |
| 127 model->Set(item1, last_item); |
| 128 } |
| 129 |
| 130 ASSERT_EQ(++button_count, test.GetButtonCount()); |
| 131 EXPECT_EQ(LauncherButton::STATE_RUNNING, test.GetButton(button1)->state()); |
| 132 EXPECT_EQ(LauncherButton::STATE_ACTIVE, test.GetButton(button2)->state()); |
| 133 } |
| 134 |
101 } // namespace ash | 135 } // namespace ash |
OLD | NEW |