Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl_browsertest.cc

Issue 2671923002: mash: Cleanup ash shelf application menu code. (Closed)
Patch Set: Add comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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.
229 int GetNumApplicationMenuItems(const ash::ShelfItem& item) {
230 const int event_flags = 0;
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 }
241
242 ChromeLauncherControllerImpl* controller_; 227 ChromeLauncherControllerImpl* controller_;
243 228
244 private: 229 private:
245 DISALLOW_COPY_AND_ASSIGN(LauncherPlatformAppBrowserTest); 230 DISALLOW_COPY_AND_ASSIGN(LauncherPlatformAppBrowserTest);
246 }; 231 };
247 232
248 enum RipOffCommand { 233 enum RipOffCommand {
249 // Drag the item off the shelf and let the mouse go. 234 // Drag the item off the shelf and let the mouse go.
250 RIP_OFF_ITEM, 235 RIP_OFF_ITEM,
251 // Drag the item off the shelf, move the mouse back and then let go. 236 // Drag the item off the shelf, move the mouse back and then let go.
(...skipping 19 matching lines...) Expand all
271 ash::WmShelf::ForWindow(ash::WmShell::Get()->GetPrimaryRootWindow()); 256 ash::WmShelf::ForWindow(ash::WmShell::Get()->GetPrimaryRootWindow());
272 model_ = ash::WmShell::Get()->shelf_model(); 257 model_ = ash::WmShell::Get()->shelf_model();
273 controller_ = GetChromeLauncherControllerImpl(); 258 controller_ = GetChromeLauncherControllerImpl();
274 ASSERT_TRUE(controller_); 259 ASSERT_TRUE(controller_);
275 return ExtensionBrowserTest::RunTestOnMainThreadLoop(); 260 return ExtensionBrowserTest::RunTestOnMainThreadLoop();
276 } 261 }
277 262
278 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) { 263 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) {
279 LauncherItemController* item_controller = 264 LauncherItemController* item_controller =
280 controller_->GetBrowserShortcutLauncherItemController(); 265 controller_->GetBrowserShortcutLauncherItemController();
281 int items = item_controller->GetApplicationList( 266 return item_controller
282 show_all_tabs ? ui::EF_SHIFT_DOWN : 0).size(); 267 ->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. 268 .size();
284 return items ? (items - 1) : 0;
285 } 269 }
286 270
287 const Extension* LoadAndLaunchExtension( 271 const Extension* LoadAndLaunchExtension(
288 const char* name, 272 const char* name,
289 extensions::LaunchContainer container, 273 extensions::LaunchContainer container,
290 WindowOpenDisposition disposition) { 274 WindowOpenDisposition disposition) {
291 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name))); 275 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name)));
292 276
293 ExtensionService* service = extensions::ExtensionSystem::Get( 277 ExtensionService* service = extensions::ExtensionSystem::Get(
294 profile())->extension_service(); 278 profile())->extension_service();
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 // Then close it, make sure the item's gone. 528 // Then close it, make sure the item's gone.
545 CloseAppWindow(window); 529 CloseAppWindow(window);
546 --item_count; 530 --item_count;
547 ASSERT_EQ(item_count, shelf_model()->item_count()); 531 ASSERT_EQ(item_count, shelf_model()->item_count());
548 } 532 }
549 533
550 // Test that we can launch a platform app with more than one window. 534 // Test that we can launch a platform app with more than one window.
551 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) { 535 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) {
552 int item_count = shelf_model()->item_count(); 536 int item_count = shelf_model()->item_count();
553 537
554 // First run app. 538 // Run the application; a shelf item should be added with one app menu item.
555 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); 539 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched");
556 AppWindow* window1 = CreateAppWindow(browser()->profile(), extension); 540 AppWindow* window1 = CreateAppWindow(browser()->profile(), extension);
557 ++item_count; 541 ASSERT_EQ(item_count + 1, shelf_model()->item_count());
558 ASSERT_EQ(item_count, shelf_model()->item_count());
559 const ash::ShelfItem& item1 = GetLastLauncherItem(); 542 const ash::ShelfItem& item1 = GetLastLauncherItem();
560 ash::ShelfID item_id = item1.id; 543 ash::ShelfID item_id = item1.id;
561 EXPECT_EQ(ash::TYPE_APP, item1.type); 544 EXPECT_EQ(ash::TYPE_APP, item1.type);
562 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); 545 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
563 EXPECT_EQ(2, GetNumApplicationMenuItems(item1)); // Title + 1 window 546 EXPECT_EQ(1u, controller_->GetAppMenuItems(item1, 0).size()); // 1 window
564 547
565 // Add second window. 548 // Add a second window; confirm the shelf item stays; check the app menu.
566 AppWindow* window2 = CreateAppWindow(browser()->profile(), extension); 549 AppWindow* window2 = CreateAppWindow(browser()->profile(), extension);
567 // Confirm item stays. 550 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); 551 const ash::ShelfItem& item2 = *shelf_model()->ItemByID(item_id);
570 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); 552 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status);
571 EXPECT_EQ(3, GetNumApplicationMenuItems(item2)); // Title + 2 windows 553 EXPECT_EQ(2u, controller_->GetAppMenuItems(item2, 0).size()); // 2 windows
572 554
573 // Close second window. 555 // Close the second window; confirm the shelf item stays; check the app menu.
574 CloseAppWindow(window2); 556 CloseAppWindow(window2);
575 // Confirm item stays. 557 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); 558 const ash::ShelfItem& item3 = *shelf_model()->ItemByID(item_id);
578 EXPECT_EQ(ash::STATUS_ACTIVE, item3.status); 559 EXPECT_EQ(ash::STATUS_ACTIVE, item3.status);
579 EXPECT_EQ(2, GetNumApplicationMenuItems(item3)); // Title + 1 window 560 EXPECT_EQ(1u, controller_->GetAppMenuItems(item3, 0).size()); // 1 window
580 561
581 // Close first window. 562 // Close the first window; the shelf item should be removed.
582 CloseAppWindow(window1); 563 CloseAppWindow(window1);
583 // Confirm item is removed.
584 --item_count;
585 ASSERT_EQ(item_count, shelf_model()->item_count()); 564 ASSERT_EQ(item_count, shelf_model()->item_count());
586 } 565 }
587 566
588 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) { 567 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) {
589 int item_count = shelf_model()->item_count(); 568 int item_count = shelf_model()->item_count();
590 569
591 // First run app. 570 // First run app.
592 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched"); 571 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched");
593 AppWindow* window1 = CreateAppWindow(browser()->profile(), extension1); 572 AppWindow* window1 = CreateAppWindow(browser()->profile(), extension1);
594 ++item_count; 573 ++item_count;
(...skipping 1817 matching lines...) Expand 10 before | Expand all | Expand 10 after
2412 2391
2413 // Close all windows via the menu item. 2392 // Close all windows via the menu item.
2414 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); 2393 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE);
2415 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); 2394 EXPECT_EQ(0u, BrowserList::GetInstance()->size());
2416 2395
2417 // Check if "Close" is removed from the context menu. 2396 // Check if "Close" is removed from the context menu.
2418 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); 2397 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu();
2419 ASSERT_FALSE( 2398 ASSERT_FALSE(
2420 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); 2399 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE));
2421 } 2400 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698