| OLD | NEW |
| 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 <string> | 6 #include <string> |
| 7 #include <unordered_set> | 7 #include <unordered_set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } | 170 } |
| 171 | 171 |
| 172 FakeAppContextMenuDelegate* menu_delegate() { | 172 FakeAppContextMenuDelegate* menu_delegate() { |
| 173 return menu_delegate_.get(); | 173 return menu_delegate_.get(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 Profile* profile() { | 176 Profile* profile() { |
| 177 return profile_.get(); | 177 return profile_.get(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void AddSeparator(std::vector<MenuState>* states) { | 180 void AddSeparator(std::vector<MenuState>& states) { |
| 181 if (states->empty() || states->back().command_id == -1) | 181 if (states.empty() || states.back().command_id == -1) |
| 182 return; | 182 return; |
| 183 states->push_back(MenuState()); | 183 states.push_back(MenuState()); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void TestExtensionApp(const std::string& app_id, | 186 void TestExtensionApp(const std::string& app_id, |
| 187 bool platform_app, | 187 bool platform_app, |
| 188 bool can_create_shortcuts, | 188 bool can_create_shortcuts, |
| 189 bool can_show_app_info, | 189 bool can_show_app_info, |
| 190 AppListControllerDelegate::Pinnable pinnable, | 190 AppListControllerDelegate::Pinnable pinnable, |
| 191 extensions::LaunchType launch_type) { | 191 extensions::LaunchType launch_type) { |
| 192 controller_.reset(new FakeAppListControllerDelegate()); | 192 controller_.reset(new FakeAppListControllerDelegate()); |
| 193 controller_->SetAppPinnable(app_id, pinnable); | 193 controller_->SetAppPinnable(app_id, pinnable); |
| 194 controller_->SetCanCreateShortcuts(can_create_shortcuts); | 194 controller_->SetCanCreateShortcuts(can_create_shortcuts); |
| 195 controller_->SetCanShowAppInfo(can_show_app_info); | 195 controller_->SetCanShowAppInfo(can_show_app_info); |
| 196 controller_->SetExtensionLaunchType(profile(), app_id, launch_type); | 196 controller_->SetExtensionLaunchType(profile(), app_id, launch_type); |
| 197 app_list::ExtensionAppContextMenu menu(menu_delegate(), | 197 app_list::ExtensionAppContextMenu menu(menu_delegate(), |
| 198 profile(), | 198 profile(), |
| 199 app_id, | 199 app_id, |
| 200 controller()); | 200 controller()); |
| 201 menu.set_is_platform_app(platform_app); | 201 menu.set_is_platform_app(platform_app); |
| 202 ui::MenuModel* menu_model = menu.GetMenuModel(); | 202 ui::MenuModel* menu_model = menu.GetMenuModel(); |
| 203 ASSERT_NE(nullptr, menu_model); | 203 ASSERT_NE(nullptr, menu_model); |
| 204 | 204 |
| 205 std::vector<MenuState> states; | 205 std::vector<MenuState> states; |
| 206 if (!platform_app) | 206 if (!platform_app) |
| 207 states.push_back(MenuState(app_list::AppContextMenu::LAUNCH_NEW)); | 207 states.push_back(MenuState(app_list::AppContextMenu::LAUNCH_NEW)); |
| 208 if (pinnable != AppListControllerDelegate::NO_PIN) { | 208 if (pinnable != AppListControllerDelegate::NO_PIN) { |
| 209 AddSeparator(&states); | 209 AddSeparator(states); |
| 210 states.push_back(MenuState( | 210 states.push_back(MenuState( |
| 211 app_list::AppContextMenu::TOGGLE_PIN, | 211 app_list::AppContextMenu::TOGGLE_PIN, |
| 212 pinnable != AppListControllerDelegate::PIN_FIXED, | 212 pinnable != AppListControllerDelegate::PIN_FIXED, |
| 213 false)); | 213 false)); |
| 214 } | 214 } |
| 215 if (can_create_shortcuts) | 215 if (can_create_shortcuts) |
| 216 states.push_back(MenuState(app_list::AppContextMenu::CREATE_SHORTCUTS)); | 216 states.push_back(MenuState(app_list::AppContextMenu::CREATE_SHORTCUTS)); |
| 217 AddSeparator(&states); | 217 AddSeparator(states); |
| 218 | 218 |
| 219 if (!platform_app) { | 219 if (!platform_app) { |
| 220 if (extensions::util::CanHostedAppsOpenInWindows() && | 220 if (extensions::util::CanHostedAppsOpenInWindows() && |
| 221 extensions::util::IsNewBookmarkAppsEnabled()) { | 221 extensions::util::IsNewBookmarkAppsEnabled()) { |
| 222 bool checked = launch_type == extensions::LAUNCH_TYPE_WINDOW || | 222 bool checked = launch_type == extensions::LAUNCH_TYPE_WINDOW || |
| 223 launch_type == extensions::LAUNCH_TYPE_FULLSCREEN; | 223 launch_type == extensions::LAUNCH_TYPE_FULLSCREEN; |
| 224 states.push_back(MenuState( | 224 states.push_back(MenuState( |
| 225 app_list::AppContextMenu::USE_LAUNCH_TYPE_WINDOW, true, checked)); | 225 app_list::AppContextMenu::USE_LAUNCH_TYPE_WINDOW, true, checked)); |
| 226 } else if (!extensions::util::IsNewBookmarkAppsEnabled()) { | 226 } else if (!extensions::util::IsNewBookmarkAppsEnabled()) { |
| 227 bool regular_checked = launch_type == extensions::LAUNCH_TYPE_REGULAR; | 227 bool regular_checked = launch_type == extensions::LAUNCH_TYPE_REGULAR; |
| 228 states.push_back(MenuState( | 228 states.push_back(MenuState( |
| 229 app_list::AppContextMenu::USE_LAUNCH_TYPE_REGULAR, | 229 app_list::AppContextMenu::USE_LAUNCH_TYPE_REGULAR, |
| 230 true, | 230 true, |
| 231 regular_checked)); | 231 regular_checked)); |
| 232 states.push_back(MenuState( | 232 states.push_back(MenuState( |
| 233 app_list::AppContextMenu::USE_LAUNCH_TYPE_PINNED, | 233 app_list::AppContextMenu::USE_LAUNCH_TYPE_PINNED, |
| 234 true, | 234 true, |
| 235 launch_type == extensions::LAUNCH_TYPE_PINNED)); | 235 launch_type == extensions::LAUNCH_TYPE_PINNED)); |
| 236 if (extensions::util::CanHostedAppsOpenInWindows()) { | 236 if (extensions::util::CanHostedAppsOpenInWindows()) { |
| 237 states.push_back(MenuState( | 237 states.push_back(MenuState( |
| 238 app_list::AppContextMenu::USE_LAUNCH_TYPE_WINDOW, | 238 app_list::AppContextMenu::USE_LAUNCH_TYPE_WINDOW, |
| 239 true, | 239 true, |
| 240 launch_type == extensions::LAUNCH_TYPE_WINDOW)); | 240 launch_type == extensions::LAUNCH_TYPE_WINDOW)); |
| 241 } | 241 } |
| 242 states.push_back(MenuState( | 242 states.push_back(MenuState( |
| 243 app_list::AppContextMenu::USE_LAUNCH_TYPE_FULLSCREEN, | 243 app_list::AppContextMenu::USE_LAUNCH_TYPE_FULLSCREEN, |
| 244 true, | 244 true, |
| 245 launch_type == extensions::LAUNCH_TYPE_FULLSCREEN)); | 245 launch_type == extensions::LAUNCH_TYPE_FULLSCREEN)); |
| 246 } | 246 } |
| 247 AddSeparator(&states); | 247 AddSeparator(states); |
| 248 states.push_back(MenuState(app_list::AppContextMenu::OPTIONS, | 248 states.push_back(MenuState(app_list::AppContextMenu::OPTIONS, |
| 249 false, | 249 false, |
| 250 false)); | 250 false)); |
| 251 } | 251 } |
| 252 states.push_back(MenuState(app_list::AppContextMenu::UNINSTALL)); | 252 states.push_back(MenuState(app_list::AppContextMenu::UNINSTALL)); |
| 253 if (can_show_app_info) | 253 if (can_show_app_info) |
| 254 states.push_back(MenuState(app_list::AppContextMenu::SHOW_APP_INFO)); | 254 states.push_back(MenuState(app_list::AppContextMenu::SHOW_APP_INFO)); |
| 255 | 255 |
| 256 ValidateMenuState(menu_model, states); | 256 ValidateMenuState(menu_model, states); |
| 257 } | 257 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 EXPECT_TRUE(menu->IsEnabledAt(2)); | 369 EXPECT_TRUE(menu->IsEnabledAt(2)); |
| 370 EXPECT_FALSE(menu->IsItemCheckedAt(2)); | 370 EXPECT_FALSE(menu->IsItemCheckedAt(2)); |
| 371 EXPECT_EQ(app_list::AppContextMenu::SHOW_APP_INFO, menu->GetCommandIdAt(3)); | 371 EXPECT_EQ(app_list::AppContextMenu::SHOW_APP_INFO, menu->GetCommandIdAt(3)); |
| 372 EXPECT_TRUE(menu->IsEnabledAt(3)); | 372 EXPECT_TRUE(menu->IsEnabledAt(3)); |
| 373 EXPECT_FALSE(menu->IsItemCheckedAt(3)); | 373 EXPECT_FALSE(menu->IsItemCheckedAt(3)); |
| 374 | 374 |
| 375 // Test activate request. | 375 // Test activate request. |
| 376 EXPECT_EQ(0u, arc_test.app_instance()->launch_requests().size()); | 376 EXPECT_EQ(0u, arc_test.app_instance()->launch_requests().size()); |
| 377 | 377 |
| 378 menu->ActivatedAt(0); | 378 menu->ActivatedAt(0); |
| 379 arc_test.app_instance()->WaitForIncomingMethodCall(); |
| 379 | 380 |
| 380 const ScopedVector<arc::FakeAppInstance::Request>& launch_requests = | 381 const ScopedVector<arc::FakeAppInstance::Request>& launch_requests = |
| 381 arc_test.app_instance()->launch_requests(); | 382 arc_test.app_instance()->launch_requests(); |
| 382 ASSERT_EQ(1u, launch_requests.size()); | 383 ASSERT_EQ(1u, launch_requests.size()); |
| 383 EXPECT_TRUE(launch_requests[0]->IsForApp(app_info)); | 384 EXPECT_TRUE(launch_requests[0]->IsForApp(app_info)); |
| 384 | 385 |
| 385 controller()->SetAppOpen(app_id, true); | 386 controller()->SetAppOpen(app_id, true); |
| 386 // It is not expected that menu model is unchanged on GetContextMenuModel. Arc | 387 // It is not expected that menu model is unchanged on GetContextMenuModel. Arc |
| 387 // app menu requires model to be recalculated. | 388 // app menu requires model to be recalculated. |
| 388 menu = item.GetContextMenuModel(); | 389 menu = item.GetContextMenuModel(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 EXPECT_EQ(-1, menu->GetCommandIdAt(3)); // separator | 467 EXPECT_EQ(-1, menu->GetCommandIdAt(3)); // separator |
| 467 EXPECT_EQ(app_list::AppContextMenu::UNINSTALL, menu->GetCommandIdAt(4)); | 468 EXPECT_EQ(app_list::AppContextMenu::UNINSTALL, menu->GetCommandIdAt(4)); |
| 468 EXPECT_TRUE(menu->IsEnabledAt(4)); | 469 EXPECT_TRUE(menu->IsEnabledAt(4)); |
| 469 EXPECT_FALSE(menu->IsItemCheckedAt(4)); | 470 EXPECT_FALSE(menu->IsItemCheckedAt(4)); |
| 470 EXPECT_EQ(app_list::AppContextMenu::SHOW_APP_INFO, menu->GetCommandIdAt(5)); | 471 EXPECT_EQ(app_list::AppContextMenu::SHOW_APP_INFO, menu->GetCommandIdAt(5)); |
| 471 EXPECT_TRUE(menu->IsEnabledAt(5)); | 472 EXPECT_TRUE(menu->IsEnabledAt(5)); |
| 472 EXPECT_FALSE(menu->IsItemCheckedAt(5)); | 473 EXPECT_FALSE(menu->IsItemCheckedAt(5)); |
| 473 } | 474 } |
| 474 } | 475 } |
| 475 #endif | 476 #endif |
| OLD | NEW |