| 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 "base/command_line.h" | 9 #include "base/command_line.h" |
| 9 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/automation/automation_util.h" | 12 #include "chrome/browser/automation/automation_util.h" |
| 12 #include "chrome/browser/extensions/extension_apitest.h" | 13 #include "chrome/browser/extensions/extension_apitest.h" |
| 13 #include "chrome/browser/extensions/extension_browsertest.h" | 14 #include "chrome/browser/extensions/extension_browsertest.h" |
| 14 #include "chrome/browser/extensions/extension_function_test_utils.h" | 15 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/extension_test_message_listener.h" | 17 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 17 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | 18 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 39 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) { | 40 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) { |
| 40 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); | 41 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); |
| 41 int item_count = launcher->model()->item_count(); | 42 int item_count = launcher->model()->item_count(); |
| 42 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | 43 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
| 43 ShellWindow* window = CreateShellWindow(extension); | 44 ShellWindow* window = CreateShellWindow(extension); |
| 44 ++item_count; | 45 ++item_count; |
| 45 ASSERT_EQ(item_count, launcher->model()->item_count()); | 46 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 46 ash::LauncherItem item = | 47 ash::LauncherItem item = |
| 47 launcher->model()->items()[launcher->model()->item_count() - 2]; | 48 launcher->model()->items()[launcher->model()->item_count() - 2]; |
| 48 ASSERT_EQ(ash::TYPE_PLATFORM_APP, item.type); | 49 ASSERT_EQ(ash::TYPE_PLATFORM_APP, item.type); |
| 49 ASSERT_EQ(ash::STATUS_RUNNING, item.status); | 50 ASSERT_EQ(ash::STATUS_ACTIVE, item.status); |
| 50 CloseShellWindow(window); | 51 CloseShellWindow(window); |
| 51 --item_count; | 52 --item_count; |
| 52 ASSERT_EQ(item_count, launcher->model()->item_count()); | 53 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 53 } | 54 } |
| 54 | 55 |
| 55 // Test that we can launch a platform app that already has a shortcut. | 56 // Test that we can launch a platform app that already has a shortcut. |
| 56 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) { | 57 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) { |
| 57 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); | 58 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); |
| 58 int item_count = launcher->model()->item_count(); | 59 int item_count = launcher->model()->item_count(); |
| 59 | 60 |
| 60 // First get app_id. | 61 // First get app_id. |
| 61 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | 62 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
| 62 const std::string app_id = extension->id(); | 63 const std::string app_id = extension->id(); |
| 63 | 64 |
| 64 // Then create a shortcut. | 65 // Then create a shortcut. |
| 65 ChromeLauncherController* controller = | 66 ChromeLauncherController* controller = |
| 66 static_cast<ChromeLauncherController*>(launcher->delegate()); | 67 static_cast<ChromeLauncherController*>(launcher->delegate()); |
| 67 ash::LauncherID shortcut_id = | 68 ash::LauncherID shortcut_id = |
| 68 controller->CreateAppLauncherItem(NULL, app_id, ash::STATUS_CLOSED); | 69 controller->CreateAppLauncherItem(NULL, app_id, ash::STATUS_CLOSED); |
| 69 ++item_count; | 70 ++item_count; |
| 70 ASSERT_EQ(item_count, launcher->model()->item_count()); | 71 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 71 ash::LauncherItem item = *launcher->model()->ItemByID(shortcut_id); | 72 ash::LauncherItem item = *launcher->model()->ItemByID(shortcut_id); |
| 72 ASSERT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 73 ASSERT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 73 ASSERT_EQ(ash::STATUS_CLOSED, item.status); | 74 ASSERT_EQ(ash::STATUS_CLOSED, item.status); |
| 74 | 75 |
| 75 // Open a window. Confirm the item is now running. | 76 // Open a window. Confirm the item is now running. |
| 76 ShellWindow* window = CreateShellWindow(extension); | 77 ShellWindow* window = CreateShellWindow(extension); |
| 78 ash::wm::ActivateWindow(window->GetNativeWindow()); |
| 77 ASSERT_EQ(item_count, launcher->model()->item_count()); | 79 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 78 item = *launcher->model()->ItemByID(shortcut_id); | 80 item = *launcher->model()->ItemByID(shortcut_id); |
| 79 ASSERT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 81 ASSERT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 80 ASSERT_EQ(ash::STATUS_RUNNING, item.status); | 82 ASSERT_EQ(ash::STATUS_ACTIVE, item.status); |
| 81 | 83 |
| 82 // Then close it, make sure there's still an item. | 84 // Then close it, make sure there's still an item. |
| 83 CloseShellWindow(window); | 85 CloseShellWindow(window); |
| 84 ASSERT_EQ(item_count, launcher->model()->item_count()); | 86 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 85 item = *launcher->model()->ItemByID(shortcut_id); | 87 item = *launcher->model()->ItemByID(shortcut_id); |
| 86 ASSERT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 88 ASSERT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 87 ASSERT_EQ(ash::STATUS_CLOSED, item.status); | 89 ASSERT_EQ(ash::STATUS_CLOSED, item.status); |
| 88 } | 90 } |
| 89 | 91 |
| 90 // Test that we can launch a platform app with more than one window. | 92 // Test that we can launch a platform app with more than one window. |
| 91 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) { | 93 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) { |
| 92 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); | 94 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); |
| 93 int item_count = launcher->model()->item_count(); | 95 int item_count = launcher->model()->item_count(); |
| 94 | 96 |
| 95 // First run app. | 97 // First run app. |
| 96 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | 98 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
| 97 ShellWindow* window1 = CreateShellWindow(extension); | 99 ShellWindow* window1 = CreateShellWindow(extension); |
| 98 ++item_count; | 100 ++item_count; |
| 99 ASSERT_EQ(item_count, launcher->model()->item_count()); | 101 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 100 ash::LauncherItem item = | 102 ash::LauncherItem item = |
| 101 launcher->model()->items()[launcher->model()->item_count() - 2]; | 103 launcher->model()->items()[launcher->model()->item_count() - 2]; |
| 102 ash::LauncherID item_id = item.id; | 104 ash::LauncherID item_id = item.id; |
| 103 ASSERT_EQ(ash::TYPE_PLATFORM_APP, item.type); | 105 ASSERT_EQ(ash::TYPE_PLATFORM_APP, item.type); |
| 104 ASSERT_EQ(ash::STATUS_RUNNING, item.status); | 106 ASSERT_EQ(ash::STATUS_ACTIVE, item.status); |
| 105 | 107 |
| 106 // Add second window. | 108 // Add second window. |
| 107 ShellWindow* window2 = CreateShellWindow(extension); | 109 ShellWindow* window2 = CreateShellWindow(extension); |
| 108 // Confirm item stays. | 110 // Confirm item stays. |
| 109 ASSERT_EQ(item_count, launcher->model()->item_count()); | 111 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 110 item = *launcher->model()->ItemByID(item_id); | 112 item = *launcher->model()->ItemByID(item_id); |
| 111 ASSERT_EQ(ash::STATUS_RUNNING, item.status); | 113 ASSERT_EQ(ash::STATUS_ACTIVE, item.status); |
| 112 | 114 |
| 113 // Close second window. | 115 // Close second window. |
| 114 CloseShellWindow(window2); | 116 CloseShellWindow(window2); |
| 115 // Confirm item stays. | 117 // Confirm item stays. |
| 116 ASSERT_EQ(item_count, launcher->model()->item_count()); | 118 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 117 item = *launcher->model()->ItemByID(item_id); | 119 item = *launcher->model()->ItemByID(item_id); |
| 118 ASSERT_EQ(ash::STATUS_RUNNING, item.status); | 120 ASSERT_EQ(ash::STATUS_ACTIVE, item.status); |
| 119 | 121 |
| 120 // Close first window. | 122 // Close first window. |
| 121 CloseShellWindow(window1); | 123 CloseShellWindow(window1); |
| 122 // Confirm item is removed. | 124 // Confirm item is removed. |
| 123 --item_count; | 125 --item_count; |
| 124 ASSERT_EQ(item_count, launcher->model()->item_count()); | 126 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 125 } | 127 } |
| 128 |
| 129 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) { |
| 130 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); |
| 131 int item_count = launcher->model()->item_count(); |
| 132 |
| 133 // First run app. |
| 134 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); |
| 135 ShellWindow* window1 = CreateShellWindow(extension1); |
| 136 ++item_count; |
| 137 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 138 ash::LauncherItem item1 = |
| 139 launcher->model()->items()[launcher->model()->item_count() - 2]; |
| 140 ash::LauncherID item_id1 = item1.id; |
| 141 ASSERT_EQ(ash::TYPE_PLATFORM_APP, item1.type); |
| 142 ASSERT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 143 |
| 144 // Then run second app. |
| 145 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2"); |
| 146 ShellWindow* window2 = CreateShellWindow(extension2); |
| 147 ++item_count; |
| 148 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 149 ash::LauncherItem item2 = |
| 150 launcher->model()->items()[launcher->model()->item_count() - 2]; |
| 151 ash::LauncherID item_id2 = item2.id; |
| 152 ASSERT_EQ(ash::TYPE_PLATFORM_APP, item2.type); |
| 153 ASSERT_EQ(ash::STATUS_ACTIVE, item2.status); |
| 154 |
| 155 ASSERT_NE(item_id1, item_id2); |
| 156 ASSERT_EQ(ash::STATUS_RUNNING, launcher->model()->ItemByID(item_id1)->status); |
| 157 |
| 158 // Close second app. |
| 159 CloseShellWindow(window2); |
| 160 --item_count; |
| 161 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 162 // First app should be active again. |
| 163 ASSERT_EQ(ash::STATUS_ACTIVE, launcher->model()->ItemByID(item_id1)->status); |
| 164 |
| 165 // Close first app. |
| 166 CloseShellWindow(window1); |
| 167 --item_count; |
| 168 ASSERT_EQ(item_count, launcher->model()->item_count()); |
| 169 |
| 170 } |
| OLD | NEW |