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 "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
6 | 6 |
7 #include "ash/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
8 #include "ash/launcher/launcher_model.h" | 8 #include "ash/launcher/launcher_model.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 }; | 98 }; |
99 | 99 |
100 // Test that we can launch a platform app and get a running item. | 100 // Test that we can launch a platform app and get a running item. |
101 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) { | 101 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) { |
102 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); | 102 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); |
103 int item_count = launcher->model()->item_count(); | 103 int item_count = launcher->model()->item_count(); |
104 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | 104 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
105 ShellWindow* window = CreateShellWindow(extension); | 105 ShellWindow* window = CreateShellWindow(extension); |
106 ++item_count; | 106 ++item_count; |
107 ASSERT_EQ(item_count, launcher->model()->item_count()); | 107 ASSERT_EQ(item_count, launcher->model()->item_count()); |
108 ash::LauncherItem item = | 108 ash::LauncherItem item = launcher->model()->items()[item_count - 1]; |
109 launcher->model()->items()[launcher->model()->item_count() - 2]; | |
110 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); | 109 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); |
111 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); | 110 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
112 CloseShellWindow(window); | 111 CloseShellWindow(window); |
113 --item_count; | 112 --item_count; |
114 EXPECT_EQ(item_count, launcher->model()->item_count()); | 113 EXPECT_EQ(item_count, launcher->model()->item_count()); |
115 } | 114 } |
116 | 115 |
117 // Test that we can launch a platform app that already has a shortcut. | 116 // Test that we can launch a platform app that already has a shortcut. |
118 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) { | 117 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) { |
119 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); | 118 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, PinRunning) { | 152 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, PinRunning) { |
154 // Run. | 153 // Run. |
155 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); | 154 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); |
156 ChromeLauncherController* controller = | 155 ChromeLauncherController* controller = |
157 static_cast<ChromeLauncherController*>(launcher->delegate()); | 156 static_cast<ChromeLauncherController*>(launcher->delegate()); |
158 int item_count = launcher->model()->item_count(); | 157 int item_count = launcher->model()->item_count(); |
159 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | 158 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
160 ShellWindow* window = CreateShellWindow(extension); | 159 ShellWindow* window = CreateShellWindow(extension); |
161 ++item_count; | 160 ++item_count; |
162 ASSERT_EQ(item_count, launcher->model()->item_count()); | 161 ASSERT_EQ(item_count, launcher->model()->item_count()); |
163 ash::LauncherItem item = | 162 ash::LauncherItem item = launcher->model()->items()[item_count - 1]; |
164 launcher->model()->items()[launcher->model()->item_count() - 2]; | |
165 ash::LauncherID id = item.id; | 163 ash::LauncherID id = item.id; |
166 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); | 164 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); |
167 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); | 165 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
168 | 166 |
169 // Create a shortcut. The app item should be after it. | 167 // Create a shortcut. The app item should be after it. |
170 ash::LauncherID foo_id = controller->CreateAppLauncherItem( | 168 ash::LauncherID foo_id = controller->CreateAppLauncherItem( |
171 NULL, std::string("foo"), ash::STATUS_CLOSED); | 169 NULL, std::string("foo"), ash::STATUS_CLOSED); |
172 ++item_count; | 170 ++item_count; |
173 ASSERT_EQ(item_count, launcher->model()->item_count()); | 171 ASSERT_EQ(item_count, launcher->model()->item_count()); |
174 EXPECT_LT(launcher->model()->ItemIndexByID(foo_id), | 172 EXPECT_LT(launcher->model()->ItemIndexByID(foo_id), |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 // Test that we can launch a platform app with more than one window. | 247 // Test that we can launch a platform app with more than one window. |
250 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) { | 248 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) { |
251 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); | 249 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); |
252 int item_count = launcher->model()->item_count(); | 250 int item_count = launcher->model()->item_count(); |
253 | 251 |
254 // First run app. | 252 // First run app. |
255 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | 253 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
256 ShellWindow* window1 = CreateShellWindow(extension); | 254 ShellWindow* window1 = CreateShellWindow(extension); |
257 ++item_count; | 255 ++item_count; |
258 ASSERT_EQ(item_count, launcher->model()->item_count()); | 256 ASSERT_EQ(item_count, launcher->model()->item_count()); |
259 ash::LauncherItem item = | 257 ash::LauncherItem item = launcher->model()->items()[item_count - 1]; |
260 launcher->model()->items()[launcher->model()->item_count() - 2]; | |
261 ash::LauncherID item_id = item.id; | 258 ash::LauncherID item_id = item.id; |
262 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); | 259 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); |
263 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); | 260 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
264 | 261 |
265 // Add second window. | 262 // Add second window. |
266 ShellWindow* window2 = CreateShellWindow(extension); | 263 ShellWindow* window2 = CreateShellWindow(extension); |
267 // Confirm item stays. | 264 // Confirm item stays. |
268 ASSERT_EQ(item_count, launcher->model()->item_count()); | 265 ASSERT_EQ(item_count, launcher->model()->item_count()); |
269 item = *launcher->model()->ItemByID(item_id); | 266 item = *launcher->model()->ItemByID(item_id); |
270 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); | 267 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
(...skipping 14 matching lines...) Expand all Loading... |
285 | 282 |
286 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) { | 283 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) { |
287 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); | 284 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); |
288 int item_count = launcher->model()->item_count(); | 285 int item_count = launcher->model()->item_count(); |
289 | 286 |
290 // First run app. | 287 // First run app. |
291 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); | 288 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); |
292 ShellWindow* window1 = CreateShellWindow(extension1); | 289 ShellWindow* window1 = CreateShellWindow(extension1); |
293 ++item_count; | 290 ++item_count; |
294 ASSERT_EQ(item_count, launcher->model()->item_count()); | 291 ASSERT_EQ(item_count, launcher->model()->item_count()); |
295 ash::LauncherItem item1 = | 292 ash::LauncherItem item1 = launcher->model()->items()[item_count - 1]; |
296 launcher->model()->items()[launcher->model()->item_count() - 2]; | |
297 ash::LauncherID item_id1 = item1.id; | 293 ash::LauncherID item_id1 = item1.id; |
298 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | 294 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); |
299 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 295 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
300 | 296 |
301 // Then run second app. | 297 // Then run second app. |
302 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2"); | 298 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2"); |
303 ShellWindow* window2 = CreateShellWindow(extension2); | 299 ShellWindow* window2 = CreateShellWindow(extension2); |
304 ++item_count; | 300 ++item_count; |
305 ASSERT_EQ(item_count, launcher->model()->item_count()); | 301 ASSERT_EQ(item_count, launcher->model()->item_count()); |
306 ash::LauncherItem item2 = | 302 ash::LauncherItem item2 = launcher->model()->items()[item_count - 1]; |
307 launcher->model()->items()[launcher->model()->item_count() - 2]; | |
308 ash::LauncherID item_id2 = item2.id; | 303 ash::LauncherID item_id2 = item2.id; |
309 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item2.type); | 304 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item2.type); |
310 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); | 305 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); |
311 | 306 |
312 EXPECT_NE(item_id1, item_id2); | 307 EXPECT_NE(item_id1, item_id2); |
313 EXPECT_EQ(ash::STATUS_RUNNING, launcher->model()->ItemByID(item_id1)->status); | 308 EXPECT_EQ(ash::STATUS_RUNNING, launcher->model()->ItemByID(item_id1)->status); |
314 | 309 |
315 // Close second app. | 310 // Close second app. |
316 CloseShellWindow(window2); | 311 CloseShellWindow(window2); |
317 --item_count; | 312 --item_count; |
(...skipping 12 matching lines...) Expand all Loading... |
330 // the correct activation order is maintained. | 325 // the correct activation order is maintained. |
331 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowActivation) { | 326 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowActivation) { |
332 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); | 327 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); |
333 int item_count = launcher->model()->item_count(); | 328 int item_count = launcher->model()->item_count(); |
334 | 329 |
335 // First run app. | 330 // First run app. |
336 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); | 331 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); |
337 ShellWindow* window1 = CreateShellWindow(extension1); | 332 ShellWindow* window1 = CreateShellWindow(extension1); |
338 ++item_count; | 333 ++item_count; |
339 ASSERT_EQ(item_count, launcher->model()->item_count()); | 334 ASSERT_EQ(item_count, launcher->model()->item_count()); |
340 ash::LauncherItem item1 = | 335 ash::LauncherItem item1 = launcher->model()->items()[item_count - 1]; |
341 launcher->model()->items()[launcher->model()->item_count() - 2]; | |
342 ash::LauncherID item_id1 = item1.id; | 336 ash::LauncherID item_id1 = item1.id; |
343 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | 337 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); |
344 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 338 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
345 | 339 |
346 // Then run second app. | 340 // Then run second app. |
347 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2"); | 341 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2"); |
348 ShellWindow* window2 = CreateShellWindow(extension2); | 342 ShellWindow* window2 = CreateShellWindow(extension2); |
349 ++item_count; | 343 ++item_count; |
350 ASSERT_EQ(item_count, launcher->model()->item_count()); | 344 ASSERT_EQ(item_count, launcher->model()->item_count()); |
351 ash::LauncherItem item2 = | 345 ash::LauncherItem item2 = launcher->model()->items()[item_count - 1]; |
352 launcher->model()->items()[launcher->model()->item_count() - 2]; | |
353 ash::LauncherID item_id2 = item2.id; | 346 ash::LauncherID item_id2 = item2.id; |
354 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item2.type); | 347 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item2.type); |
355 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); | 348 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); |
356 | 349 |
357 EXPECT_NE(item_id1, item_id2); | 350 EXPECT_NE(item_id1, item_id2); |
358 EXPECT_EQ(ash::STATUS_RUNNING, launcher->model()->ItemByID(item_id1)->status); | 351 EXPECT_EQ(ash::STATUS_RUNNING, launcher->model()->ItemByID(item_id1)->status); |
359 | 352 |
360 // Activate first one. | 353 // Activate first one. |
361 launcher->ActivateLauncherItem(launcher->model()->ItemIndexByID(item_id1)); | 354 launcher->ActivateLauncherItem(launcher->model()->ItemIndexByID(item_id1)); |
362 EXPECT_EQ(ash::STATUS_ACTIVE, launcher->model()->ItemByID(item_id1)->status); | 355 EXPECT_EQ(ash::STATUS_ACTIVE, launcher->model()->ItemByID(item_id1)->status); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 | 407 |
415 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, BrowserActivation) { | 408 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, BrowserActivation) { |
416 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); | 409 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); |
417 int item_count = launcher->model()->item_count(); | 410 int item_count = launcher->model()->item_count(); |
418 | 411 |
419 // First run app. | 412 // First run app. |
420 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); | 413 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); |
421 CreateShellWindow(extension1); | 414 CreateShellWindow(extension1); |
422 ++item_count; | 415 ++item_count; |
423 ASSERT_EQ(item_count, launcher->model()->item_count()); | 416 ASSERT_EQ(item_count, launcher->model()->item_count()); |
424 ash::LauncherItem item1 = | 417 ash::LauncherItem item1 = launcher->model()->items()[item_count - 1]; |
425 launcher->model()->items()[launcher->model()->item_count() - 2]; | |
426 ash::LauncherID item_id1 = item1.id; | 418 ash::LauncherID item_id1 = item1.id; |
427 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | 419 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); |
428 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 420 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
429 | 421 |
430 ash::wm::ActivateWindow(browser()->window()->GetNativeWindow()); | 422 ash::wm::ActivateWindow(browser()->window()->GetNativeWindow()); |
431 EXPECT_EQ(ash::STATUS_RUNNING, launcher->model()->ItemByID(item_id1)->status); | 423 EXPECT_EQ(ash::STATUS_RUNNING, launcher->model()->ItemByID(item_id1)->status); |
432 } | 424 } |
433 | 425 |
434 // Test that we can launch an app with a shortcut. | 426 // Test that we can launch an app with a shortcut. |
435 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchPinned) { | 427 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchPinned) { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 // Navigate away. | 582 // Navigate away. |
591 ui_test_utils::NavigateToURL( | 583 ui_test_utils::NavigateToURL( |
592 browser(), GURL("http://www.example.com/path0/bar.html")); | 584 browser(), GURL("http://www.example.com/path0/bar.html")); |
593 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); | 585 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); |
594 | 586 |
595 // Navigate back. | 587 // Navigate back. |
596 ui_test_utils::NavigateToURL( | 588 ui_test_utils::NavigateToURL( |
597 browser(), GURL("http://www.example.com/path1/foo.html")); | 589 browser(), GURL("http://www.example.com/path1/foo.html")); |
598 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); | 590 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); |
599 } | 591 } |
OLD | NEW |