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

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

Issue 2791463002: mash: Remove ShelfDelegate; move functions to ShelfModel. (Closed)
Patch Set: Address comment. 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
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/ash_test_helper.h"
13 #include "ash/test/shell_test_api.h" 14 #include "ash/test/shell_test_api.h"
15 #include "ash/test/test_shell_delegate.h"
14 #include "ash/wm_window.h" 16 #include "ash/wm_window.h"
15 #include "base/macros.h" 17 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
17 #include "chrome/app/chrome_command_ids.h" 19 #include "chrome/app/chrome_command_ids.h"
18 #include "chrome/browser/prefs/incognito_mode_prefs.h" 20 #include "chrome/browser/prefs/incognito_mode_prefs.h"
19 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" 22 #include "chrome/browser/ui/app_list/arc/arc_app_test.h"
21 #include "chrome/browser/ui/ash/launcher/arc_app_shelf_id.h" 23 #include "chrome/browser/ui/ash/launcher/arc_app_shelf_id.h"
22 #include "chrome/browser/ui/ash/launcher/arc_launcher_context_menu.h" 24 #include "chrome/browser/ui/ash/launcher/arc_launcher_context_menu.h"
23 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" 25 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h"
24 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" 26 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h"
25 #include "chrome/browser/ui/ash/launcher/desktop_shell_launcher_context_menu.h" 27 #include "chrome/browser/ui/ash/launcher/desktop_shell_launcher_context_menu.h"
26 #include "chrome/browser/ui/ash/launcher/extension_launcher_context_menu.h" 28 #include "chrome/browser/ui/ash/launcher/extension_launcher_context_menu.h"
27 #include "chrome/test/base/testing_profile.h" 29 #include "chrome/test/base/testing_profile.h"
28 #include "components/arc/test/fake_app_instance.h" 30 #include "components/arc/test/fake_app_instance.h"
29 #include "components/exo/shell_surface.h" 31 #include "components/exo/shell_surface.h"
30 #include "components/prefs/pref_service.h" 32 #include "components/prefs/pref_service.h"
31 #include "components/session_manager/core/session_manager.h" 33 #include "components/session_manager/core/session_manager.h"
32 #include "ui/aura/window_event_dispatcher.h" 34 #include "ui/aura/window_event_dispatcher.h"
33 #include "ui/display/display.h" 35 #include "ui/display/display.h"
34 #include "ui/display/screen.h" 36 #include "ui/display/screen.h"
35 #include "ui/views/widget/widget.h" 37 #include "ui/views/widget/widget.h"
36 38
39 namespace {
40
41 // A shell delegate that owns a ChromeLauncherController, like production.
42 class ChromeLauncherTestShellDelegate : public ash::test::TestShellDelegate {
43 public:
44 explicit ChromeLauncherTestShellDelegate(Profile* profile)
45 : profile_(profile) {}
46
47 ChromeLauncherControllerImpl* controller() { return controller_.get(); }
48
49 // ash::test::TestShellDelegate:
50 void ShelfInit() override {
51 if (!controller_) {
52 controller_ = base::MakeUnique<ChromeLauncherControllerImpl>(
53 profile_, ash::Shell::Get()->shelf_model());
54 controller_->Init();
55 }
56 }
57 void ShelfShutdown() override { controller_.reset(); }
58
59 private:
60 Profile* profile_;
61 std::unique_ptr<ChromeLauncherControllerImpl> controller_;
62
63 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherTestShellDelegate);
64 };
65
37 class LauncherContextMenuTest : public ash::test::AshTestBase { 66 class LauncherContextMenuTest : public ash::test::AshTestBase {
38 protected: 67 protected:
39 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { 68 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) {
40 return menu->GetIndexOfCommandId(command_id) != -1; 69 return menu->GetIndexOfCommandId(command_id) != -1;
41 } 70 }
42 71
43 LauncherContextMenuTest() : profile_(new TestingProfile()) {} 72 LauncherContextMenuTest() {}
44 73
45 void SetUp() override { 74 void SetUp() override {
46 arc_test_.SetUp(profile_.get()); 75 arc_test_.SetUp(&profile_);
47 session_manager_ = base::MakeUnique<session_manager::SessionManager>(); 76 session_manager_ = base::MakeUnique<session_manager::SessionManager>();
77 shell_delegate_ = new ChromeLauncherTestShellDelegate(&profile_);
78 ash_test_helper()->set_test_shell_delegate(shell_delegate_);
48 ash::test::AshTestBase::SetUp(); 79 ash::test::AshTestBase::SetUp();
49 std::unique_ptr<ChromeLauncherControllerImpl> controller =
50 base::MakeUnique<ChromeLauncherControllerImpl>(
51 profile(), ash::Shell::Get()->shelf_model());
52 controller_ = controller.get();
53 controller_->Init();
54 ash::test::ShellTestApi().SetShelfDelegate(std::move(controller));
55 }
56
57 void TearDown() override {
58 ash::test::AshTestBase::TearDown();
59 } 80 }
60 81
61 ash::WmShelf* GetWmShelf(int64_t display_id) { 82 ash::WmShelf* GetWmShelf(int64_t display_id) {
62 ash::RootWindowController* root_window_controller = 83 ash::RootWindowController* root_window_controller =
63 ash::Shell::GetRootWindowControllerWithDisplayId(display_id); 84 ash::Shell::GetRootWindowControllerWithDisplayId(display_id);
64 EXPECT_NE(nullptr, root_window_controller); 85 EXPECT_NE(nullptr, root_window_controller);
65 return root_window_controller->GetShelf(); 86 return root_window_controller->GetShelf();
66 } 87 }
67 88
68 LauncherContextMenu* CreateLauncherContextMenu( 89 LauncherContextMenu* CreateLauncherContextMenu(
69 ash::ShelfItemType shelf_item_type, 90 ash::ShelfItemType shelf_item_type,
70 ash::WmShelf* wm_shelf) { 91 ash::WmShelf* wm_shelf) {
71 ash::ShelfItem item; 92 ash::ShelfItem item;
72 item.id = 123; // dummy id 93 item.id = 123; // dummy id
73 item.type = shelf_item_type; 94 item.type = shelf_item_type;
74 return LauncherContextMenu::Create(controller_, &item, wm_shelf); 95 return LauncherContextMenu::Create(controller(), &item, wm_shelf);
75 } 96 }
76 97
77 LauncherContextMenu* CreateLauncherContextMenuForDesktopShell( 98 LauncherContextMenu* CreateLauncherContextMenuForDesktopShell(
78 ash::WmShelf* wm_shelf) { 99 ash::WmShelf* wm_shelf) {
79 ash::ShelfItem* item = nullptr; 100 return LauncherContextMenu::Create(controller(), nullptr, wm_shelf);
80 return LauncherContextMenu::Create(controller_, item, wm_shelf);
81 } 101 }
82 102
83 // Creates app window and set optional ARC application id. 103 // Creates app window and set optional ARC application id.
84 views::Widget* CreateArcWindow(std::string& window_app_id) { 104 views::Widget* CreateArcWindow(std::string& window_app_id) {
85 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 105 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
86 views::Widget* widget = new views::Widget(); 106 views::Widget* widget = new views::Widget();
87 widget->Init(params); 107 widget->Init(params);
88 widget->Show(); 108 widget->Show();
89 widget->Activate(); 109 widget->Activate();
90 exo::ShellSurface::SetApplicationId(widget->GetNativeWindow(), 110 exo::ShellSurface::SetApplicationId(widget->GetNativeWindow(),
91 window_app_id); 111 window_app_id);
92 return widget; 112 return widget;
93 } 113 }
94 114
95 ArcAppTest& arc_test() { return arc_test_; } 115 ArcAppTest& arc_test() { return arc_test_; }
96 116
97 Profile* profile() { return profile_.get(); } 117 Profile* profile() { return &profile_; }
98 118
99 ChromeLauncherControllerImpl* controller() { return controller_; } 119 ChromeLauncherControllerImpl* controller() {
120 return shell_delegate_->controller();
121 }
100 122
101 private: 123 private:
102 std::unique_ptr<TestingProfile> profile_; 124 TestingProfile profile_;
103 ChromeLauncherControllerImpl* controller_ = nullptr; 125 ChromeLauncherTestShellDelegate* shell_delegate_ = nullptr;
104 ArcAppTest arc_test_; 126 ArcAppTest arc_test_;
105 std::unique_ptr<session_manager::SessionManager> session_manager_; 127 std::unique_ptr<session_manager::SessionManager> session_manager_;
106 128
107 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest); 129 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest);
108 }; 130 };
109 131
110 // Verifies that "New Incognito window" menu item in the launcher context 132 // Verifies that "New Incognito window" menu item in the launcher context
111 // menu is disabled when Incognito mode is switched off (by a policy). 133 // menu is disabled when Incognito mode is switched off (by a policy).
112 TEST_F(LauncherContextMenuTest, 134 TEST_F(LauncherContextMenuTest,
113 NewIncognitoWindowMenuIsDisabledWhenIncognitoModeOff) { 135 NewIncognitoWindowMenuIsDisabledWhenIncognitoModeOff) {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 widget->SetFullscreen(true); 325 widget->SetFullscreen(true);
304 std::unique_ptr<LauncherContextMenu> primary_menu(CreateLauncherContextMenu( 326 std::unique_ptr<LauncherContextMenu> primary_menu(CreateLauncherContextMenu(
305 ash::TYPE_BROWSER_SHORTCUT, GetWmShelf(primary_id))); 327 ash::TYPE_BROWSER_SHORTCUT, GetWmShelf(primary_id)));
306 std::unique_ptr<LauncherContextMenu> secondary_menu(CreateLauncherContextMenu( 328 std::unique_ptr<LauncherContextMenu> secondary_menu(CreateLauncherContextMenu(
307 ash::TYPE_BROWSER_SHORTCUT, GetWmShelf(secondary_id))); 329 ash::TYPE_BROWSER_SHORTCUT, GetWmShelf(secondary_id)));
308 EXPECT_FALSE(IsItemPresentInMenu(primary_menu.get(), 330 EXPECT_FALSE(IsItemPresentInMenu(primary_menu.get(),
309 LauncherContextMenu::MENU_AUTO_HIDE)); 331 LauncherContextMenu::MENU_AUTO_HIDE));
310 EXPECT_TRUE(IsItemPresentInMenu(secondary_menu.get(), 332 EXPECT_TRUE(IsItemPresentInMenu(secondary_menu.get(),
311 LauncherContextMenu::MENU_AUTO_HIDE)); 333 LauncherContextMenu::MENU_AUTO_HIDE));
312 } 334 }
335
336 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698