Chromium Code Reviews| 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 "apps/native_app_window.h" | 7 #include "apps/native_app_window.h" |
| 8 #include "apps/shell_window.h" | 8 #include "apps/shell_window.h" |
| 9 #include "apps/shell_window_registry.h" | 9 #include "apps/shell_window_registry.h" |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| 11 #include "ash/display/display_controller.h" | |
| 11 #include "ash/launcher/launcher.h" | 12 #include "ash/launcher/launcher.h" |
| 12 #include "ash/launcher/launcher_model.h" | 13 #include "ash/launcher/launcher_model.h" |
| 14 #include "ash/launcher/launcher_util.h" | |
| 15 #include "ash/launcher/launcher_view.h" | |
| 13 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 14 #include "ash/test/launcher_view_test_api.h" | 17 #include "ash/test/launcher_view_test_api.h" |
| 15 #include "ash/test/shell_test_api.h" | 18 #include "ash/test/shell_test_api.h" |
| 16 #include "ash/wm/window_util.h" | 19 #include "ash/wm/window_util.h" |
| 17 #include "base/command_line.h" | |
| 18 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 20 #include "chrome/browser/apps/app_browsertest_util.h" | 22 #include "chrome/browser/apps/app_browsertest_util.h" |
| 21 #include "chrome/browser/automation/automation_util.h" | 23 #include "chrome/browser/automation/automation_util.h" |
| 22 #include "chrome/browser/chrome_notification_types.h" | 24 #include "chrome/browser/chrome_notification_types.h" |
| 23 #include "chrome/browser/extensions/extension_apitest.h" | 25 #include "chrome/browser/extensions/extension_apitest.h" |
| 24 #include "chrome/browser/extensions/extension_browsertest.h" | 26 #include "chrome/browser/extensions/extension_browsertest.h" |
| 25 #include "chrome/browser/extensions/extension_function_test_utils.h" | 27 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 26 #include "chrome/browser/extensions/extension_service.h" | 28 #include "chrome/browser/extensions/extension_service.h" |
| 27 #include "chrome/browser/extensions/extension_system.h" | 29 #include "chrome/browser/extensions/extension_system.h" |
| 28 #include "chrome/browser/extensions/extension_test_message_listener.h" | 30 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 29 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
| 32 #include "chrome/browser/ui/app_list/app_list_service.h" | |
| 33 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" | |
| 34 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | |
| 30 #include "chrome/browser/ui/browser.h" | 35 #include "chrome/browser/ui/browser.h" |
| 31 #include "chrome/browser/ui/browser_commands.h" | 36 #include "chrome/browser/ui/browser_commands.h" |
| 37 #include "chrome/browser/ui/browser_finder.h" | |
| 38 #include "chrome/browser/ui/browser_list.h" | |
| 32 #include "chrome/browser/ui/browser_window.h" | 39 #include "chrome/browser/ui/browser_window.h" |
| 33 #include "chrome/browser/ui/extensions/application_launch.h" | 40 #include "chrome/browser/ui/extensions/application_launch.h" |
| 34 #include "chrome/browser/ui/host_desktop.h" | 41 #include "chrome/browser/ui/host_desktop.h" |
| 35 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 42 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 36 #include "chrome/common/chrome_switches.h" | 43 #include "chrome/common/chrome_switches.h" |
| 37 #include "chrome/common/extensions/extension_constants.h" | 44 #include "chrome/common/extensions/extension_constants.h" |
| 38 #include "chrome/test/base/ui_test_utils.h" | 45 #include "chrome/test/base/ui_test_utils.h" |
| 39 #include "content/public/browser/notification_service.h" | 46 #include "content/public/browser/notification_service.h" |
| 40 #include "content/public/browser/notification_source.h" | 47 #include "content/public/browser/notification_source.h" |
| 41 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
| 49 #include "extensions/common/switches.h" | |
| 42 #include "testing/gtest/include/gtest/gtest.h" | 50 #include "testing/gtest/include/gtest/gtest.h" |
| 51 #include "ui/app_list/views/apps_grid_view.h" | |
| 43 #include "ui/aura/client/aura_constants.h" | 52 #include "ui/aura/client/aura_constants.h" |
| 53 #include "ui/aura/test/event_generator.h" | |
| 44 #include "ui/aura/window.h" | 54 #include "ui/aura/window.h" |
| 55 #include "ui/base/events/event.h" | |
| 45 | 56 |
| 46 using apps::ShellWindow; | 57 using apps::ShellWindow; |
| 47 using extensions::Extension; | 58 using extensions::Extension; |
| 48 using content::WebContents; | 59 using content::WebContents; |
| 49 | 60 |
| 61 namespace { | |
| 62 | |
| 63 class TestEvent : public ui::Event { | |
| 64 public: | |
| 65 explicit TestEvent(ui::EventType type) | |
| 66 : ui::Event(type, base::TimeDelta(), 0) { | |
| 67 } | |
| 68 virtual ~TestEvent() { | |
| 69 } | |
| 70 | |
| 71 private: | |
| 72 DISALLOW_COPY_AND_ASSIGN(TestEvent); | |
| 73 }; | |
| 74 | |
| 75 class TestShellWindowRegistryObserver | |
| 76 : public apps::ShellWindowRegistry::Observer { | |
| 77 public: | |
| 78 explicit TestShellWindowRegistryObserver(Profile* profile) | |
| 79 : profile_(profile), | |
| 80 icon_updates_(0) { | |
| 81 apps::ShellWindowRegistry::Get(profile_)->AddObserver(this); | |
| 82 } | |
| 83 | |
| 84 virtual ~TestShellWindowRegistryObserver() { | |
| 85 apps::ShellWindowRegistry::Get(profile_)->RemoveObserver(this); | |
| 86 } | |
| 87 | |
| 88 // Overridden from ShellWindowRegistry::Observer: | |
| 89 virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE {} | |
| 90 | |
| 91 virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE { | |
| 92 ++icon_updates_; | |
| 93 } | |
| 94 | |
| 95 virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE {} | |
| 96 | |
| 97 int icon_updates() { return icon_updates_; } | |
| 98 | |
| 99 private: | |
| 100 Profile* profile_; | |
| 101 int icon_updates_; | |
| 102 | |
| 103 DISALLOW_COPY_AND_ASSIGN(TestShellWindowRegistryObserver); | |
| 104 }; | |
| 105 | |
| 106 } // namespace | |
| 107 | |
| 50 class LauncherPlatformAppBrowserTest | 108 class LauncherPlatformAppBrowserTest |
| 51 : public extensions::PlatformAppBrowserTest { | 109 : public extensions::PlatformAppBrowserTest { |
| 52 protected: | 110 protected: |
| 53 LauncherPlatformAppBrowserTest() | 111 LauncherPlatformAppBrowserTest() : launcher_(NULL), controller_(NULL) { |
| 54 : launcher_(NULL), | |
| 55 controller_(NULL) { | |
| 56 } | 112 } |
| 57 | 113 |
| 58 virtual ~LauncherPlatformAppBrowserTest() {} | 114 virtual ~LauncherPlatformAppBrowserTest() {} |
| 59 | 115 |
| 116 virtual void RunTestOnMainThreadLoop() OVERRIDE { | |
| 117 launcher_ = ash::Launcher::ForPrimaryDisplay(); | |
| 118 controller_ = ChromeLauncherController::instance(); | |
| 119 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop(); | |
| 120 } | |
| 121 | |
| 60 ash::LauncherModel* launcher_model() { | 122 ash::LauncherModel* launcher_model() { |
| 61 return ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); | 123 return ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); |
| 62 } | 124 } |
| 63 | 125 |
| 64 virtual void RunTestOnMainThreadLoop() OVERRIDE { | |
| 65 launcher_ = ash::Launcher::ForPrimaryDisplay(); | |
| 66 controller_ = static_cast<ChromeLauncherController*>(launcher_->delegate()); | |
| 67 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop(); | |
| 68 } | |
| 69 | |
| 70 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 71 PlatformAppBrowserTest::SetUpCommandLine(command_line); | |
| 72 command_line->AppendSwitch(ash::switches::kAshDisablePerAppLauncher); | |
| 73 } | |
| 74 | |
| 75 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& name) { | 126 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& name) { |
| 76 return controller_->CreateAppShortcutLauncherItem( | 127 return controller_->CreateAppShortcutLauncherItem( |
| 77 name, controller_->model()->item_count()); | 128 name, controller_->model()->item_count()); |
| 78 } | 129 } |
| 79 | 130 |
| 80 const ash::LauncherItem& GetLastLauncherItem() { | 131 const ash::LauncherItem& GetLastLauncherItem() { |
| 81 // Unless there are any panels, the item at index [count - 1] will be | 132 // Unless there are any panels, the item at index [count - 1] will be |
| 82 // the app list, and the item at [count - 2] will be the desited item. | 133 // the app list, and the item at [count - 2] will be the desired item. |
| 83 return launcher_model()->items()[launcher_model()->item_count() - 2]; | 134 return launcher_model()->items()[launcher_model()->item_count() - 2]; |
| 84 } | 135 } |
| 85 | 136 |
| 86 const ash::LauncherItem& GetLastLauncherPanelItem() { | 137 const ash::LauncherItem& GetLastLauncherPanelItem() { |
| 87 // Panels show up on the right side of the launcher, so the desired item | 138 // Panels show up on the right side of the launcher, so the desired item |
| 88 // will be the last one. | 139 // will be the last one. |
| 89 return launcher_model()->items()[launcher_model()->item_count() - 1]; | 140 return launcher_model()->items()[launcher_model()->item_count() - 1]; |
| 90 } | 141 } |
| 91 | 142 |
| 143 LauncherItemController* GetItemController(ash::LauncherID id) { | |
| 144 return controller_->id_to_item_controller_map_[id]; | |
| 145 } | |
| 146 | |
| 147 // Returns the number of menu items, ignoring separators. | |
| 148 int GetNumApplicationMenuItems(const ash::LauncherItem& item) { | |
| 149 const int event_flags = 0; | |
| 150 scoped_ptr<ash::LauncherMenuModel> menu( | |
| 151 controller_->CreateApplicationMenu(item, event_flags)); | |
| 152 int num_items = 0; | |
| 153 for (int i = 0; i < menu->GetItemCount(); ++i) { | |
| 154 if (menu->GetTypeAt(i) != ui::MenuModel::TYPE_SEPARATOR) | |
| 155 ++num_items; | |
| 156 } | |
| 157 return num_items; | |
| 158 } | |
| 159 | |
| 160 // Activate the launcher item with the given |id|. | |
| 161 void ActivateLauncherItem(int id) { | |
| 162 launcher_->ActivateLauncherItem(id); | |
| 163 } | |
| 164 | |
| 92 ash::Launcher* launcher_; | 165 ash::Launcher* launcher_; |
| 93 ChromeLauncherController* controller_; | 166 ChromeLauncherController* controller_; |
| 167 | |
| 168 private: | |
| 169 | |
| 170 DISALLOW_COPY_AND_ASSIGN(LauncherPlatformAppBrowserTest); | |
| 94 }; | 171 }; |
| 95 | 172 |
| 96 class LauncherAppBrowserTest : public ExtensionBrowserTest { | 173 class LauncherAppBrowserTest : public ExtensionBrowserTest { |
| 97 protected: | 174 protected: |
| 98 LauncherAppBrowserTest() | 175 LauncherAppBrowserTest() : launcher_(NULL), model_(NULL), controller_(NULL) { |
| 99 : launcher_(NULL), | |
| 100 model_(NULL) { | |
| 101 } | 176 } |
| 102 | 177 |
| 103 virtual ~LauncherAppBrowserTest() {} | 178 virtual ~LauncherAppBrowserTest() {} |
| 104 | 179 |
| 105 virtual void RunTestOnMainThreadLoop() OVERRIDE { | 180 virtual void RunTestOnMainThreadLoop() OVERRIDE { |
| 106 launcher_ = ash::Launcher::ForPrimaryDisplay(); | 181 launcher_ = ash::Launcher::ForPrimaryDisplay(); |
| 107 model_ = | 182 model_ = |
| 108 ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); | 183 ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); |
| 184 controller_ = ChromeLauncherController::instance(); | |
| 109 return ExtensionBrowserTest::RunTestOnMainThreadLoop(); | 185 return ExtensionBrowserTest::RunTestOnMainThreadLoop(); |
| 110 } | 186 } |
| 111 | 187 |
| 112 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 188 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) { |
| 113 ExtensionBrowserTest::SetUpCommandLine(command_line); | 189 LauncherItemController* item_controller = |
| 114 command_line->AppendSwitch(ash::switches::kAshDisablePerAppLauncher); | 190 controller_->GetBrowserShortcutLauncherItemController(); |
| 191 int items = item_controller->GetApplicationList( | |
| 192 show_all_tabs ? ui::EF_SHIFT_DOWN : 0).size(); | |
| 193 // If we have at least one item, we have also a title which we remove here. | |
| 194 return items ? (items - 1) : 0; | |
| 115 } | 195 } |
| 116 | 196 |
| 117 const Extension* LoadAndLaunchExtension( | 197 const Extension* LoadAndLaunchExtension( |
| 118 const char* name, | 198 const char* name, |
| 119 extension_misc::LaunchContainer container, | 199 extension_misc::LaunchContainer container, |
| 120 WindowOpenDisposition disposition) { | 200 WindowOpenDisposition disposition) { |
| 121 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name))); | 201 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name))); |
| 122 | 202 |
| 123 ExtensionService* service = extensions::ExtensionSystem::Get( | 203 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 124 browser()->profile())->extension_service(); | 204 profile())->extension_service(); |
| 125 const Extension* extension = | 205 const Extension* extension = |
| 126 service->GetExtensionById(last_loaded_extension_id_, false); | 206 service->GetExtensionById(last_loaded_extension_id_, false); |
| 127 EXPECT_TRUE(extension); | 207 EXPECT_TRUE(extension); |
| 128 | 208 |
| 129 chrome::OpenApplication(chrome::AppLaunchParams( | 209 chrome::OpenApplication(chrome::AppLaunchParams(profile(), |
| 130 browser()->profile(), extension, container, disposition)); | 210 extension, |
| 211 container, | |
| 212 disposition)); | |
| 131 return extension; | 213 return extension; |
| 132 } | 214 } |
| 133 | 215 |
| 134 ash::LauncherID CreateShortcut(const char* name) { | 216 ash::LauncherID CreateShortcut(const char* name) { |
| 135 ExtensionService* service = extensions::ExtensionSystem::Get( | 217 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 136 browser()->profile())->extension_service(); | 218 profile())->extension_service(); |
| 137 LoadExtension(test_data_dir_.AppendASCII(name)); | 219 LoadExtension(test_data_dir_.AppendASCII(name)); |
| 138 | 220 |
| 139 // First get app_id. | 221 // First get app_id. |
| 140 const Extension* extension = | 222 const Extension* extension = |
| 141 service->GetExtensionById(last_loaded_extension_id_, false); | 223 service->GetExtensionById(last_loaded_extension_id_, false); |
| 142 const std::string app_id = extension->id(); | 224 const std::string app_id = extension->id(); |
| 143 | 225 |
| 144 // Then create a shortcut. | 226 // Then create a shortcut. |
| 145 ChromeLauncherController* controller = | |
| 146 static_cast<ChromeLauncherController*>(launcher_->delegate()); | |
| 147 int item_count = model_->item_count(); | 227 int item_count = model_->item_count(); |
| 148 ash::LauncherID shortcut_id = controller->CreateAppShortcutLauncherItem( | 228 ash::LauncherID shortcut_id = controller_->CreateAppShortcutLauncherItem( |
| 149 app_id, item_count); | 229 app_id, |
| 150 controller->PersistPinnedState(); | 230 item_count); |
| 231 controller_->PersistPinnedState(); | |
| 151 EXPECT_EQ(++item_count, model_->item_count()); | 232 EXPECT_EQ(++item_count, model_->item_count()); |
| 152 ash::LauncherItem item = *model_->ItemByID(shortcut_id); | 233 const ash::LauncherItem& item = *model_->ItemByID(shortcut_id); |
| 153 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 234 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 154 return item.id; | 235 return item.id; |
| 155 } | 236 } |
| 156 | 237 |
| 238 // Activate the launcher item with the given |id|. | |
| 239 void ActivateLauncherItem(int id) { | |
| 240 launcher_->ActivateLauncherItem(id); | |
| 241 } | |
| 242 | |
| 157 ash::LauncherID PinFakeApp(const std::string& name) { | 243 ash::LauncherID PinFakeApp(const std::string& name) { |
| 158 ChromeLauncherController* controller = | 244 return controller_->CreateAppShortcutLauncherItem( |
| 159 static_cast<ChromeLauncherController*>(launcher_->delegate()); | |
| 160 return controller->CreateAppShortcutLauncherItem( | |
| 161 name, model_->item_count()); | 245 name, model_->item_count()); |
| 162 } | 246 } |
| 163 | 247 |
| 164 ash::Launcher* launcher_; | 248 ash::Launcher* launcher_; |
| 165 ash::LauncherModel* model_; | 249 ash::LauncherModel* model_; |
| 250 ChromeLauncherController* controller_; | |
| 251 | |
| 252 private: | |
| 253 | |
| 254 DISALLOW_COPY_AND_ASSIGN(LauncherAppBrowserTest); | |
| 166 }; | 255 }; |
| 167 | 256 |
| 257 class LauncherAppBrowserTestNoDefaultBrowser : public LauncherAppBrowserTest { | |
| 258 protected: | |
| 259 LauncherAppBrowserTestNoDefaultBrowser() {} | |
| 260 virtual ~LauncherAppBrowserTestNoDefaultBrowser() {} | |
| 261 | |
| 262 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 263 LauncherAppBrowserTest::SetUpCommandLine(command_line); | |
| 264 command_line->AppendSwitch(switches::kNoStartupWindow); | |
| 265 } | |
| 266 | |
| 267 private: | |
| 268 | |
| 269 DISALLOW_COPY_AND_ASSIGN(LauncherAppBrowserTestNoDefaultBrowser); | |
| 270 }; | |
| 271 | |
| 272 // Since the default for minimizing on click might change, I added both classes | |
| 273 // to either get the minimize on click or not. | |
| 274 class LauncherAppBrowserNoMinimizeOnClick | |
| 275 : public LauncherPlatformAppBrowserTest { | |
| 276 protected: | |
| 277 LauncherAppBrowserNoMinimizeOnClick() {} | |
| 278 virtual ~LauncherAppBrowserNoMinimizeOnClick() {} | |
| 279 | |
| 280 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 281 LauncherPlatformAppBrowserTest::SetUpCommandLine(command_line); | |
| 282 command_line->AppendSwitch( | |
| 283 switches::kDisableMinimizeOnSecondLauncherItemClick); | |
| 284 } | |
| 285 | |
| 286 private: | |
| 287 | |
| 288 DISALLOW_COPY_AND_ASSIGN(LauncherAppBrowserNoMinimizeOnClick); | |
| 289 }; | |
| 290 | |
| 291 typedef LauncherPlatformAppBrowserTest LauncherAppBrowserMinimizeOnClick; | |
| 292 | |
| 168 // Test that we can launch a platform app and get a running item. | 293 // Test that we can launch a platform app and get a running item. |
| 169 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) { | 294 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) { |
| 170 int item_count = launcher_model()->item_count(); | 295 int item_count = launcher_model()->item_count(); |
| 171 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | 296 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
| 172 ShellWindow* window = CreateShellWindow(extension); | 297 ShellWindow* window = CreateShellWindow(extension); |
| 173 ++item_count; | 298 ++item_count; |
| 174 ASSERT_EQ(item_count, launcher_model()->item_count()); | 299 ASSERT_EQ(item_count, launcher_model()->item_count()); |
| 175 const ash::LauncherItem& item = GetLastLauncherItem(); | 300 const ash::LauncherItem& item = GetLastLauncherItem(); |
| 176 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); | 301 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); |
| 177 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); | 302 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 | 424 |
| 300 // Test that we can launch a platform app with more than one window. | 425 // Test that we can launch a platform app with more than one window. |
| 301 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) { | 426 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) { |
| 302 int item_count = launcher_model()->item_count(); | 427 int item_count = launcher_model()->item_count(); |
| 303 | 428 |
| 304 // First run app. | 429 // First run app. |
| 305 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | 430 const Extension* extension = LoadAndLaunchPlatformApp("launch"); |
| 306 ShellWindow* window1 = CreateShellWindow(extension); | 431 ShellWindow* window1 = CreateShellWindow(extension); |
| 307 ++item_count; | 432 ++item_count; |
| 308 ASSERT_EQ(item_count, launcher_model()->item_count()); | 433 ASSERT_EQ(item_count, launcher_model()->item_count()); |
| 309 const ash::LauncherItem& item1 = GetLastLauncherItem(); | 434 const ash::LauncherItem& item = GetLastLauncherItem(); |
|
Mr4D (OOO till 08-26)
2013/08/19 16:13:56
Can you please make this an item1 again (otherwise
simonhong_
2013/08/19 21:00:57
Done.
| |
| 310 ash::LauncherID item_id = item1.id; | 435 ash::LauncherID item_id = item.id; |
| 311 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | 436 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); |
| 312 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 437 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
| 438 EXPECT_EQ(2, GetNumApplicationMenuItems(item)); // Title + 1 window | |
| 313 | 439 |
| 314 // Add second window. | 440 // Add second window. |
| 315 ShellWindow* window2 = CreateShellWindow(extension); | 441 ShellWindow* window2 = CreateShellWindow(extension); |
| 316 // Confirm item stays. | 442 // Confirm item stays. |
| 317 ASSERT_EQ(item_count, launcher_model()->item_count()); | 443 ASSERT_EQ(item_count, launcher_model()->item_count()); |
| 318 const ash::LauncherItem& item2 = *launcher_model()->ItemByID(item_id); | 444 const ash::LauncherItem& item2 = *launcher_model()->ItemByID(item_id); |
| 319 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); | 445 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); |
| 446 EXPECT_EQ(3, GetNumApplicationMenuItems(item2)); // Title + 2 windows | |
| 320 | 447 |
| 321 // Close second window. | 448 // Close second window. |
| 322 CloseShellWindow(window2); | 449 CloseShellWindow(window2); |
| 323 // Confirm item stays. | 450 // Confirm item stays. |
| 324 ASSERT_EQ(item_count, launcher_model()->item_count()); | 451 ASSERT_EQ(item_count, launcher_model()->item_count()); |
| 325 const ash::LauncherItem& item3 = *launcher_model()->ItemByID(item_id); | 452 const ash::LauncherItem& item3 = *launcher_model()->ItemByID(item_id); |
| 326 EXPECT_EQ(ash::STATUS_ACTIVE, item3.status); | 453 EXPECT_EQ(ash::STATUS_ACTIVE, item3.status); |
| 454 EXPECT_EQ(2, GetNumApplicationMenuItems(item3)); // Title + 1 window | |
| 327 | 455 |
| 328 // Close first window. | 456 // Close first window. |
| 329 CloseShellWindow(window1); | 457 CloseShellWindow(window1); |
| 330 // Confirm item is removed. | 458 // Confirm item is removed. |
| 331 --item_count; | 459 --item_count; |
| 332 ASSERT_EQ(item_count, launcher_model()->item_count()); | 460 ASSERT_EQ(item_count, launcher_model()->item_count()); |
| 333 } | 461 } |
| 334 | 462 |
| 335 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) { | 463 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) { |
| 336 int item_count = launcher_model()->item_count(); | 464 int item_count = launcher_model()->item_count(); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 364 --item_count; | 492 --item_count; |
| 365 ASSERT_EQ(item_count, launcher_model()->item_count()); | 493 ASSERT_EQ(item_count, launcher_model()->item_count()); |
| 366 // First app should be active again. | 494 // First app should be active again. |
| 367 EXPECT_EQ(ash::STATUS_ACTIVE, | 495 EXPECT_EQ(ash::STATUS_ACTIVE, |
| 368 launcher_model()->ItemByID(item_id1)->status); | 496 launcher_model()->ItemByID(item_id1)->status); |
| 369 | 497 |
| 370 // Close first app. | 498 // Close first app. |
| 371 CloseShellWindow(window1); | 499 CloseShellWindow(window1); |
| 372 --item_count; | 500 --item_count; |
| 373 ASSERT_EQ(item_count, launcher_model()->item_count()); | 501 ASSERT_EQ(item_count, launcher_model()->item_count()); |
| 502 | |
|
Mr4D (OOO till 08-26)
2013/08/19 16:13:56
This line can go.
simonhong_
2013/08/19 21:00:57
Done.
| |
| 374 } | 503 } |
| 375 | 504 |
| 376 // Test that we can launch a platform app panel and get a running item. | |
| 377 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPanelWindow) { | |
| 378 int item_count = launcher_model()->item_count(); | |
| 379 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | |
| 380 ShellWindow::CreateParams params; | |
| 381 params.window_type = ShellWindow::WINDOW_TYPE_PANEL; | |
| 382 params.focused = false; | |
| 383 ShellWindow* window = CreateShellWindowFromParams(extension, params); | |
| 384 ++item_count; | |
| 385 ASSERT_EQ(item_count, launcher_model()->item_count()); | |
| 386 const ash::LauncherItem& item = GetLastLauncherPanelItem(); | |
| 387 EXPECT_EQ(ash::TYPE_APP_PANEL, item.type); | |
| 388 // Opening a panel does not activate it. | |
| 389 EXPECT_EQ(ash::STATUS_RUNNING, item.status); | |
| 390 CloseShellWindow(window); | |
| 391 --item_count; | |
| 392 EXPECT_EQ(item_count, launcher_model()->item_count()); | |
| 393 } | |
| 394 | |
| 395 #if defined(OS_CHROMEOS) | |
| 396 #define MAYBE_WindowActivation DISABLED_WindowActivation | |
| 397 #else | |
| 398 #define MAYBE_WindowActivation WindowActivation | |
| 399 #endif | |
| 400 // Confirm that app windows can be reactivated by clicking their icons and that | 505 // Confirm that app windows can be reactivated by clicking their icons and that |
| 401 // the correct activation order is maintained. | 506 // the correct activation order is maintained. |
| 402 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MAYBE_WindowActivation) { | 507 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowActivation) { |
| 403 int item_count = launcher_model()->item_count(); | 508 int item_count = launcher_model()->item_count(); |
| 404 | 509 |
| 405 // First run app. | 510 // First run app. |
| 406 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); | 511 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); |
| 407 ShellWindow* window1 = CreateShellWindow(extension1); | 512 ShellWindow* window1 = CreateShellWindow(extension1); |
| 408 ++item_count; | 513 ++item_count; |
| 409 ASSERT_EQ(item_count, launcher_model()->item_count()); | 514 ASSERT_EQ(item_count, launcher_model()->item_count()); |
| 410 const ash::LauncherItem& item1 = GetLastLauncherItem(); | 515 const ash::LauncherItem& item1 = GetLastLauncherItem(); |
| 411 ash::LauncherID item_id1 = item1.id; | 516 ash::LauncherID item_id1 = item1.id; |
| 412 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | 517 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); |
| 413 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 518 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 414 | 519 |
| 415 // Then run second app. | 520 // Then run second app. |
| 416 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2"); | 521 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2"); |
| 417 ShellWindow* window2 = CreateShellWindow(extension2); | 522 ShellWindow* window2 = CreateShellWindow(extension2); |
| 418 ++item_count; | 523 ++item_count; |
| 419 ASSERT_EQ(item_count, launcher_model()->item_count()); | 524 ASSERT_EQ(item_count, launcher_model()->item_count()); |
| 420 const ash::LauncherItem& item2 = GetLastLauncherItem(); | 525 const ash::LauncherItem& item2 = GetLastLauncherItem(); |
| 421 ash::LauncherID item_id2 = item2.id; | 526 ash::LauncherID item_id2 = item2.id; |
| 422 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item2.type); | 527 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item2.type); |
| 423 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); | 528 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); |
| 424 | 529 |
| 425 EXPECT_NE(item_id1, item_id2); | 530 EXPECT_NE(item_id1, item_id2); |
| 426 EXPECT_EQ(ash::STATUS_RUNNING, | 531 EXPECT_EQ(ash::STATUS_RUNNING, |
| 427 launcher_model()->ItemByID(item_id1)->status); | 532 launcher_model()->ItemByID(item_id1)->status); |
| 428 | 533 |
| 429 // Activate first one. | 534 // Activate first one. |
| 430 launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1)); | 535 ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1)); |
| 431 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id1)->status); | 536 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id1)->status); |
| 432 EXPECT_EQ(ash::STATUS_RUNNING, | 537 EXPECT_EQ(ash::STATUS_RUNNING, |
| 433 launcher_model()->ItemByID(item_id2)->status); | 538 launcher_model()->ItemByID(item_id2)->status); |
| 434 EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); | 539 EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); |
| 435 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); | 540 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); |
| 436 | 541 |
| 437 // Activate second one. | 542 // Activate second one. |
| 438 launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id2)); | 543 ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id2)); |
| 439 EXPECT_EQ(ash::STATUS_RUNNING, | 544 EXPECT_EQ(ash::STATUS_RUNNING, |
| 440 launcher_model()->ItemByID(item_id1)->status); | 545 launcher_model()->ItemByID(item_id1)->status); |
| 441 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id2)->status); | 546 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id2)->status); |
| 442 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); | 547 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); |
| 443 EXPECT_TRUE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); | 548 EXPECT_TRUE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); |
| 444 | 549 |
| 445 // Add window for app1. This will activate it. | 550 // Add window for app1. This will activate it. |
| 446 ShellWindow* window1b = CreateShellWindow(extension1); | 551 ShellWindow* window1b = CreateShellWindow(extension1); |
| 447 ash::wm::ActivateWindow(window1b->GetNativeWindow()); | 552 ash::wm::ActivateWindow(window1b->GetNativeWindow()); |
| 448 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); | 553 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); |
| 449 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); | 554 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); |
| 450 EXPECT_TRUE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); | 555 EXPECT_TRUE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); |
| 451 | 556 |
| 452 // Activate launcher item for app1, this will activate the first app window. | 557 // Activate launcher item for app1, this will activate the first app window. |
| 453 launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1)); | 558 ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1)); |
| 454 EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); | 559 EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); |
| 455 EXPECT_FALSE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); | 560 EXPECT_FALSE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); |
| 456 launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1)); | 561 ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1)); |
| 457 EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); | 562 EXPECT_TRUE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); |
| 458 | 563 |
| 459 // Activate the second app again | 564 // Activate the second app again |
| 460 launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id2)); | 565 ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id2)); |
| 461 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); | 566 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); |
| 462 EXPECT_TRUE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); | 567 EXPECT_TRUE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); |
| 463 EXPECT_FALSE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); | 568 EXPECT_FALSE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); |
| 464 | 569 |
| 465 // Activate the first app again | 570 // Activate the first app again |
| 466 launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1)); | 571 ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1)); |
| 467 EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); | 572 EXPECT_TRUE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); |
| 468 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); | 573 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); |
| 469 EXPECT_FALSE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); | 574 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); |
| 470 | 575 |
| 471 // Close second app. | 576 // Close second app. |
| 472 CloseShellWindow(window2); | 577 CloseShellWindow(window2); |
| 473 --item_count; | 578 --item_count; |
| 474 EXPECT_EQ(item_count, launcher_model()->item_count()); | 579 EXPECT_EQ(item_count, launcher_model()->item_count()); |
| 475 // First app should be active again. | 580 // First app should be active again. |
| 476 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id1)->status); | 581 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id1)->status); |
| 477 | 582 |
| 478 // Close first app. | 583 // Close first app. |
| 479 CloseShellWindow(window1b); | 584 CloseShellWindow(window1b); |
| 480 CloseShellWindow(window1); | 585 CloseShellWindow(window1); |
| 481 --item_count; | 586 --item_count; |
| 482 EXPECT_EQ(item_count, launcher_model()->item_count()); | 587 EXPECT_EQ(item_count, launcher_model()->item_count()); |
| 483 } | 588 } |
| 484 | 589 |
| 590 // Confirm that Click behavior for app windows is correnct. | |
| 591 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserNoMinimizeOnClick, | |
| 592 AppClickBehavior) { | |
| 593 // Launch a platform app and create a window for it. | |
| 594 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); | |
| 595 ShellWindow* window1 = CreateShellWindow(extension1); | |
| 596 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | |
| 597 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | |
| 598 // Confirm that a controller item was created and is the correct state. | |
| 599 const ash::LauncherItem& item1 = GetLastLauncherItem(); | |
| 600 LauncherItemController* item1_controller = GetItemController(item1.id); | |
| 601 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | |
| 602 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | |
| 603 EXPECT_EQ(LauncherItemController::TYPE_APP, item1_controller->type()); | |
| 604 // Clicking the item should have no effect. | |
| 605 TestEvent click_event(ui::ET_MOUSE_PRESSED); | |
| 606 item1_controller->Clicked(click_event); | |
| 607 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | |
| 608 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | |
| 609 // Minimize the window and confirm that the controller item is updated. | |
| 610 window1->GetBaseWindow()->Minimize(); | |
| 611 EXPECT_FALSE(window1->GetNativeWindow()->IsVisible()); | |
| 612 EXPECT_FALSE(window1->GetBaseWindow()->IsActive()); | |
| 613 EXPECT_EQ(ash::STATUS_RUNNING, item1.status); | |
| 614 // Clicking the item should activate the window. | |
| 615 item1_controller->Clicked(click_event); | |
| 616 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | |
| 617 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | |
| 618 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | |
| 619 // Maximizing a window should preserve state after minimize + click. | |
| 620 window1->GetBaseWindow()->Maximize(); | |
| 621 window1->GetBaseWindow()->Minimize(); | |
| 622 item1_controller->Clicked(click_event); | |
| 623 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | |
| 624 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | |
| 625 EXPECT_TRUE(window1->GetBaseWindow()->IsMaximized()); | |
| 626 } | |
| 627 | |
| 628 // Confirm the minimizing click behavior for apps. | |
| 629 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserMinimizeOnClick, | |
| 630 PackagedAppClickBehaviorInMinimizeMode) { | |
| 631 // Launch one platform app and create a window for it. | |
| 632 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); | |
| 633 ShellWindow* window1 = CreateShellWindow(extension1); | |
| 634 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | |
| 635 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | |
| 636 | |
| 637 // Confirm that a controller item was created and is the correct state. | |
| 638 const ash::LauncherItem& item1 = GetLastLauncherItem(); | |
| 639 LauncherItemController* item1_controller = GetItemController(item1.id); | |
| 640 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | |
| 641 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | |
| 642 EXPECT_EQ(LauncherItemController::TYPE_APP, item1_controller->type()); | |
| 643 // Since it is already active, clicking it should minimize. | |
| 644 TestEvent click_event(ui::ET_MOUSE_PRESSED); | |
| 645 item1_controller->Clicked(click_event); | |
| 646 EXPECT_FALSE(window1->GetNativeWindow()->IsVisible()); | |
| 647 EXPECT_FALSE(window1->GetBaseWindow()->IsActive()); | |
| 648 EXPECT_TRUE(window1->GetBaseWindow()->IsMinimized()); | |
| 649 EXPECT_EQ(ash::STATUS_RUNNING, item1.status); | |
| 650 // Clicking the item again should activate the window again. | |
| 651 item1_controller->Clicked(click_event); | |
| 652 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | |
| 653 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | |
| 654 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | |
| 655 // Maximizing a window should preserve state after minimize + click. | |
| 656 window1->GetBaseWindow()->Maximize(); | |
| 657 window1->GetBaseWindow()->Minimize(); | |
| 658 item1_controller->Clicked(click_event); | |
| 659 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | |
| 660 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | |
| 661 EXPECT_TRUE(window1->GetBaseWindow()->IsMaximized()); | |
| 662 window1->GetBaseWindow()->Restore(); | |
| 663 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | |
| 664 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | |
| 665 EXPECT_FALSE(window1->GetBaseWindow()->IsMaximized()); | |
| 666 | |
| 667 // Creating a second window of the same type should change the behavior so | |
| 668 // that a click does not change the activation state. | |
| 669 ShellWindow* window1a = CreateShellWindow(extension1); | |
| 670 EXPECT_TRUE(window1a->GetNativeWindow()->IsVisible()); | |
| 671 EXPECT_TRUE(window1a->GetBaseWindow()->IsActive()); | |
| 672 // The first click does nothing. | |
| 673 item1_controller->Clicked(click_event); | |
| 674 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | |
| 675 EXPECT_TRUE(window1a->GetNativeWindow()->IsVisible()); | |
| 676 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | |
| 677 EXPECT_FALSE(window1a->GetBaseWindow()->IsActive()); | |
| 678 // The second neither. | |
| 679 item1_controller->Clicked(click_event); | |
| 680 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | |
| 681 EXPECT_TRUE(window1a->GetNativeWindow()->IsVisible()); | |
| 682 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | |
| 683 EXPECT_FALSE(window1a->GetBaseWindow()->IsActive()); | |
| 684 } | |
| 685 | |
| 686 // Confirm that click behavior for app panels is correct. | |
| 687 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, AppPanelClickBehavior) { | |
| 688 // Enable experimental APIs to allow panel creation. | |
| 689 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 690 extensions::switches::kEnableExperimentalExtensionApis); | |
| 691 // Launch a platform app and create a panel window for it. | |
| 692 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); | |
| 693 ShellWindow::CreateParams params; | |
| 694 params.window_type = ShellWindow::WINDOW_TYPE_PANEL; | |
| 695 params.focused = false; | |
| 696 ShellWindow* panel = CreateShellWindowFromParams(extension1, params); | |
| 697 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); | |
| 698 // Panels should not be active by default. | |
| 699 EXPECT_FALSE(panel->GetBaseWindow()->IsActive()); | |
| 700 // Confirm that a controller item was created and is the correct state. | |
| 701 const ash::LauncherItem& item1 = GetLastLauncherPanelItem(); | |
| 702 LauncherItemController* item1_controller = GetItemController(item1.id); | |
| 703 EXPECT_EQ(ash::TYPE_APP_PANEL, item1.type); | |
| 704 EXPECT_EQ(ash::STATUS_RUNNING, item1.status); | |
| 705 EXPECT_EQ(LauncherItemController::TYPE_APP_PANEL, item1_controller->type()); | |
| 706 // Click the item and confirm that the panel is activated. | |
| 707 TestEvent click_event(ui::ET_MOUSE_PRESSED); | |
| 708 item1_controller->Clicked(click_event); | |
| 709 EXPECT_TRUE(panel->GetBaseWindow()->IsActive()); | |
| 710 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | |
| 711 // Click the item again and confirm that the panel is minimized. | |
| 712 item1_controller->Clicked(click_event); | |
| 713 EXPECT_TRUE(panel->GetBaseWindow()->IsMinimized()); | |
| 714 EXPECT_EQ(ash::STATUS_RUNNING, item1.status); | |
| 715 // Click the item again and confirm that the panel is activated. | |
| 716 item1_controller->Clicked(click_event); | |
| 717 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); | |
| 718 EXPECT_TRUE(panel->GetBaseWindow()->IsActive()); | |
| 719 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | |
| 720 } | |
| 721 | |
| 485 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, BrowserActivation) { | 722 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, BrowserActivation) { |
| 486 int item_count = launcher_model()->item_count(); | 723 int item_count = launcher_model()->item_count(); |
| 487 | 724 |
| 488 // First run app. | 725 // First run app. |
| 489 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); | 726 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); |
| 490 CreateShellWindow(extension1); | 727 CreateShellWindow(extension1); |
| 491 ++item_count; | 728 ++item_count; |
| 492 ASSERT_EQ(item_count, launcher_model()->item_count()); | 729 ASSERT_EQ(item_count, launcher_model()->item_count()); |
| 493 const ash::LauncherItem& item1 = GetLastLauncherItem(); | 730 const ash::LauncherItem& item1 = GetLastLauncherItem(); |
| 494 ash::LauncherID item_id1 = item1.id; | 731 ash::LauncherID item_id1 = item1.id; |
| 495 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | 732 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); |
| 496 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 733 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 497 | 734 |
| 498 ash::wm::ActivateWindow(browser()->window()->GetNativeWindow()); | 735 ash::wm::ActivateWindow(browser()->window()->GetNativeWindow()); |
| 499 EXPECT_EQ(ash::STATUS_RUNNING, | 736 EXPECT_EQ(ash::STATUS_RUNNING, |
| 500 launcher_model()->ItemByID(item_id1)->status); | 737 launcher_model()->ItemByID(item_id1)->status); |
| 501 } | 738 } |
| 502 | 739 |
| 503 // Test that draw attention sets the launcher item status. | 740 // Test that opening an app sets the correct icon |
| 504 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, DrawAttention) { | 741 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, SetIcon) { |
| 505 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | 742 TestShellWindowRegistryObserver test_observer(browser()->profile()); |
| 506 ShellWindow* shell_window = CreateShellWindow(extension); | 743 |
| 507 const ash::LauncherItem& item = GetLastLauncherItem(); | 744 // Enable experimental APIs to allow panel creation. |
| 508 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); | 745 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 509 // Set Minimize window to deactivate the launcher item. | 746 extensions::switches::kEnableExperimentalExtensionApis); |
| 510 shell_window->GetBaseWindow()->Minimize(); | 747 |
| 511 EXPECT_EQ(ash::STATUS_RUNNING, item.status); | 748 int base_launcher_item_count = launcher_model()->item_count(); |
| 512 // Set DrawAttention property. | 749 ExtensionTestMessageListener launched_listener("Launched", false); |
| 513 shell_window->GetNativeWindow()->SetProperty( | 750 ExtensionTestMessageListener completed_listener("Completed", false); |
| 514 aura::client::kDrawAttentionKey, true); | 751 LoadAndLaunchPlatformApp("app_icon"); |
| 515 EXPECT_EQ(ash::STATUS_ATTENTION, item.status); | 752 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 516 // Activate window, should clear DrawAttention. | 753 ASSERT_TRUE(completed_listener.WaitUntilSatisfied()); |
| 517 shell_window->GetBaseWindow()->Activate(); | 754 |
| 518 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); | 755 // Now wait until the WebContent has decoded the icons and chrome has |
| 519 EXPECT_FALSE(shell_window->GetNativeWindow()->GetProperty( | 756 // processed it. This needs to be in a loop since the renderer runs in a |
| 520 aura::client::kDrawAttentionKey)); | 757 // different process. |
| 758 while (test_observer.icon_updates() < 3) { | |
| 759 base::RunLoop run_loop; | |
| 760 run_loop.RunUntilIdle(); | |
| 761 } | |
| 762 | |
| 763 // This test creates one shell window and one panel window. | |
| 764 int launcher_item_count = launcher_model()->item_count(); | |
| 765 ASSERT_EQ(base_launcher_item_count + 2, launcher_item_count); | |
| 766 // The Panel will be the last item, the app list second-to-last, the app | |
| 767 // third from last. | |
| 768 const ash::LauncherItem& app_item = | |
| 769 launcher_model()->items()[launcher_item_count - 3]; | |
| 770 const ash::LauncherItem& panel_item = | |
| 771 launcher_model()->items()[launcher_item_count - 1]; | |
| 772 const LauncherItemController* app_item_controller = | |
| 773 GetItemController(app_item.id); | |
| 774 const LauncherItemController* panel_item_controller = | |
| 775 GetItemController(panel_item.id); | |
| 776 // Icons for Apps are set by the ShellWindowLauncherController, so | |
| 777 // image_set_by_controller() should be set. | |
| 778 EXPECT_TRUE(app_item_controller->image_set_by_controller()); | |
| 779 EXPECT_TRUE(panel_item_controller->image_set_by_controller()); | |
| 780 // Ensure icon heights are correct (see test.js in app_icon/ test directory) | |
| 781 EXPECT_EQ(48, app_item.image.height()); | |
| 782 EXPECT_EQ(64, panel_item.image.height()); | |
| 521 } | 783 } |
| 522 | 784 |
| 523 // Test that we can launch an app with a shortcut. | 785 // Test that we can launch an app with a shortcut. |
| 524 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchPinned) { | 786 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchPinned) { |
| 525 TabStripModel* tab_strip = browser()->tab_strip_model(); | 787 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 526 int tab_count = tab_strip->count(); | 788 int tab_count = tab_strip->count(); |
| 527 ash::LauncherID shortcut_id = CreateShortcut("app1"); | 789 ash::LauncherID shortcut_id = CreateShortcut("app1"); |
| 528 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); | 790 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); |
| 529 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); | 791 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); |
| 530 EXPECT_EQ(++tab_count, tab_strip->count()); | 792 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 531 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); | 793 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); |
| 532 WebContents* tab = tab_strip->GetActiveWebContents(); | 794 WebContents* tab = tab_strip->GetActiveWebContents(); |
| 533 content::WindowedNotificationObserver close_observer( | 795 content::WindowedNotificationObserver close_observer( |
| 534 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 796 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 535 content::Source<WebContents>(tab)); | 797 content::Source<WebContents>(tab)); |
| 536 browser()->tab_strip_model()->CloseSelectedTabs(); | 798 browser()->tab_strip_model()->CloseSelectedTabs(); |
| 537 close_observer.Wait(); | 799 close_observer.Wait(); |
| 538 EXPECT_EQ(--tab_count, tab_strip->count()); | 800 EXPECT_EQ(--tab_count, tab_strip->count()); |
| 539 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); | 801 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 579 content::NotificationService::AllSources()); | 841 content::NotificationService::AllSources()); |
| 580 chrome::NewEmptyWindow(browser()->profile(), chrome::HOST_DESKTOP_TYPE_ASH); | 842 chrome::NewEmptyWindow(browser()->profile(), chrome::HOST_DESKTOP_TYPE_ASH); |
| 581 open_observer.Wait(); | 843 open_observer.Wait(); |
| 582 Browser* browser2 = content::Source<Browser>(open_observer.source()).ptr(); | 844 Browser* browser2 = content::Source<Browser>(open_observer.source()).ptr(); |
| 583 aura::Window* window2 = browser2->window()->GetNativeWindow(); | 845 aura::Window* window2 = browser2->window()->GetNativeWindow(); |
| 584 TabStripModel* tab_strip = browser2->tab_strip_model(); | 846 TabStripModel* tab_strip = browser2->tab_strip_model(); |
| 585 int tab_count = tab_strip->count(); | 847 int tab_count = tab_strip->count(); |
| 586 ash::wm::MaximizeWindow(window2); | 848 ash::wm::MaximizeWindow(window2); |
| 587 | 849 |
| 588 ash::LauncherID shortcut_id = CreateShortcut("app1"); | 850 ash::LauncherID shortcut_id = CreateShortcut("app1"); |
| 589 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); | 851 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); |
| 590 EXPECT_EQ(++tab_count, tab_strip->count()); | 852 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 591 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); | 853 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); |
| 592 | 854 |
| 593 window1->Show(); | 855 window1->Show(); |
| 594 ash::wm::ActivateWindow(window1); | 856 ash::wm::ActivateWindow(window1); |
| 595 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut_id)).status); | 857 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut_id)).status); |
| 596 | 858 |
| 597 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); | 859 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); |
| 598 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); | 860 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); |
| 599 } | 861 } |
| 600 | 862 |
| 601 // Activating the same app multiple times should launch only a single copy. | 863 // Activating the same app multiple times should launch only a single copy. |
| 602 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateApp) { | 864 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateApp) { |
| 603 TabStripModel* tab_strip = browser()->tab_strip_model(); | 865 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 604 int tab_count = tab_strip->count(); | 866 int tab_count = tab_strip->count(); |
| 605 const Extension* extension = | 867 const Extension* extension = |
| 606 LoadExtension(test_data_dir_.AppendASCII("app1")); | 868 LoadExtension(test_data_dir_.AppendASCII("app1")); |
| 607 | 869 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 628 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleApps) { | 890 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleApps) { |
| 629 int item_count = model_->item_count(); | 891 int item_count = model_->item_count(); |
| 630 TabStripModel* tab_strip = browser()->tab_strip_model(); | 892 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 631 int tab_count = tab_strip->count(); | 893 int tab_count = tab_strip->count(); |
| 632 ash::LauncherID shortcut1 = CreateShortcut("app1"); | 894 ash::LauncherID shortcut1 = CreateShortcut("app1"); |
| 633 EXPECT_EQ(++item_count, model_->item_count()); | 895 EXPECT_EQ(++item_count, model_->item_count()); |
| 634 ash::LauncherID shortcut2 = CreateShortcut("app2"); | 896 ash::LauncherID shortcut2 = CreateShortcut("app2"); |
| 635 EXPECT_EQ(++item_count, model_->item_count()); | 897 EXPECT_EQ(++item_count, model_->item_count()); |
| 636 | 898 |
| 637 // Launch first app. | 899 // Launch first app. |
| 638 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut1)); | 900 ActivateLauncherItem(model_->ItemIndexByID(shortcut1)); |
| 639 EXPECT_EQ(++tab_count, tab_strip->count()); | 901 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 640 WebContents* tab1 = tab_strip->GetActiveWebContents(); | 902 WebContents* tab1 = tab_strip->GetActiveWebContents(); |
| 641 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status); | 903 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status); |
| 642 | 904 |
| 643 // Launch second app. | 905 // Launch second app. |
| 644 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut2)); | 906 ActivateLauncherItem(model_->ItemIndexByID(shortcut2)); |
| 645 EXPECT_EQ(++tab_count, tab_strip->count()); | 907 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 646 WebContents* tab2 = tab_strip->GetActiveWebContents(); | 908 WebContents* tab2 = tab_strip->GetActiveWebContents(); |
| 647 ASSERT_NE(tab1, tab2); | 909 ASSERT_NE(tab1, tab2); |
| 648 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status); | 910 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status); |
| 649 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status); | 911 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status); |
| 650 | 912 |
| 651 // Reactivate first app. | 913 // Reactivate first app. |
| 652 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut1)); | 914 ActivateLauncherItem(model_->ItemIndexByID(shortcut1)); |
| 653 EXPECT_EQ(tab_count, tab_strip->count()); | 915 EXPECT_EQ(tab_count, tab_strip->count()); |
| 654 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab1); | 916 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab1); |
| 655 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status); | 917 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status); |
| 656 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut2)).status); | 918 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut2)).status); |
| 657 | 919 |
| 658 // Open second tab for second app. This should activate it. | 920 // Open second tab for second app. This should activate it. |
| 659 ui_test_utils::NavigateToURLWithDisposition( | 921 ui_test_utils::NavigateToURLWithDisposition( |
| 660 browser(), | 922 browser(), |
| 661 GURL("http://www.example.com/path3/foo.html"), | 923 GURL("http://www.example.com/path3/foo.html"), |
| 662 NEW_FOREGROUND_TAB, | 924 NEW_FOREGROUND_TAB, |
| 663 0); | 925 0); |
| 664 EXPECT_EQ(++tab_count, tab_strip->count()); | 926 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 665 WebContents* tab3 = tab_strip->GetActiveWebContents(); | |
| 666 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status); | 927 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status); |
| 667 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status); | 928 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status); |
| 668 | 929 |
| 669 // Reactivate first app. | 930 // Reactivate first app. |
| 670 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut1)); | 931 ActivateLauncherItem(model_->ItemIndexByID(shortcut1)); |
| 671 EXPECT_EQ(tab_count, tab_strip->count()); | 932 EXPECT_EQ(tab_count, tab_strip->count()); |
| 672 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab1); | 933 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab1); |
| 673 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status); | 934 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status); |
| 674 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut2)).status); | 935 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut2)).status); |
| 675 | 936 |
| 676 // And second again. This time the second tab should become active. | 937 // And second again. This time the second tab should become active. |
| 677 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut2)); | 938 ActivateLauncherItem(model_->ItemIndexByID(shortcut2)); |
| 678 EXPECT_EQ(tab_count, tab_strip->count()); | 939 EXPECT_EQ(tab_count, tab_strip->count()); |
| 679 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab3); | 940 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab2); |
| 680 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status); | 941 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status); |
| 681 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status); | 942 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status); |
| 682 } | 943 } |
| 683 | 944 |
| 684 // Confirm that a page can be navigated from and to while maintaining the | 945 // Confirm that a page can be navigated from and to while maintaining the |
| 685 // correct running state. | 946 // correct running state. |
| 686 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, Navigation) { | 947 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, Navigation) { |
| 687 ash::LauncherID shortcut_id = CreateShortcut("app1"); | 948 ash::LauncherID shortcut_id = CreateShortcut("app1"); |
| 688 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); | 949 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); |
| 689 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); | 950 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); |
| 690 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); | 951 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); |
| 691 | 952 |
| 692 // Navigate away. | 953 // Navigate away. |
| 693 ui_test_utils::NavigateToURL( | 954 ui_test_utils::NavigateToURL( |
| 694 browser(), GURL("http://www.example.com/path0/bar.html")); | 955 browser(), GURL("http://www.example.com/path0/bar.html")); |
| 695 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); | 956 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); |
| 696 | 957 |
| 697 // Navigate back. | 958 // Navigate back. |
| 698 ui_test_utils::NavigateToURL( | 959 ui_test_utils::NavigateToURL( |
| 699 browser(), GURL("http://www.example.com/path1/foo.html")); | 960 browser(), GURL("http://www.example.com/path1/foo.html")); |
| 700 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); | 961 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); |
| 701 } | 962 } |
| 702 | 963 |
| 703 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleOwnedTabs) { | 964 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleOwnedTabs) { |
| 704 TabStripModel* tab_strip = browser()->tab_strip_model(); | 965 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 705 int tab_count = tab_strip->count(); | 966 int tab_count = tab_strip->count(); |
| 706 ash::LauncherID shortcut_id = CreateShortcut("app1"); | 967 ash::LauncherID shortcut_id = CreateShortcut("app1"); |
| 707 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); | 968 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); |
| 708 EXPECT_EQ(++tab_count, tab_strip->count()); | 969 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 709 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); | 970 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); |
| 971 WebContents* first_tab = tab_strip->GetActiveWebContents(); | |
| 710 | 972 |
| 711 // Create new tab owned by app. | 973 // Create new tab owned by app. |
| 712 ui_test_utils::NavigateToURLWithDisposition( | 974 ui_test_utils::NavigateToURLWithDisposition( |
| 713 browser(), | 975 browser(), |
| 714 GURL("http://www.example.com/path2/bar.html"), | 976 GURL("http://www.example.com/path2/bar.html"), |
| 715 NEW_FOREGROUND_TAB, | 977 NEW_FOREGROUND_TAB, |
| 716 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 978 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 717 EXPECT_EQ(++tab_count, tab_strip->count()); | 979 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 718 // Confirm app is still active. | 980 // Confirm app is still active. |
| 719 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); | 981 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); |
| 720 WebContents* second_tab = tab_strip->GetActiveWebContents(); | |
| 721 | 982 |
| 722 // Create new tab not owned by app. | 983 // Create new tab not owned by app. |
| 723 ui_test_utils::NavigateToURLWithDisposition( | 984 ui_test_utils::NavigateToURLWithDisposition( |
| 724 browser(), | 985 browser(), |
| 725 GURL("http://www.example.com/path3/foo.html"), | 986 GURL("http://www.example.com/path3/foo.html"), |
| 726 NEW_FOREGROUND_TAB, | 987 NEW_FOREGROUND_TAB, |
| 727 0); | 988 0); |
| 728 EXPECT_EQ(++tab_count, tab_strip->count()); | 989 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 729 // No longer active. | 990 // No longer active. |
| 730 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); | 991 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); |
| 731 | 992 |
| 732 // Activating app makes second tab active again. | 993 // Activating app makes first tab active again. |
| 733 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); | 994 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); |
| 734 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); | 995 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); |
| 735 EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab); | 996 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab); |
| 736 } | 997 } |
| 737 | 998 |
| 738 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilter) { | 999 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilter) { |
| 739 ChromeLauncherController* controller = | |
| 740 static_cast<ChromeLauncherController*>(launcher_->delegate()); | |
| 741 TabStripModel* tab_strip = browser()->tab_strip_model(); | 1000 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 742 int tab_count = tab_strip->count(); | 1001 int tab_count = tab_strip->count(); |
| 743 ash::LauncherID shortcut_id = CreateShortcut("app1"); | 1002 ash::LauncherID shortcut_id = CreateShortcut("app1"); |
| 744 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); | 1003 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); |
| 745 EXPECT_EQ(++tab_count, tab_strip->count()); | 1004 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 746 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); | 1005 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); |
| 747 WebContents* first_tab = tab_strip->GetActiveWebContents(); | 1006 WebContents* first_tab = tab_strip->GetActiveWebContents(); |
| 748 | 1007 |
| 749 controller->SetRefocusURLPatternForTest( | 1008 controller_->SetRefocusURLPatternForTest( |
| 750 shortcut_id, GURL("http://www.example.com/path1/*")); | 1009 shortcut_id, GURL("http://www.example.com/path1/*")); |
| 751 // Create new tab owned by app. | 1010 // Create new tab owned by app. |
| 752 ui_test_utils::NavigateToURLWithDisposition( | 1011 ui_test_utils::NavigateToURLWithDisposition( |
| 753 browser(), | 1012 browser(), |
| 754 GURL("http://www.example.com/path2/bar.html"), | 1013 GURL("http://www.example.com/path2/bar.html"), |
| 755 NEW_FOREGROUND_TAB, | 1014 NEW_FOREGROUND_TAB, |
| 756 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1015 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 757 EXPECT_EQ(++tab_count, tab_strip->count()); | 1016 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 758 // Confirm app is still active. | 1017 // Confirm app is still active. |
| 759 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); | 1018 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); |
| 760 | 1019 |
| 761 // Create new tab not owned by app. | 1020 // Create new tab not owned by app. |
| 762 ui_test_utils::NavigateToURLWithDisposition( | 1021 ui_test_utils::NavigateToURLWithDisposition( |
| 763 browser(), | 1022 browser(), |
| 764 GURL("http://www.example.com/path3/foo.html"), | 1023 GURL("http://www.example.com/path3/foo.html"), |
| 765 NEW_FOREGROUND_TAB, | 1024 NEW_FOREGROUND_TAB, |
| 766 0); | 1025 0); |
| 767 EXPECT_EQ(++tab_count, tab_strip->count()); | 1026 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 768 // No longer active. | 1027 // No longer active. |
| 769 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); | 1028 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); |
| 770 | 1029 |
| 771 // Activating app makes first tab active again, because second tab isn't | 1030 // Activating app makes first tab active again, because second tab isn't |
| 772 // in its refocus url path. | 1031 // in its refocus url path. |
| 773 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); | 1032 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); |
| 774 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); | 1033 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); |
| 775 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab); | 1034 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab); |
| 776 } | 1035 } |
| 777 | 1036 |
| 778 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilterLaunch) { | 1037 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilterLaunch) { |
| 779 ChromeLauncherController* controller = | |
| 780 static_cast<ChromeLauncherController*>(launcher_->delegate()); | |
| 781 TabStripModel* tab_strip = browser()->tab_strip_model(); | 1038 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 782 int tab_count = tab_strip->count(); | 1039 int tab_count = tab_strip->count(); |
| 783 ash::LauncherID shortcut_id = CreateShortcut("app1"); | 1040 ash::LauncherID shortcut_id = CreateShortcut("app1"); |
| 784 controller->SetRefocusURLPatternForTest( | 1041 controller_->SetRefocusURLPatternForTest( |
| 785 shortcut_id, GURL("http://www.example.com/path1/*")); | 1042 shortcut_id, GURL("http://www.example.com/path1/*")); |
| 786 | 1043 |
| 787 // Create new tab owned by app. | 1044 // Create new tab. |
| 788 ui_test_utils::NavigateToURLWithDisposition( | 1045 ui_test_utils::NavigateToURLWithDisposition( |
| 789 browser(), | 1046 browser(), |
| 790 GURL("http://www.example.com/path2/bar.html"), | 1047 GURL("http://www.example2.com/path2/bar.html"), |
| 791 NEW_FOREGROUND_TAB, | 1048 NEW_FOREGROUND_TAB, |
| 792 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1049 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 793 EXPECT_EQ(++tab_count, tab_strip->count()); | 1050 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 794 WebContents* first_tab = tab_strip->GetActiveWebContents(); | 1051 WebContents* first_tab = tab_strip->GetActiveWebContents(); |
| 795 // Confirm app is active. | 1052 // Confirm app is not active. |
| 796 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); | 1053 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); |
| 797 | 1054 |
| 798 // Activating app should launch new tab, because second tab isn't | 1055 // Activating app should launch new tab, because second tab isn't |
| 799 // in its refocus url path. | 1056 // in its refocus url path. |
| 800 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); | 1057 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); |
| 801 EXPECT_EQ(++tab_count, tab_strip->count()); | 1058 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 802 WebContents* second_tab = tab_strip->GetActiveWebContents(); | 1059 WebContents* second_tab = tab_strip->GetActiveWebContents(); |
| 803 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); | 1060 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); |
| 804 EXPECT_NE(first_tab, second_tab); | 1061 EXPECT_NE(first_tab, second_tab); |
| 805 EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab); | 1062 EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab); |
| 806 } | 1063 } |
| 807 | 1064 |
| 1065 // Check the launcher activation state for applications and browser. | |
| 1066 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivationStateCheck) { | |
| 1067 TabStripModel* tab_strip = browser()->tab_strip_model(); | |
| 1068 // Get the browser item index | |
| 1069 int browser_index = ash::launcher::GetBrowserItemIndex(*controller_->model()); | |
| 1070 EXPECT_TRUE(browser_index >= 0); | |
| 1071 | |
| 1072 // Even though we are just comming up, the browser should be active. | |
| 1073 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status); | |
| 1074 | |
| 1075 ash::LauncherID shortcut_id = CreateShortcut("app1"); | |
| 1076 controller_->SetRefocusURLPatternForTest( | |
| 1077 shortcut_id, GURL("http://www.example.com/path1/*")); | |
| 1078 | |
| 1079 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); | |
| 1080 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status); | |
| 1081 | |
| 1082 // Create new tab which would be the running app. | |
| 1083 ui_test_utils::NavigateToURLWithDisposition( | |
| 1084 browser(), | |
| 1085 GURL("http://www.example.com/path1/bar.html"), | |
| 1086 NEW_FOREGROUND_TAB, | |
| 1087 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 1088 | |
| 1089 // There should never be two items active at the same time. | |
| 1090 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); | |
| 1091 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[browser_index].status); | |
| 1092 | |
| 1093 tab_strip->ActivateTabAt(0, false); | |
| 1094 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); | |
| 1095 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status); | |
| 1096 | |
| 1097 tab_strip->CloseWebContentsAt(1, TabStripModel::CLOSE_NONE); | |
| 1098 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); | |
| 1099 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status); | |
| 1100 | |
| 1101 ash::wm::DeactivateWindow(browser()->window()->GetNativeWindow()); | |
| 1102 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); | |
| 1103 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[browser_index].status); | |
| 1104 } | |
| 1105 | |
| 1106 // Check that the launcher activation state for a V1 application stays closed | |
| 1107 // even after an asynchronous browser event comes in after the tab got | |
| 1108 // destroyed. | |
| 1109 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, AsyncActivationStateCheck) { | |
| 1110 TabStripModel* tab_strip = browser()->tab_strip_model(); | |
| 1111 | |
| 1112 ash::LauncherID shortcut_id = CreateShortcut("app1"); | |
| 1113 controller_->SetRefocusURLPatternForTest( | |
| 1114 shortcut_id, GURL("http://www.example.com/path1/*")); | |
| 1115 | |
| 1116 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); | |
| 1117 | |
| 1118 // Create new tab which would be the running app. | |
| 1119 ui_test_utils::NavigateToURLWithDisposition( | |
| 1120 browser(), | |
| 1121 GURL("http://www.example.com/path1/bar.html"), | |
| 1122 NEW_FOREGROUND_TAB, | |
| 1123 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 1124 | |
| 1125 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); | |
| 1126 // To address the issue of crbug.com/174050, the tab we are about to close | |
| 1127 // has to be active. | |
| 1128 tab_strip->ActivateTabAt(1, false); | |
| 1129 EXPECT_EQ(1, tab_strip->active_index()); | |
| 1130 | |
| 1131 // Close the web contents. | |
| 1132 tab_strip->CloseWebContentsAt(1, TabStripModel::CLOSE_NONE); | |
| 1133 // The status should now be set to closed. | |
| 1134 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); | |
| 1135 } | |
| 1136 | |
| 1137 // Checks that a windowed application does not add an item to the browser list. | |
| 1138 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser, | |
| 1139 WindowedAppDoesNotAddToBrowser) { | |
| 1140 // Get the number of items in the browser menu. | |
| 1141 size_t items = NumberOfDetectedLauncherBrowsers(false); | |
| 1142 size_t running_browser = chrome::GetTotalBrowserCount(); | |
| 1143 EXPECT_EQ(0u, items); | |
| 1144 EXPECT_EQ(0u, running_browser); | |
| 1145 | |
| 1146 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_WINDOW, NEW_WINDOW); | |
| 1147 | |
| 1148 // No new browser should get detected, even though one more is running. | |
| 1149 EXPECT_EQ(0u, NumberOfDetectedLauncherBrowsers(false)); | |
| 1150 EXPECT_EQ(++running_browser, chrome::GetTotalBrowserCount()); | |
| 1151 | |
| 1152 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, NEW_WINDOW); | |
| 1153 | |
| 1154 // A new browser should get detected and one more should be running. | |
| 1155 EXPECT_EQ(NumberOfDetectedLauncherBrowsers(false), 1u); | |
| 1156 EXPECT_EQ(++running_browser, chrome::GetTotalBrowserCount()); | |
| 1157 } | |
| 1158 | |
| 1159 // Checks the functionality to enumerate all browsers vs. all tabs. | |
| 1160 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser, | |
| 1161 EnumerateALlBrowsersAndTabs) { | |
| 1162 // Create at least one browser. | |
| 1163 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, NEW_WINDOW); | |
| 1164 size_t browsers = NumberOfDetectedLauncherBrowsers(false); | |
| 1165 size_t tabs = NumberOfDetectedLauncherBrowsers(true); | |
| 1166 | |
| 1167 // Create a second browser. | |
| 1168 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, NEW_WINDOW); | |
| 1169 | |
| 1170 EXPECT_EQ(++browsers, NumberOfDetectedLauncherBrowsers(false)); | |
| 1171 EXPECT_EQ(++tabs, NumberOfDetectedLauncherBrowsers(true)); | |
| 1172 | |
| 1173 // Create only a tab. | |
| 1174 LoadAndLaunchExtension("app1", | |
| 1175 extension_misc::LAUNCH_TAB, | |
| 1176 NEW_FOREGROUND_TAB); | |
| 1177 | |
| 1178 EXPECT_EQ(browsers, NumberOfDetectedLauncherBrowsers(false)); | |
| 1179 EXPECT_EQ(++tabs, NumberOfDetectedLauncherBrowsers(true)); | |
| 1180 } | |
| 1181 | |
| 1182 // Check that the keyboard activation of a launcher item tabs properly through | |
| 1183 // the items at hand. | |
| 1184 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, AltNumberTabsTabbing) { | |
| 1185 TabStripModel* tab_strip = browser()->tab_strip_model(); | |
| 1186 | |
| 1187 ash::LauncherID shortcut_id = CreateShortcut("app"); | |
| 1188 controller_->SetRefocusURLPatternForTest( | |
| 1189 shortcut_id, GURL("http://www.example.com/path/*")); | |
| 1190 std::string url = "http://www.example.com/path/bla"; | |
| 1191 | |
| 1192 int shortcut_index = model_->ItemIndexByID(shortcut_id); | |
| 1193 | |
| 1194 // Create an application handled browser tab. | |
| 1195 ui_test_utils::NavigateToURLWithDisposition( | |
| 1196 browser(), | |
| 1197 GURL(url), | |
| 1198 NEW_FOREGROUND_TAB, | |
| 1199 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 1200 | |
| 1201 content::WebContents* content1 = tab_strip->GetActiveWebContents(); | |
| 1202 | |
| 1203 // Create some other browser tab. | |
| 1204 ui_test_utils::NavigateToURLWithDisposition( | |
| 1205 browser(), | |
| 1206 GURL("http://www.test.com"), | |
| 1207 NEW_FOREGROUND_TAB, | |
| 1208 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 1209 content::WebContents* content1a = tab_strip->GetActiveWebContents(); | |
| 1210 | |
| 1211 // Make sure that the active tab is now our handled tab. | |
| 1212 EXPECT_NE(content1a, content1); | |
| 1213 | |
| 1214 // The active tab should still be the unnamed tab. Then we switch and reach | |
| 1215 // the first app and stay there. | |
| 1216 EXPECT_EQ(content1a, tab_strip->GetActiveWebContents()); | |
| 1217 ActivateLauncherItem(shortcut_index); | |
| 1218 EXPECT_EQ(content1, tab_strip->GetActiveWebContents()); | |
| 1219 ActivateLauncherItem(shortcut_index); | |
| 1220 EXPECT_EQ(content1, tab_strip->GetActiveWebContents()); | |
| 1221 | |
| 1222 ui_test_utils::NavigateToURLWithDisposition( | |
| 1223 browser(), | |
| 1224 GURL(url), | |
| 1225 NEW_FOREGROUND_TAB, | |
| 1226 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 1227 content::WebContents* content2 = tab_strip->GetActiveWebContents(); | |
| 1228 | |
| 1229 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents()); | |
| 1230 ActivateLauncherItem(shortcut_index); | |
| 1231 EXPECT_EQ(content1, browser()->tab_strip_model()->GetActiveWebContents()); | |
| 1232 ActivateLauncherItem(shortcut_index); | |
| 1233 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents()); | |
| 1234 } | |
| 1235 | |
| 1236 // Check that the keyboard activation of a launcher item tabs properly through | |
| 1237 // the items at hand. | |
| 1238 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, | |
| 1239 AltNumberAppsTabbing) { | |
| 1240 // First run app. | |
| 1241 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); | |
| 1242 ui::BaseWindow* window1 = CreateShellWindow(extension1)->GetBaseWindow(); | |
| 1243 const ash::LauncherItem& item1 = GetLastLauncherItem(); | |
| 1244 ash::LauncherID app_id = item1.id; | |
| 1245 int app_index = launcher_model()->ItemIndexByID(app_id); | |
| 1246 | |
| 1247 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | |
| 1248 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | |
| 1249 | |
| 1250 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2"); | |
| 1251 ui::BaseWindow* window2 = CreateShellWindow(extension2)->GetBaseWindow(); | |
| 1252 | |
| 1253 // By now the browser should be active. Issue Alt keystrokes several times to | |
| 1254 // see that we stay on that application. | |
| 1255 EXPECT_TRUE(window2->IsActive()); | |
| 1256 ActivateLauncherItem(app_index); | |
| 1257 EXPECT_TRUE(window1->IsActive()); | |
| 1258 ActivateLauncherItem(app_index); | |
| 1259 EXPECT_TRUE(window1->IsActive()); | |
| 1260 | |
| 1261 ui::BaseWindow* window1a = CreateShellWindow(extension1)->GetBaseWindow(); | |
| 1262 | |
| 1263 EXPECT_TRUE(window1a->IsActive()); | |
| 1264 EXPECT_FALSE(window1->IsActive()); | |
| 1265 ActivateLauncherItem(app_index); | |
| 1266 EXPECT_TRUE(window1->IsActive()); | |
| 1267 ActivateLauncherItem(app_index); | |
| 1268 EXPECT_TRUE(window1a->IsActive()); | |
| 1269 } | |
| 1270 | |
| 1271 // Test that we can launch a platform app panel and get a running item. | |
| 1272 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, | |
| 1273 LaunchPanelWindow) { | |
| 1274 int item_count = launcher_model()->item_count(); | |
| 1275 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | |
| 1276 ShellWindow::CreateParams params; | |
| 1277 params.window_type = ShellWindow::WINDOW_TYPE_PANEL; | |
| 1278 params.focused = false; | |
| 1279 ShellWindow* window = CreateShellWindowFromParams(extension, params); | |
| 1280 ++item_count; | |
| 1281 ASSERT_EQ(item_count, launcher_model()->item_count()); | |
| 1282 const ash::LauncherItem& item = GetLastLauncherPanelItem(); | |
| 1283 EXPECT_EQ(ash::TYPE_APP_PANEL, item.type); | |
| 1284 // Opening a panel does not activate it. | |
| 1285 EXPECT_EQ(ash::STATUS_RUNNING, item.status); | |
| 1286 CloseShellWindow(window); | |
| 1287 --item_count; | |
| 1288 EXPECT_EQ(item_count, launcher_model()->item_count()); | |
| 1289 } | |
| 1290 | |
| 1291 // Test attention states of windows. | |
| 1292 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowAttentionStatus) { | |
| 1293 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | |
| 1294 ShellWindow::CreateParams params; | |
| 1295 params.window_type = ShellWindow::WINDOW_TYPE_PANEL; | |
| 1296 params.focused = false; | |
| 1297 ShellWindow* panel = CreateShellWindowFromParams(extension, params); | |
| 1298 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); | |
| 1299 // Panels should not be active by default. | |
| 1300 EXPECT_FALSE(panel->GetBaseWindow()->IsActive()); | |
| 1301 // Confirm that a controller item was created and is the correct state. | |
| 1302 const ash::LauncherItem& item = GetLastLauncherPanelItem(); | |
| 1303 LauncherItemController* item_controller = GetItemController(item.id); | |
| 1304 EXPECT_EQ(ash::TYPE_APP_PANEL, item.type); | |
| 1305 EXPECT_EQ(ash::STATUS_RUNNING, item.status); | |
| 1306 EXPECT_EQ(LauncherItemController::TYPE_APP_PANEL, item_controller->type()); | |
| 1307 | |
| 1308 // App windows should go to attention state. | |
| 1309 panel->GetNativeWindow()->SetProperty(aura::client::kDrawAttentionKey, true); | |
| 1310 EXPECT_EQ(ash::STATUS_ATTENTION, item.status); | |
| 1311 | |
| 1312 // Click the item and confirm that the panel is activated. | |
| 1313 TestEvent click_event(ui::ET_MOUSE_PRESSED); | |
| 1314 item_controller->Clicked(click_event); | |
| 1315 EXPECT_TRUE(panel->GetBaseWindow()->IsActive()); | |
| 1316 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); | |
| 1317 | |
| 1318 // Active windows don't show attention. | |
| 1319 panel->GetNativeWindow()->SetProperty(aura::client::kDrawAttentionKey, true); | |
| 1320 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); | |
| 1321 } | |
| 1322 | |
| 1323 // Checks that the browser Alt "tabbing" is properly done. | |
| 1324 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser, | |
| 1325 AltNumberBrowserTabbing) { | |
| 1326 // Get the number of items in the browser menu. | |
| 1327 EXPECT_EQ(0u, chrome::GetTotalBrowserCount()); | |
| 1328 // The first activation should create a browser. | |
| 1329 launcher_->ActivateLauncherItem(0); | |
| 1330 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | |
| 1331 // A second activation should not create a new instance. | |
| 1332 launcher_->ActivateLauncherItem(0); | |
| 1333 Browser* browser1 = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); | |
| 1334 EXPECT_TRUE(browser1); | |
| 1335 aura::Window* window1 = browser1->window()->GetNativeWindow(); | |
| 1336 Browser* browser2 = CreateBrowser(profile()); | |
| 1337 aura::Window* window2 = browser2->window()->GetNativeWindow(); | |
| 1338 | |
| 1339 EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); | |
| 1340 EXPECT_NE(window1, window2); | |
| 1341 EXPECT_EQ(window2, ash::wm::GetActiveWindow()); | |
| 1342 | |
| 1343 // Activate multiple times the switcher to see that the windows get activated. | |
| 1344 launcher_->ActivateLauncherItem(0); | |
| 1345 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); | |
| 1346 launcher_->ActivateLauncherItem(0); | |
| 1347 EXPECT_EQ(window2, ash::wm::GetActiveWindow()); | |
| 1348 | |
| 1349 // Create a third browser - make sure that we do not toggle simply between | |
| 1350 // two windows. | |
| 1351 Browser* browser3 = CreateBrowser(profile()); | |
| 1352 aura::Window* window3 = browser3->window()->GetNativeWindow(); | |
| 1353 | |
| 1354 EXPECT_EQ(3u, chrome::GetTotalBrowserCount()); | |
| 1355 EXPECT_NE(window1, window3); | |
| 1356 EXPECT_NE(window2, window3); | |
| 1357 EXPECT_EQ(window3, ash::wm::GetActiveWindow()); | |
| 1358 | |
| 1359 launcher_->ActivateLauncherItem(0); | |
| 1360 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); | |
| 1361 launcher_->ActivateLauncherItem(0); | |
| 1362 EXPECT_EQ(window2, ash::wm::GetActiveWindow()); | |
| 1363 launcher_->ActivateLauncherItem(0); | |
| 1364 EXPECT_EQ(window3, ash::wm::GetActiveWindow()); | |
| 1365 launcher_->ActivateLauncherItem(0); | |
| 1366 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); | |
| 1367 | |
| 1368 // Create anther app and make sure that none of our browsers is active. | |
| 1369 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, NEW_WINDOW); | |
| 1370 EXPECT_NE(window1, ash::wm::GetActiveWindow()); | |
| 1371 EXPECT_NE(window2, ash::wm::GetActiveWindow()); | |
| 1372 | |
| 1373 // After activation our browser should be active again. | |
| 1374 launcher_->ActivateLauncherItem(0); | |
| 1375 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); | |
| 1376 } | |
| 1377 | |
| 1378 // Checks that after a session restore, we do not start applications on an | |
| 1379 // activation. | |
| 1380 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateAfterSessionRestore) { | |
| 1381 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | |
| 1382 | |
| 1383 // Create a known application. | |
| 1384 ash::LauncherID shortcut_id = CreateShortcut("app1"); | |
| 1385 | |
| 1386 // Create a new browser - without activating it - and load an "app" into it. | |
| 1387 Browser::CreateParams params = | |
| 1388 Browser::CreateParams(profile(), chrome::GetActiveDesktop()); | |
| 1389 params.initial_show_state = ui::SHOW_STATE_INACTIVE; | |
| 1390 Browser* browser2 = new Browser(params); | |
| 1391 controller_->SetRefocusURLPatternForTest( | |
| 1392 shortcut_id, GURL("http://www.example.com/path/*")); | |
| 1393 std::string url = "http://www.example.com/path/bla"; | |
| 1394 ui_test_utils::NavigateToURLWithDisposition( | |
| 1395 browser2, | |
| 1396 GURL(url), | |
| 1397 NEW_FOREGROUND_TAB, | |
| 1398 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 1399 | |
| 1400 // Remember the number of tabs for each browser. | |
| 1401 TabStripModel* tab_strip = browser()->tab_strip_model(); | |
| 1402 int tab_count1 = tab_strip->count(); | |
| 1403 TabStripModel* tab_strip2 = browser2->tab_strip_model(); | |
| 1404 int tab_count2 = tab_strip2->count(); | |
| 1405 | |
| 1406 // Check that we have two browsers and the inactive browser remained inactive. | |
| 1407 EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); | |
| 1408 EXPECT_EQ(chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()), | |
| 1409 browser()); | |
| 1410 // Check that the LRU browser list does only contain the original browser. | |
| 1411 BrowserList* ash_browser_list = | |
| 1412 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | |
| 1413 BrowserList::const_reverse_iterator it = | |
| 1414 ash_browser_list->begin_last_active(); | |
| 1415 EXPECT_EQ(*it, browser()); | |
| 1416 ++it; | |
| 1417 EXPECT_EQ(it, ash_browser_list->end_last_active()); | |
| 1418 | |
| 1419 // Now request to either activate an existing app or create a new one. | |
| 1420 controller_->ItemSelected(*model_->ItemByID(shortcut_id), | |
| 1421 ui::KeyEvent(ui::ET_KEY_RELEASED, | |
| 1422 ui::VKEY_RETURN, | |
| 1423 0, | |
| 1424 false)); | |
| 1425 | |
| 1426 // Check that we have set focus on the existing application and nothing new | |
| 1427 // was created. | |
| 1428 EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); | |
| 1429 EXPECT_EQ(tab_count1, tab_strip->count()); | |
| 1430 EXPECT_EQ(tab_count2, tab_strip2->count()); | |
| 1431 EXPECT_EQ(chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()), | |
| 1432 browser2); | |
| 1433 } | |
| 1434 | |
| 1435 // Do various drag and drop interaction tests between the application list and | |
| 1436 // the launcher. | |
| 1437 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, DragAndDrop) { | |
| 1438 // Get a number of interfaces we need. | |
| 1439 aura::test::EventGenerator generator( | |
| 1440 ash::Shell::GetPrimaryRootWindow(), gfx::Point()); | |
| 1441 ash::test::LauncherViewTestAPI test(launcher_->GetLauncherViewForTest()); | |
| 1442 AppListService* service = AppListService::Get(); | |
| 1443 | |
| 1444 // There should be two items in our launcher by this time. | |
| 1445 EXPECT_EQ(2, model_->item_count()); | |
| 1446 EXPECT_FALSE(service->IsAppListVisible()); | |
| 1447 | |
| 1448 // Open the app list menu and check that the drag and drop host was set. | |
| 1449 gfx::Rect app_list_bounds = | |
| 1450 test.launcher_view()->GetAppListButtonView()->GetBoundsInScreen(); | |
| 1451 generator.MoveMouseTo(app_list_bounds.CenterPoint().x(), | |
| 1452 app_list_bounds.CenterPoint().y()); | |
| 1453 base::MessageLoop::current()->RunUntilIdle(); | |
| 1454 generator.ClickLeftButton(); | |
| 1455 | |
| 1456 EXPECT_TRUE(service->IsAppListVisible()); | |
| 1457 app_list::AppsGridView* grid_view = | |
| 1458 app_list::AppsGridView::GetLastGridViewForTest(); | |
| 1459 ASSERT_TRUE(grid_view); | |
| 1460 ASSERT_TRUE(grid_view->has_drag_and_drop_host_for_test()); | |
| 1461 | |
| 1462 // There should be 2 items in our application list. | |
| 1463 const views::ViewModel* vm_grid = grid_view->view_model_for_test(); | |
| 1464 EXPECT_EQ(2, vm_grid->view_size()); | |
| 1465 | |
| 1466 // Test #1: Drag an app list which does not exist yet item into the | |
| 1467 // launcher. Keeping it dragged, see that a new item gets created. Continuing | |
| 1468 // to drag it out should remove it again. | |
| 1469 | |
| 1470 // Get over item #1 of the application list and press the mouse button. | |
| 1471 views::View* item1 = vm_grid->view_at(1); | |
| 1472 gfx::Rect bounds_grid_1 = item1->GetBoundsInScreen(); | |
| 1473 generator.MoveMouseTo(bounds_grid_1.CenterPoint().x(), | |
| 1474 bounds_grid_1.CenterPoint().y()); | |
| 1475 base::MessageLoop::current()->RunUntilIdle(); | |
| 1476 generator.PressLeftButton(); | |
| 1477 | |
| 1478 EXPECT_FALSE(grid_view->forward_events_to_drag_and_drop_host_for_test()); | |
| 1479 | |
| 1480 // Drag the item into the launcher and check that a new item gets created. | |
| 1481 const views::ViewModel* vm_launcher = | |
| 1482 test.launcher_view()->view_model_for_test(); | |
| 1483 views::View* launcher1 = vm_launcher->view_at(1); | |
| 1484 gfx::Rect bounds_launcher_1 = launcher1->GetBoundsInScreen(); | |
| 1485 generator.MoveMouseTo(bounds_launcher_1.CenterPoint().x(), | |
| 1486 bounds_launcher_1.CenterPoint().y()); | |
| 1487 base::MessageLoop::current()->RunUntilIdle(); | |
| 1488 | |
| 1489 // Check that a new item got created. | |
| 1490 EXPECT_EQ(3, model_->item_count()); | |
| 1491 EXPECT_TRUE(grid_view->forward_events_to_drag_and_drop_host_for_test()); | |
| 1492 | |
| 1493 // Move it where the item originally was and check that it disappears again. | |
| 1494 generator.MoveMouseTo(bounds_grid_1.CenterPoint().x(), | |
| 1495 bounds_grid_1.CenterPoint().y()); | |
| 1496 base::MessageLoop::current()->RunUntilIdle(); | |
| 1497 EXPECT_EQ(2, model_->item_count()); | |
| 1498 EXPECT_FALSE(grid_view->forward_events_to_drag_and_drop_host_for_test()); | |
| 1499 | |
| 1500 // Dropping it should keep the launcher as it originally was. | |
| 1501 generator.ReleaseLeftButton(); | |
| 1502 base::MessageLoop::current()->RunUntilIdle(); | |
| 1503 EXPECT_EQ(2, model_->item_count()); | |
| 1504 // There are a few animations which need finishing before we can continue. | |
| 1505 test.RunMessageLoopUntilAnimationsDone(); | |
| 1506 // Move the mouse outside of the launcher. | |
| 1507 generator.MoveMouseTo(0, 0); | |
| 1508 | |
| 1509 // Test #2: Check that the unknown item dropped into the launcher will | |
| 1510 // create a new item. | |
| 1511 generator.MoveMouseTo(bounds_grid_1.CenterPoint().x(), | |
| 1512 bounds_grid_1.CenterPoint().y()); | |
| 1513 generator.PressLeftButton(); | |
| 1514 generator.MoveMouseTo(bounds_launcher_1.CenterPoint().x(), | |
| 1515 bounds_launcher_1.CenterPoint().y()); | |
| 1516 base::MessageLoop::current()->RunUntilIdle(); | |
| 1517 EXPECT_EQ(3, model_->item_count()); | |
| 1518 EXPECT_TRUE(grid_view->forward_events_to_drag_and_drop_host_for_test()); | |
| 1519 generator.ReleaseLeftButton(); | |
| 1520 base::MessageLoop::current()->RunUntilIdle(); | |
| 1521 EXPECT_FALSE(grid_view->forward_events_to_drag_and_drop_host_for_test()); | |
| 1522 EXPECT_EQ(3, model_->item_count()); // It should be still there. | |
| 1523 test.RunMessageLoopUntilAnimationsDone(); | |
| 1524 | |
| 1525 // Test #3: Check that the now known item dropped into the launcher will | |
| 1526 // not create a new item. | |
| 1527 generator.MoveMouseTo(bounds_grid_1.CenterPoint().x(), | |
| 1528 bounds_grid_1.CenterPoint().y()); | |
| 1529 generator.PressLeftButton(); | |
| 1530 generator.MoveMouseTo(bounds_launcher_1.CenterPoint().x(), | |
| 1531 bounds_launcher_1.CenterPoint().y()); | |
| 1532 base::MessageLoop::current()->RunUntilIdle(); | |
| 1533 EXPECT_EQ(3, model_->item_count()); // No new item got added. | |
| 1534 EXPECT_TRUE(grid_view->forward_events_to_drag_and_drop_host_for_test()); | |
| 1535 generator.ReleaseLeftButton(); | |
| 1536 base::MessageLoop::current()->RunUntilIdle(); | |
| 1537 EXPECT_FALSE(grid_view->forward_events_to_drag_and_drop_host_for_test()); | |
| 1538 EXPECT_EQ(3, model_->item_count()); // And it remains that way. | |
| 1539 } | |
| 1540 | |
| 1541 // Check that clicking on an app launcher item launches a new browser. | |
| 1542 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ClickItem) { | |
| 1543 // Get a number of interfaces we need. | |
| 1544 aura::test::EventGenerator generator( | |
| 1545 ash::Shell::GetPrimaryRootWindow(), gfx::Point()); | |
| 1546 ash::test::LauncherViewTestAPI test(launcher_->GetLauncherViewForTest()); | |
| 1547 AppListService* service = AppListService::Get(); | |
| 1548 // There should be two items in our launcher by this time. | |
| 1549 EXPECT_EQ(2, model_->item_count()); | |
| 1550 EXPECT_FALSE(service->IsAppListVisible()); | |
| 1551 | |
| 1552 // Open the app list menu and check that the drag and drop host was set. | |
| 1553 gfx::Rect app_list_bounds = | |
| 1554 test.launcher_view()->GetAppListButtonView()->GetBoundsInScreen(); | |
| 1555 generator.MoveMouseTo(app_list_bounds.CenterPoint().x(), | |
| 1556 app_list_bounds.CenterPoint().y()); | |
| 1557 generator.ClickLeftButton(); | |
| 1558 base::MessageLoop::current()->RunUntilIdle(); | |
| 1559 | |
| 1560 EXPECT_TRUE(service->IsAppListVisible()); | |
| 1561 app_list::AppsGridView* grid_view = | |
| 1562 app_list::AppsGridView::GetLastGridViewForTest(); | |
| 1563 ASSERT_TRUE(grid_view); | |
| 1564 const views::ViewModel* vm_grid = grid_view->view_model_for_test(); | |
| 1565 EXPECT_EQ(2, vm_grid->view_size()); | |
| 1566 gfx::Rect bounds_grid_1 = vm_grid->view_at(1)->GetBoundsInScreen(); | |
| 1567 // Test now that a click does create a new application tab. | |
| 1568 TabStripModel* tab_strip = browser()->tab_strip_model(); | |
| 1569 int tab_count = tab_strip->count(); | |
| 1570 generator.MoveMouseTo(bounds_grid_1.CenterPoint().x(), | |
| 1571 bounds_grid_1.CenterPoint().y()); | |
| 1572 generator.ClickLeftButton(); | |
| 1573 base::MessageLoop::current()->RunUntilIdle(); | |
| 1574 EXPECT_EQ(tab_count + 1, tab_strip->count()); | |
| 1575 } | |
| 1576 | |
| 1577 // Check LauncherItemController of Browser Shortcut functionality. | |
| 1578 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser, | |
| 1579 BrowserShortcutLauncherItemController) { | |
| 1580 LauncherItemController* item_controller = | |
| 1581 controller_->GetBrowserShortcutLauncherItemController(); | |
| 1582 | |
| 1583 // Get the number of browsers. | |
| 1584 size_t running_browser = chrome::GetTotalBrowserCount(); | |
| 1585 EXPECT_EQ(0u, running_browser); | |
| 1586 EXPECT_FALSE(item_controller->IsOpen()); | |
| 1587 | |
| 1588 // Activate. This creates new browser | |
| 1589 item_controller->Activate(); | |
| 1590 // New Window is created. | |
| 1591 running_browser = chrome::GetTotalBrowserCount(); | |
| 1592 EXPECT_EQ(1u, running_browser); | |
| 1593 EXPECT_TRUE(item_controller->IsOpen()); | |
| 1594 | |
| 1595 // Minimize Window. | |
| 1596 aura::Window* window = ash::wm::GetActiveWindow(); | |
| 1597 ash::wm::MinimizeWindow(window); | |
| 1598 EXPECT_TRUE(ash::wm::IsWindowMinimized(window)); | |
| 1599 | |
| 1600 // Activate again. This doesn't create new browser. | |
| 1601 // It activates window. | |
| 1602 item_controller->Activate(); | |
| 1603 running_browser = chrome::GetTotalBrowserCount(); | |
| 1604 EXPECT_EQ(1u, running_browser); | |
| 1605 EXPECT_TRUE(item_controller->IsOpen()); | |
| 1606 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); | |
| 1607 } | |
| 1608 | |
| 1609 // Check that GetIDByWindow() returns |LauncherID| of the active tab. | |
| 1610 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MatchingLauncherIDandActiveTab) { | |
| 1611 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | |
| 1612 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
| 1613 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); | |
| 1614 EXPECT_EQ(2, model_->item_count()); | |
| 1615 | |
| 1616 aura::Window* window = browser()->window()->GetNativeWindow(); | |
| 1617 | |
| 1618 int browser_index = ash::launcher::GetBrowserItemIndex(*model_); | |
| 1619 ash::LauncherID browser_id = model_->items()[browser_index].id; | |
| 1620 EXPECT_EQ(browser_id, controller_->GetIDByWindow(window)); | |
| 1621 | |
| 1622 ash::LauncherID app_id = CreateShortcut("app1"); | |
| 1623 EXPECT_EQ(3, model_->item_count()); | |
| 1624 | |
| 1625 // Creates a new tab for "app1" and checks that GetIDByWindow() returns | |
| 1626 // |LauncherID| of "app1". | |
| 1627 ActivateLauncherItem(model_->ItemIndexByID(app_id)); | |
| 1628 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | |
| 1629 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); | |
| 1630 EXPECT_EQ(app_id, controller_->GetIDByWindow(window)); | |
| 1631 | |
| 1632 // Makes tab at index 0(NTP) as an active tab and checks that GetIDByWindow() | |
| 1633 // returns |LauncherID| of browser shortcut. | |
| 1634 browser()->tab_strip_model()->ActivateTabAt(0, false); | |
| 1635 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); | |
| 1636 EXPECT_EQ(browser_id, controller_->GetIDByWindow(window)); | |
| 1637 } | |
| 1638 | |
| 808 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, OverflowBubble) { | 1639 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, OverflowBubble) { |
| 809 // Make sure to have a browser window | 1640 // Make sure to have a browser window |
| 810 chrome::NewTab(browser()); | 1641 chrome::NewTab(browser()); |
| 811 | 1642 |
| 812 // No overflow yet. | 1643 // No overflow yet. |
| 813 EXPECT_FALSE(launcher_->IsShowingOverflowBubble()); | 1644 EXPECT_FALSE(launcher_->IsShowingOverflowBubble()); |
| 814 | 1645 |
| 815 ash::test::LauncherViewTestAPI test(launcher_->GetLauncherViewForTest()); | 1646 ash::test::LauncherViewTestAPI test(launcher_->GetLauncherViewForTest()); |
| 816 | 1647 |
| 817 int items_added = 0; | 1648 int items_added = 0; |
| 818 while (!test.IsOverflowButtonVisible()) { | 1649 while (!test.IsOverflowButtonVisible()) { |
| 819 std::string fake_app_id = base::StringPrintf("fake_app_%d", items_added); | 1650 std::string fake_app_id = base::StringPrintf("fake_app_%d", items_added); |
| 820 PinFakeApp(fake_app_id); | 1651 PinFakeApp(fake_app_id); |
| 821 | 1652 |
| 822 ++items_added; | 1653 ++items_added; |
| 823 ASSERT_LT(items_added, 10000); | 1654 ASSERT_LT(items_added, 10000); |
| 824 } | 1655 } |
| 825 | 1656 |
| 826 // Now show overflow bubble. | 1657 // Now show overflow bubble. |
| 827 test.ShowOverflowBubble(); | 1658 test.ShowOverflowBubble(); |
| 828 EXPECT_TRUE(launcher_->IsShowingOverflowBubble()); | 1659 EXPECT_TRUE(launcher_->IsShowingOverflowBubble()); |
| 829 | 1660 |
| 830 // Unpin first pinned app and there should be no crash. | 1661 // Unpin first pinned app and there should be no crash. |
| 831 ChromeLauncherController* controller = | 1662 controller_->UnpinAppsWithID(std::string("fake_app_0")); |
| 832 static_cast<ChromeLauncherController*>(launcher_->delegate()); | |
| 833 controller->UnpinAppsWithID(std::string("fake_app_0")); | |
| 834 | 1663 |
| 835 test.RunMessageLoopUntilAnimationsDone(); | 1664 test.RunMessageLoopUntilAnimationsDone(); |
| 836 EXPECT_FALSE(launcher_->IsShowingOverflowBubble()); | 1665 EXPECT_FALSE(launcher_->IsShowingOverflowBubble()); |
| 837 } | 1666 } |
| OLD | NEW |