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_model.h" | 6 #include "ash/launcher/launcher_model.h" |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/wm/window_util.h" | 8 #include "ash/wm/window_util.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); | 82 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
83 | 83 |
84 // Then close it, make sure there's still an item. | 84 // Then close it, make sure there's still an item. |
85 CloseShellWindow(window); | 85 CloseShellWindow(window); |
86 ASSERT_EQ(item_count, launcher->model()->item_count()); | 86 ASSERT_EQ(item_count, launcher->model()->item_count()); |
87 item = *launcher->model()->ItemByID(shortcut_id); | 87 item = *launcher->model()->ItemByID(shortcut_id); |
88 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 88 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
89 EXPECT_EQ(ash::STATUS_CLOSED, item.status); | 89 EXPECT_EQ(ash::STATUS_CLOSED, item.status); |
90 } | 90 } |
91 | 91 |
| 92 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, PinRunning) { |
| 93 // Run. |
| 94 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); |
| 95 ChromeLauncherController* controller = |
| 96 static_cast<ChromeLauncherController*>(launcher->delegate()); |
| 97 int item_count = launcher->model()->item_count(); |
| 98 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
| 99 ShellWindow* window = CreateShellWindow(extension); |
| 100 ++item_count; |
| 101 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 102 ash::LauncherItem item = |
| 103 launcher->model()->items()[launcher->model()->item_count() - 2]; |
| 104 ash::LauncherID id = item.id; |
| 105 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); |
| 106 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
| 107 |
| 108 // Create a shortcut. The app item should be after it. |
| 109 ash::LauncherID foo_id = controller->CreateAppLauncherItem( |
| 110 NULL, std::string("foo"), ash::STATUS_CLOSED); |
| 111 ++item_count; |
| 112 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 113 EXPECT_LT(launcher->model()->ItemIndexByID(foo_id), |
| 114 launcher->model()->ItemIndexByID(id)); |
| 115 |
| 116 // Pin the app. The item should remain. |
| 117 controller->Pin(id); |
| 118 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 119 item = *launcher->model()->ItemByID(id); |
| 120 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 121 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
| 122 |
| 123 // New shortcuts should come after the item. |
| 124 ash::LauncherID bar_id = controller->CreateAppLauncherItem( |
| 125 NULL, std::string("bar"), ash::STATUS_CLOSED); |
| 126 ++item_count; |
| 127 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 128 EXPECT_LT(launcher->model()->ItemIndexByID(id), |
| 129 launcher->model()->ItemIndexByID(bar_id)); |
| 130 |
| 131 // Then close it, make sure the item remains. |
| 132 CloseShellWindow(window); |
| 133 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 134 } |
| 135 |
| 136 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) { |
| 137 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); |
| 138 int item_count = launcher->model()->item_count(); |
| 139 |
| 140 // First get app_id. |
| 141 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
| 142 const std::string app_id = extension->id(); |
| 143 |
| 144 // Then create a shortcut. |
| 145 ChromeLauncherController* controller = |
| 146 static_cast<ChromeLauncherController*>(launcher->delegate()); |
| 147 ash::LauncherID shortcut_id = |
| 148 controller->CreateAppLauncherItem(NULL, app_id, ash::STATUS_CLOSED); |
| 149 ++item_count; |
| 150 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 151 ash::LauncherItem item = *launcher->model()->ItemByID(shortcut_id); |
| 152 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 153 EXPECT_EQ(ash::STATUS_CLOSED, item.status); |
| 154 |
| 155 // Create a second shortcut. This will be needed to force the first one to |
| 156 // move once it gets unpinned. |
| 157 ash::LauncherID foo_id = controller->CreateAppLauncherItem( |
| 158 NULL, std::string("foo"), ash::STATUS_CLOSED); |
| 159 ++item_count; |
| 160 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 161 EXPECT_LT(launcher->model()->ItemIndexByID(shortcut_id), |
| 162 launcher->model()->ItemIndexByID(foo_id)); |
| 163 |
| 164 // Open a window. Confirm the item is now running. |
| 165 ShellWindow* window = CreateShellWindow(extension); |
| 166 ash::wm::ActivateWindow(window->GetNativeWindow()); |
| 167 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 168 item = *launcher->model()->ItemByID(shortcut_id); |
| 169 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 170 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
| 171 |
| 172 // Unpin the app. The item should remain. |
| 173 controller->Unpin(shortcut_id); |
| 174 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 175 item = *launcher->model()->ItemByID(shortcut_id); |
| 176 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); |
| 177 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
| 178 // The item should have moved after the other shortcuts. |
| 179 EXPECT_GT(launcher->model()->ItemIndexByID(shortcut_id), |
| 180 launcher->model()->ItemIndexByID(foo_id)); |
| 181 |
| 182 // Then close it, make sure the item's gone. |
| 183 CloseShellWindow(window); |
| 184 --item_count; |
| 185 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 186 } |
| 187 |
92 // Test that we can launch a platform app with more than one window. | 188 // Test that we can launch a platform app with more than one window. |
93 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) { | 189 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) { |
94 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); | 190 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); |
95 int item_count = launcher->model()->item_count(); | 191 int item_count = launcher->model()->item_count(); |
96 | 192 |
97 // First run app. | 193 // First run app. |
98 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | 194 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
99 ShellWindow* window1 = CreateShellWindow(extension); | 195 ShellWindow* window1 = CreateShellWindow(extension); |
100 ++item_count; | 196 ++item_count; |
101 ASSERT_EQ(item_count, launcher->model()->item_count()); | 197 ASSERT_EQ(item_count, launcher->model()->item_count()); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 // First app should be active again. | 336 // First app should be active again. |
241 EXPECT_EQ(ash::STATUS_ACTIVE, launcher->model()->ItemByID(item_id1)->status); | 337 EXPECT_EQ(ash::STATUS_ACTIVE, launcher->model()->ItemByID(item_id1)->status); |
242 | 338 |
243 // Close first app. | 339 // Close first app. |
244 CloseShellWindow(window3); | 340 CloseShellWindow(window3); |
245 CloseShellWindow(window1); | 341 CloseShellWindow(window1); |
246 --item_count; | 342 --item_count; |
247 EXPECT_EQ(item_count, launcher->model()->item_count()); | 343 EXPECT_EQ(item_count, launcher->model()->item_count()); |
248 | 344 |
249 } | 345 } |
OLD | NEW |