Chromium Code Reviews| 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_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "ash/common/shelf/app_list_button.h" | 9 #include "ash/common/shelf/app_list_button.h" |
| 10 #include "ash/common/shelf/shelf_button.h" | 10 #include "ash/common/shelf/shelf_button.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 #include "chrome/browser/extensions/extension_apitest.h" | 32 #include "chrome/browser/extensions/extension_apitest.h" |
| 33 #include "chrome/browser/extensions/extension_browsertest.h" | 33 #include "chrome/browser/extensions/extension_browsertest.h" |
| 34 #include "chrome/browser/extensions/extension_function_test_utils.h" | 34 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 35 #include "chrome/browser/extensions/extension_service.h" | 35 #include "chrome/browser/extensions/extension_service.h" |
| 36 #include "chrome/browser/extensions/launch_util.h" | 36 #include "chrome/browser/extensions/launch_util.h" |
| 37 #include "chrome/browser/profiles/profile.h" | 37 #include "chrome/browser/profiles/profile.h" |
| 38 #include "chrome/browser/ui/app_list/app_list_service.h" | 38 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 39 #include "chrome/browser/ui/ash/app_list/test/app_list_service_ash_test_api.h" | 39 #include "chrome/browser/ui/ash/app_list/test/app_list_service_ash_test_api.h" |
| 40 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" | 40 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" |
| 41 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" | 41 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" |
| 42 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" | |
| 43 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" | 42 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
| 44 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | 43 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |
| 45 #include "chrome/browser/ui/ash/session_controller_client.h" | 44 #include "chrome/browser/ui/ash/session_controller_client.h" |
| 46 #include "chrome/browser/ui/browser.h" | 45 #include "chrome/browser/ui/browser.h" |
| 47 #include "chrome/browser/ui/browser_commands.h" | 46 #include "chrome/browser/ui/browser_commands.h" |
| 48 #include "chrome/browser/ui/browser_finder.h" | 47 #include "chrome/browser/ui/browser_finder.h" |
| 49 #include "chrome/browser/ui/browser_list.h" | 48 #include "chrome/browser/ui/browser_list.h" |
| 50 #include "chrome/browser/ui/browser_window.h" | 49 #include "chrome/browser/ui/browser_window.h" |
| 51 #include "chrome/browser/ui/chrome_pages.h" | 50 #include "chrome/browser/ui/chrome_pages.h" |
| 52 #include "chrome/browser/ui/extensions/app_launch_params.h" | 51 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 const ash::ShelfItem& GetLastLauncherPanelItem() { | 217 const ash::ShelfItem& GetLastLauncherPanelItem() { |
| 219 // Panels show up on the right side of the shelf, so the desired item | 218 // Panels show up on the right side of the shelf, so the desired item |
| 220 // will be the last one. | 219 // will be the last one. |
| 221 return shelf_model()->items()[shelf_model()->item_count() - 1]; | 220 return shelf_model()->items()[shelf_model()->item_count() - 1]; |
| 222 } | 221 } |
| 223 | 222 |
| 224 LauncherItemController* GetItemController(ash::ShelfID id) { | 223 LauncherItemController* GetItemController(ash::ShelfID id) { |
| 225 return controller_->GetLauncherItemController(id); | 224 return controller_->GetLauncherItemController(id); |
| 226 } | 225 } |
| 227 | 226 |
| 228 // Returns the number of menu items, ignoring separators. | 227 // Returns the number of application menu items, ignoring separators. |
| 229 int GetNumApplicationMenuItems(const ash::ShelfItem& item) { | 228 int GetNumApplicationMenuItems(const ash::ShelfItem& item) { |
| 230 const int event_flags = 0; | 229 return controller_->GetAppMenuItems(item, 0 /* event_flags */).size(); |
|
James Cook
2017/02/06 17:30:21
int / size_t conversion?
msw
2017/02/07 09:12:01
Ah, I already inlined this functionality; I have n
| |
| 231 std::unique_ptr<ui::SimpleMenuModel> menu( | |
| 232 new LauncherApplicationMenuItemModel( | |
| 233 controller_->GetApplicationList(item, event_flags))); | |
| 234 int num_items = 0; | |
| 235 for (int i = 0; i < menu->GetItemCount(); ++i) { | |
| 236 if (menu->GetTypeAt(i) != ui::MenuModel::TYPE_SEPARATOR) | |
| 237 ++num_items; | |
| 238 } | |
| 239 return num_items; | |
| 240 } | 230 } |
|
James Cook
2017/02/06 17:30:22
btw, I really like how you made GetAppMenuItems()
msw
2017/02/07 09:12:01
Acknowledged; but client-specified menu item lists
| |
| 241 | 231 |
| 242 ChromeLauncherControllerImpl* controller_; | 232 ChromeLauncherControllerImpl* controller_; |
| 243 | 233 |
| 244 private: | 234 private: |
| 245 DISALLOW_COPY_AND_ASSIGN(LauncherPlatformAppBrowserTest); | 235 DISALLOW_COPY_AND_ASSIGN(LauncherPlatformAppBrowserTest); |
| 246 }; | 236 }; |
| 247 | 237 |
| 248 enum RipOffCommand { | 238 enum RipOffCommand { |
| 249 // Drag the item off the shelf and let the mouse go. | 239 // Drag the item off the shelf and let the mouse go. |
| 250 RIP_OFF_ITEM, | 240 RIP_OFF_ITEM, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 271 ash::WmShelf::ForWindow(ash::WmShell::Get()->GetPrimaryRootWindow()); | 261 ash::WmShelf::ForWindow(ash::WmShell::Get()->GetPrimaryRootWindow()); |
| 272 model_ = ash::WmShell::Get()->shelf_model(); | 262 model_ = ash::WmShell::Get()->shelf_model(); |
| 273 controller_ = GetChromeLauncherControllerImpl(); | 263 controller_ = GetChromeLauncherControllerImpl(); |
| 274 ASSERT_TRUE(controller_); | 264 ASSERT_TRUE(controller_); |
| 275 return ExtensionBrowserTest::RunTestOnMainThreadLoop(); | 265 return ExtensionBrowserTest::RunTestOnMainThreadLoop(); |
| 276 } | 266 } |
| 277 | 267 |
| 278 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) { | 268 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) { |
| 279 LauncherItemController* item_controller = | 269 LauncherItemController* item_controller = |
| 280 controller_->GetBrowserShortcutLauncherItemController(); | 270 controller_->GetBrowserShortcutLauncherItemController(); |
| 281 int items = item_controller->GetApplicationList( | 271 return item_controller |
| 282 show_all_tabs ? ui::EF_SHIFT_DOWN : 0).size(); | 272 ->GetAppMenuItems(show_all_tabs ? ui::EF_SHIFT_DOWN : 0) |
| 283 // If we have at least one item, we have also a title which we remove here. | 273 .size(); |
| 284 return items ? (items - 1) : 0; | |
| 285 } | 274 } |
| 286 | 275 |
| 287 const Extension* LoadAndLaunchExtension( | 276 const Extension* LoadAndLaunchExtension( |
| 288 const char* name, | 277 const char* name, |
| 289 extensions::LaunchContainer container, | 278 extensions::LaunchContainer container, |
| 290 WindowOpenDisposition disposition) { | 279 WindowOpenDisposition disposition) { |
| 291 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name))); | 280 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name))); |
| 292 | 281 |
| 293 ExtensionService* service = extensions::ExtensionSystem::Get( | 282 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 294 profile())->extension_service(); | 283 profile())->extension_service(); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 // Then close it, make sure the item's gone. | 533 // Then close it, make sure the item's gone. |
| 545 CloseAppWindow(window); | 534 CloseAppWindow(window); |
| 546 --item_count; | 535 --item_count; |
| 547 ASSERT_EQ(item_count, shelf_model()->item_count()); | 536 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 548 } | 537 } |
| 549 | 538 |
| 550 // Test that we can launch a platform app with more than one window. | 539 // Test that we can launch a platform app with more than one window. |
| 551 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) { | 540 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) { |
| 552 int item_count = shelf_model()->item_count(); | 541 int item_count = shelf_model()->item_count(); |
| 553 | 542 |
| 554 // First run app. | 543 // Run the application; a shelf item should be added with one app menu item. |
| 555 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); | 544 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); |
| 556 AppWindow* window1 = CreateAppWindow(browser()->profile(), extension); | 545 AppWindow* window1 = CreateAppWindow(browser()->profile(), extension); |
| 557 ++item_count; | 546 ASSERT_EQ(item_count + 1, shelf_model()->item_count()); |
| 558 ASSERT_EQ(item_count, shelf_model()->item_count()); | |
| 559 const ash::ShelfItem& item1 = GetLastLauncherItem(); | 547 const ash::ShelfItem& item1 = GetLastLauncherItem(); |
| 560 ash::ShelfID item_id = item1.id; | 548 ash::ShelfID item_id = item1.id; |
| 561 EXPECT_EQ(ash::TYPE_APP, item1.type); | 549 EXPECT_EQ(ash::TYPE_APP, item1.type); |
| 562 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 550 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 563 EXPECT_EQ(2, GetNumApplicationMenuItems(item1)); // Title + 1 window | 551 EXPECT_EQ(1U, controller_->GetAppMenuItems(item1, 0).size()); // 1 window |
|
James Cook
2017/02/06 17:30:21
super nit question: Do we prefer 1U or 1u ?
msw
2017/02/07 09:12:01
Hmm, my grep foo is weak at the moment, so I don't
| |
| 564 | 552 |
| 565 // Add second window. | 553 // Add a second window; confirm the shelf item stays; check the app menu. |
| 566 AppWindow* window2 = CreateAppWindow(browser()->profile(), extension); | 554 AppWindow* window2 = CreateAppWindow(browser()->profile(), extension); |
| 567 // Confirm item stays. | 555 ASSERT_EQ(item_count + 1, shelf_model()->item_count()); |
| 568 ASSERT_EQ(item_count, shelf_model()->item_count()); | |
| 569 const ash::ShelfItem& item2 = *shelf_model()->ItemByID(item_id); | 556 const ash::ShelfItem& item2 = *shelf_model()->ItemByID(item_id); |
| 570 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); | 557 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); |
| 571 EXPECT_EQ(3, GetNumApplicationMenuItems(item2)); // Title + 2 windows | 558 EXPECT_EQ(2U, controller_->GetAppMenuItems(item2, 0).size()); // 2 windows |
| 572 | 559 |
| 573 // Close second window. | 560 // Close the second window; confirm the shelf item stays; check the app menu. |
| 574 CloseAppWindow(window2); | 561 CloseAppWindow(window2); |
| 575 // Confirm item stays. | 562 ASSERT_EQ(item_count + 1, shelf_model()->item_count()); |
| 576 ASSERT_EQ(item_count, shelf_model()->item_count()); | |
| 577 const ash::ShelfItem& item3 = *shelf_model()->ItemByID(item_id); | 563 const ash::ShelfItem& item3 = *shelf_model()->ItemByID(item_id); |
| 578 EXPECT_EQ(ash::STATUS_ACTIVE, item3.status); | 564 EXPECT_EQ(ash::STATUS_ACTIVE, item3.status); |
| 579 EXPECT_EQ(2, GetNumApplicationMenuItems(item3)); // Title + 1 window | 565 EXPECT_EQ(1U, controller_->GetAppMenuItems(item3, 0).size()); // 1 window |
| 580 | 566 |
| 581 // Close first window. | 567 // Close the first window; the shelf item should be removed. |
| 582 CloseAppWindow(window1); | 568 CloseAppWindow(window1); |
| 583 // Confirm item is removed. | |
| 584 --item_count; | |
| 585 ASSERT_EQ(item_count, shelf_model()->item_count()); | 569 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 586 } | 570 } |
| 587 | 571 |
| 588 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) { | 572 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) { |
| 589 int item_count = shelf_model()->item_count(); | 573 int item_count = shelf_model()->item_count(); |
| 590 | 574 |
| 591 // First run app. | 575 // First run app. |
| 592 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched"); | 576 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched"); |
| 593 AppWindow* window1 = CreateAppWindow(browser()->profile(), extension1); | 577 AppWindow* window1 = CreateAppWindow(browser()->profile(), extension1); |
| 594 ++item_count; | 578 ++item_count; |
| (...skipping 1817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2412 | 2396 |
| 2413 // Close all windows via the menu item. | 2397 // Close all windows via the menu item. |
| 2414 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); | 2398 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); |
| 2415 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); | 2399 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); |
| 2416 | 2400 |
| 2417 // Check if "Close" is removed from the context menu. | 2401 // Check if "Close" is removed from the context menu. |
| 2418 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); | 2402 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); |
| 2419 ASSERT_FALSE( | 2403 ASSERT_FALSE( |
| 2420 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); | 2404 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); |
| 2421 } | 2405 } |
| OLD | NEW |