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

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

Issue 1857213004: Refactor of LauncherContextMenu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits update Created 4 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.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | 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 "ash/shelf/shelf.h" 7 #include "ash/shelf/shelf.h"
8 #include "ash/shelf/shelf_item_types.h" 8 #include "ash/shelf/shelf_item_types.h"
9 #include "ash/shelf/shelf_model.h" 9 #include "ash/shelf/shelf_model.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h" 11 #include "ash/test/ash_test_base.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "chrome/app/chrome_command_ids.h" 13 #include "chrome/app/chrome_command_ids.h"
14 #include "chrome/browser/prefs/incognito_mode_prefs.h" 14 #include "chrome/browser/prefs/incognito_mode_prefs.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
17 #include "chrome/browser/ui/ash/launcher/desktop_shell_launcher_context_menu.h"
18 #include "chrome/browser/ui/ash/launcher/extension_launcher_context_menu.h"
17 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
18 #include "components/prefs/pref_service.h" 20 #include "components/prefs/pref_service.h"
19 #include "ui/aura/window_event_dispatcher.h" 21 #include "ui/aura/window_event_dispatcher.h"
20 22
21 class LauncherContextMenuTest : public ash::test::AshTestBase { 23 class LauncherContextMenuTest : public ash::test::AshTestBase {
22 protected: 24 protected:
23 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { 25 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) {
24 return menu->GetIndexOfCommandId(command_id) != -1; 26 return menu->GetIndexOfCommandId(command_id) != -1;
25 } 27 }
26 28
27 LauncherContextMenuTest() : profile_(new TestingProfile()) {} 29 LauncherContextMenuTest() : profile_(new TestingProfile()) {}
28 30
29 void SetUp() override { 31 void SetUp() override {
30 ash::test::AshTestBase::SetUp(); 32 ash::test::AshTestBase::SetUp();
31 controller_.reset(new ChromeLauncherController(profile(), &shelf_model_)); 33 controller_.reset(new ChromeLauncherController(profile(), &shelf_model_));
32 } 34 }
33 35
34 void TearDown() override { 36 void TearDown() override {
35 controller_.reset(nullptr); 37 controller_.reset(nullptr);
36 ash::test::AshTestBase::TearDown(); 38 ash::test::AshTestBase::TearDown();
37 } 39 }
38 40
39 LauncherContextMenu* CreateLauncherContextMenu( 41 LauncherContextMenu* CreateLauncherContextMenu(
40 ash::ShelfItemType shelf_item_type) { 42 ash::ShelfItemType shelf_item_type) {
41 ash::ShelfItem item; 43 ash::ShelfItem item;
42 item.id = 1; // dummy id 44 item.id = 1; // dummy id
43 item.type = shelf_item_type; 45 item.type = shelf_item_type;
44 ash::Shelf* shelf = ash::Shelf::ForWindow(CurrentContext()); 46 ash::Shelf* shelf = ash::Shelf::ForWindow(CurrentContext());
45 return new LauncherContextMenu(controller_.get(), &item, shelf); 47 return LauncherContextMenu::Create(controller_.get(), &item, shelf);
48 }
49
50 LauncherContextMenu* CreateLauncherContextMenuForDesktopShell() {
51 ash::ShelfItem* item = nullptr;
52 ash::Shelf* shelf = ash::Shelf::ForWindow(CurrentContext());
53 return LauncherContextMenu::Create(controller_.get(), item, shelf);
46 } 54 }
47 55
48 Profile* profile() { return profile_.get(); } 56 Profile* profile() { return profile_.get(); }
49 57
50 private: 58 private:
51 scoped_ptr<TestingProfile> profile_; 59 scoped_ptr<TestingProfile> profile_;
52 ash::ShelfModel shelf_model_; 60 ash::ShelfModel shelf_model_;
53 scoped_ptr<ChromeLauncherController> controller_; 61 scoped_ptr<ChromeLauncherController> controller_;
54 62
55 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest); 63 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); 98 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW));
91 99
92 // Disable Incognito mode. 100 // Disable Incognito mode.
93 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), 101 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(),
94 IncognitoModePrefs::FORCED); 102 IncognitoModePrefs::FORCED);
95 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT)); 103 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
96 ASSERT_TRUE(IsItemPresentInMenu( 104 ASSERT_TRUE(IsItemPresentInMenu(
97 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW)); 105 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW));
98 EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); 106 EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW));
99 } 107 }
108
109 // Verifies status of contextmenu items for desktop shell.
110 TEST_F(LauncherContextMenuTest, DesktopShellLauncherContextMenuItemCheck) {
111 scoped_ptr<LauncherContextMenu> menu(
112 CreateLauncherContextMenuForDesktopShell());
113 EXPECT_FALSE(
114 IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_OPEN_NEW));
115 EXPECT_FALSE(IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_PIN));
116 EXPECT_TRUE(
117 IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_AUTO_HIDE));
118 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_AUTO_HIDE));
119 EXPECT_TRUE(IsItemPresentInMenu(menu.get(),
120 LauncherContextMenu::MENU_ALIGNMENT_MENU));
121 EXPECT_TRUE(
122 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_ALIGNMENT_MENU));
123 #if defined(OS_CHROMEOS)
124 // By default, screen is not locked and ChangeWallPaper item is added in
125 // menu. ChangeWallPaper item is not enabled in default mode.
126 EXPECT_TRUE(IsItemPresentInMenu(menu.get(),
127 LauncherContextMenu::MENU_CHANGE_WALLPAPER));
128 EXPECT_FALSE(
129 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_CHANGE_WALLPAPER));
130 #endif
131 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/launcher_context_menu.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698