| 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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 // Override for LauncherItemController: | 264 // Override for LauncherItemController: |
| 265 ash::ShelfAction ItemSelected(ui::EventType event_type, | 265 ash::ShelfAction ItemSelected(ui::EventType event_type, |
| 266 int event_flags, | 266 int event_flags, |
| 267 int64_t display_id, | 267 int64_t display_id, |
| 268 ash::ShelfLaunchSource source) override { | 268 ash::ShelfLaunchSource source) override { |
| 269 return ash::SHELF_ACTION_WINDOW_ACTIVATED; | 269 return ash::SHELF_ACTION_WINDOW_ACTIVATED; |
| 270 } | 270 } |
| 271 ash::ShelfAppMenuItemList GetAppMenuItems(int event_flags) override { | 271 ash::ShelfAppMenuItemList GetAppMenuItems(int event_flags) override { |
| 272 ash::ShelfAppMenuItemList items; | 272 ash::ShelfAppMenuItemList items; |
| 273 items.push_back( | 273 items.push_back( |
| 274 base::MakeUnique<ash::ShelfApplicationMenuItem>(base::string16())); | 274 base::MakeUnique<ash::ShelfApplicationMenuItem>(0, base::string16())); |
| 275 items.push_back( | 275 items.push_back( |
| 276 base::MakeUnique<ash::ShelfApplicationMenuItem>(base::string16())); | 276 base::MakeUnique<ash::ShelfApplicationMenuItem>(1, base::string16())); |
| 277 return items; | 277 return items; |
| 278 } | 278 } |
| 279 void ExecuteCommand(uint32_t command_id, int event_flags) override {} |
| 279 void Close() override {} | 280 void Close() override {} |
| 280 | 281 |
| 281 private: | 282 private: |
| 282 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController); | 283 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController); |
| 283 }; | 284 }; |
| 284 | 285 |
| 285 } // namespace | 286 } // namespace |
| 286 | 287 |
| 287 class ChromeLauncherControllerImplTest : public BrowserWithTestWindowTest { | 288 class ChromeLauncherControllerImplTest : public BrowserWithTestWindowTest { |
| 288 protected: | 289 protected: |
| (...skipping 2478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2767 expected_launchers.insert(expected_launchers.begin() + 1, extension2_->id()); | 2768 expected_launchers.insert(expected_launchers.begin() + 1, extension2_->id()); |
| 2768 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); | 2769 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); |
| 2769 EXPECT_EQ(expected_launchers, actual_launchers); | 2770 EXPECT_EQ(expected_launchers, actual_launchers); |
| 2770 } | 2771 } |
| 2771 | 2772 |
| 2772 // Ensure |controller| creates the expected menu items for the given shelf item. | 2773 // Ensure |controller| creates the expected menu items for the given shelf item. |
| 2773 void CheckAppMenu(ChromeLauncherControllerImpl* controller, | 2774 void CheckAppMenu(ChromeLauncherControllerImpl* controller, |
| 2774 const ash::ShelfItem& item, | 2775 const ash::ShelfItem& item, |
| 2775 size_t expected_item_count, | 2776 size_t expected_item_count, |
| 2776 base::string16 expected_item_titles[]) { | 2777 base::string16 expected_item_titles[]) { |
| 2777 ash::ShelfAppMenuItemList items = controller->GetAppMenuItems(item, 0); | 2778 ash::ShelfAppMenuItemList items = controller->GetAppMenuItemsForTesting(item); |
| 2778 ASSERT_EQ(expected_item_count, items.size()); | 2779 ASSERT_EQ(expected_item_count, items.size()); |
| 2779 for (size_t i = 0; i < expected_item_count; i++) | 2780 for (size_t i = 0; i < expected_item_count; i++) |
| 2780 EXPECT_EQ(expected_item_titles[i], items[i]->title()); | 2781 EXPECT_EQ(expected_item_titles[i], items[i]->title()); |
| 2781 } | 2782 } |
| 2782 | 2783 |
| 2783 // Check that browsers get reflected correctly in the launcher menu. | 2784 // Check that browsers get reflected correctly in the launcher menu. |
| 2784 TEST_F(ChromeLauncherControllerImplTest, BrowserMenuGeneration) { | 2785 TEST_F(ChromeLauncherControllerImplTest, BrowserMenuGeneration) { |
| 2785 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); | 2786 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); |
| 2786 chrome::NewTab(browser()); | 2787 chrome::NewTab(browser()); |
| 2787 | 2788 |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3215 chrome::NewTab(browser()); | 3216 chrome::NewTab(browser()); |
| 3216 base::string16 title2 = ASCIIToUTF16("Test2"); | 3217 base::string16 title2 = ASCIIToUTF16("Test2"); |
| 3217 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title2); | 3218 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title2); |
| 3218 | 3219 |
| 3219 // Check that the menu is properly set. | 3220 // Check that the menu is properly set. |
| 3220 ash::ShelfItem item_gmail; | 3221 ash::ShelfItem item_gmail; |
| 3221 item_gmail.type = ash::TYPE_APP_SHORTCUT; | 3222 item_gmail.type = ash::TYPE_APP_SHORTCUT; |
| 3222 item_gmail.id = gmail_id; | 3223 item_gmail.id = gmail_id; |
| 3223 base::string16 two_menu_items[] = {title1, title2}; | 3224 base::string16 two_menu_items[] = {title1, title2}; |
| 3224 CheckAppMenu(launcher_controller_.get(), item_gmail, 2, two_menu_items); | 3225 CheckAppMenu(launcher_controller_.get(), item_gmail, 2, two_menu_items); |
| 3226 LauncherItemController* item_controller = |
| 3227 launcher_controller_->GetLauncherItemController(gmail_id); |
| 3228 ASSERT_TRUE(item_controller); |
| 3225 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); | 3229 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); |
| 3226 // Execute the second item in the menu, after the title and two separators, | 3230 // Execute the second item in the menu, after the title and two separators, |
| 3227 // this shouldn't do anything since that item is already the active tab. | 3231 // this shouldn't do anything since that item is already the active tab. |
| 3228 { | 3232 { |
| 3229 ash::ShelfApplicationMenuModel menu( | 3233 ash::ShelfApplicationMenuModel menu( |
| 3230 base::string16(), launcher_controller_->GetAppMenuItems(item_gmail, 0)); | 3234 base::string16(), |
| 3235 launcher_controller_->GetAppMenuItemsForTesting(item_gmail), |
| 3236 item_controller); |
| 3231 menu.ActivatedAt(4); | 3237 menu.ActivatedAt(4); |
| 3232 } | 3238 } |
| 3233 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); | 3239 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); |
| 3234 | 3240 |
| 3235 // Execute the first item in the menu, after the title and two separators, | 3241 // Execute the first item in the menu, after the title and two separators, |
| 3236 // this should activate the other tab. | 3242 // this should activate the other tab. |
| 3237 { | 3243 { |
| 3238 ash::ShelfApplicationMenuModel menu( | 3244 ash::ShelfApplicationMenuModel menu( |
| 3239 base::string16(), launcher_controller_->GetAppMenuItems(item_gmail, 0)); | 3245 base::string16(), |
| 3246 launcher_controller_->GetAppMenuItemsForTesting(item_gmail), |
| 3247 item_controller); |
| 3240 menu.ActivatedAt(3); | 3248 menu.ActivatedAt(3); |
| 3241 } | 3249 } |
| 3242 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); | 3250 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 3243 } | 3251 } |
| 3244 | 3252 |
| 3245 // Checks that the generated menu list properly deletes items. | 3253 // Checks that the generated menu list properly deletes items. |
| 3246 TEST_F(ChromeLauncherControllerImplTest, V1AppMenuDeletionExecution) { | 3254 TEST_F(ChromeLauncherControllerImplTest, V1AppMenuDeletionExecution) { |
| 3247 InitLauncherControllerWithBrowser(); | 3255 InitLauncherControllerWithBrowser(); |
| 3248 | 3256 |
| 3249 // Add |extension3_| to the launcher and add two items. | 3257 // Add |extension3_| to the launcher and add two items. |
| 3250 GURL gmail = GURL("https://mail.google.com/mail/u"); | 3258 GURL gmail = GURL("https://mail.google.com/mail/u"); |
| 3251 ash::ShelfID gmail_id = model_->next_id(); | 3259 ash::ShelfID gmail_id = model_->next_id(); |
| 3252 extension_service_->AddExtension(extension3_.get()); | 3260 extension_service_->AddExtension(extension3_.get()); |
| 3253 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url)); | 3261 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url)); |
| 3254 base::string16 title1 = ASCIIToUTF16("Test1"); | 3262 base::string16 title1 = ASCIIToUTF16("Test1"); |
| 3255 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1); | 3263 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1); |
| 3256 chrome::NewTab(browser()); | 3264 chrome::NewTab(browser()); |
| 3257 base::string16 title2 = ASCIIToUTF16("Test2"); | 3265 base::string16 title2 = ASCIIToUTF16("Test2"); |
| 3258 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title2); | 3266 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title2); |
| 3259 | 3267 |
| 3260 // Check that the menu is properly set. | 3268 // Check that the menu is properly set. |
| 3261 ash::ShelfItem item_gmail; | 3269 ash::ShelfItem item_gmail; |
| 3262 item_gmail.type = ash::TYPE_APP_SHORTCUT; | 3270 item_gmail.type = ash::TYPE_APP_SHORTCUT; |
| 3263 item_gmail.id = gmail_id; | 3271 item_gmail.id = gmail_id; |
| 3264 base::string16 two_menu_items[] = {title1, title2}; | 3272 base::string16 two_menu_items[] = {title1, title2}; |
| 3265 CheckAppMenu(launcher_controller_.get(), item_gmail, 2, two_menu_items); | 3273 CheckAppMenu(launcher_controller_.get(), item_gmail, 2, two_menu_items); |
| 3266 | 3274 |
| 3275 LauncherItemController* item_controller = |
| 3276 launcher_controller_->GetLauncherItemController(gmail_id); |
| 3277 ASSERT_TRUE(item_controller); |
| 3267 int tabs = browser()->tab_strip_model()->count(); | 3278 int tabs = browser()->tab_strip_model()->count(); |
| 3268 // Activate the proper tab through the menu item. | 3279 // Activate the proper tab through the menu item. |
| 3269 { | 3280 { |
| 3270 ash::ShelfAppMenuItemList items = | 3281 ash::ShelfAppMenuItemList items = |
| 3271 launcher_controller_->GetAppMenuItems(item_gmail, 0); | 3282 launcher_controller_->GetAppMenuItemsForTesting(item_gmail); |
| 3272 items[1]->Execute(0); | 3283 item_controller->ExecuteCommand(items[1]->command_id(), ui::EF_NONE); |
| 3273 EXPECT_EQ(tabs, browser()->tab_strip_model()->count()); | 3284 EXPECT_EQ(tabs, browser()->tab_strip_model()->count()); |
| 3274 } | 3285 } |
| 3275 | 3286 |
| 3276 // Delete one tab through the menu item. | 3287 // Delete one tab through the menu item. |
| 3277 { | 3288 { |
| 3278 ash::ShelfAppMenuItemList items = | 3289 ash::ShelfAppMenuItemList items = |
| 3279 launcher_controller_->GetAppMenuItems(item_gmail, 0); | 3290 launcher_controller_->GetAppMenuItemsForTesting(item_gmail); |
| 3280 items[1]->Execute(ui::EF_SHIFT_DOWN); | 3291 item_controller->ExecuteCommand(items[1]->command_id(), ui::EF_SHIFT_DOWN); |
| 3281 EXPECT_EQ(--tabs, browser()->tab_strip_model()->count()); | 3292 EXPECT_EQ(--tabs, browser()->tab_strip_model()->count()); |
| 3282 } | 3293 } |
| 3283 } | 3294 } |
| 3284 | 3295 |
| 3285 // Tests that panels create launcher items correctly | 3296 // Tests that panels create launcher items correctly |
| 3286 TEST_F(ChromeLauncherControllerImplTest, AppPanels) { | 3297 TEST_F(ChromeLauncherControllerImplTest, AppPanels) { |
| 3287 InitLauncherController(); | 3298 InitLauncherController(); |
| 3288 model_observer_->clear_counts(); | 3299 model_observer_->clear_counts(); |
| 3289 const std::string app_id = extension1_->id(); | 3300 const std::string app_id = extension1_->id(); |
| 3290 | 3301 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3348 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type); | 3359 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type); |
| 3349 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); | 3360 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); |
| 3350 | 3361 |
| 3351 // Check that it is now handled. | 3362 // Check that it is now handled. |
| 3352 EXPECT_TRUE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); | 3363 EXPECT_TRUE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); |
| 3353 | 3364 |
| 3354 // Check also that the app has detected that properly. | 3365 // Check also that the app has detected that properly. |
| 3355 ash::ShelfItem item_gmail; | 3366 ash::ShelfItem item_gmail; |
| 3356 item_gmail.type = ash::TYPE_APP_SHORTCUT; | 3367 item_gmail.type = ash::TYPE_APP_SHORTCUT; |
| 3357 item_gmail.id = gmail_id; | 3368 item_gmail.id = gmail_id; |
| 3358 EXPECT_EQ(1U, launcher_controller_->GetAppMenuItems(item_gmail, 0).size()); | 3369 EXPECT_EQ(1U, |
| 3370 launcher_controller_->GetAppMenuItemsForTesting(item_gmail).size()); |
| 3359 } | 3371 } |
| 3360 | 3372 |
| 3361 // Tests that the Gmail extension does not match the offline verison. | 3373 // Tests that the Gmail extension does not match the offline verison. |
| 3362 TEST_F(ChromeLauncherControllerImplTest, GmailOfflineMatching) { | 3374 TEST_F(ChromeLauncherControllerImplTest, GmailOfflineMatching) { |
| 3363 InitLauncherControllerWithBrowser(); | 3375 InitLauncherControllerWithBrowser(); |
| 3364 | 3376 |
| 3365 // Create a Gmail browser tab. | 3377 // Create a Gmail browser tab. |
| 3366 chrome::NewTab(browser()); | 3378 chrome::NewTab(browser()); |
| 3367 base::string16 title = ASCIIToUTF16("Test"); | 3379 base::string16 title = ASCIIToUTF16("Test"); |
| 3368 NavigateAndCommitActiveTabWithTitle(browser(), | 3380 NavigateAndCommitActiveTabWithTitle(browser(), |
| (...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4210 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, | 4222 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, |
| 4211 shelf_controller->auto_hide()); | 4223 shelf_controller->auto_hide()); |
| 4212 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count()); | 4224 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count()); |
| 4213 | 4225 |
| 4214 PrefService* prefs = profile()->GetTestingPrefService(); | 4226 PrefService* prefs = profile()->GetTestingPrefService(); |
| 4215 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal)); | 4227 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal)); |
| 4216 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment)); | 4228 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment)); |
| 4217 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal)); | 4229 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal)); |
| 4218 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior)); | 4230 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior)); |
| 4219 } | 4231 } |
| OLD | NEW |