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

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

Issue 2812693002: mash: Fix controller ownership in LauncherContextMenuTest. (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « chrome/browser/ui/ash/launcher/launcher_context_menu.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/launcher_context_menu.h" 5 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ash/public/cpp/shelf_item.h" 9 #include "ash/public/cpp/shelf_item.h"
10 #include "ash/root_window_controller.h" 10 #include "ash/root_window_controller.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
13 #include "ash/test/shell_test_api.h"
13 #include "ash/wm_shell.h" 14 #include "ash/wm_shell.h"
14 #include "ash/wm_window.h" 15 #include "ash/wm_window.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
17 #include "chrome/app/chrome_command_ids.h" 18 #include "chrome/app/chrome_command_ids.h"
18 #include "chrome/browser/prefs/incognito_mode_prefs.h" 19 #include "chrome/browser/prefs/incognito_mode_prefs.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" 21 #include "chrome/browser/ui/app_list/arc/arc_app_test.h"
21 #include "chrome/browser/ui/ash/launcher/arc_app_shelf_id.h" 22 #include "chrome/browser/ui/ash/launcher/arc_app_shelf_id.h"
22 #include "chrome/browser/ui/ash/launcher/arc_launcher_context_menu.h" 23 #include "chrome/browser/ui/ash/launcher/arc_launcher_context_menu.h"
(...skipping 16 matching lines...) Expand all
39 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { 40 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) {
40 return menu->GetIndexOfCommandId(command_id) != -1; 41 return menu->GetIndexOfCommandId(command_id) != -1;
41 } 42 }
42 43
43 LauncherContextMenuTest() : profile_(new TestingProfile()) {} 44 LauncherContextMenuTest() : profile_(new TestingProfile()) {}
44 45
45 void SetUp() override { 46 void SetUp() override {
46 arc_test_.SetUp(profile_.get()); 47 arc_test_.SetUp(profile_.get());
47 session_manager_ = base::MakeUnique<session_manager::SessionManager>(); 48 session_manager_ = base::MakeUnique<session_manager::SessionManager>();
48 ash::test::AshTestBase::SetUp(); 49 ash::test::AshTestBase::SetUp();
49 controller_.reset(new ChromeLauncherControllerImpl( 50 std::unique_ptr<ChromeLauncherControllerImpl> controller =
50 profile(), ash::Shell::Get()->shelf_model())); 51 base::MakeUnique<ChromeLauncherControllerImpl>(
52 profile(), ash::Shell::Get()->shelf_model());
53 controller_ = controller.get();
51 controller_->Init(); 54 controller_->Init();
55 ash::test::ShellTestApi().SetShelfDelegate(std::move(controller));
52 } 56 }
53 57
54 void TearDown() override { 58 void TearDown() override {
55 controller_.reset(nullptr);
56 ash::test::AshTestBase::TearDown(); 59 ash::test::AshTestBase::TearDown();
57 } 60 }
58 61
59 ash::WmShelf* GetWmShelf(int64_t display_id) { 62 ash::WmShelf* GetWmShelf(int64_t display_id) {
60 ash::RootWindowController* root_window_controller = 63 ash::RootWindowController* root_window_controller =
61 ash::Shell::GetRootWindowControllerWithDisplayId(display_id); 64 ash::Shell::GetRootWindowControllerWithDisplayId(display_id);
62 EXPECT_NE(nullptr, root_window_controller); 65 EXPECT_NE(nullptr, root_window_controller);
63 return root_window_controller->GetShelf(); 66 return root_window_controller->GetShelf();
64 } 67 }
65 68
66 LauncherContextMenu* CreateLauncherContextMenu( 69 LauncherContextMenu* CreateLauncherContextMenu(
67 ash::ShelfItemType shelf_item_type, 70 ash::ShelfItemType shelf_item_type,
68 ash::WmShelf* wm_shelf) { 71 ash::WmShelf* wm_shelf) {
69 ash::ShelfItem item; 72 ash::ShelfItem item;
70 item.id = 123; // dummy id 73 item.id = 123; // dummy id
71 item.type = shelf_item_type; 74 item.type = shelf_item_type;
72 return LauncherContextMenu::Create(controller_.get(), &item, wm_shelf); 75 return LauncherContextMenu::Create(controller_, &item, wm_shelf);
73 } 76 }
74 77
75 LauncherContextMenu* CreateLauncherContextMenuForDesktopShell( 78 LauncherContextMenu* CreateLauncherContextMenuForDesktopShell(
76 ash::WmShelf* wm_shelf) { 79 ash::WmShelf* wm_shelf) {
77 ash::ShelfItem* item = nullptr; 80 ash::ShelfItem* item = nullptr;
78 return LauncherContextMenu::Create(controller_.get(), item, wm_shelf); 81 return LauncherContextMenu::Create(controller_, item, wm_shelf);
79 } 82 }
80 83
81 // Creates app window and set optional ARC application id. 84 // Creates app window and set optional ARC application id.
82 views::Widget* CreateArcWindow(std::string& window_app_id) { 85 views::Widget* CreateArcWindow(std::string& window_app_id) {
83 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 86 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
84 views::Widget* widget = new views::Widget(); 87 views::Widget* widget = new views::Widget();
85 widget->Init(params); 88 widget->Init(params);
86 widget->Show(); 89 widget->Show();
87 widget->Activate(); 90 widget->Activate();
88 exo::ShellSurface::SetApplicationId(widget->GetNativeWindow(), 91 exo::ShellSurface::SetApplicationId(widget->GetNativeWindow(),
89 window_app_id); 92 window_app_id);
90 return widget; 93 return widget;
91 } 94 }
92 95
93 ArcAppTest& arc_test() { return arc_test_; } 96 ArcAppTest& arc_test() { return arc_test_; }
94 97
95 Profile* profile() { return profile_.get(); } 98 Profile* profile() { return profile_.get(); }
96 99
97 ChromeLauncherControllerImpl* controller() { return controller_.get(); } 100 ChromeLauncherControllerImpl* controller() { return controller_; }
98 101
99 private: 102 private:
100 std::unique_ptr<TestingProfile> profile_; 103 std::unique_ptr<TestingProfile> profile_;
101 std::unique_ptr<ChromeLauncherControllerImpl> controller_; 104 ChromeLauncherControllerImpl* controller_ = nullptr;
102 ArcAppTest arc_test_; 105 ArcAppTest arc_test_;
103 std::unique_ptr<session_manager::SessionManager> session_manager_; 106 std::unique_ptr<session_manager::SessionManager> session_manager_;
104 107
105 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest); 108 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest);
106 }; 109 };
107 110
108 // Verifies that "New Incognito window" menu item in the launcher context 111 // Verifies that "New Incognito window" menu item in the launcher context
109 // menu is disabled when Incognito mode is switched off (by a policy). 112 // menu is disabled when Incognito mode is switched off (by a policy).
110 TEST_F(LauncherContextMenuTest, 113 TEST_F(LauncherContextMenuTest,
111 NewIncognitoWindowMenuIsDisabledWhenIncognitoModeOff) { 114 NewIncognitoWindowMenuIsDisabledWhenIncognitoModeOff) {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 widget->SetFullscreen(true); 304 widget->SetFullscreen(true);
302 std::unique_ptr<LauncherContextMenu> primary_menu(CreateLauncherContextMenu( 305 std::unique_ptr<LauncherContextMenu> primary_menu(CreateLauncherContextMenu(
303 ash::TYPE_BROWSER_SHORTCUT, GetWmShelf(primary_id))); 306 ash::TYPE_BROWSER_SHORTCUT, GetWmShelf(primary_id)));
304 std::unique_ptr<LauncherContextMenu> secondary_menu(CreateLauncherContextMenu( 307 std::unique_ptr<LauncherContextMenu> secondary_menu(CreateLauncherContextMenu(
305 ash::TYPE_BROWSER_SHORTCUT, GetWmShelf(secondary_id))); 308 ash::TYPE_BROWSER_SHORTCUT, GetWmShelf(secondary_id)));
306 EXPECT_FALSE(IsItemPresentInMenu(primary_menu.get(), 309 EXPECT_FALSE(IsItemPresentInMenu(primary_menu.get(),
307 LauncherContextMenu::MENU_AUTO_HIDE)); 310 LauncherContextMenu::MENU_AUTO_HIDE));
308 EXPECT_TRUE(IsItemPresentInMenu(secondary_menu.get(), 311 EXPECT_TRUE(IsItemPresentInMenu(secondary_menu.get(),
309 LauncherContextMenu::MENU_AUTO_HIDE)); 312 LauncherContextMenu::MENU_AUTO_HIDE));
310 } 313 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/launcher_context_menu.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698