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

Side by Side Diff: chrome/browser/ui/app_list/app_context_menu_unittest.cc

Issue 2787693002: Remove more dead app list code. (Closed)
Patch Set: updated 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <map> 5 #include <map>
6 #include <memory> 6 #include <memory>
7 #include <string> 7 #include <string>
8 #include <unordered_set> 8 #include <unordered_set>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12
13 #include "chrome/browser/extensions/extension_util.h" 12 #include "chrome/browser/extensions/extension_util.h"
14 #include "chrome/browser/extensions/menu_manager_factory.h" 13 #include "chrome/browser/extensions/menu_manager_factory.h"
15 #include "chrome/browser/ui/app_list/app_context_menu_delegate.h" 14 #include "chrome/browser/ui/app_list/app_context_menu_delegate.h"
16 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 15 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
17 #include "chrome/browser/ui/app_list/app_list_test_util.h" 16 #include "chrome/browser/ui/app_list/app_list_test_util.h"
17 #include "chrome/browser/ui/app_list/arc/arc_app_item.h"
18 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
19 #include "chrome/browser/ui/app_list/arc/arc_app_test.h"
18 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" 20 #include "chrome/browser/ui/app_list/chrome_app_list_item.h"
19 #include "chrome/browser/ui/app_list/extension_app_context_menu.h" 21 #include "chrome/browser/ui/app_list/extension_app_context_menu.h"
20 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" 22 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h"
21 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
24 #include "components/arc/test/fake_app_instance.h"
22 #include "components/keyed_service/core/keyed_service.h" 25 #include "components/keyed_service/core/keyed_service.h"
23 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
24 27
25 #if defined(OS_CHROMEOS)
26 #include "chrome/browser/ui/app_list/arc/arc_app_item.h"
27 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
28 #include "chrome/browser/ui/app_list/arc/arc_app_test.h"
29 #include "components/arc/test/fake_app_instance.h"
30 #endif
31
32 namespace { 28 namespace {
33 29
34 class FakeAppContextMenuDelegate : public app_list::AppContextMenuDelegate { 30 class FakeAppContextMenuDelegate : public app_list::AppContextMenuDelegate {
35 public: 31 public:
36 FakeAppContextMenuDelegate() = default; 32 FakeAppContextMenuDelegate() = default;
37 ~FakeAppContextMenuDelegate() override = default; 33 ~FakeAppContextMenuDelegate() override = default;
38 34
39 // app_list::AppContextMenuDelegate overrides: 35 // app_list::AppContextMenuDelegate overrides:
40 void ExecuteLaunchCommand(int event_flags) override {} 36 void ExecuteLaunchCommand(int event_flags) override {}
41 37
(...skipping 15 matching lines...) Expand all
57 if (open) 53 if (open)
58 open_apps_.insert(app_id); 54 open_apps_.insert(app_id);
59 else 55 else
60 open_apps_.erase(app_id); 56 open_apps_.erase(app_id);
61 } 57 }
62 58
63 bool IsAppOpen(const std::string& app_id) const override { 59 bool IsAppOpen(const std::string& app_id) const override {
64 return open_apps_.count(app_id) != 0; 60 return open_apps_.count(app_id) != 0;
65 } 61 }
66 62
67 void SetCanCreateShortcuts(bool can_create_shortcuts) {
68 can_create_shortcuts_ = can_create_shortcuts;
69 }
70
71 void SetCanShowAppInfo(bool can_show_app_info) { 63 void SetCanShowAppInfo(bool can_show_app_info) {
72 can_show_app_info_ = can_show_app_info; 64 can_show_app_info_ = can_show_app_info;
73 } 65 }
74 66
75 // test::TestAppListControllerDelegate overrides: 67 // test::TestAppListControllerDelegate overrides:
76 Pinnable GetPinnable(const std::string& app_id) override { 68 Pinnable GetPinnable(const std::string& app_id) override {
77 std::map<std::string, Pinnable>::const_iterator it; 69 std::map<std::string, Pinnable>::const_iterator it;
78 it = pinnable_apps_.find(app_id); 70 it = pinnable_apps_.find(app_id);
79 if (it == pinnable_apps_.end()) 71 if (it == pinnable_apps_.end())
80 return NO_PIN; 72 return NO_PIN;
81 return it->second; 73 return it->second;
82 } 74 }
83 bool CanDoCreateShortcutsFlow() override { return can_create_shortcuts_; }
84 bool CanDoShowAppInfoFlow() override { return can_show_app_info_; } 75 bool CanDoShowAppInfoFlow() override { return can_show_app_info_; }
85 76
86 private: 77 private:
87 std::map<std::string, Pinnable> pinnable_apps_; 78 std::map<std::string, Pinnable> pinnable_apps_;
88 std::unordered_set<std::string> open_apps_; 79 std::unordered_set<std::string> open_apps_;
89 bool can_create_shortcuts_ = false;
90 bool can_show_app_info_ = false; 80 bool can_show_app_info_ = false;
91 81
92 DISALLOW_COPY_AND_ASSIGN(FakeAppListControllerDelegate); 82 DISALLOW_COPY_AND_ASSIGN(FakeAppListControllerDelegate);
93 }; 83 };
94 84
95 std::unique_ptr<KeyedService> MenuManagerFactory( 85 std::unique_ptr<KeyedService> MenuManagerFactory(
96 content::BrowserContext* context) { 86 content::BrowserContext* context) {
97 return extensions::MenuManagerFactory::BuildServiceInstanceForTesting( 87 return extensions::MenuManagerFactory::BuildServiceInstanceForTesting(
98 context); 88 context);
99 } 89 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 173 }
184 174
185 void AddSeparator(std::vector<MenuState>* states) { 175 void AddSeparator(std::vector<MenuState>* states) {
186 if (states->empty() || states->back().command_id == -1) 176 if (states->empty() || states->back().command_id == -1)
187 return; 177 return;
188 states->push_back(MenuState()); 178 states->push_back(MenuState());
189 } 179 }
190 180
191 void TestExtensionApp(const std::string& app_id, 181 void TestExtensionApp(const std::string& app_id,
192 bool platform_app, 182 bool platform_app,
193 bool can_create_shortcuts,
194 bool can_show_app_info, 183 bool can_show_app_info,
195 AppListControllerDelegate::Pinnable pinnable, 184 AppListControllerDelegate::Pinnable pinnable,
196 extensions::LaunchType launch_type) { 185 extensions::LaunchType launch_type) {
197 controller_.reset(new FakeAppListControllerDelegate()); 186 controller_.reset(new FakeAppListControllerDelegate());
198 controller_->SetAppPinnable(app_id, pinnable); 187 controller_->SetAppPinnable(app_id, pinnable);
199 controller_->SetCanCreateShortcuts(can_create_shortcuts);
200 controller_->SetCanShowAppInfo(can_show_app_info); 188 controller_->SetCanShowAppInfo(can_show_app_info);
201 controller_->SetExtensionLaunchType(profile(), app_id, launch_type); 189 controller_->SetExtensionLaunchType(profile(), app_id, launch_type);
202 app_list::ExtensionAppContextMenu menu(menu_delegate(), 190 app_list::ExtensionAppContextMenu menu(menu_delegate(),
203 profile(), 191 profile(),
204 app_id, 192 app_id,
205 controller()); 193 controller());
206 menu.set_is_platform_app(platform_app); 194 menu.set_is_platform_app(platform_app);
207 ui::MenuModel* menu_model = menu.GetMenuModel(); 195 ui::MenuModel* menu_model = menu.GetMenuModel();
208 ASSERT_NE(nullptr, menu_model); 196 ASSERT_NE(nullptr, menu_model);
209 197
210 std::vector<MenuState> states; 198 std::vector<MenuState> states;
211 if (!platform_app) 199 if (!platform_app)
212 states.push_back(MenuState(app_list::AppContextMenu::LAUNCH_NEW)); 200 states.push_back(MenuState(app_list::AppContextMenu::LAUNCH_NEW));
213 if (pinnable != AppListControllerDelegate::NO_PIN) { 201 if (pinnable != AppListControllerDelegate::NO_PIN) {
214 AddSeparator(&states); 202 AddSeparator(&states);
215 states.push_back(MenuState( 203 states.push_back(MenuState(
216 app_list::AppContextMenu::TOGGLE_PIN, 204 app_list::AppContextMenu::TOGGLE_PIN,
217 pinnable != AppListControllerDelegate::PIN_FIXED, 205 pinnable != AppListControllerDelegate::PIN_FIXED,
218 false)); 206 false));
219 } 207 }
220 if (can_create_shortcuts)
221 states.push_back(MenuState(app_list::AppContextMenu::CREATE_SHORTCUTS));
222 AddSeparator(&states); 208 AddSeparator(&states);
223 209
224 if (!platform_app) { 210 if (!platform_app) {
225 if (extensions::util::CanHostedAppsOpenInWindows() && 211 if (extensions::util::CanHostedAppsOpenInWindows() &&
226 extensions::util::IsNewBookmarkAppsEnabled()) { 212 extensions::util::IsNewBookmarkAppsEnabled()) {
227 bool checked = launch_type == extensions::LAUNCH_TYPE_WINDOW || 213 bool checked = launch_type == extensions::LAUNCH_TYPE_WINDOW ||
228 launch_type == extensions::LAUNCH_TYPE_FULLSCREEN; 214 launch_type == extensions::LAUNCH_TYPE_FULLSCREEN;
229 states.push_back(MenuState( 215 states.push_back(MenuState(
230 app_list::AppContextMenu::USE_LAUNCH_TYPE_WINDOW, true, checked)); 216 app_list::AppContextMenu::USE_LAUNCH_TYPE_WINDOW, true, checked));
231 } else if (!extensions::util::IsNewBookmarkAppsEnabled()) { 217 } else if (!extensions::util::IsNewBookmarkAppsEnabled()) {
(...skipping 22 matching lines...) Expand all
254 false, 240 false,
255 false)); 241 false));
256 } 242 }
257 states.push_back(MenuState(app_list::AppContextMenu::UNINSTALL)); 243 states.push_back(MenuState(app_list::AppContextMenu::UNINSTALL));
258 if (can_show_app_info) 244 if (can_show_app_info)
259 states.push_back(MenuState(app_list::AppContextMenu::SHOW_APP_INFO)); 245 states.push_back(MenuState(app_list::AppContextMenu::SHOW_APP_INFO));
260 246
261 ValidateMenuState(menu_model, states); 247 ValidateMenuState(menu_model, states);
262 } 248 }
263 249
264 void TestChromeApp(bool can_create_shortcuts, 250 void TestChromeApp(bool can_show_app_info) {
265 bool can_show_app_info) {
266 controller_.reset(new FakeAppListControllerDelegate()); 251 controller_.reset(new FakeAppListControllerDelegate());
267 controller_->SetCanCreateShortcuts(can_create_shortcuts);
268 controller_->SetCanShowAppInfo(can_show_app_info); 252 controller_->SetCanShowAppInfo(can_show_app_info);
269 app_list::ExtensionAppContextMenu menu(menu_delegate(), 253 app_list::ExtensionAppContextMenu menu(menu_delegate(),
270 profile(), 254 profile(),
271 extension_misc::kChromeAppId, 255 extension_misc::kChromeAppId,
272 controller()); 256 controller());
273 ui::MenuModel* menu_model = menu.GetMenuModel(); 257 ui::MenuModel* menu_model = menu.GetMenuModel();
274 ASSERT_NE(nullptr, menu_model); 258 ASSERT_NE(nullptr, menu_model);
275 259
276 std::vector<MenuState> states; 260 std::vector<MenuState> states;
277 states.push_back(MenuState(app_list::AppContextMenu::MENU_NEW_WINDOW)); 261 states.push_back(MenuState(app_list::AppContextMenu::MENU_NEW_WINDOW));
(...skipping 19 matching lines...) Expand all
297 app_list::ExtensionAppContextMenu::DisableInstalledExtensionCheckForTesting( 281 app_list::ExtensionAppContextMenu::DisableInstalledExtensionCheckForTesting(
298 false); 282 false);
299 for (extensions::LaunchType launch_type = extensions::LAUNCH_TYPE_FIRST; 283 for (extensions::LaunchType launch_type = extensions::LAUNCH_TYPE_FIRST;
300 launch_type < extensions::NUM_LAUNCH_TYPES; 284 launch_type < extensions::NUM_LAUNCH_TYPES;
301 launch_type = static_cast<extensions::LaunchType>(launch_type+1)) { 285 launch_type = static_cast<extensions::LaunchType>(launch_type+1)) {
302 AppListControllerDelegate::Pinnable pinnable; 286 AppListControllerDelegate::Pinnable pinnable;
303 for (pinnable = AppListControllerDelegate::NO_PIN; 287 for (pinnable = AppListControllerDelegate::NO_PIN;
304 pinnable <= AppListControllerDelegate::PIN_FIXED; 288 pinnable <= AppListControllerDelegate::PIN_FIXED;
305 pinnable = 289 pinnable =
306 static_cast<AppListControllerDelegate::Pinnable>(pinnable+1)) { 290 static_cast<AppListControllerDelegate::Pinnable>(pinnable+1)) {
307 for (size_t combinations = 0; combinations < (1 << 3); ++combinations) { 291 for (size_t combinations = 0; combinations < (1 << 2); ++combinations) {
308 TestExtensionApp(AppListTestBase::kHostedAppId, 292 TestExtensionApp(AppListTestBase::kHostedAppId,
309 (combinations & (1 << 0)) != 0, 293 (combinations & (1 << 0)) != 0,
310 (combinations & (1 << 1)) != 0, 294 (combinations & (1 << 1)) != 0,
311 (combinations & (1 << 2)) != 0,
312 pinnable, 295 pinnable,
313 launch_type); 296 launch_type);
314 TestExtensionApp(AppListTestBase::kPackagedApp1Id, 297 TestExtensionApp(AppListTestBase::kPackagedApp1Id,
315 (combinations & (1 << 0)) != 0, 298 (combinations & (1 << 0)) != 0,
316 (combinations & (1 << 1)) != 0, 299 (combinations & (1 << 1)) != 0,
317 (combinations & (1 << 2)) != 0,
318 pinnable, 300 pinnable,
319 launch_type); 301 launch_type);
320 TestExtensionApp(AppListTestBase::kPackagedApp2Id, 302 TestExtensionApp(AppListTestBase::kPackagedApp2Id,
321 (combinations & (1 << 0)) != 0, 303 (combinations & (1 << 0)) != 0,
322 (combinations & (1 << 1)) != 0, 304 (combinations & (1 << 1)) != 0,
323 (combinations & (1 << 2)) != 0,
324 pinnable, 305 pinnable,
325 launch_type); 306 launch_type);
326 } 307 }
327 } 308 }
328 } 309 }
329 } 310 }
330 311
331 TEST_F(AppContextMenuTest, ChromeApp) { 312 TEST_F(AppContextMenuTest, ChromeApp) {
332 app_list::ExtensionAppContextMenu::DisableInstalledExtensionCheckForTesting( 313 app_list::ExtensionAppContextMenu::DisableInstalledExtensionCheckForTesting(
333 true); 314 true);
334 for (size_t combinations = 0; combinations < (1 << 2); ++combinations) { 315 for (bool can_show_app_info : {true, false})
335 TestChromeApp((combinations & (1 << 0)) != 0, 316 TestChromeApp(can_show_app_info);
336 (combinations & (1 << 1)) != 0);
337 }
338 } 317 }
339 318
340 TEST_F(AppContextMenuTest, NonExistingExtensionApp) { 319 TEST_F(AppContextMenuTest, NonExistingExtensionApp) {
341 app_list::ExtensionAppContextMenu::DisableInstalledExtensionCheckForTesting( 320 app_list::ExtensionAppContextMenu::DisableInstalledExtensionCheckForTesting(
342 false); 321 false);
343 app_list::ExtensionAppContextMenu menu(menu_delegate(), 322 app_list::ExtensionAppContextMenu menu(menu_delegate(),
344 profile(), 323 profile(),
345 "some_non_existing_extension_app", 324 "some_non_existing_extension_app",
346 controller()); 325 controller());
347 ui::MenuModel* menu_model = menu.GetMenuModel(); 326 ui::MenuModel* menu_model = menu.GetMenuModel();
348 EXPECT_EQ(nullptr, menu_model); 327 EXPECT_EQ(nullptr, menu_model);
349 } 328 }
350 329
351 #if defined(OS_CHROMEOS)
352 TEST_F(AppContextMenuTest, ArcMenu) { 330 TEST_F(AppContextMenuTest, ArcMenu) {
353 ArcAppTest arc_test; 331 ArcAppTest arc_test;
354 arc_test.SetUp(profile()); 332 arc_test.SetUp(profile());
355 333
356 const arc::mojom::AppInfo& app_info = arc_test.fake_apps()[1]; 334 const arc::mojom::AppInfo& app_info = arc_test.fake_apps()[1];
357 const std::string app_id = ArcAppTest::GetAppId(app_info); 335 const std::string app_id = ArcAppTest::GetAppId(app_info);
358 controller()->SetAppPinnable(app_id, AppListControllerDelegate::PIN_EDITABLE); 336 controller()->SetAppPinnable(app_id, AppListControllerDelegate::PIN_EDITABLE);
359 337
360 arc_test.app_instance()->RefreshAppList(); 338 arc_test.app_instance()->RefreshAppList();
361 arc_test.app_instance()->SendRefreshAppList(arc_test.fake_apps()); 339 arc_test.app_instance()->SendRefreshAppList(arc_test.fake_apps());
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 463
486 ASSERT_EQ(5, menu->GetItemCount()); 464 ASSERT_EQ(5, menu->GetItemCount());
487 ValidateItemState(menu, 0, MenuState(app_list::AppContextMenu::LAUNCH_NEW)); 465 ValidateItemState(menu, 0, MenuState(app_list::AppContextMenu::LAUNCH_NEW));
488 ValidateItemState(menu, 1, MenuState()); // separator 466 ValidateItemState(menu, 1, MenuState()); // separator
489 ValidateItemState(menu, 2, MenuState(app_list::AppContextMenu::TOGGLE_PIN)); 467 ValidateItemState(menu, 2, MenuState(app_list::AppContextMenu::TOGGLE_PIN));
490 ValidateItemState(menu, 3, MenuState()); // separator 468 ValidateItemState(menu, 3, MenuState()); // separator
491 ValidateItemState( 469 ValidateItemState(
492 menu, 4, MenuState(app_list::AppContextMenu::SHOW_APP_INFO)); 470 menu, 4, MenuState(app_list::AppContextMenu::SHOW_APP_INFO));
493 } 471 }
494 } 472 }
495
496 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/app_context_menu.cc ('k') | chrome/browser/ui/app_list/app_list_controller_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698