| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "ash/public/cpp/app_launch_id.h" | 9 #include "ash/public/cpp/app_launch_id.h" |
| 10 #include "ash/public/cpp/shelf_item_delegate.h" | 10 #include "ash/public/cpp/shelf_item_delegate.h" |
| 11 #include "ash/public/cpp/window_properties.h" | 11 #include "ash/public/cpp/window_properties.h" |
| 12 #include "ash/shelf/app_list_button.h" | 12 #include "ash/shelf/app_list_button.h" |
| 13 #include "ash/shelf/shelf_button.h" | 13 #include "ash/shelf/shelf_button.h" |
| 14 #include "ash/shelf/shelf_constants.h" | 14 #include "ash/shelf/shelf_constants.h" |
| 15 #include "ash/shelf/shelf_model.h" | 15 #include "ash/shelf/shelf_model.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 30 #include "base/strings/utf_string_conversions.h" | 30 #include "base/strings/utf_string_conversions.h" |
| 31 #include "build/build_config.h" | 31 #include "build/build_config.h" |
| 32 #include "chrome/browser/apps/app_browsertest_util.h" | 32 #include "chrome/browser/apps/app_browsertest_util.h" |
| 33 #include "chrome/browser/chrome_notification_types.h" | 33 #include "chrome/browser/chrome_notification_types.h" |
| 34 #include "chrome/browser/extensions/extension_apitest.h" | 34 #include "chrome/browser/extensions/extension_apitest.h" |
| 35 #include "chrome/browser/extensions/extension_browsertest.h" | 35 #include "chrome/browser/extensions/extension_browsertest.h" |
| 36 #include "chrome/browser/extensions/extension_function_test_utils.h" | 36 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 37 #include "chrome/browser/extensions/extension_service.h" | 37 #include "chrome/browser/extensions/extension_service.h" |
| 38 #include "chrome/browser/extensions/launch_util.h" | 38 #include "chrome/browser/extensions/launch_util.h" |
| 39 #include "chrome/browser/profiles/profile.h" | 39 #include "chrome/browser/profiles/profile.h" |
| 40 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
| 40 #include "chrome/browser/ui/app_list/app_list_service.h" | 41 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 41 #include "chrome/browser/ui/ash/app_list/test/app_list_service_ash_test_api.h" | 42 #include "chrome/browser/ui/ash/app_list/test/app_list_service_ash_test_api.h" |
| 42 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" | 43 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" |
| 43 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" | 44 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" |
| 44 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" | 45 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
| 45 #include "chrome/browser/ui/ash/session_controller_client.h" | 46 #include "chrome/browser/ui/ash/session_controller_client.h" |
| 46 #include "chrome/browser/ui/browser.h" | 47 #include "chrome/browser/ui/browser.h" |
| 47 #include "chrome/browser/ui/browser_commands.h" | 48 #include "chrome/browser/ui/browser_commands.h" |
| 48 #include "chrome/browser/ui/browser_finder.h" | 49 #include "chrome/browser/ui/browser_finder.h" |
| 49 #include "chrome/browser/ui/browser_list.h" | 50 #include "chrome/browser/ui/browser_list.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 #include "ui/events/event_constants.h" | 84 #include "ui/events/event_constants.h" |
| 84 #include "ui/events/test/event_generator.h" | 85 #include "ui/events/test/event_generator.h" |
| 85 | 86 |
| 86 using ash::WmShelf; | 87 using ash::WmShelf; |
| 87 using extensions::AppWindow; | 88 using extensions::AppWindow; |
| 88 using extensions::Extension; | 89 using extensions::Extension; |
| 89 using content::WebContents; | 90 using content::WebContents; |
| 90 | 91 |
| 91 namespace { | 92 namespace { |
| 92 | 93 |
| 93 ChromeLauncherControllerImpl* GetChromeLauncherControllerImpl() { | |
| 94 return static_cast<ChromeLauncherControllerImpl*>( | |
| 95 ChromeLauncherController::instance()); | |
| 96 } | |
| 97 | |
| 98 // A callback that records the action taken when a shelf item is selected. | 94 // A callback that records the action taken when a shelf item is selected. |
| 99 void SelectItemCallback(ash::ShelfAction* action_taken, | 95 void SelectItemCallback(ash::ShelfAction* action_taken, |
| 100 base::RunLoop* run_loop, | 96 base::RunLoop* run_loop, |
| 101 ash::ShelfAction action, | 97 ash::ShelfAction action, |
| 102 base::Optional<ash::MenuItemList>) { | 98 base::Optional<ash::MenuItemList>) { |
| 103 *action_taken = action; | 99 *action_taken = action; |
| 104 run_loop->Quit(); | 100 run_loop->Quit(); |
| 105 } | 101 } |
| 106 | 102 |
| 107 // Calls ShelfItemDelegate::SelectItem with an event type and default arguments. | 103 // Calls ShelfItemDelegate::SelectItem with an event type and default arguments. |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 : public extensions::PlatformAppBrowserTest { | 217 : public extensions::PlatformAppBrowserTest { |
| 222 protected: | 218 protected: |
| 223 LauncherPlatformAppBrowserTest() : controller_(nullptr) {} | 219 LauncherPlatformAppBrowserTest() : controller_(nullptr) {} |
| 224 | 220 |
| 225 ~LauncherPlatformAppBrowserTest() override {} | 221 ~LauncherPlatformAppBrowserTest() override {} |
| 226 | 222 |
| 227 void SetUpOnMainThread() override { | 223 void SetUpOnMainThread() override { |
| 228 // Ensure ash starts the session and creates the shelf and controller. | 224 // Ensure ash starts the session and creates the shelf and controller. |
| 229 SessionControllerClient::FlushForTesting(); | 225 SessionControllerClient::FlushForTesting(); |
| 230 | 226 |
| 231 controller_ = GetChromeLauncherControllerImpl(); | 227 controller_ = ChromeLauncherController::instance(); |
| 232 ASSERT_TRUE(controller_); | 228 ASSERT_TRUE(controller_); |
| 233 extensions::PlatformAppBrowserTest::SetUpOnMainThread(); | 229 extensions::PlatformAppBrowserTest::SetUpOnMainThread(); |
| 234 } | 230 } |
| 235 | 231 |
| 236 ash::ShelfModel* shelf_model() { return ash::Shell::Get()->shelf_model(); } | 232 ash::ShelfModel* shelf_model() { return ash::Shell::Get()->shelf_model(); } |
| 237 | 233 |
| 238 ash::ShelfID CreateAppShortcutLauncherItem( | 234 ash::ShelfID CreateAppShortcutLauncherItem( |
| 239 const ash::AppLaunchId& app_launch_id) { | 235 const ash::AppLaunchId& app_launch_id) { |
| 240 return controller_->CreateAppShortcutLauncherItem( | 236 return controller_->CreateAppShortcutLauncherItem( |
| 241 app_launch_id, shelf_model()->item_count()); | 237 app_launch_id, shelf_model()->item_count()); |
| 242 } | 238 } |
| 243 | 239 |
| 244 const ash::ShelfItem& GetLastLauncherItem() { | 240 const ash::ShelfItem& GetLastLauncherItem() { |
| 245 // Unless there are any panels, the item at index [count - 1] will be | 241 // Unless there are any panels, the item at index [count - 1] will be |
| 246 // the desired item. | 242 // the desired item. |
| 247 return shelf_model()->items()[shelf_model()->item_count() - 1]; | 243 return shelf_model()->items()[shelf_model()->item_count() - 1]; |
| 248 } | 244 } |
| 249 | 245 |
| 250 const ash::ShelfItem& GetLastLauncherPanelItem() { | 246 const ash::ShelfItem& GetLastLauncherPanelItem() { |
| 251 // Panels show up on the right side of the shelf, so the desired item | 247 // Panels show up on the right side of the shelf, so the desired item |
| 252 // will be the last one. | 248 // will be the last one. |
| 253 return shelf_model()->items()[shelf_model()->item_count() - 1]; | 249 return shelf_model()->items()[shelf_model()->item_count() - 1]; |
| 254 } | 250 } |
| 255 | 251 |
| 256 ash::ShelfItemDelegate* GetShelfItemDelegate(ash::ShelfID id) { | 252 ash::ShelfItemDelegate* GetShelfItemDelegate(ash::ShelfID id) { |
| 257 return shelf_model()->GetShelfItemDelegate(id); | 253 return shelf_model()->GetShelfItemDelegate(id); |
| 258 } | 254 } |
| 259 | 255 |
| 260 ChromeLauncherControllerImpl* controller_; | 256 ChromeLauncherController* controller_; |
| 261 | 257 |
| 262 private: | 258 private: |
| 263 DISALLOW_COPY_AND_ASSIGN(LauncherPlatformAppBrowserTest); | 259 DISALLOW_COPY_AND_ASSIGN(LauncherPlatformAppBrowserTest); |
| 264 }; | 260 }; |
| 265 | 261 |
| 266 enum RipOffCommand { | 262 enum RipOffCommand { |
| 267 // Drag the item off the shelf and let the mouse go. | 263 // Drag the item off the shelf and let the mouse go. |
| 268 RIP_OFF_ITEM, | 264 RIP_OFF_ITEM, |
| 269 // Drag the item off the shelf, move the mouse back and then let go. | 265 // Drag the item off the shelf, move the mouse back and then let go. |
| 270 RIP_OFF_ITEM_AND_RETURN, | 266 RIP_OFF_ITEM_AND_RETURN, |
| 271 // Drag the item off the shelf and then issue a cancel command. | 267 // Drag the item off the shelf and then issue a cancel command. |
| 272 RIP_OFF_ITEM_AND_CANCEL, | 268 RIP_OFF_ITEM_AND_CANCEL, |
| 273 // Drag the item off the shelf and do not release the mouse. | 269 // Drag the item off the shelf and do not release the mouse. |
| 274 RIP_OFF_ITEM_AND_DONT_RELEASE_MOUSE, | 270 RIP_OFF_ITEM_AND_DONT_RELEASE_MOUSE, |
| 275 }; | 271 }; |
| 276 | 272 |
| 277 class ShelfAppBrowserTest : public ExtensionBrowserTest { | 273 class ShelfAppBrowserTest : public ExtensionBrowserTest { |
| 278 protected: | 274 protected: |
| 279 ShelfAppBrowserTest() : shelf_(NULL), model_(NULL), controller_(NULL) { | 275 ShelfAppBrowserTest() : shelf_(NULL), model_(NULL), controller_(NULL) {} |
| 280 } | |
| 281 | 276 |
| 282 ~ShelfAppBrowserTest() override {} | 277 ~ShelfAppBrowserTest() override {} |
| 283 | 278 |
| 284 void SetUpOnMainThread() override { | 279 void SetUpOnMainThread() override { |
| 285 // Ensure ash starts the session and creates the shelf and controller. | 280 // Ensure ash starts the session and creates the shelf and controller. |
| 286 SessionControllerClient::FlushForTesting(); | 281 SessionControllerClient::FlushForTesting(); |
| 287 | 282 |
| 288 shelf_ = | 283 shelf_ = |
| 289 ash::WmShelf::ForWindow(ash::ShellPort::Get()->GetPrimaryRootWindow()); | 284 ash::WmShelf::ForWindow(ash::ShellPort::Get()->GetPrimaryRootWindow()); |
| 290 model_ = ash::Shell::Get()->shelf_model(); | 285 model_ = ash::Shell::Get()->shelf_model(); |
| 291 controller_ = GetChromeLauncherControllerImpl(); | 286 controller_ = ChromeLauncherController::instance(); |
| 292 ASSERT_TRUE(controller_); | 287 ASSERT_TRUE(controller_); |
| 293 ExtensionBrowserTest::SetUpOnMainThread(); | 288 ExtensionBrowserTest::SetUpOnMainThread(); |
| 294 } | 289 } |
| 295 | 290 |
| 296 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) { | 291 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) { |
| 297 ash::ShelfItemDelegate* item_controller = | 292 ash::ShelfItemDelegate* item_controller = |
| 298 controller_->GetBrowserShortcutLauncherItemController(); | 293 controller_->GetBrowserShortcutLauncherItemController(); |
| 299 return item_controller | 294 return item_controller |
| 300 ->GetAppMenuItems(show_all_tabs ? ui::EF_SHIFT_DOWN : 0) | 295 ->GetAppMenuItems(show_all_tabs ? ui::EF_SHIFT_DOWN : 0) |
| 301 .size(); | 296 .size(); |
| 302 } | 297 } |
| 303 | 298 |
| 304 const Extension* LoadAndLaunchExtension( | 299 const Extension* LoadAndLaunchExtension(const char* name, |
| 305 const char* name, | 300 extensions::LaunchContainer container, |
| 306 extensions::LaunchContainer container, | 301 WindowOpenDisposition disposition) { |
| 307 WindowOpenDisposition disposition) { | |
| 308 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name))); | 302 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name))); |
| 309 | 303 |
| 310 ExtensionService* service = extensions::ExtensionSystem::Get( | 304 ExtensionService* service = |
| 311 profile())->extension_service(); | 305 extensions::ExtensionSystem::Get(profile())->extension_service(); |
| 312 const Extension* extension = | 306 const Extension* extension = |
| 313 service->GetExtensionById(last_loaded_extension_id(), false); | 307 service->GetExtensionById(last_loaded_extension_id(), false); |
| 314 EXPECT_TRUE(extension); | 308 EXPECT_TRUE(extension); |
| 315 | 309 |
| 316 OpenApplication(AppLaunchParams(profile(), extension, container, | 310 OpenApplication(AppLaunchParams(profile(), extension, container, |
| 317 disposition, extensions::SOURCE_TEST)); | 311 disposition, extensions::SOURCE_TEST)); |
| 318 return extension; | 312 return extension; |
| 319 } | 313 } |
| 320 | 314 |
| 321 ash::ShelfID CreateShortcut(const char* name) { | 315 ash::ShelfID CreateShortcut(const char* name) { |
| 322 ExtensionService* service = extensions::ExtensionSystem::Get( | 316 ExtensionService* service = |
| 323 profile())->extension_service(); | 317 extensions::ExtensionSystem::Get(profile())->extension_service(); |
| 324 LoadExtension(test_data_dir_.AppendASCII(name)); | 318 LoadExtension(test_data_dir_.AppendASCII(name)); |
| 325 | 319 |
| 326 // First get app_id. | 320 // First get app_id. |
| 327 const Extension* extension = | 321 const Extension* extension = |
| 328 service->GetExtensionById(last_loaded_extension_id(), false); | 322 service->GetExtensionById(last_loaded_extension_id(), false); |
| 329 const std::string app_id = extension->id(); | 323 const std::string app_id = extension->id(); |
| 330 | 324 |
| 331 // Then create a shortcut. | 325 // Then create a shortcut. |
| 332 int item_count = model_->item_count(); | 326 int item_count = model_->item_count(); |
| 333 ash::ShelfID shortcut_id = controller_->CreateAppShortcutLauncherItem( | 327 ash::ShelfID shortcut_id = controller_->CreateAppShortcutLauncherItem( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 DCHECK(root_window); | 390 DCHECK(root_window); |
| 397 return root_window; | 391 return root_window; |
| 398 } | 392 } |
| 399 | 393 |
| 400 bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { | 394 bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { |
| 401 return menu->GetIndexOfCommandId(command_id) != -1; | 395 return menu->GetIndexOfCommandId(command_id) != -1; |
| 402 } | 396 } |
| 403 | 397 |
| 404 ash::WmShelf* shelf_; | 398 ash::WmShelf* shelf_; |
| 405 ash::ShelfModel* model_; | 399 ash::ShelfModel* model_; |
| 406 ChromeLauncherControllerImpl* controller_; | 400 ChromeLauncherController* controller_; |
| 407 | 401 |
| 408 private: | 402 private: |
| 409 DISALLOW_COPY_AND_ASSIGN(ShelfAppBrowserTest); | 403 DISALLOW_COPY_AND_ASSIGN(ShelfAppBrowserTest); |
| 410 }; | 404 }; |
| 411 | 405 |
| 412 class ShelfAppBrowserTestNoDefaultBrowser : public ShelfAppBrowserTest { | 406 class ShelfAppBrowserTestNoDefaultBrowser : public ShelfAppBrowserTest { |
| 413 protected: | 407 protected: |
| 414 ShelfAppBrowserTestNoDefaultBrowser() {} | 408 ShelfAppBrowserTestNoDefaultBrowser() {} |
| 415 ~ShelfAppBrowserTestNoDefaultBrowser() override {} | 409 ~ShelfAppBrowserTestNoDefaultBrowser() override {} |
| 416 | 410 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched"); | 591 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched"); |
| 598 AppWindow* window1 = CreateAppWindow(browser()->profile(), extension1); | 592 AppWindow* window1 = CreateAppWindow(browser()->profile(), extension1); |
| 599 ++item_count; | 593 ++item_count; |
| 600 ASSERT_EQ(item_count, shelf_model()->item_count()); | 594 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 601 const ash::ShelfItem& item1 = GetLastLauncherItem(); | 595 const ash::ShelfItem& item1 = GetLastLauncherItem(); |
| 602 ash::ShelfID item_id1 = item1.id; | 596 ash::ShelfID item_id1 = item1.id; |
| 603 EXPECT_EQ(ash::TYPE_APP, item1.type); | 597 EXPECT_EQ(ash::TYPE_APP, item1.type); |
| 604 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 598 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 605 | 599 |
| 606 // Then run second app. | 600 // Then run second app. |
| 607 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2", | 601 const Extension* extension2 = |
| 608 "Launched"); | 602 LoadAndLaunchPlatformApp("launch_2", "Launched"); |
| 609 AppWindow* window2 = CreateAppWindow(browser()->profile(), extension2); | 603 AppWindow* window2 = CreateAppWindow(browser()->profile(), extension2); |
| 610 ++item_count; | 604 ++item_count; |
| 611 ASSERT_EQ(item_count, shelf_model()->item_count()); | 605 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 612 const ash::ShelfItem& item2 = GetLastLauncherItem(); | 606 const ash::ShelfItem& item2 = GetLastLauncherItem(); |
| 613 ash::ShelfID item_id2 = item2.id; | 607 ash::ShelfID item_id2 = item2.id; |
| 614 EXPECT_EQ(ash::TYPE_APP, item2.type); | 608 EXPECT_EQ(ash::TYPE_APP, item2.type); |
| 615 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); | 609 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); |
| 616 | 610 |
| 617 EXPECT_NE(item_id1, item_id2); | 611 EXPECT_NE(item_id1, item_id2); |
| 618 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status); | 612 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 639 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched"); | 633 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched"); |
| 640 AppWindow* window1 = CreateAppWindow(browser()->profile(), extension1); | 634 AppWindow* window1 = CreateAppWindow(browser()->profile(), extension1); |
| 641 ++item_count; | 635 ++item_count; |
| 642 ASSERT_EQ(item_count, shelf_model()->item_count()); | 636 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 643 const ash::ShelfItem& item1 = GetLastLauncherItem(); | 637 const ash::ShelfItem& item1 = GetLastLauncherItem(); |
| 644 ash::ShelfID item_id1 = item1.id; | 638 ash::ShelfID item_id1 = item1.id; |
| 645 EXPECT_EQ(ash::TYPE_APP, item1.type); | 639 EXPECT_EQ(ash::TYPE_APP, item1.type); |
| 646 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 640 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 647 | 641 |
| 648 // Then run second app. | 642 // Then run second app. |
| 649 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2", | 643 const Extension* extension2 = |
| 650 "Launched"); | 644 LoadAndLaunchPlatformApp("launch_2", "Launched"); |
| 651 AppWindow* window2 = CreateAppWindow(browser()->profile(), extension2); | 645 AppWindow* window2 = CreateAppWindow(browser()->profile(), extension2); |
| 652 ++item_count; | 646 ++item_count; |
| 653 ASSERT_EQ(item_count, shelf_model()->item_count()); | 647 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 654 const ash::ShelfItem& item2 = GetLastLauncherItem(); | 648 const ash::ShelfItem& item2 = GetLastLauncherItem(); |
| 655 ash::ShelfID item_id2 = item2.id; | 649 ash::ShelfID item_id2 = item2.id; |
| 656 EXPECT_EQ(ash::TYPE_APP, item2.type); | 650 EXPECT_EQ(ash::TYPE_APP, item2.type); |
| 657 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); | 651 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); |
| 658 | 652 |
| 659 EXPECT_NE(item_id1, item_id2); | 653 EXPECT_NE(item_id1, item_id2); |
| 660 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status); | 654 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status); |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 | 1063 |
| 1070 // Confirm that a page can be navigated from and to while maintaining the | 1064 // Confirm that a page can be navigated from and to while maintaining the |
| 1071 // correct running state. | 1065 // correct running state. |
| 1072 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, Navigation) { | 1066 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, Navigation) { |
| 1073 ash::ShelfID shortcut_id = CreateShortcut("app1"); | 1067 ash::ShelfID shortcut_id = CreateShortcut("app1"); |
| 1074 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); | 1068 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); |
| 1075 WmShelf::ActivateShelfItem(model_->ItemIndexByID(shortcut_id)); | 1069 WmShelf::ActivateShelfItem(model_->ItemIndexByID(shortcut_id)); |
| 1076 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); | 1070 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); |
| 1077 | 1071 |
| 1078 // Navigate away. | 1072 // Navigate away. |
| 1079 ui_test_utils::NavigateToURL( | 1073 ui_test_utils::NavigateToURL(browser(), |
| 1080 browser(), GURL("http://www.example.com/path0/bar.html")); | 1074 GURL("http://www.example.com/path0/bar.html")); |
| 1081 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); | 1075 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); |
| 1082 | 1076 |
| 1083 // Navigate back. | 1077 // Navigate back. |
| 1084 ui_test_utils::NavigateToURL( | 1078 ui_test_utils::NavigateToURL(browser(), |
| 1085 browser(), GURL("http://www.example.com/path1/foo.html")); | 1079 GURL("http://www.example.com/path1/foo.html")); |
| 1086 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); | 1080 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); |
| 1087 } | 1081 } |
| 1088 | 1082 |
| 1089 // Confirm that a tab can be moved between browsers while maintaining the | 1083 // Confirm that a tab can be moved between browsers while maintaining the |
| 1090 // correct running state. | 1084 // correct running state. |
| 1091 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, TabDragAndDrop) { | 1085 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, TabDragAndDrop) { |
| 1092 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 1086 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 1093 TabStripModel* tab_strip_model1 = browser()->tab_strip_model(); | 1087 TabStripModel* tab_strip_model1 = browser()->tab_strip_model(); |
| 1094 EXPECT_EQ(1, tab_strip_model1->count()); | 1088 EXPECT_EQ(1, tab_strip_model1->count()); |
| 1095 const int browser_index = GetIndexOfShelfItemType(ash::TYPE_BROWSER_SHORTCUT); | 1089 const int browser_index = GetIndexOfShelfItemType(ash::TYPE_BROWSER_SHORTCUT); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1110 Browser* browser2 = CreateBrowser(profile()); | 1104 Browser* browser2 = CreateBrowser(profile()); |
| 1111 EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); | 1105 EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); |
| 1112 TabStripModel* tab_strip_model2 = browser2->tab_strip_model(); | 1106 TabStripModel* tab_strip_model2 = browser2->tab_strip_model(); |
| 1113 EXPECT_EQ(1, tab_strip_model2->count()); | 1107 EXPECT_EQ(1, tab_strip_model2->count()); |
| 1114 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status); | 1108 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status); |
| 1115 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut_id)).status); | 1109 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut_id)).status); |
| 1116 | 1110 |
| 1117 // Detach a tab at index 1 (app1) from |tab_strip_model1| and insert it as an | 1111 // Detach a tab at index 1 (app1) from |tab_strip_model1| and insert it as an |
| 1118 // active tab at index 1 to |tab_strip_model2|. | 1112 // active tab at index 1 to |tab_strip_model2|. |
| 1119 content::WebContents* detached_tab = tab_strip_model1->DetachWebContentsAt(1); | 1113 content::WebContents* detached_tab = tab_strip_model1->DetachWebContentsAt(1); |
| 1120 tab_strip_model2->InsertWebContentsAt(1, | 1114 tab_strip_model2->InsertWebContentsAt(1, detached_tab, |
| 1121 detached_tab, | |
| 1122 TabStripModel::ADD_ACTIVE); | 1115 TabStripModel::ADD_ACTIVE); |
| 1123 EXPECT_EQ(1, tab_strip_model1->count()); | 1116 EXPECT_EQ(1, tab_strip_model1->count()); |
| 1124 EXPECT_EQ(2, tab_strip_model2->count()); | 1117 EXPECT_EQ(2, tab_strip_model2->count()); |
| 1125 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[browser_index].status); | 1118 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[browser_index].status); |
| 1126 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); | 1119 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); |
| 1127 | 1120 |
| 1128 tab_strip_model1->CloseAllTabs(); | 1121 tab_strip_model1->CloseAllTabs(); |
| 1129 tab_strip_model2->CloseAllTabs(); | 1122 tab_strip_model2->CloseAllTabs(); |
| 1130 } | 1123 } |
| 1131 | 1124 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_WINDOW, | 1320 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_WINDOW, |
| 1328 WindowOpenDisposition::NEW_WINDOW); | 1321 WindowOpenDisposition::NEW_WINDOW); |
| 1329 app_browser = FindBrowserForApp(extension->id()); | 1322 app_browser = FindBrowserForApp(extension->id()); |
| 1330 ASSERT_TRUE(app_browser); | 1323 ASSERT_TRUE(app_browser); |
| 1331 window = app_browser->window()->GetNativeWindow(); | 1324 window = app_browser->window()->GetNativeWindow(); |
| 1332 EXPECT_FALSE(ash::wm::GetWindowState(window)->IsMaximized()); | 1325 EXPECT_FALSE(ash::wm::GetWindowState(window)->IsMaximized()); |
| 1333 } | 1326 } |
| 1334 | 1327 |
| 1335 // Checks that a windowed application does not add an item to the browser list. | 1328 // Checks that a windowed application does not add an item to the browser list. |
| 1336 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTestNoDefaultBrowser, | 1329 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTestNoDefaultBrowser, |
| 1337 WindowedAppDoesNotAddToBrowser) { | 1330 WindowedAppDoesNotAddToBrowser) { |
| 1338 // Get the number of items in the browser menu. | 1331 // Get the number of items in the browser menu. |
| 1339 size_t items = NumberOfDetectedLauncherBrowsers(false); | 1332 size_t items = NumberOfDetectedLauncherBrowsers(false); |
| 1340 size_t running_browser = chrome::GetTotalBrowserCount(); | 1333 size_t running_browser = chrome::GetTotalBrowserCount(); |
| 1341 EXPECT_EQ(0u, items); | 1334 EXPECT_EQ(0u, items); |
| 1342 EXPECT_EQ(0u, running_browser); | 1335 EXPECT_EQ(0u, running_browser); |
| 1343 | 1336 |
| 1344 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_WINDOW, | 1337 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_WINDOW, |
| 1345 WindowOpenDisposition::NEW_WINDOW); | 1338 WindowOpenDisposition::NEW_WINDOW); |
| 1346 | 1339 |
| 1347 // No new browser should get detected, even though one more is running. | 1340 // No new browser should get detected, even though one more is running. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1424 | 1417 |
| 1425 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents()); | 1418 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents()); |
| 1426 WmShelf::ActivateShelfItem(shortcut_index); | 1419 WmShelf::ActivateShelfItem(shortcut_index); |
| 1427 EXPECT_EQ(content1, browser()->tab_strip_model()->GetActiveWebContents()); | 1420 EXPECT_EQ(content1, browser()->tab_strip_model()->GetActiveWebContents()); |
| 1428 WmShelf::ActivateShelfItem(shortcut_index); | 1421 WmShelf::ActivateShelfItem(shortcut_index); |
| 1429 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents()); | 1422 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents()); |
| 1430 } | 1423 } |
| 1431 | 1424 |
| 1432 // Check that the keyboard activation of a launcher item tabs properly through | 1425 // Check that the keyboard activation of a launcher item tabs properly through |
| 1433 // the items at hand. | 1426 // the items at hand. |
| 1434 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, | 1427 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, AltNumberAppsTabbing) { |
| 1435 AltNumberAppsTabbing) { | |
| 1436 // First run app. | 1428 // First run app. |
| 1437 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched"); | 1429 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched"); |
| 1438 ui::BaseWindow* window1 = | 1430 ui::BaseWindow* window1 = |
| 1439 CreateAppWindow(browser()->profile(), extension1)->GetBaseWindow(); | 1431 CreateAppWindow(browser()->profile(), extension1)->GetBaseWindow(); |
| 1440 const ash::ShelfItem& item1 = GetLastLauncherItem(); | 1432 const ash::ShelfItem& item1 = GetLastLauncherItem(); |
| 1441 ash::ShelfID app_id = item1.id; | 1433 ash::ShelfID app_id = item1.id; |
| 1442 int app_index = shelf_model()->ItemIndexByID(app_id); | 1434 int app_index = shelf_model()->ItemIndexByID(app_id); |
| 1443 | 1435 |
| 1444 EXPECT_EQ(ash::TYPE_APP, item1.type); | 1436 EXPECT_EQ(ash::TYPE_APP, item1.type); |
| 1445 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 1437 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 1446 | 1438 |
| 1447 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2", | 1439 const Extension* extension2 = |
| 1448 "Launched"); | 1440 LoadAndLaunchPlatformApp("launch_2", "Launched"); |
| 1449 ui::BaseWindow* window2 = | 1441 ui::BaseWindow* window2 = |
| 1450 CreateAppWindow(browser()->profile(), extension2)->GetBaseWindow(); | 1442 CreateAppWindow(browser()->profile(), extension2)->GetBaseWindow(); |
| 1451 | 1443 |
| 1452 // By now the browser should be active. Issue Alt keystrokes several times to | 1444 // By now the browser should be active. Issue Alt keystrokes several times to |
| 1453 // see that we stay on that application. | 1445 // see that we stay on that application. |
| 1454 EXPECT_TRUE(window2->IsActive()); | 1446 EXPECT_TRUE(window2->IsActive()); |
| 1455 WmShelf::ActivateShelfItem(app_index); | 1447 WmShelf::ActivateShelfItem(app_index); |
| 1456 EXPECT_TRUE(window1->IsActive()); | 1448 EXPECT_TRUE(window1->IsActive()); |
| 1457 WmShelf::ActivateShelfItem(app_index); | 1449 WmShelf::ActivateShelfItem(app_index); |
| 1458 EXPECT_TRUE(window1->IsActive()); | 1450 EXPECT_TRUE(window1->IsActive()); |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2002 CreateShortcut("app1"); | 1994 CreateShortcut("app1"); |
| 2003 test.RunMessageLoopUntilAnimationsDone(); | 1995 test.RunMessageLoopUntilAnimationsDone(); |
| 2004 EXPECT_EQ(3, model_->item_count()); | 1996 EXPECT_EQ(3, model_->item_count()); |
| 2005 | 1997 |
| 2006 // Test #1: Ripping out the browser item should not change anything. | 1998 // Test #1: Ripping out the browser item should not change anything. |
| 2007 int browser_index = GetIndexOfShelfItemType(ash::TYPE_BROWSER_SHORTCUT); | 1999 int browser_index = GetIndexOfShelfItemType(ash::TYPE_BROWSER_SHORTCUT); |
| 2008 EXPECT_LE(0, browser_index); | 2000 EXPECT_LE(0, browser_index); |
| 2009 RipOffItemIndex(browser_index, &generator, &test, RIP_OFF_ITEM); | 2001 RipOffItemIndex(browser_index, &generator, &test, RIP_OFF_ITEM); |
| 2010 // => It should not have been removed and the location should be unchanged. | 2002 // => It should not have been removed and the location should be unchanged. |
| 2011 EXPECT_EQ(3, model_->item_count()); | 2003 EXPECT_EQ(3, model_->item_count()); |
| 2012 EXPECT_EQ(browser_index, | 2004 EXPECT_EQ(browser_index, GetIndexOfShelfItemType(ash::TYPE_BROWSER_SHORTCUT)); |
| 2013 GetIndexOfShelfItemType(ash::TYPE_BROWSER_SHORTCUT)); | |
| 2014 // Make sure that the hide state has been unset after the snap back animation | 2005 // Make sure that the hide state has been unset after the snap back animation |
| 2015 // finished. | 2006 // finished. |
| 2016 ash::ShelfButton* button = test.GetButton(browser_index); | 2007 ash::ShelfButton* button = test.GetButton(browser_index); |
| 2017 EXPECT_FALSE(button->state() & ash::ShelfButton::STATE_HIDDEN); | 2008 EXPECT_FALSE(button->state() & ash::ShelfButton::STATE_HIDDEN); |
| 2018 | 2009 |
| 2019 // Test #2: Ripping out the application and canceling the operation should | 2010 // Test #2: Ripping out the application and canceling the operation should |
| 2020 // not change anything. | 2011 // not change anything. |
| 2021 int app_index = GetIndexOfShelfItemType(ash::TYPE_PINNED_APP); | 2012 int app_index = GetIndexOfShelfItemType(ash::TYPE_PINNED_APP); |
| 2022 EXPECT_LE(0, app_index); | 2013 EXPECT_LE(0, app_index); |
| 2023 RipOffItemIndex(app_index, &generator, &test, RIP_OFF_ITEM_AND_CANCEL); | 2014 RipOffItemIndex(app_index, &generator, &test, RIP_OFF_ITEM_AND_CANCEL); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2038 // => It should not have been removed and the location should be unchanged. | 2029 // => It should not have been removed and the location should be unchanged. |
| 2039 EXPECT_EQ(2, model_->item_count()); | 2030 EXPECT_EQ(2, model_->item_count()); |
| 2040 EXPECT_EQ(-1, GetIndexOfShelfItemType(ash::TYPE_PINNED_APP)); | 2031 EXPECT_EQ(-1, GetIndexOfShelfItemType(ash::TYPE_PINNED_APP)); |
| 2041 | 2032 |
| 2042 // Test #5: Uninstalling an application while it is being ripped off should | 2033 // Test #5: Uninstalling an application while it is being ripped off should |
| 2043 // not crash. | 2034 // not crash. |
| 2044 CreateShortcut("app2"); | 2035 CreateShortcut("app2"); |
| 2045 test.RunMessageLoopUntilAnimationsDone(); | 2036 test.RunMessageLoopUntilAnimationsDone(); |
| 2046 int app2_index = GetIndexOfShelfItemType(ash::TYPE_PINNED_APP); | 2037 int app2_index = GetIndexOfShelfItemType(ash::TYPE_PINNED_APP); |
| 2047 EXPECT_EQ(3, model_->item_count()); // And it remains that way. | 2038 EXPECT_EQ(3, model_->item_count()); // And it remains that way. |
| 2048 RipOffItemIndex(app2_index, | 2039 RipOffItemIndex(app2_index, &generator, &test, |
| 2049 &generator, | |
| 2050 &test, | |
| 2051 RIP_OFF_ITEM_AND_DONT_RELEASE_MOUSE); | 2040 RIP_OFF_ITEM_AND_DONT_RELEASE_MOUSE); |
| 2052 controller_->UnpinAppWithID("app2"); | 2041 controller_->UnpinAppWithID("app2"); |
| 2053 test.RunMessageLoopUntilAnimationsDone(); | 2042 test.RunMessageLoopUntilAnimationsDone(); |
| 2054 EXPECT_EQ(2, model_->item_count()); // The item should now be gone. | 2043 EXPECT_EQ(2, model_->item_count()); // The item should now be gone. |
| 2055 generator.ReleaseLeftButton(); | 2044 generator.ReleaseLeftButton(); |
| 2056 base::RunLoop().RunUntilIdle(); | 2045 base::RunLoop().RunUntilIdle(); |
| 2057 EXPECT_EQ(2, model_->item_count()); // And it remains that way. | 2046 EXPECT_EQ(2, model_->item_count()); // And it remains that way. |
| 2058 EXPECT_EQ(-1, GetIndexOfShelfItemType(ash::TYPE_PINNED_APP)); | 2047 EXPECT_EQ(-1, GetIndexOfShelfItemType(ash::TYPE_PINNED_APP)); |
| 2059 | 2048 |
| 2060 // Test #6: Ripping out the application when the overflow button exists. | 2049 // Test #6: Ripping out the application when the overflow button exists. |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2278 chrome::SettingsWindowManager::GetInstance(); | 2267 chrome::SettingsWindowManager::GetInstance(); |
| 2279 ash::ShelfModel* shelf_model = ash::Shell::Get()->shelf_model(); | 2268 ash::ShelfModel* shelf_model = ash::Shell::Get()->shelf_model(); |
| 2280 | 2269 |
| 2281 // Get the number of items in the shelf and browser menu. | 2270 // Get the number of items in the shelf and browser menu. |
| 2282 int item_count = shelf_model->item_count(); | 2271 int item_count = shelf_model->item_count(); |
| 2283 size_t browser_count = NumberOfDetectedLauncherBrowsers(false); | 2272 size_t browser_count = NumberOfDetectedLauncherBrowsers(false); |
| 2284 | 2273 |
| 2285 // Open a settings window. Number of browser items should remain unchanged, | 2274 // Open a settings window. Number of browser items should remain unchanged, |
| 2286 // number of shelf items should increase. | 2275 // number of shelf items should increase. |
| 2287 settings_manager->ShowChromePageForProfile( | 2276 settings_manager->ShowChromePageForProfile( |
| 2288 browser()->profile(), | 2277 browser()->profile(), chrome::GetSettingsUrl(std::string())); |
| 2289 chrome::GetSettingsUrl(std::string())); | |
| 2290 Browser* settings_browser = | 2278 Browser* settings_browser = |
| 2291 settings_manager->FindBrowserForProfile(browser()->profile()); | 2279 settings_manager->FindBrowserForProfile(browser()->profile()); |
| 2292 ASSERT_TRUE(settings_browser); | 2280 ASSERT_TRUE(settings_browser); |
| 2293 EXPECT_EQ(browser_count, NumberOfDetectedLauncherBrowsers(false)); | 2281 EXPECT_EQ(browser_count, NumberOfDetectedLauncherBrowsers(false)); |
| 2294 EXPECT_EQ(item_count + 1, shelf_model->item_count()); | 2282 EXPECT_EQ(item_count + 1, shelf_model->item_count()); |
| 2295 | 2283 |
| 2296 // TODO(stevenjb): Test multiprofile on Chrome OS when test support is addded. | 2284 // TODO(stevenjb): Test multiprofile on Chrome OS when test support is addded. |
| 2297 // crbug.com/230464. | 2285 // crbug.com/230464. |
| 2298 } | 2286 } |
| 2299 | 2287 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2409 | 2397 |
| 2410 // Close all windows via the menu item. | 2398 // Close all windows via the menu item. |
| 2411 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); | 2399 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); |
| 2412 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); | 2400 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); |
| 2413 | 2401 |
| 2414 // Check if "Close" is removed from the context menu. | 2402 // Check if "Close" is removed from the context menu. |
| 2415 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); | 2403 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); |
| 2416 ASSERT_FALSE( | 2404 ASSERT_FALSE( |
| 2417 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); | 2405 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); |
| 2418 } | 2406 } |
| OLD | NEW |