OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/chrome_launcher_controller_impl.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 // Test implementation of a V2 app launcher item controller. | 255 // Test implementation of a V2 app launcher item controller. |
256 class TestV2AppLauncherItemController : public LauncherItemController { | 256 class TestV2AppLauncherItemController : public LauncherItemController { |
257 public: | 257 public: |
258 TestV2AppLauncherItemController(const std::string& app_id, | 258 TestV2AppLauncherItemController(const std::string& app_id, |
259 ChromeLauncherController* controller) | 259 ChromeLauncherController* controller) |
260 : LauncherItemController(app_id, std::string(), controller) {} | 260 : LauncherItemController(app_id, std::string(), controller) {} |
261 | 261 |
262 ~TestV2AppLauncherItemController() override {} | 262 ~TestV2AppLauncherItemController() override {} |
263 | 263 |
264 // Override for LauncherItemController: | 264 // Override for LauncherItemController: |
265 ash::ShelfAction ItemSelected(ui::EventType event_type, | 265 void ItemSelected(std::unique_ptr<ui::Event> event, |
266 int event_flags, | 266 int64_t display_id, |
267 int64_t display_id, | 267 ash::ShelfLaunchSource source, |
268 ash::ShelfLaunchSource source) override { | 268 const ItemSelectedCallback& callback) override { |
269 return ash::SHELF_ACTION_WINDOW_ACTIVATED; | 269 callback.Run(ash::SHELF_ACTION_WINDOW_ACTIVATED, MenuItemList()); |
270 } | 270 } |
271 ash::ShelfAppMenuItemList GetAppMenuItems(int event_flags) override { | 271 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override {} |
272 ash::ShelfAppMenuItemList items; | |
273 items.push_back( | |
274 base::MakeUnique<ash::ShelfApplicationMenuItem>(0, base::string16())); | |
275 items.push_back( | |
276 base::MakeUnique<ash::ShelfApplicationMenuItem>(1, base::string16())); | |
277 return items; | |
278 } | |
279 void ExecuteCommand(uint32_t command_id, int event_flags) override {} | |
280 void Close() override {} | 272 void Close() override {} |
281 | 273 |
282 private: | 274 private: |
283 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController); | 275 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController); |
284 }; | 276 }; |
285 | 277 |
286 // Proxies to ShelfDelegate invocation to the given | 278 // Proxies to ShelfDelegate invocation to the given |
287 // ChromeLauncherControllerImpl instance. Because of ownership management, | 279 // ChromeLauncherControllerImpl instance. Because of ownership management, |
288 // ChromeLauncherControllerImpl instance cannot be injected to WmShell. | 280 // ChromeLauncherControllerImpl instance cannot be injected to WmShell. |
289 // This wraps the instance, so that it can be injected. | 281 // This wraps the instance, so that it can be injected. |
(...skipping 2554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2844 expected_launchers.insert(expected_launchers.begin() + 1, extension2_->id()); | 2836 expected_launchers.insert(expected_launchers.begin() + 1, extension2_->id()); |
2845 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); | 2837 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); |
2846 EXPECT_EQ(expected_launchers, actual_launchers); | 2838 EXPECT_EQ(expected_launchers, actual_launchers); |
2847 } | 2839 } |
2848 | 2840 |
2849 // Ensure |controller| creates the expected menu items for the given shelf item. | 2841 // Ensure |controller| creates the expected menu items for the given shelf item. |
2850 void CheckAppMenu(ChromeLauncherControllerImpl* controller, | 2842 void CheckAppMenu(ChromeLauncherControllerImpl* controller, |
2851 const ash::ShelfItem& item, | 2843 const ash::ShelfItem& item, |
2852 size_t expected_item_count, | 2844 size_t expected_item_count, |
2853 base::string16 expected_item_titles[]) { | 2845 base::string16 expected_item_titles[]) { |
2854 ash::ShelfAppMenuItemList items = controller->GetAppMenuItemsForTesting(item); | 2846 ash::ShelfItemDelegate::MenuItemList items = |
| 2847 controller->GetAppMenuItemsForTesting(item); |
2855 ASSERT_EQ(expected_item_count, items.size()); | 2848 ASSERT_EQ(expected_item_count, items.size()); |
2856 for (size_t i = 0; i < expected_item_count; i++) | 2849 for (size_t i = 0; i < expected_item_count; i++) |
2857 EXPECT_EQ(expected_item_titles[i], items[i]->title()); | 2850 EXPECT_EQ(expected_item_titles[i], items[i]->label); |
2858 } | 2851 } |
2859 | 2852 |
2860 // Check that browsers get reflected correctly in the launcher menu. | 2853 // Check that browsers get reflected correctly in the launcher menu. |
2861 TEST_F(ChromeLauncherControllerImplTest, BrowserMenuGeneration) { | 2854 TEST_F(ChromeLauncherControllerImplTest, BrowserMenuGeneration) { |
2862 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); | 2855 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); |
2863 chrome::NewTab(browser()); | 2856 chrome::NewTab(browser()); |
2864 | 2857 |
2865 InitLauncherController(); | 2858 InitLauncherController(); |
2866 | 2859 |
2867 // Check that the browser list is empty at this time. | 2860 // Check that the browser list is empty at this time. |
(...skipping 22 matching lines...) Expand all Loading... |
2890 | 2883 |
2891 // Check that the list contains now two entries - make furthermore sure that | 2884 // Check that the list contains now two entries - make furthermore sure that |
2892 // the active item is the first entry. | 2885 // the active item is the first entry. |
2893 base::string16 two_menu_items[] = {title1, title2}; | 2886 base::string16 two_menu_items[] = {title1, title2}; |
2894 CheckAppMenu(launcher_controller_.get(), item_browser, 2, two_menu_items); | 2887 CheckAppMenu(launcher_controller_.get(), item_browser, 2, two_menu_items); |
2895 | 2888 |
2896 // Apparently we have to close all tabs we have. | 2889 // Apparently we have to close all tabs we have. |
2897 chrome::CloseTab(browser2.get()); | 2890 chrome::CloseTab(browser2.get()); |
2898 } | 2891 } |
2899 | 2892 |
2900 // Check the multi profile case where only user related browsers should show | 2893 // Check the multi profile case where only user related browsers should show up. |
2901 // up. | |
2902 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest, | 2894 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest, |
2903 BrowserMenuGenerationTwoUsers) { | 2895 BrowserMenuGenerationTwoUsers) { |
2904 // Create a browser item in the LauncherController. | 2896 // Create a browser item in the LauncherController. |
2905 InitLauncherController(); | 2897 InitLauncherController(); |
2906 | 2898 |
2907 ash::ShelfItem item_browser; | 2899 ash::ShelfItem item_browser; |
2908 item_browser.type = ash::TYPE_BROWSER_SHORTCUT; | 2900 item_browser.type = ash::TYPE_BROWSER_SHORTCUT; |
2909 item_browser.id = | 2901 item_browser.id = |
2910 launcher_controller_->GetShelfIDForAppID(extension_misc::kChromeAppId); | 2902 launcher_controller_->GetShelfIDForAppID(extension_misc::kChromeAppId); |
2911 | 2903 |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3351 item_gmail.id = gmail_id; | 3343 item_gmail.id = gmail_id; |
3352 base::string16 two_menu_items[] = {title1, title2}; | 3344 base::string16 two_menu_items[] = {title1, title2}; |
3353 CheckAppMenu(launcher_controller_.get(), item_gmail, 2, two_menu_items); | 3345 CheckAppMenu(launcher_controller_.get(), item_gmail, 2, two_menu_items); |
3354 | 3346 |
3355 LauncherItemController* item_controller = | 3347 LauncherItemController* item_controller = |
3356 launcher_controller_->GetLauncherItemController(gmail_id); | 3348 launcher_controller_->GetLauncherItemController(gmail_id); |
3357 ASSERT_TRUE(item_controller); | 3349 ASSERT_TRUE(item_controller); |
3358 int tabs = browser()->tab_strip_model()->count(); | 3350 int tabs = browser()->tab_strip_model()->count(); |
3359 // Activate the proper tab through the menu item. | 3351 // Activate the proper tab through the menu item. |
3360 { | 3352 { |
3361 ash::ShelfAppMenuItemList items = | 3353 ash::ShelfItemDelegate::MenuItemList items = |
3362 launcher_controller_->GetAppMenuItemsForTesting(item_gmail); | 3354 launcher_controller_->GetAppMenuItemsForTesting(item_gmail); |
3363 item_controller->ExecuteCommand(items[1]->command_id(), ui::EF_NONE); | 3355 item_controller->ExecuteCommand(items[1]->command_id, ui::EF_NONE); |
3364 EXPECT_EQ(tabs, browser()->tab_strip_model()->count()); | 3356 EXPECT_EQ(tabs, browser()->tab_strip_model()->count()); |
3365 } | 3357 } |
3366 | 3358 |
3367 // Delete one tab through the menu item. | 3359 // Delete one tab through the menu item. |
3368 { | 3360 { |
3369 ash::ShelfAppMenuItemList items = | 3361 ash::ShelfItemDelegate::MenuItemList items = |
3370 launcher_controller_->GetAppMenuItemsForTesting(item_gmail); | 3362 launcher_controller_->GetAppMenuItemsForTesting(item_gmail); |
3371 item_controller->ExecuteCommand(items[1]->command_id(), ui::EF_SHIFT_DOWN); | 3363 item_controller->ExecuteCommand(items[1]->command_id, ui::EF_SHIFT_DOWN); |
3372 EXPECT_EQ(--tabs, browser()->tab_strip_model()->count()); | 3364 EXPECT_EQ(--tabs, browser()->tab_strip_model()->count()); |
3373 } | 3365 } |
3374 } | 3366 } |
3375 | 3367 |
3376 // Tests that panels create launcher items correctly | 3368 // Tests that panels create launcher items correctly |
3377 TEST_F(ChromeLauncherControllerImplTest, AppPanels) { | 3369 TEST_F(ChromeLauncherControllerImplTest, AppPanels) { |
3378 InitLauncherController(); | 3370 InitLauncherController(); |
3379 model_observer_->clear_counts(); | 3371 model_observer_->clear_counts(); |
3380 const std::string app_id = extension1_->id(); | 3372 const std::string app_id = extension1_->id(); |
3381 | 3373 |
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4310 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, | 4302 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, |
4311 shelf_controller->auto_hide()); | 4303 shelf_controller->auto_hide()); |
4312 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count()); | 4304 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count()); |
4313 | 4305 |
4314 PrefService* prefs = profile()->GetTestingPrefService(); | 4306 PrefService* prefs = profile()->GetTestingPrefService(); |
4315 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal)); | 4307 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal)); |
4316 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment)); | 4308 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment)); |
4317 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal)); | 4309 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal)); |
4318 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior)); | 4310 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior)); |
4319 } | 4311 } |
OLD | NEW |