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

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

Issue 2869473002: Fix crash on openning settings when DCHECK is on. (Closed)
Patch Set: use new id for app list Created 3 years, 7 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.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/shelf_item_delegate.h" 9 #include "ash/public/cpp/shelf_item_delegate.h"
10 #include "ash/public/cpp/window_properties.h" 10 #include "ash/public/cpp/window_properties.h"
(...skipping 26 matching lines...) Expand all
37 #include "chrome/browser/profiles/profile.h" 37 #include "chrome/browser/profiles/profile.h"
38 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 38 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
39 #include "chrome/browser/ui/app_list/app_list_service.h" 39 #include "chrome/browser/ui/app_list/app_list_service.h"
40 #include "chrome/browser/ui/ash/app_list/test/app_list_service_ash_test_api.h" 40 #include "chrome/browser/ui/ash/app_list/test/app_list_service_ash_test_api.h"
41 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" 41 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h"
42 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" 42 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h"
43 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" 43 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
44 #include "chrome/browser/ui/ash/session_controller_client.h" 44 #include "chrome/browser/ui/ash/session_controller_client.h"
45 #include "chrome/browser/ui/browser.h" 45 #include "chrome/browser/ui/browser.h"
46 #include "chrome/browser/ui/browser_commands.h" 46 #include "chrome/browser/ui/browser_commands.h"
47 #include "chrome/browser/ui/browser_dialogs.h"
47 #include "chrome/browser/ui/browser_finder.h" 48 #include "chrome/browser/ui/browser_finder.h"
48 #include "chrome/browser/ui/browser_list.h" 49 #include "chrome/browser/ui/browser_list.h"
49 #include "chrome/browser/ui/browser_window.h" 50 #include "chrome/browser/ui/browser_window.h"
50 #include "chrome/browser/ui/chrome_pages.h" 51 #include "chrome/browser/ui/chrome_pages.h"
51 #include "chrome/browser/ui/extensions/app_launch_params.h" 52 #include "chrome/browser/ui/extensions/app_launch_params.h"
52 #include "chrome/browser/ui/extensions/application_launch.h" 53 #include "chrome/browser/ui/extensions/application_launch.h"
53 #include "chrome/browser/ui/settings_window_manager.h" 54 #include "chrome/browser/ui/settings_window_manager.h"
54 #include "chrome/browser/ui/tabs/tab_strip_model.h" 55 #include "chrome/browser/ui/tabs/tab_strip_model.h"
55 #include "chrome/browser/web_applications/web_app.h" 56 #include "chrome/browser/web_applications/web_app.h"
56 #include "chrome/common/chrome_switches.h" 57 #include "chrome/common/chrome_switches.h"
57 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 58 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
58 #include "chrome/test/base/ui_test_utils.h" 59 #include "chrome/test/base/ui_test_utils.h"
60 #include "components/crx_file/id_util.h"
59 #include "content/public/browser/notification_service.h" 61 #include "content/public/browser/notification_service.h"
60 #include "content/public/browser/notification_source.h" 62 #include "content/public/browser/notification_source.h"
61 #include "content/public/browser/web_contents.h" 63 #include "content/public/browser/web_contents.h"
62 #include "content/public/test/browser_test_utils.h" 64 #include "content/public/test/browser_test_utils.h"
63 #include "extensions/browser/app_window/app_window.h" 65 #include "extensions/browser/app_window/app_window.h"
64 #include "extensions/browser/app_window/app_window_registry.h" 66 #include "extensions/browser/app_window/app_window_registry.h"
65 #include "extensions/browser/app_window/native_app_window.h" 67 #include "extensions/browser/app_window/native_app_window.h"
66 #include "extensions/browser/extension_system.h" 68 #include "extensions/browser/extension_system.h"
67 #include "extensions/common/constants.h" 69 #include "extensions/common/constants.h"
68 #include "extensions/common/switches.h" 70 #include "extensions/common/switches.h"
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); 470 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched");
469 AppWindow* window = CreateAppWindow(browser()->profile(), extension); 471 AppWindow* window = CreateAppWindow(browser()->profile(), extension);
470 ++item_count; 472 ++item_count;
471 ASSERT_EQ(item_count, shelf_model()->item_count()); 473 ASSERT_EQ(item_count, shelf_model()->item_count());
472 const ash::ShelfItem& item1 = GetLastLauncherItem(); 474 const ash::ShelfItem& item1 = GetLastLauncherItem();
473 ash::ShelfID id = item1.id; 475 ash::ShelfID id = item1.id;
474 EXPECT_EQ(ash::TYPE_APP, item1.type); 476 EXPECT_EQ(ash::TYPE_APP, item1.type);
475 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); 477 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
476 478
477 // Create a shortcut. The app item should be after it. 479 // Create a shortcut. The app item should be after it.
478 ash::ShelfID foo_id = CreateAppShortcutLauncherItem(ash::ShelfID("foo")); 480 ash::ShelfID foo_id = CreateAppShortcutLauncherItem(
481 ash::ShelfID(extension_misc::kYoutubeAppId));
479 ++item_count; 482 ++item_count;
480 ASSERT_EQ(item_count, shelf_model()->item_count()); 483 ASSERT_EQ(item_count, shelf_model()->item_count());
481 EXPECT_LT(shelf_model()->ItemIndexByID(foo_id), 484 EXPECT_LT(shelf_model()->ItemIndexByID(foo_id),
482 shelf_model()->ItemIndexByID(id)); 485 shelf_model()->ItemIndexByID(id));
483 486
484 // Pin the app. The item should remain. 487 // Pin the app. The item should remain.
485 controller_->PinAppWithID(extension->id()); 488 controller_->PinAppWithID(extension->id());
486 ASSERT_EQ(item_count, shelf_model()->item_count()); 489 ASSERT_EQ(item_count, shelf_model()->item_count());
487 const ash::ShelfItem& item2 = *shelf_model()->ItemByID(id); 490 const ash::ShelfItem& item2 = *shelf_model()->ItemByID(id);
488 EXPECT_EQ(ash::TYPE_PINNED_APP, item2.type); 491 EXPECT_EQ(ash::TYPE_PINNED_APP, item2.type);
489 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); 492 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status);
490 493
491 // New shortcuts should come after the item. 494 // New shortcuts should come after the item.
492 ash::ShelfID bar_id = CreateAppShortcutLauncherItem(ash::ShelfID("bar")); 495 ash::ShelfID bar_id = CreateAppShortcutLauncherItem(
496 ash::ShelfID(extension_misc::kGoogleDocAppId));
493 ++item_count; 497 ++item_count;
494 ASSERT_EQ(item_count, shelf_model()->item_count()); 498 ASSERT_EQ(item_count, shelf_model()->item_count());
495 EXPECT_LT(shelf_model()->ItemIndexByID(id), 499 EXPECT_LT(shelf_model()->ItemIndexByID(id),
496 shelf_model()->ItemIndexByID(bar_id)); 500 shelf_model()->ItemIndexByID(bar_id));
497 501
498 // Then close it, make sure the item remains. 502 // Then close it, make sure the item remains.
499 CloseAppWindow(window); 503 CloseAppWindow(window);
500 ASSERT_EQ(item_count, shelf_model()->item_count()); 504 ASSERT_EQ(item_count, shelf_model()->item_count());
501 } 505 }
502 506
503 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) { 507 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) {
504 int item_count = shelf_model()->item_count(); 508 int item_count = shelf_model()->item_count();
505 509
506 // First get app_id. 510 // First get app_id.
507 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); 511 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched");
508 const std::string app_id = extension->id(); 512 const std::string app_id = extension->id();
509 513
510 // Then create a shortcut. 514 // Then create a shortcut.
511 ash::ShelfID shortcut_id = 515 ash::ShelfID shortcut_id =
512 CreateAppShortcutLauncherItem(ash::ShelfID(app_id)); 516 CreateAppShortcutLauncherItem(ash::ShelfID(app_id));
513 ++item_count; 517 ++item_count;
514 ASSERT_EQ(item_count, shelf_model()->item_count()); 518 ASSERT_EQ(item_count, shelf_model()->item_count());
515 ash::ShelfItem item = *shelf_model()->ItemByID(shortcut_id); 519 ash::ShelfItem item = *shelf_model()->ItemByID(shortcut_id);
516 EXPECT_EQ(ash::TYPE_PINNED_APP, item.type); 520 EXPECT_EQ(ash::TYPE_PINNED_APP, item.type);
517 EXPECT_EQ(ash::STATUS_CLOSED, item.status); 521 EXPECT_EQ(ash::STATUS_CLOSED, item.status);
518 522
519 // Create a second shortcut. This will be needed to force the first one to 523 // Create a second shortcut. This will be needed to force the first one to
520 // move once it gets unpinned. 524 // move once it gets unpinned.
521 ash::ShelfID foo_id = CreateAppShortcutLauncherItem(ash::ShelfID("foo")); 525 ash::ShelfID foo_id = CreateAppShortcutLauncherItem(
526 ash::ShelfID(extension_misc::kYoutubeAppId));
522 ++item_count; 527 ++item_count;
523 ASSERT_EQ(item_count, shelf_model()->item_count()); 528 ASSERT_EQ(item_count, shelf_model()->item_count());
524 EXPECT_LT(shelf_model()->ItemIndexByID(shortcut_id), 529 EXPECT_LT(shelf_model()->ItemIndexByID(shortcut_id),
525 shelf_model()->ItemIndexByID(foo_id)); 530 shelf_model()->ItemIndexByID(foo_id));
526 531
527 // Open a window. Confirm the item is now running. 532 // Open a window. Confirm the item is now running.
528 AppWindow* window = CreateAppWindow(browser()->profile(), extension); 533 AppWindow* window = CreateAppWindow(browser()->profile(), extension);
529 ash::wm::ActivateWindow(window->GetNativeWindow()); 534 ash::wm::ActivateWindow(window->GetNativeWindow());
530 ASSERT_EQ(item_count, shelf_model()->item_count()); 535 ASSERT_EQ(item_count, shelf_model()->item_count());
531 item = *shelf_model()->ItemByID(shortcut_id); 536 item = *shelf_model()->ItemByID(shortcut_id);
(...skipping 1722 matching lines...) Expand 10 before | Expand all | Expand 10 after
2254 // Make sure the navigation was entirely performed. 2259 // Make sure the navigation was entirely performed.
2255 base::RunLoop().RunUntilIdle(); 2260 base::RunLoop().RunUntilIdle();
2256 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(id)->status); 2261 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(id)->status);
2257 app_browser->tab_strip_model()->CloseWebContentsAt(0, 2262 app_browser->tab_strip_model()->CloseWebContentsAt(0,
2258 TabStripModel::CLOSE_NONE); 2263 TabStripModel::CLOSE_NONE);
2259 // Make sure that the app is really gone. 2264 // Make sure that the app is really gone.
2260 base::RunLoop().RunUntilIdle(); 2265 base::RunLoop().RunUntilIdle();
2261 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(id)->status); 2266 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(id)->status);
2262 } 2267 }
2263 2268
2264 // Checks that a opening a settings window creates a new launcher item. 2269 // Checks that a opening a settings and task manager windows creates a new
2265 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, SettingsWindow) { 2270 // launcher items.
2271 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, SettingsAndTaskManagerWindows) {
2266 chrome::SettingsWindowManager* settings_manager = 2272 chrome::SettingsWindowManager* settings_manager =
2267 chrome::SettingsWindowManager::GetInstance(); 2273 chrome::SettingsWindowManager::GetInstance();
2268 ash::ShelfModel* shelf_model = ash::Shell::Get()->shelf_model(); 2274 ash::ShelfModel* shelf_model = ash::Shell::Get()->shelf_model();
2269 2275
2270 // Get the number of items in the shelf and browser menu. 2276 // Get the number of items in the shelf and browser menu.
2271 int item_count = shelf_model->item_count(); 2277 int item_count = shelf_model->item_count();
2278 // At least App List should exist.
2279 ASSERT_GE(item_count, 1);
2272 size_t browser_count = NumberOfDetectedLauncherBrowsers(false); 2280 size_t browser_count = NumberOfDetectedLauncherBrowsers(false);
2273 2281
2274 // Open a settings window. Number of browser items should remain unchanged, 2282 // Open a settings window. Number of browser items should remain unchanged,
2275 // number of shelf items should increase. 2283 // number of shelf items should increase.
2276 settings_manager->ShowChromePageForProfile( 2284 settings_manager->ShowChromePageForProfile(
2277 browser()->profile(), chrome::GetSettingsUrl(std::string())); 2285 browser()->profile(), chrome::GetSettingsUrl(std::string()));
2278 Browser* settings_browser = 2286 Browser* settings_browser =
2279 settings_manager->FindBrowserForProfile(browser()->profile()); 2287 settings_manager->FindBrowserForProfile(browser()->profile());
2280 ASSERT_TRUE(settings_browser); 2288 ASSERT_TRUE(settings_browser);
2281 EXPECT_EQ(browser_count, NumberOfDetectedLauncherBrowsers(false)); 2289 EXPECT_EQ(browser_count, NumberOfDetectedLauncherBrowsers(false));
2282 EXPECT_EQ(item_count + 1, shelf_model->item_count()); 2290 EXPECT_EQ(item_count + 1, shelf_model->item_count());
2283 2291
2292 chrome::ShowTaskManager(browser());
2293 EXPECT_EQ(item_count + 2, shelf_model->item_count());
2294
2295 // Validates that all items have valid app id.
2296 for (const auto& item : shelf_model->items())
2297 EXPECT_TRUE(crx_file::id_util::IdIsValid(item.id.app_id));
2298
2284 // TODO(stevenjb): Test multiprofile on Chrome OS when test support is addded. 2299 // TODO(stevenjb): Test multiprofile on Chrome OS when test support is addded.
2285 // crbug.com/230464. 2300 // crbug.com/230464.
2286 } 2301 }
2287 2302
2288 // Check that tabbed hosted and bookmark apps have correct shelf presence. 2303 // Check that tabbed hosted and bookmark apps have correct shelf presence.
2289 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, TabbedHostedAndBookmarkApps) { 2304 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, TabbedHostedAndBookmarkApps) {
2290 // Load and pin a hosted app. 2305 // Load and pin a hosted app.
2291 const Extension* hosted_app = 2306 const Extension* hosted_app =
2292 LoadExtension(test_data_dir_.AppendASCII("app1/")); 2307 LoadExtension(test_data_dir_.AppendASCII("app1/"));
2293 ASSERT_TRUE(hosted_app); 2308 ASSERT_TRUE(hosted_app);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2397 2412
2398 // Close all windows via the menu item. 2413 // Close all windows via the menu item.
2399 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); 2414 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE);
2400 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); 2415 EXPECT_EQ(0u, BrowserList::GetInstance()->size());
2401 2416
2402 // Check if "Close" is removed from the context menu. 2417 // Check if "Close" is removed from the context menu.
2403 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); 2418 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu();
2404 ASSERT_FALSE( 2419 ASSERT_FALSE(
2405 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); 2420 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE));
2406 } 2421 }
OLDNEW
« no previous file with comments | « ash/shelf/shelf_model_unittest.cc ('k') | chrome/browser/ui/ash/launcher/chrome_launcher_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698