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

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

Issue 1838263002: Arc app integration in shelf launcher context menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor and comments&inlucdes cleanup 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
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/arc_launcher_context_menu.h"
16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
18 #include "chrome/browser/ui/ash/launcher/desktop_shell_launcher_context_menu.h"
19 #include "chrome/browser/ui/ash/launcher/extension_launcher_context_menu.h"
17 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
18 #include "components/prefs/pref_service.h" 21 #include "components/prefs/pref_service.h"
19 #include "ui/aura/window_event_dispatcher.h" 22 #include "ui/aura/window_event_dispatcher.h"
20 23
21 class LauncherContextMenuTest : public ash::test::AshTestBase { 24 class LauncherContextMenuTest : public ash::test::AshTestBase {
22 protected: 25 protected:
23 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { 26 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) {
24 return menu->GetIndexOfCommandId(command_id) != -1; 27 return menu->GetIndexOfCommandId(command_id) != -1;
25 } 28 }
26 29
27 LauncherContextMenuTest() : profile_(new TestingProfile()) {} 30 LauncherContextMenuTest() : profile_(new TestingProfile()) {}
28 31
29 void SetUp() override { 32 void SetUp() override {
30 ash::test::AshTestBase::SetUp(); 33 ash::test::AshTestBase::SetUp();
31 controller_.reset(new ChromeLauncherController(profile(), &shelf_model_)); 34 controller_.reset(new ChromeLauncherController(profile(), &shelf_model_));
32 } 35 }
33 36
34 void TearDown() override { 37 void TearDown() override {
35 controller_.reset(nullptr); 38 controller_.reset(nullptr);
36 ash::test::AshTestBase::TearDown(); 39 ash::test::AshTestBase::TearDown();
37 } 40 }
38 41
39 LauncherContextMenu* CreateLauncherContextMenu( 42 LauncherContextMenu* CreateLauncherContextMenu(
40 ash::ShelfItemType shelf_item_type) { 43 ash::ShelfItemType shelf_item_type) {
41 ash::ShelfItem item; 44 ash::ShelfItem item;
42 item.id = 1; // dummy id 45 item.id = 1; // dummy id
43 item.type = shelf_item_type; 46 item.type = shelf_item_type;
44 ash::Shelf* shelf = ash::Shelf::ForWindow(CurrentContext()); 47 ash::Shelf* shelf = ash::Shelf::ForWindow(CurrentContext());
45 return new LauncherContextMenu(controller_.get(), &item, shelf); 48 return LauncherContextMenu::Create(controller_.get(), &item, shelf);
46 } 49 }
47 50
51 LauncherContextMenu* CreateLauncherContextMenuForDesktopShell() {
52 ash::ShelfItem* item = nullptr;
53 ash::Shelf* shelf = ash::Shelf::ForWindow(CurrentContext());
54 return LauncherContextMenu::Create(controller_.get(), item, shelf);
55 }
56
57 LauncherContextMenu* CreateLauncherContextMenuForArcApp() {
khmel 2016/03/30 00:58:46 This must be under #if defined(OS_CHROMEOS) #end
lgcheng 2016/03/30 02:06:25 Done.
58 ash::ShelfItem item;
59 item.id = 1;
60 ash::Shelf* shelf = ash::Shelf::ForWindow(CurrentContext());
61 return new ArcLauncherContextMenu(controller_.get(), &item, shelf);
62 }
48 Profile* profile() { return profile_.get(); } 63 Profile* profile() { return profile_.get(); }
49 64
50 private: 65 private:
51 scoped_ptr<TestingProfile> profile_; 66 scoped_ptr<TestingProfile> profile_;
52 ash::ShelfModel shelf_model_; 67 ash::ShelfModel shelf_model_;
53 scoped_ptr<ChromeLauncherController> controller_; 68 scoped_ptr<ChromeLauncherController> controller_;
54 69
55 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest); 70 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest);
56 }; 71 };
57 72
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); 105 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW));
91 106
92 // Disable Incognito mode. 107 // Disable Incognito mode.
93 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), 108 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(),
94 IncognitoModePrefs::FORCED); 109 IncognitoModePrefs::FORCED);
95 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT)); 110 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
96 ASSERT_TRUE(IsItemPresentInMenu( 111 ASSERT_TRUE(IsItemPresentInMenu(
97 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW)); 112 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW));
98 EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); 113 EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW));
99 } 114 }
115
116 // Verifies status of contextmenu items for desktop shell.
117 TEST_F(LauncherContextMenuTest, DesktopShellLauncherContextMenuItemCheck) {
118 scoped_ptr<LauncherContextMenu> menu(
119 CreateLauncherContextMenuForDesktopShell());
120 EXPECT_FALSE(
121 IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_OPEN_NEW));
122 EXPECT_FALSE(IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_PIN));
123 EXPECT_TRUE(
124 IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_AUTO_HIDE));
125 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_AUTO_HIDE));
126 EXPECT_TRUE(IsItemPresentInMenu(menu.get(),
127 LauncherContextMenu::MENU_ALIGNMENT_MENU));
128 EXPECT_TRUE(
129 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_ALIGNMENT_MENU));
130 #if defined(OS_CHROMEOS)
131 // By default, screen is not locked and ChangeWallPaper item is added in
132 // menu. ChangeWallPaper item is not enabled in default mode.
133 EXPECT_TRUE(IsItemPresentInMenu(menu.get(),
134 LauncherContextMenu::MENU_CHANGE_WALLPAPER));
135 EXPECT_FALSE(
136 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_CHANGE_WALLPAPER));
137 #endif
138 }
139
140 // Verifies contextmenu items for Arc app
141 TEST_F(LauncherContextMenuTest, ArcLauncherContextMenuItemCheck) {
142 #if defined(OS_CHROMEOS)
khmel 2016/03/30 00:58:46 Whole test must be under #if defined(OS_CHROMEOS)
lgcheng 2016/03/30 02:06:25 Done.
143 scoped_ptr<LauncherContextMenu> menu(CreateLauncherContextMenuForArcApp());
144 EXPECT_TRUE(
145 IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_OPEN_NEW));
146 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_OPEN_NEW));
147 EXPECT_TRUE(
148 IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_AUTO_HIDE));
149 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_AUTO_HIDE));
150 EXPECT_TRUE(IsItemPresentInMenu(menu.get(),
151 LauncherContextMenu::MENU_ALIGNMENT_MENU));
152 EXPECT_TRUE(
153 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_ALIGNMENT_MENU));
154 // By default, screen is not locked and ChangeWallPaper item is added in
155 // menu. ChangeWallPaper item is not enabled in default mode.
156 EXPECT_TRUE(IsItemPresentInMenu(menu.get(),
157 LauncherContextMenu::MENU_CHANGE_WALLPAPER));
158 EXPECT_FALSE(
159 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_CHANGE_WALLPAPER));
160 #endif
161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698