| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "apps/shell_window.h" | 7 #include "apps/app_window.h" |
| 8 #include "apps/shell_window_registry.h" | 8 #include "apps/app_window_registry.h" |
| 9 #include "apps/ui/native_app_window.h" | 9 #include "apps/ui/native_app_window.h" |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| 11 #include "ash/display/display_controller.h" | 11 #include "ash/display/display_controller.h" |
| 12 #include "ash/shelf/shelf.h" | 12 #include "ash/shelf/shelf.h" |
| 13 #include "ash/shelf/shelf_button.h" | 13 #include "ash/shelf/shelf_button.h" |
| 14 #include "ash/shelf/shelf_model.h" | 14 #include "ash/shelf/shelf_model.h" |
| 15 #include "ash/shelf/shelf_util.h" | 15 #include "ash/shelf/shelf_util.h" |
| 16 #include "ash/shelf/shelf_view.h" | 16 #include "ash/shelf/shelf_view.h" |
| 17 #include "ash/shell.h" | 17 #include "ash/shell.h" |
| 18 #include "ash/test/app_list_controller_test_api.h" | 18 #include "ash/test/app_list_controller_test_api.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 #include "extensions/browser/extension_system.h" | 53 #include "extensions/browser/extension_system.h" |
| 54 #include "extensions/common/constants.h" | 54 #include "extensions/common/constants.h" |
| 55 #include "extensions/common/switches.h" | 55 #include "extensions/common/switches.h" |
| 56 #include "testing/gtest/include/gtest/gtest.h" | 56 #include "testing/gtest/include/gtest/gtest.h" |
| 57 #include "ui/app_list/views/apps_grid_view.h" | 57 #include "ui/app_list/views/apps_grid_view.h" |
| 58 #include "ui/aura/client/aura_constants.h" | 58 #include "ui/aura/client/aura_constants.h" |
| 59 #include "ui/aura/test/event_generator.h" | 59 #include "ui/aura/test/event_generator.h" |
| 60 #include "ui/aura/window.h" | 60 #include "ui/aura/window.h" |
| 61 #include "ui/events/event.h" | 61 #include "ui/events/event.h" |
| 62 | 62 |
| 63 using apps::ShellWindow; | 63 using apps::AppWindow; |
| 64 using extensions::Extension; | 64 using extensions::Extension; |
| 65 using content::WebContents; | 65 using content::WebContents; |
| 66 | 66 |
| 67 namespace { | 67 namespace { |
| 68 | 68 |
| 69 class TestEvent : public ui::Event { | 69 class TestEvent : public ui::Event { |
| 70 public: | 70 public: |
| 71 explicit TestEvent(ui::EventType type) | 71 explicit TestEvent(ui::EventType type) |
| 72 : ui::Event(type, base::TimeDelta(), 0) { | 72 : ui::Event(type, base::TimeDelta(), 0) { |
| 73 } | 73 } |
| 74 virtual ~TestEvent() { | 74 virtual ~TestEvent() { |
| 75 } | 75 } |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 DISALLOW_COPY_AND_ASSIGN(TestEvent); | 78 DISALLOW_COPY_AND_ASSIGN(TestEvent); |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 class TestShellWindowRegistryObserver | 81 class TestAppWindowRegistryObserver : public apps::AppWindowRegistry::Observer { |
| 82 : public apps::ShellWindowRegistry::Observer { | |
| 83 public: | 82 public: |
| 84 explicit TestShellWindowRegistryObserver(Profile* profile) | 83 explicit TestAppWindowRegistryObserver(Profile* profile) |
| 85 : profile_(profile), | 84 : profile_(profile), icon_updates_(0) { |
| 86 icon_updates_(0) { | 85 apps::AppWindowRegistry::Get(profile_)->AddObserver(this); |
| 87 apps::ShellWindowRegistry::Get(profile_)->AddObserver(this); | |
| 88 } | 86 } |
| 89 | 87 |
| 90 virtual ~TestShellWindowRegistryObserver() { | 88 virtual ~TestAppWindowRegistryObserver() { |
| 91 apps::ShellWindowRegistry::Get(profile_)->RemoveObserver(this); | 89 apps::AppWindowRegistry::Get(profile_)->RemoveObserver(this); |
| 92 } | 90 } |
| 93 | 91 |
| 94 // Overridden from ShellWindowRegistry::Observer: | 92 // Overridden from AppWindowRegistry::Observer: |
| 95 virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE {} | 93 virtual void OnAppWindowAdded(AppWindow* app_window) OVERRIDE {} |
| 96 | 94 |
| 97 virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE { | 95 virtual void OnAppWindowIconChanged(AppWindow* app_window) OVERRIDE { |
| 98 ++icon_updates_; | 96 ++icon_updates_; |
| 99 } | 97 } |
| 100 | 98 |
| 101 virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE {} | 99 virtual void OnAppWindowRemoved(AppWindow* app_window) OVERRIDE {} |
| 102 | 100 |
| 103 int icon_updates() { return icon_updates_; } | 101 int icon_updates() { return icon_updates_; } |
| 104 | 102 |
| 105 private: | 103 private: |
| 106 Profile* profile_; | 104 Profile* profile_; |
| 107 int icon_updates_; | 105 int icon_updates_; |
| 108 | 106 |
| 109 DISALLOW_COPY_AND_ASSIGN(TestShellWindowRegistryObserver); | 107 DISALLOW_COPY_AND_ASSIGN(TestAppWindowRegistryObserver); |
| 110 }; | 108 }; |
| 111 | 109 |
| 112 } // namespace | 110 } // namespace |
| 113 | 111 |
| 114 class LauncherPlatformAppBrowserTest | 112 class LauncherPlatformAppBrowserTest |
| 115 : public extensions::PlatformAppBrowserTest { | 113 : public extensions::PlatformAppBrowserTest { |
| 116 protected: | 114 protected: |
| 117 LauncherPlatformAppBrowserTest() : shelf_(NULL), controller_(NULL) { | 115 LauncherPlatformAppBrowserTest() : shelf_(NULL), controller_(NULL) { |
| 118 } | 116 } |
| 119 | 117 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 339 |
| 342 DISALLOW_COPY_AND_ASSIGN(ShelfAppBrowserNoMinimizeOnClick); | 340 DISALLOW_COPY_AND_ASSIGN(ShelfAppBrowserNoMinimizeOnClick); |
| 343 }; | 341 }; |
| 344 | 342 |
| 345 typedef LauncherPlatformAppBrowserTest ShelfAppBrowserMinimizeOnClick; | 343 typedef LauncherPlatformAppBrowserTest ShelfAppBrowserMinimizeOnClick; |
| 346 | 344 |
| 347 // Test that we can launch a platform app and get a running item. | 345 // Test that we can launch a platform app and get a running item. |
| 348 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) { | 346 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) { |
| 349 int item_count = shelf_model()->item_count(); | 347 int item_count = shelf_model()->item_count(); |
| 350 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | 348 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
| 351 ShellWindow* window = CreateShellWindow(extension); | 349 AppWindow* window = CreateAppWindow(extension); |
| 352 ++item_count; | 350 ++item_count; |
| 353 ASSERT_EQ(item_count, shelf_model()->item_count()); | 351 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 354 const ash::ShelfItem& item = GetLastLauncherItem(); | 352 const ash::ShelfItem& item = GetLastLauncherItem(); |
| 355 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); | 353 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); |
| 356 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); | 354 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
| 357 CloseShellWindow(window); | 355 CloseAppWindow(window); |
| 358 --item_count; | 356 --item_count; |
| 359 EXPECT_EQ(item_count, shelf_model()->item_count()); | 357 EXPECT_EQ(item_count, shelf_model()->item_count()); |
| 360 } | 358 } |
| 361 | 359 |
| 362 // Test that we can launch a platform app that already has a shortcut. | 360 // Test that we can launch a platform app that already has a shortcut. |
| 363 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) { | 361 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) { |
| 364 int item_count = shelf_model()->item_count(); | 362 int item_count = shelf_model()->item_count(); |
| 365 | 363 |
| 366 // First get app_id. | 364 // First get app_id. |
| 367 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | 365 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
| 368 const std::string app_id = extension->id(); | 366 const std::string app_id = extension->id(); |
| 369 | 367 |
| 370 // Then create a shortcut. | 368 // Then create a shortcut. |
| 371 ash::ShelfID shortcut_id = CreateAppShortcutLauncherItem(app_id); | 369 ash::ShelfID shortcut_id = CreateAppShortcutLauncherItem(app_id); |
| 372 ++item_count; | 370 ++item_count; |
| 373 ASSERT_EQ(item_count, shelf_model()->item_count()); | 371 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 374 ash::ShelfItem item = *shelf_model()->ItemByID(shortcut_id); | 372 ash::ShelfItem item = *shelf_model()->ItemByID(shortcut_id); |
| 375 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 373 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 376 EXPECT_EQ(ash::STATUS_CLOSED, item.status); | 374 EXPECT_EQ(ash::STATUS_CLOSED, item.status); |
| 377 | 375 |
| 378 // Open a window. Confirm the item is now running. | 376 // Open a window. Confirm the item is now running. |
| 379 ShellWindow* window = CreateShellWindow(extension); | 377 AppWindow* window = CreateAppWindow(extension); |
| 380 ash::wm::ActivateWindow(window->GetNativeWindow()); | 378 ash::wm::ActivateWindow(window->GetNativeWindow()); |
| 381 ASSERT_EQ(item_count, shelf_model()->item_count()); | 379 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 382 item = *shelf_model()->ItemByID(shortcut_id); | 380 item = *shelf_model()->ItemByID(shortcut_id); |
| 383 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 381 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 384 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); | 382 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
| 385 | 383 |
| 386 // Then close it, make sure there's still an item. | 384 // Then close it, make sure there's still an item. |
| 387 CloseShellWindow(window); | 385 CloseAppWindow(window); |
| 388 ASSERT_EQ(item_count, shelf_model()->item_count()); | 386 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 389 item = *shelf_model()->ItemByID(shortcut_id); | 387 item = *shelf_model()->ItemByID(shortcut_id); |
| 390 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 388 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 391 EXPECT_EQ(ash::STATUS_CLOSED, item.status); | 389 EXPECT_EQ(ash::STATUS_CLOSED, item.status); |
| 392 } | 390 } |
| 393 | 391 |
| 394 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, PinRunning) { | 392 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, PinRunning) { |
| 395 // Run. | 393 // Run. |
| 396 int item_count = shelf_model()->item_count(); | 394 int item_count = shelf_model()->item_count(); |
| 397 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | 395 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
| 398 ShellWindow* window = CreateShellWindow(extension); | 396 AppWindow* window = CreateAppWindow(extension); |
| 399 ++item_count; | 397 ++item_count; |
| 400 ASSERT_EQ(item_count, shelf_model()->item_count()); | 398 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 401 const ash::ShelfItem& item1 = GetLastLauncherItem(); | 399 const ash::ShelfItem& item1 = GetLastLauncherItem(); |
| 402 ash::ShelfID id = item1.id; | 400 ash::ShelfID id = item1.id; |
| 403 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | 401 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); |
| 404 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 402 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 405 | 403 |
| 406 // Create a shortcut. The app item should be after it. | 404 // Create a shortcut. The app item should be after it. |
| 407 ash::ShelfID foo_id = CreateAppShortcutLauncherItem("foo"); | 405 ash::ShelfID foo_id = CreateAppShortcutLauncherItem("foo"); |
| 408 ++item_count; | 406 ++item_count; |
| 409 ASSERT_EQ(item_count, shelf_model()->item_count()); | 407 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 410 EXPECT_LT(shelf_model()->ItemIndexByID(foo_id), | 408 EXPECT_LT(shelf_model()->ItemIndexByID(foo_id), |
| 411 shelf_model()->ItemIndexByID(id)); | 409 shelf_model()->ItemIndexByID(id)); |
| 412 | 410 |
| 413 // Pin the app. The item should remain. | 411 // Pin the app. The item should remain. |
| 414 controller_->Pin(id); | 412 controller_->Pin(id); |
| 415 ASSERT_EQ(item_count, shelf_model()->item_count()); | 413 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 416 const ash::ShelfItem& item2 = *shelf_model()->ItemByID(id); | 414 const ash::ShelfItem& item2 = *shelf_model()->ItemByID(id); |
| 417 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item2.type); | 415 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item2.type); |
| 418 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); | 416 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); |
| 419 | 417 |
| 420 // New shortcuts should come after the item. | 418 // New shortcuts should come after the item. |
| 421 ash::ShelfID bar_id = CreateAppShortcutLauncherItem("bar"); | 419 ash::ShelfID bar_id = CreateAppShortcutLauncherItem("bar"); |
| 422 ++item_count; | 420 ++item_count; |
| 423 ASSERT_EQ(item_count, shelf_model()->item_count()); | 421 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 424 EXPECT_LT(shelf_model()->ItemIndexByID(id), | 422 EXPECT_LT(shelf_model()->ItemIndexByID(id), |
| 425 shelf_model()->ItemIndexByID(bar_id)); | 423 shelf_model()->ItemIndexByID(bar_id)); |
| 426 | 424 |
| 427 // Then close it, make sure the item remains. | 425 // Then close it, make sure the item remains. |
| 428 CloseShellWindow(window); | 426 CloseAppWindow(window); |
| 429 ASSERT_EQ(item_count, shelf_model()->item_count()); | 427 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 430 } | 428 } |
| 431 | 429 |
| 432 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) { | 430 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) { |
| 433 int item_count = shelf_model()->item_count(); | 431 int item_count = shelf_model()->item_count(); |
| 434 | 432 |
| 435 // First get app_id. | 433 // First get app_id. |
| 436 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | 434 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
| 437 const std::string app_id = extension->id(); | 435 const std::string app_id = extension->id(); |
| 438 | 436 |
| 439 // Then create a shortcut. | 437 // Then create a shortcut. |
| 440 ash::ShelfID shortcut_id = CreateAppShortcutLauncherItem(app_id); | 438 ash::ShelfID shortcut_id = CreateAppShortcutLauncherItem(app_id); |
| 441 ++item_count; | 439 ++item_count; |
| 442 ASSERT_EQ(item_count, shelf_model()->item_count()); | 440 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 443 ash::ShelfItem item = *shelf_model()->ItemByID(shortcut_id); | 441 ash::ShelfItem item = *shelf_model()->ItemByID(shortcut_id); |
| 444 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 442 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 445 EXPECT_EQ(ash::STATUS_CLOSED, item.status); | 443 EXPECT_EQ(ash::STATUS_CLOSED, item.status); |
| 446 | 444 |
| 447 // Create a second shortcut. This will be needed to force the first one to | 445 // Create a second shortcut. This will be needed to force the first one to |
| 448 // move once it gets unpinned. | 446 // move once it gets unpinned. |
| 449 ash::ShelfID foo_id = CreateAppShortcutLauncherItem("foo"); | 447 ash::ShelfID foo_id = CreateAppShortcutLauncherItem("foo"); |
| 450 ++item_count; | 448 ++item_count; |
| 451 ASSERT_EQ(item_count, shelf_model()->item_count()); | 449 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 452 EXPECT_LT(shelf_model()->ItemIndexByID(shortcut_id), | 450 EXPECT_LT(shelf_model()->ItemIndexByID(shortcut_id), |
| 453 shelf_model()->ItemIndexByID(foo_id)); | 451 shelf_model()->ItemIndexByID(foo_id)); |
| 454 | 452 |
| 455 // Open a window. Confirm the item is now running. | 453 // Open a window. Confirm the item is now running. |
| 456 ShellWindow* window = CreateShellWindow(extension); | 454 AppWindow* window = CreateAppWindow(extension); |
| 457 ash::wm::ActivateWindow(window->GetNativeWindow()); | 455 ash::wm::ActivateWindow(window->GetNativeWindow()); |
| 458 ASSERT_EQ(item_count, shelf_model()->item_count()); | 456 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 459 item = *shelf_model()->ItemByID(shortcut_id); | 457 item = *shelf_model()->ItemByID(shortcut_id); |
| 460 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 458 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 461 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); | 459 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
| 462 | 460 |
| 463 // Unpin the app. The item should remain. | 461 // Unpin the app. The item should remain. |
| 464 controller_->Unpin(shortcut_id); | 462 controller_->Unpin(shortcut_id); |
| 465 ASSERT_EQ(item_count, shelf_model()->item_count()); | 463 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 466 item = *shelf_model()->ItemByID(shortcut_id); | 464 item = *shelf_model()->ItemByID(shortcut_id); |
| 467 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); | 465 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); |
| 468 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); | 466 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
| 469 // The item should have moved after the other shortcuts. | 467 // The item should have moved after the other shortcuts. |
| 470 EXPECT_GT(shelf_model()->ItemIndexByID(shortcut_id), | 468 EXPECT_GT(shelf_model()->ItemIndexByID(shortcut_id), |
| 471 shelf_model()->ItemIndexByID(foo_id)); | 469 shelf_model()->ItemIndexByID(foo_id)); |
| 472 | 470 |
| 473 // Then close it, make sure the item's gone. | 471 // Then close it, make sure the item's gone. |
| 474 CloseShellWindow(window); | 472 CloseAppWindow(window); |
| 475 --item_count; | 473 --item_count; |
| 476 ASSERT_EQ(item_count, shelf_model()->item_count()); | 474 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 477 } | 475 } |
| 478 | 476 |
| 479 // Test that we can launch a platform app with more than one window. | 477 // Test that we can launch a platform app with more than one window. |
| 480 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) { | 478 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) { |
| 481 int item_count = shelf_model()->item_count(); | 479 int item_count = shelf_model()->item_count(); |
| 482 | 480 |
| 483 // First run app. | 481 // First run app. |
| 484 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | 482 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
| 485 ShellWindow* window1 = CreateShellWindow(extension); | 483 AppWindow* window1 = CreateAppWindow(extension); |
| 486 ++item_count; | 484 ++item_count; |
| 487 ASSERT_EQ(item_count, shelf_model()->item_count()); | 485 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 488 const ash::ShelfItem& item1 = GetLastLauncherItem(); | 486 const ash::ShelfItem& item1 = GetLastLauncherItem(); |
| 489 ash::ShelfID item_id = item1.id; | 487 ash::ShelfID item_id = item1.id; |
| 490 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | 488 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); |
| 491 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 489 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 492 EXPECT_EQ(2, GetNumApplicationMenuItems(item1)); // Title + 1 window | 490 EXPECT_EQ(2, GetNumApplicationMenuItems(item1)); // Title + 1 window |
| 493 | 491 |
| 494 // Add second window. | 492 // Add second window. |
| 495 ShellWindow* window2 = CreateShellWindow(extension); | 493 AppWindow* window2 = CreateAppWindow(extension); |
| 496 // Confirm item stays. | 494 // Confirm item stays. |
| 497 ASSERT_EQ(item_count, shelf_model()->item_count()); | 495 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 498 const ash::ShelfItem& item2 = *shelf_model()->ItemByID(item_id); | 496 const ash::ShelfItem& item2 = *shelf_model()->ItemByID(item_id); |
| 499 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); | 497 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); |
| 500 EXPECT_EQ(3, GetNumApplicationMenuItems(item2)); // Title + 2 windows | 498 EXPECT_EQ(3, GetNumApplicationMenuItems(item2)); // Title + 2 windows |
| 501 | 499 |
| 502 // Close second window. | 500 // Close second window. |
| 503 CloseShellWindow(window2); | 501 CloseAppWindow(window2); |
| 504 // Confirm item stays. | 502 // Confirm item stays. |
| 505 ASSERT_EQ(item_count, shelf_model()->item_count()); | 503 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 506 const ash::ShelfItem& item3 = *shelf_model()->ItemByID(item_id); | 504 const ash::ShelfItem& item3 = *shelf_model()->ItemByID(item_id); |
| 507 EXPECT_EQ(ash::STATUS_ACTIVE, item3.status); | 505 EXPECT_EQ(ash::STATUS_ACTIVE, item3.status); |
| 508 EXPECT_EQ(2, GetNumApplicationMenuItems(item3)); // Title + 1 window | 506 EXPECT_EQ(2, GetNumApplicationMenuItems(item3)); // Title + 1 window |
| 509 | 507 |
| 510 // Close first window. | 508 // Close first window. |
| 511 CloseShellWindow(window1); | 509 CloseAppWindow(window1); |
| 512 // Confirm item is removed. | 510 // Confirm item is removed. |
| 513 --item_count; | 511 --item_count; |
| 514 ASSERT_EQ(item_count, shelf_model()->item_count()); | 512 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 515 } | 513 } |
| 516 | 514 |
| 517 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) { | 515 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) { |
| 518 int item_count = shelf_model()->item_count(); | 516 int item_count = shelf_model()->item_count(); |
| 519 | 517 |
| 520 // First run app. | 518 // First run app. |
| 521 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); | 519 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); |
| 522 ShellWindow* window1 = CreateShellWindow(extension1); | 520 AppWindow* window1 = CreateAppWindow(extension1); |
| 523 ++item_count; | 521 ++item_count; |
| 524 ASSERT_EQ(item_count, shelf_model()->item_count()); | 522 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 525 const ash::ShelfItem& item1 = GetLastLauncherItem(); | 523 const ash::ShelfItem& item1 = GetLastLauncherItem(); |
| 526 ash::ShelfID item_id1 = item1.id; | 524 ash::ShelfID item_id1 = item1.id; |
| 527 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | 525 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); |
| 528 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 526 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 529 | 527 |
| 530 // Then run second app. | 528 // Then run second app. |
| 531 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2"); | 529 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2"); |
| 532 ShellWindow* window2 = CreateShellWindow(extension2); | 530 AppWindow* window2 = CreateAppWindow(extension2); |
| 533 ++item_count; | 531 ++item_count; |
| 534 ASSERT_EQ(item_count, shelf_model()->item_count()); | 532 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 535 const ash::ShelfItem& item2 = GetLastLauncherItem(); | 533 const ash::ShelfItem& item2 = GetLastLauncherItem(); |
| 536 ash::ShelfID item_id2 = item2.id; | 534 ash::ShelfID item_id2 = item2.id; |
| 537 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item2.type); | 535 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item2.type); |
| 538 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); | 536 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); |
| 539 | 537 |
| 540 EXPECT_NE(item_id1, item_id2); | 538 EXPECT_NE(item_id1, item_id2); |
| 541 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status); | 539 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status); |
| 542 | 540 |
| 543 // Close second app. | 541 // Close second app. |
| 544 CloseShellWindow(window2); | 542 CloseAppWindow(window2); |
| 545 --item_count; | 543 --item_count; |
| 546 ASSERT_EQ(item_count, shelf_model()->item_count()); | 544 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 547 // First app should be active again. | 545 // First app should be active again. |
| 548 EXPECT_EQ(ash::STATUS_ACTIVE, shelf_model()->ItemByID(item_id1)->status); | 546 EXPECT_EQ(ash::STATUS_ACTIVE, shelf_model()->ItemByID(item_id1)->status); |
| 549 | 547 |
| 550 // Close first app. | 548 // Close first app. |
| 551 CloseShellWindow(window1); | 549 CloseAppWindow(window1); |
| 552 --item_count; | 550 --item_count; |
| 553 ASSERT_EQ(item_count, shelf_model()->item_count()); | 551 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 554 } | 552 } |
| 555 | 553 |
| 556 // Confirm that app windows can be reactivated by clicking their icons and that | 554 // Confirm that app windows can be reactivated by clicking their icons and that |
| 557 // the correct activation order is maintained. | 555 // the correct activation order is maintained. |
| 558 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowActivation) { | 556 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowActivation) { |
| 559 int item_count = shelf_model()->item_count(); | 557 int item_count = shelf_model()->item_count(); |
| 560 | 558 |
| 561 // First run app. | 559 // First run app. |
| 562 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); | 560 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); |
| 563 ShellWindow* window1 = CreateShellWindow(extension1); | 561 AppWindow* window1 = CreateAppWindow(extension1); |
| 564 ++item_count; | 562 ++item_count; |
| 565 ASSERT_EQ(item_count, shelf_model()->item_count()); | 563 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 566 const ash::ShelfItem& item1 = GetLastLauncherItem(); | 564 const ash::ShelfItem& item1 = GetLastLauncherItem(); |
| 567 ash::ShelfID item_id1 = item1.id; | 565 ash::ShelfID item_id1 = item1.id; |
| 568 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | 566 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); |
| 569 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 567 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 570 | 568 |
| 571 // Then run second app. | 569 // Then run second app. |
| 572 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2"); | 570 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2"); |
| 573 ShellWindow* window2 = CreateShellWindow(extension2); | 571 AppWindow* window2 = CreateAppWindow(extension2); |
| 574 ++item_count; | 572 ++item_count; |
| 575 ASSERT_EQ(item_count, shelf_model()->item_count()); | 573 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 576 const ash::ShelfItem& item2 = GetLastLauncherItem(); | 574 const ash::ShelfItem& item2 = GetLastLauncherItem(); |
| 577 ash::ShelfID item_id2 = item2.id; | 575 ash::ShelfID item_id2 = item2.id; |
| 578 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item2.type); | 576 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item2.type); |
| 579 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); | 577 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); |
| 580 | 578 |
| 581 EXPECT_NE(item_id1, item_id2); | 579 EXPECT_NE(item_id1, item_id2); |
| 582 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status); | 580 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status); |
| 583 | 581 |
| 584 // Activate first one. | 582 // Activate first one. |
| 585 ActivateShelfItem(shelf_model()->ItemIndexByID(item_id1)); | 583 ActivateShelfItem(shelf_model()->ItemIndexByID(item_id1)); |
| 586 EXPECT_EQ(ash::STATUS_ACTIVE, shelf_model()->ItemByID(item_id1)->status); | 584 EXPECT_EQ(ash::STATUS_ACTIVE, shelf_model()->ItemByID(item_id1)->status); |
| 587 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id2)->status); | 585 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id2)->status); |
| 588 EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); | 586 EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); |
| 589 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); | 587 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); |
| 590 | 588 |
| 591 // Activate second one. | 589 // Activate second one. |
| 592 ActivateShelfItem(shelf_model()->ItemIndexByID(item_id2)); | 590 ActivateShelfItem(shelf_model()->ItemIndexByID(item_id2)); |
| 593 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status); | 591 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status); |
| 594 EXPECT_EQ(ash::STATUS_ACTIVE, shelf_model()->ItemByID(item_id2)->status); | 592 EXPECT_EQ(ash::STATUS_ACTIVE, shelf_model()->ItemByID(item_id2)->status); |
| 595 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); | 593 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); |
| 596 EXPECT_TRUE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); | 594 EXPECT_TRUE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); |
| 597 | 595 |
| 598 // Add window for app1. This will activate it. | 596 // Add window for app1. This will activate it. |
| 599 ShellWindow* window1b = CreateShellWindow(extension1); | 597 AppWindow* window1b = CreateAppWindow(extension1); |
| 600 ash::wm::ActivateWindow(window1b->GetNativeWindow()); | 598 ash::wm::ActivateWindow(window1b->GetNativeWindow()); |
| 601 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); | 599 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); |
| 602 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); | 600 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); |
| 603 EXPECT_TRUE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); | 601 EXPECT_TRUE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); |
| 604 | 602 |
| 605 // Activate launcher item for app1, this will activate the first app window. | 603 // Activate launcher item for app1, this will activate the first app window. |
| 606 ActivateShelfItem(shelf_model()->ItemIndexByID(item_id1)); | 604 ActivateShelfItem(shelf_model()->ItemIndexByID(item_id1)); |
| 607 EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); | 605 EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); |
| 608 EXPECT_FALSE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); | 606 EXPECT_FALSE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); |
| 609 ActivateShelfItem(shelf_model()->ItemIndexByID(item_id1)); | 607 ActivateShelfItem(shelf_model()->ItemIndexByID(item_id1)); |
| 610 EXPECT_TRUE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); | 608 EXPECT_TRUE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); |
| 611 | 609 |
| 612 // Activate the second app again | 610 // Activate the second app again |
| 613 ActivateShelfItem(shelf_model()->ItemIndexByID(item_id2)); | 611 ActivateShelfItem(shelf_model()->ItemIndexByID(item_id2)); |
| 614 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); | 612 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); |
| 615 EXPECT_TRUE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); | 613 EXPECT_TRUE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); |
| 616 EXPECT_FALSE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); | 614 EXPECT_FALSE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); |
| 617 | 615 |
| 618 // Activate the first app again | 616 // Activate the first app again |
| 619 ActivateShelfItem(shelf_model()->ItemIndexByID(item_id1)); | 617 ActivateShelfItem(shelf_model()->ItemIndexByID(item_id1)); |
| 620 EXPECT_TRUE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); | 618 EXPECT_TRUE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); |
| 621 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); | 619 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); |
| 622 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); | 620 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); |
| 623 | 621 |
| 624 // Close second app. | 622 // Close second app. |
| 625 CloseShellWindow(window2); | 623 CloseAppWindow(window2); |
| 626 --item_count; | 624 --item_count; |
| 627 EXPECT_EQ(item_count, shelf_model()->item_count()); | 625 EXPECT_EQ(item_count, shelf_model()->item_count()); |
| 628 // First app should be active again. | 626 // First app should be active again. |
| 629 EXPECT_EQ(ash::STATUS_ACTIVE, shelf_model()->ItemByID(item_id1)->status); | 627 EXPECT_EQ(ash::STATUS_ACTIVE, shelf_model()->ItemByID(item_id1)->status); |
| 630 | 628 |
| 631 // Close first app. | 629 // Close first app. |
| 632 CloseShellWindow(window1b); | 630 CloseAppWindow(window1b); |
| 633 CloseShellWindow(window1); | 631 CloseAppWindow(window1); |
| 634 --item_count; | 632 --item_count; |
| 635 EXPECT_EQ(item_count, shelf_model()->item_count()); | 633 EXPECT_EQ(item_count, shelf_model()->item_count()); |
| 636 } | 634 } |
| 637 | 635 |
| 638 // Confirm that Click behavior for app windows is correnct. | 636 // Confirm that Click behavior for app windows is correnct. |
| 639 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserNoMinimizeOnClick, AppClickBehavior) { | 637 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserNoMinimizeOnClick, AppClickBehavior) { |
| 640 // Launch a platform app and create a window for it. | 638 // Launch a platform app and create a window for it. |
| 641 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); | 639 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); |
| 642 ShellWindow* window1 = CreateShellWindow(extension1); | 640 AppWindow* window1 = CreateAppWindow(extension1); |
| 643 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | 641 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); |
| 644 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | 642 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); |
| 645 // Confirm that a controller item was created and is the correct state. | 643 // Confirm that a controller item was created and is the correct state. |
| 646 const ash::ShelfItem& item1 = GetLastLauncherItem(); | 644 const ash::ShelfItem& item1 = GetLastLauncherItem(); |
| 647 LauncherItemController* item1_controller = GetItemController(item1.id); | 645 LauncherItemController* item1_controller = GetItemController(item1.id); |
| 648 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | 646 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); |
| 649 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 647 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 650 EXPECT_EQ(LauncherItemController::TYPE_APP, item1_controller->type()); | 648 EXPECT_EQ(LauncherItemController::TYPE_APP, item1_controller->type()); |
| 651 // Clicking the item should have no effect. | 649 // Clicking the item should have no effect. |
| 652 TestEvent click_event(ui::ET_MOUSE_PRESSED); | 650 TestEvent click_event(ui::ET_MOUSE_PRESSED); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 670 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | 668 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); |
| 671 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | 669 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); |
| 672 EXPECT_TRUE(window1->GetBaseWindow()->IsMaximized()); | 670 EXPECT_TRUE(window1->GetBaseWindow()->IsMaximized()); |
| 673 } | 671 } |
| 674 | 672 |
| 675 // Confirm the minimizing click behavior for apps. | 673 // Confirm the minimizing click behavior for apps. |
| 676 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserMinimizeOnClick, | 674 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserMinimizeOnClick, |
| 677 PackagedAppClickBehaviorInMinimizeMode) { | 675 PackagedAppClickBehaviorInMinimizeMode) { |
| 678 // Launch one platform app and create a window for it. | 676 // Launch one platform app and create a window for it. |
| 679 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); | 677 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); |
| 680 ShellWindow* window1 = CreateShellWindow(extension1); | 678 AppWindow* window1 = CreateAppWindow(extension1); |
| 681 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | 679 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); |
| 682 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | 680 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); |
| 683 | 681 |
| 684 // Confirm that a controller item was created and is the correct state. | 682 // Confirm that a controller item was created and is the correct state. |
| 685 const ash::ShelfItem& item1 = GetLastLauncherItem(); | 683 const ash::ShelfItem& item1 = GetLastLauncherItem(); |
| 686 LauncherItemController* item1_controller = GetItemController(item1.id); | 684 LauncherItemController* item1_controller = GetItemController(item1.id); |
| 687 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | 685 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); |
| 688 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 686 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 689 EXPECT_EQ(LauncherItemController::TYPE_APP, item1_controller->type()); | 687 EXPECT_EQ(LauncherItemController::TYPE_APP, item1_controller->type()); |
| 690 // Since it is already active, clicking it should minimize. | 688 // Since it is already active, clicking it should minimize. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 706 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | 704 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); |
| 707 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | 705 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); |
| 708 EXPECT_TRUE(window1->GetBaseWindow()->IsMaximized()); | 706 EXPECT_TRUE(window1->GetBaseWindow()->IsMaximized()); |
| 709 window1->GetBaseWindow()->Restore(); | 707 window1->GetBaseWindow()->Restore(); |
| 710 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | 708 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); |
| 711 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | 709 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); |
| 712 EXPECT_FALSE(window1->GetBaseWindow()->IsMaximized()); | 710 EXPECT_FALSE(window1->GetBaseWindow()->IsMaximized()); |
| 713 | 711 |
| 714 // Creating a second window of the same type should change the behavior so | 712 // Creating a second window of the same type should change the behavior so |
| 715 // that a click does not change the activation state. | 713 // that a click does not change the activation state. |
| 716 ShellWindow* window1a = CreateShellWindow(extension1); | 714 AppWindow* window1a = CreateAppWindow(extension1); |
| 717 EXPECT_TRUE(window1a->GetNativeWindow()->IsVisible()); | 715 EXPECT_TRUE(window1a->GetNativeWindow()->IsVisible()); |
| 718 EXPECT_TRUE(window1a->GetBaseWindow()->IsActive()); | 716 EXPECT_TRUE(window1a->GetBaseWindow()->IsActive()); |
| 719 // The first click does nothing. | 717 // The first click does nothing. |
| 720 item1_controller->ItemSelected(click_event); | 718 item1_controller->ItemSelected(click_event); |
| 721 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | 719 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); |
| 722 EXPECT_TRUE(window1a->GetNativeWindow()->IsVisible()); | 720 EXPECT_TRUE(window1a->GetNativeWindow()->IsVisible()); |
| 723 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | 721 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); |
| 724 EXPECT_FALSE(window1a->GetBaseWindow()->IsActive()); | 722 EXPECT_FALSE(window1a->GetBaseWindow()->IsActive()); |
| 725 // The second neither. | 723 // The second neither. |
| 726 item1_controller->ItemSelected(click_event); | 724 item1_controller->ItemSelected(click_event); |
| 727 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | 725 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); |
| 728 EXPECT_TRUE(window1a->GetNativeWindow()->IsVisible()); | 726 EXPECT_TRUE(window1a->GetNativeWindow()->IsVisible()); |
| 729 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | 727 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); |
| 730 EXPECT_FALSE(window1a->GetBaseWindow()->IsActive()); | 728 EXPECT_FALSE(window1a->GetBaseWindow()->IsActive()); |
| 731 } | 729 } |
| 732 | 730 |
| 733 // Confirm that click behavior for app panels is correct. | 731 // Confirm that click behavior for app panels is correct. |
| 734 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, AppPanelClickBehavior) { | 732 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, AppPanelClickBehavior) { |
| 735 // Enable experimental APIs to allow panel creation. | 733 // Enable experimental APIs to allow panel creation. |
| 736 CommandLine::ForCurrentProcess()->AppendSwitch( | 734 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 737 extensions::switches::kEnableExperimentalExtensionApis); | 735 extensions::switches::kEnableExperimentalExtensionApis); |
| 738 // Launch a platform app and create a panel window for it. | 736 // Launch a platform app and create a panel window for it. |
| 739 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); | 737 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); |
| 740 ShellWindow::CreateParams params; | 738 AppWindow::CreateParams params; |
| 741 params.window_type = ShellWindow::WINDOW_TYPE_PANEL; | 739 params.window_type = AppWindow::WINDOW_TYPE_PANEL; |
| 742 params.focused = false; | 740 params.focused = false; |
| 743 ShellWindow* panel = CreateShellWindowFromParams(extension1, params); | 741 AppWindow* panel = CreateAppWindowFromParams(extension1, params); |
| 744 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); | 742 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); |
| 745 // Panels should not be active by default. | 743 // Panels should not be active by default. |
| 746 EXPECT_FALSE(panel->GetBaseWindow()->IsActive()); | 744 EXPECT_FALSE(panel->GetBaseWindow()->IsActive()); |
| 747 // Confirm that a controller item was created and is the correct state. | 745 // Confirm that a controller item was created and is the correct state. |
| 748 const ash::ShelfItem& item1 = GetLastLauncherPanelItem(); | 746 const ash::ShelfItem& item1 = GetLastLauncherPanelItem(); |
| 749 LauncherItemController* item1_controller = GetItemController(item1.id); | 747 LauncherItemController* item1_controller = GetItemController(item1.id); |
| 750 EXPECT_EQ(ash::TYPE_APP_PANEL, item1.type); | 748 EXPECT_EQ(ash::TYPE_APP_PANEL, item1.type); |
| 751 EXPECT_EQ(ash::STATUS_RUNNING, item1.status); | 749 EXPECT_EQ(ash::STATUS_RUNNING, item1.status); |
| 752 EXPECT_EQ(LauncherItemController::TYPE_APP_PANEL, item1_controller->type()); | 750 EXPECT_EQ(LauncherItemController::TYPE_APP_PANEL, item1_controller->type()); |
| 753 // Click the item and confirm that the panel is activated. | 751 // Click the item and confirm that the panel is activated. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 764 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); | 762 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); |
| 765 EXPECT_TRUE(panel->GetBaseWindow()->IsActive()); | 763 EXPECT_TRUE(panel->GetBaseWindow()->IsActive()); |
| 766 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 764 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 767 } | 765 } |
| 768 | 766 |
| 769 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, BrowserActivation) { | 767 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, BrowserActivation) { |
| 770 int item_count = shelf_model()->item_count(); | 768 int item_count = shelf_model()->item_count(); |
| 771 | 769 |
| 772 // First run app. | 770 // First run app. |
| 773 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); | 771 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); |
| 774 CreateShellWindow(extension1); | 772 CreateAppWindow(extension1); |
| 775 ++item_count; | 773 ++item_count; |
| 776 ASSERT_EQ(item_count, shelf_model()->item_count()); | 774 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 777 const ash::ShelfItem& item1 = GetLastLauncherItem(); | 775 const ash::ShelfItem& item1 = GetLastLauncherItem(); |
| 778 ash::ShelfID item_id1 = item1.id; | 776 ash::ShelfID item_id1 = item1.id; |
| 779 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | 777 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); |
| 780 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 778 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 781 | 779 |
| 782 ash::wm::ActivateWindow(browser()->window()->GetNativeWindow()); | 780 ash::wm::ActivateWindow(browser()->window()->GetNativeWindow()); |
| 783 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status); | 781 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status); |
| 784 } | 782 } |
| 785 | 783 |
| 786 // Test that opening an app sets the correct icon | 784 // Test that opening an app sets the correct icon |
| 787 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, SetIcon) { | 785 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, SetIcon) { |
| 788 TestShellWindowRegistryObserver test_observer(browser()->profile()); | 786 TestAppWindowRegistryObserver test_observer(browser()->profile()); |
| 789 | 787 |
| 790 // Enable experimental APIs to allow panel creation. | 788 // Enable experimental APIs to allow panel creation. |
| 791 CommandLine::ForCurrentProcess()->AppendSwitch( | 789 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 792 extensions::switches::kEnableExperimentalExtensionApis); | 790 extensions::switches::kEnableExperimentalExtensionApis); |
| 793 | 791 |
| 794 int base_shelf_item_count = shelf_model()->item_count(); | 792 int base_shelf_item_count = shelf_model()->item_count(); |
| 795 ExtensionTestMessageListener launched_listener("Launched", false); | 793 ExtensionTestMessageListener launched_listener("Launched", false); |
| 796 ExtensionTestMessageListener completed_listener("Completed", false); | 794 ExtensionTestMessageListener completed_listener("Completed", false); |
| 797 LoadAndLaunchPlatformApp("app_icon"); | 795 LoadAndLaunchPlatformApp("app_icon"); |
| 798 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 796 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 799 ASSERT_TRUE(completed_listener.WaitUntilSatisfied()); | 797 ASSERT_TRUE(completed_listener.WaitUntilSatisfied()); |
| 800 | 798 |
| 801 // Now wait until the WebContent has decoded the icons and chrome has | 799 // Now wait until the WebContent has decoded the icons and chrome has |
| 802 // processed it. This needs to be in a loop since the renderer runs in a | 800 // processed it. This needs to be in a loop since the renderer runs in a |
| 803 // different process. | 801 // different process. |
| 804 while (test_observer.icon_updates() < 3) { | 802 while (test_observer.icon_updates() < 3) { |
| 805 base::RunLoop run_loop; | 803 base::RunLoop run_loop; |
| 806 run_loop.RunUntilIdle(); | 804 run_loop.RunUntilIdle(); |
| 807 } | 805 } |
| 808 | 806 |
| 809 // This test creates one shell window and one panel window. | 807 // This test creates one app window and one panel window. |
| 810 int shelf_item_count = shelf_model()->item_count(); | 808 int shelf_item_count = shelf_model()->item_count(); |
| 811 ASSERT_EQ(base_shelf_item_count + 2, shelf_item_count); | 809 ASSERT_EQ(base_shelf_item_count + 2, shelf_item_count); |
| 812 // The Panel will be the last item, the app second-to-last. | 810 // The Panel will be the last item, the app second-to-last. |
| 813 const ash::ShelfItem& app_item = | 811 const ash::ShelfItem& app_item = |
| 814 shelf_model()->items()[shelf_item_count - 2]; | 812 shelf_model()->items()[shelf_item_count - 2]; |
| 815 const ash::ShelfItem& panel_item = | 813 const ash::ShelfItem& panel_item = |
| 816 shelf_model()->items()[shelf_item_count - 1]; | 814 shelf_model()->items()[shelf_item_count - 1]; |
| 817 const LauncherItemController* app_item_controller = | 815 const LauncherItemController* app_item_controller = |
| 818 GetItemController(app_item.id); | 816 GetItemController(app_item.id); |
| 819 const LauncherItemController* panel_item_controller = | 817 const LauncherItemController* panel_item_controller = |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 ActivateShelfItem(shortcut_index); | 1325 ActivateShelfItem(shortcut_index); |
| 1328 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents()); | 1326 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents()); |
| 1329 } | 1327 } |
| 1330 | 1328 |
| 1331 // Check that the keyboard activation of a launcher item tabs properly through | 1329 // Check that the keyboard activation of a launcher item tabs properly through |
| 1332 // the items at hand. | 1330 // the items at hand. |
| 1333 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, | 1331 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, |
| 1334 AltNumberAppsTabbing) { | 1332 AltNumberAppsTabbing) { |
| 1335 // First run app. | 1333 // First run app. |
| 1336 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); | 1334 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); |
| 1337 ui::BaseWindow* window1 = CreateShellWindow(extension1)->GetBaseWindow(); | 1335 ui::BaseWindow* window1 = CreateAppWindow(extension1)->GetBaseWindow(); |
| 1338 const ash::ShelfItem& item1 = GetLastLauncherItem(); | 1336 const ash::ShelfItem& item1 = GetLastLauncherItem(); |
| 1339 ash::ShelfID app_id = item1.id; | 1337 ash::ShelfID app_id = item1.id; |
| 1340 int app_index = shelf_model()->ItemIndexByID(app_id); | 1338 int app_index = shelf_model()->ItemIndexByID(app_id); |
| 1341 | 1339 |
| 1342 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | 1340 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); |
| 1343 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 1341 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 1344 | 1342 |
| 1345 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2"); | 1343 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2"); |
| 1346 ui::BaseWindow* window2 = CreateShellWindow(extension2)->GetBaseWindow(); | 1344 ui::BaseWindow* window2 = CreateAppWindow(extension2)->GetBaseWindow(); |
| 1347 | 1345 |
| 1348 // By now the browser should be active. Issue Alt keystrokes several times to | 1346 // By now the browser should be active. Issue Alt keystrokes several times to |
| 1349 // see that we stay on that application. | 1347 // see that we stay on that application. |
| 1350 EXPECT_TRUE(window2->IsActive()); | 1348 EXPECT_TRUE(window2->IsActive()); |
| 1351 ActivateShelfItem(app_index); | 1349 ActivateShelfItem(app_index); |
| 1352 EXPECT_TRUE(window1->IsActive()); | 1350 EXPECT_TRUE(window1->IsActive()); |
| 1353 ActivateShelfItem(app_index); | 1351 ActivateShelfItem(app_index); |
| 1354 EXPECT_TRUE(window1->IsActive()); | 1352 EXPECT_TRUE(window1->IsActive()); |
| 1355 | 1353 |
| 1356 ui::BaseWindow* window1a = CreateShellWindow(extension1)->GetBaseWindow(); | 1354 ui::BaseWindow* window1a = CreateAppWindow(extension1)->GetBaseWindow(); |
| 1357 | 1355 |
| 1358 EXPECT_TRUE(window1a->IsActive()); | 1356 EXPECT_TRUE(window1a->IsActive()); |
| 1359 EXPECT_FALSE(window1->IsActive()); | 1357 EXPECT_FALSE(window1->IsActive()); |
| 1360 ActivateShelfItem(app_index); | 1358 ActivateShelfItem(app_index); |
| 1361 EXPECT_TRUE(window1->IsActive()); | 1359 EXPECT_TRUE(window1->IsActive()); |
| 1362 ActivateShelfItem(app_index); | 1360 ActivateShelfItem(app_index); |
| 1363 EXPECT_TRUE(window1a->IsActive()); | 1361 EXPECT_TRUE(window1a->IsActive()); |
| 1364 } | 1362 } |
| 1365 | 1363 |
| 1366 // Test that we can launch a platform app panel and get a running item. | 1364 // Test that we can launch a platform app panel and get a running item. |
| 1367 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPanelWindow) { | 1365 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPanelWindow) { |
| 1368 int item_count = shelf_model()->item_count(); | 1366 int item_count = shelf_model()->item_count(); |
| 1369 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | 1367 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
| 1370 ShellWindow::CreateParams params; | 1368 AppWindow::CreateParams params; |
| 1371 params.window_type = ShellWindow::WINDOW_TYPE_PANEL; | 1369 params.window_type = AppWindow::WINDOW_TYPE_PANEL; |
| 1372 params.focused = false; | 1370 params.focused = false; |
| 1373 ShellWindow* window = CreateShellWindowFromParams(extension, params); | 1371 AppWindow* window = CreateAppWindowFromParams(extension, params); |
| 1374 ++item_count; | 1372 ++item_count; |
| 1375 ASSERT_EQ(item_count, shelf_model()->item_count()); | 1373 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 1376 const ash::ShelfItem& item = GetLastLauncherPanelItem(); | 1374 const ash::ShelfItem& item = GetLastLauncherPanelItem(); |
| 1377 EXPECT_EQ(ash::TYPE_APP_PANEL, item.type); | 1375 EXPECT_EQ(ash::TYPE_APP_PANEL, item.type); |
| 1378 // Opening a panel does not activate it. | 1376 // Opening a panel does not activate it. |
| 1379 EXPECT_EQ(ash::STATUS_RUNNING, item.status); | 1377 EXPECT_EQ(ash::STATUS_RUNNING, item.status); |
| 1380 CloseShellWindow(window); | 1378 CloseAppWindow(window); |
| 1381 --item_count; | 1379 --item_count; |
| 1382 EXPECT_EQ(item_count, shelf_model()->item_count()); | 1380 EXPECT_EQ(item_count, shelf_model()->item_count()); |
| 1383 } | 1381 } |
| 1384 | 1382 |
| 1385 // Test attention states of windows. | 1383 // Test attention states of windows. |
| 1386 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowAttentionStatus) { | 1384 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowAttentionStatus) { |
| 1387 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | 1385 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
| 1388 ShellWindow::CreateParams params; | 1386 AppWindow::CreateParams params; |
| 1389 params.window_type = ShellWindow::WINDOW_TYPE_PANEL; | 1387 params.window_type = AppWindow::WINDOW_TYPE_PANEL; |
| 1390 params.focused = false; | 1388 params.focused = false; |
| 1391 ShellWindow* panel = CreateShellWindowFromParams(extension, params); | 1389 AppWindow* panel = CreateAppWindowFromParams(extension, params); |
| 1392 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); | 1390 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); |
| 1393 // Panels should not be active by default. | 1391 // Panels should not be active by default. |
| 1394 EXPECT_FALSE(panel->GetBaseWindow()->IsActive()); | 1392 EXPECT_FALSE(panel->GetBaseWindow()->IsActive()); |
| 1395 // Confirm that a controller item was created and is the correct state. | 1393 // Confirm that a controller item was created and is the correct state. |
| 1396 const ash::ShelfItem& item = GetLastLauncherPanelItem(); | 1394 const ash::ShelfItem& item = GetLastLauncherPanelItem(); |
| 1397 LauncherItemController* item_controller = GetItemController(item.id); | 1395 LauncherItemController* item_controller = GetItemController(item.id); |
| 1398 EXPECT_EQ(ash::TYPE_APP_PANEL, item.type); | 1396 EXPECT_EQ(ash::TYPE_APP_PANEL, item.type); |
| 1399 EXPECT_EQ(ash::STATUS_RUNNING, item.status); | 1397 EXPECT_EQ(ash::STATUS_RUNNING, item.status); |
| 1400 EXPECT_EQ(LauncherItemController::TYPE_APP_PANEL, item_controller->type()); | 1398 EXPECT_EQ(LauncherItemController::TYPE_APP_PANEL, item_controller->type()); |
| 1401 | 1399 |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2024 GURL("http://www.foo.com/bar.html")); | 2022 GURL("http://www.foo.com/bar.html")); |
| 2025 // Make sure the navigation was entirely performed. | 2023 // Make sure the navigation was entirely performed. |
| 2026 base::MessageLoop::current()->RunUntilIdle(); | 2024 base::MessageLoop::current()->RunUntilIdle(); |
| 2027 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(id)->status); | 2025 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(id)->status); |
| 2028 app_browser->tab_strip_model()->CloseWebContentsAt(0, | 2026 app_browser->tab_strip_model()->CloseWebContentsAt(0, |
| 2029 TabStripModel::CLOSE_NONE); | 2027 TabStripModel::CLOSE_NONE); |
| 2030 // Make sure that the app is really gone. | 2028 // Make sure that the app is really gone. |
| 2031 base::MessageLoop::current()->RunUntilIdle(); | 2029 base::MessageLoop::current()->RunUntilIdle(); |
| 2032 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(id)->status); | 2030 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(id)->status); |
| 2033 } | 2031 } |
| OLD | NEW |