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