| 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.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 "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
| 10 #include "ash/common/shelf/shelf_constants.h" | 10 #include "ash/common/shelf/shelf_constants.h" |
| 11 #include "ash/common/shelf/shelf_model.h" | 11 #include "ash/common/shelf/shelf_model.h" |
| 12 #include "ash/common/wm/window_state.h" | 12 #include "ash/common/wm/window_state.h" |
| 13 #include "ash/shelf/shelf.h" | 13 #include "ash/shelf/shelf.h" |
| 14 #include "ash/shelf/shelf_button.h" | 14 #include "ash/shelf/shelf_button.h" |
| 15 #include "ash/shelf/shelf_util.h" | 15 #include "ash/shelf/shelf_util.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 #include "ui/events/event.h" | 76 #include "ui/events/event.h" |
| 77 #include "ui/events/event_constants.h" | 77 #include "ui/events/event_constants.h" |
| 78 #include "ui/events/test/event_generator.h" | 78 #include "ui/events/test/event_generator.h" |
| 79 | 79 |
| 80 using extensions::AppWindow; | 80 using extensions::AppWindow; |
| 81 using extensions::Extension; | 81 using extensions::Extension; |
| 82 using content::WebContents; | 82 using content::WebContents; |
| 83 | 83 |
| 84 namespace { | 84 namespace { |
| 85 | 85 |
| 86 ChromeLauncherControllerImpl* GetChromeLauncherControllerImpl() { |
| 87 return static_cast<ChromeLauncherControllerImpl*>( |
| 88 ChromeLauncherController::instance()); |
| 89 } |
| 90 |
| 86 class TestEvent : public ui::Event { | 91 class TestEvent : public ui::Event { |
| 87 public: | 92 public: |
| 88 explicit TestEvent(ui::EventType type) | 93 explicit TestEvent(ui::EventType type) |
| 89 : ui::Event(type, base::TimeTicks(), 0) {} | 94 : ui::Event(type, base::TimeTicks(), 0) {} |
| 90 ~TestEvent() override {} | 95 ~TestEvent() override {} |
| 91 | 96 |
| 92 private: | 97 private: |
| 93 DISALLOW_COPY_AND_ASSIGN(TestEvent); | 98 DISALLOW_COPY_AND_ASSIGN(TestEvent); |
| 94 }; | 99 }; |
| 95 | 100 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 class LauncherPlatformAppBrowserTest | 186 class LauncherPlatformAppBrowserTest |
| 182 : public extensions::PlatformAppBrowserTest { | 187 : public extensions::PlatformAppBrowserTest { |
| 183 protected: | 188 protected: |
| 184 LauncherPlatformAppBrowserTest() : shelf_(NULL), controller_(NULL) { | 189 LauncherPlatformAppBrowserTest() : shelf_(NULL), controller_(NULL) { |
| 185 } | 190 } |
| 186 | 191 |
| 187 ~LauncherPlatformAppBrowserTest() override {} | 192 ~LauncherPlatformAppBrowserTest() override {} |
| 188 | 193 |
| 189 void RunTestOnMainThreadLoop() override { | 194 void RunTestOnMainThreadLoop() override { |
| 190 shelf_ = ash::Shelf::ForPrimaryDisplay(); | 195 shelf_ = ash::Shelf::ForPrimaryDisplay(); |
| 191 controller_ = ChromeLauncherController::instance(); | 196 controller_ = GetChromeLauncherControllerImpl(); |
| 192 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop(); | 197 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop(); |
| 193 } | 198 } |
| 194 | 199 |
| 195 ash::ShelfModel* shelf_model() { | 200 ash::ShelfModel* shelf_model() { |
| 196 return ash::test::ShellTestApi(ash::Shell::GetInstance()).shelf_model(); | 201 return ash::test::ShellTestApi(ash::Shell::GetInstance()).shelf_model(); |
| 197 } | 202 } |
| 198 | 203 |
| 199 ash::ShelfID CreateAppShortcutLauncherItem(const std::string& name) { | 204 ash::ShelfID CreateAppShortcutLauncherItem(const std::string& name) { |
| 200 return controller_->CreateAppShortcutLauncherItem( | 205 return controller_->CreateAppShortcutLauncherItem( |
| 201 name, shelf_model()->item_count()); | 206 name, shelf_model()->item_count()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 230 } | 235 } |
| 231 return num_items; | 236 return num_items; |
| 232 } | 237 } |
| 233 | 238 |
| 234 // Activate the shelf item with the given |id|. | 239 // Activate the shelf item with the given |id|. |
| 235 void ActivateShelfItem(int id) { | 240 void ActivateShelfItem(int id) { |
| 236 shelf_->ActivateShelfItem(id); | 241 shelf_->ActivateShelfItem(id); |
| 237 } | 242 } |
| 238 | 243 |
| 239 ash::Shelf* shelf_; | 244 ash::Shelf* shelf_; |
| 240 ChromeLauncherController* controller_; | 245 ChromeLauncherControllerImpl* controller_; |
| 241 | 246 |
| 242 private: | 247 private: |
| 243 | 248 |
| 244 DISALLOW_COPY_AND_ASSIGN(LauncherPlatformAppBrowserTest); | 249 DISALLOW_COPY_AND_ASSIGN(LauncherPlatformAppBrowserTest); |
| 245 }; | 250 }; |
| 246 | 251 |
| 247 enum RipOffCommand { | 252 enum RipOffCommand { |
| 248 // Drag the item off the shelf and let the mouse go. | 253 // Drag the item off the shelf and let the mouse go. |
| 249 RIP_OFF_ITEM, | 254 RIP_OFF_ITEM, |
| 250 // Drag the item off the shelf, move the mouse back and then let go. | 255 // Drag the item off the shelf, move the mouse back and then let go. |
| 251 RIP_OFF_ITEM_AND_RETURN, | 256 RIP_OFF_ITEM_AND_RETURN, |
| 252 // Drag the item off the shelf and then issue a cancel command. | 257 // Drag the item off the shelf and then issue a cancel command. |
| 253 RIP_OFF_ITEM_AND_CANCEL, | 258 RIP_OFF_ITEM_AND_CANCEL, |
| 254 // Drag the item off the shelf and do not release the mouse. | 259 // Drag the item off the shelf and do not release the mouse. |
| 255 RIP_OFF_ITEM_AND_DONT_RELEASE_MOUSE, | 260 RIP_OFF_ITEM_AND_DONT_RELEASE_MOUSE, |
| 256 }; | 261 }; |
| 257 | 262 |
| 258 class ShelfAppBrowserTest : public ExtensionBrowserTest { | 263 class ShelfAppBrowserTest : public ExtensionBrowserTest { |
| 259 protected: | 264 protected: |
| 260 ShelfAppBrowserTest() : shelf_(NULL), model_(NULL), controller_(NULL) { | 265 ShelfAppBrowserTest() : shelf_(NULL), model_(NULL), controller_(NULL) { |
| 261 } | 266 } |
| 262 | 267 |
| 263 ~ShelfAppBrowserTest() override {} | 268 ~ShelfAppBrowserTest() override {} |
| 264 | 269 |
| 265 void RunTestOnMainThreadLoop() override { | 270 void RunTestOnMainThreadLoop() override { |
| 266 shelf_ = ash::Shelf::ForPrimaryDisplay(); | 271 shelf_ = ash::Shelf::ForPrimaryDisplay(); |
| 267 model_ = ash::test::ShellTestApi(ash::Shell::GetInstance()).shelf_model(); | 272 model_ = ash::test::ShellTestApi(ash::Shell::GetInstance()).shelf_model(); |
| 268 controller_ = ChromeLauncherController::instance(); | 273 controller_ = GetChromeLauncherControllerImpl(); |
| 269 return ExtensionBrowserTest::RunTestOnMainThreadLoop(); | 274 return ExtensionBrowserTest::RunTestOnMainThreadLoop(); |
| 270 } | 275 } |
| 271 | 276 |
| 272 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) { | 277 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) { |
| 273 LauncherItemController* item_controller = | 278 LauncherItemController* item_controller = |
| 274 controller_->GetBrowserShortcutLauncherItemController(); | 279 controller_->GetBrowserShortcutLauncherItemController(); |
| 275 int items = item_controller->GetApplicationList( | 280 int items = item_controller->GetApplicationList( |
| 276 show_all_tabs ? ui::EF_SHIFT_DOWN : 0).size(); | 281 show_all_tabs ? ui::EF_SHIFT_DOWN : 0).size(); |
| 277 // If we have at least one item, we have also a title which we remove here. | 282 // If we have at least one item, we have also a title which we remove here. |
| 278 return items ? (items - 1) : 0; | 283 return items ? (items - 1) : 0; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 DCHECK(root_window); | 387 DCHECK(root_window); |
| 383 return root_window; | 388 return root_window; |
| 384 } | 389 } |
| 385 | 390 |
| 386 bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { | 391 bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { |
| 387 return menu->GetIndexOfCommandId(command_id) != -1; | 392 return menu->GetIndexOfCommandId(command_id) != -1; |
| 388 } | 393 } |
| 389 | 394 |
| 390 ash::Shelf* shelf_; | 395 ash::Shelf* shelf_; |
| 391 ash::ShelfModel* model_; | 396 ash::ShelfModel* model_; |
| 392 ChromeLauncherController* controller_; | 397 ChromeLauncherControllerImpl* controller_; |
| 393 | 398 |
| 394 private: | 399 private: |
| 395 | |
| 396 DISALLOW_COPY_AND_ASSIGN(ShelfAppBrowserTest); | 400 DISALLOW_COPY_AND_ASSIGN(ShelfAppBrowserTest); |
| 397 }; | 401 }; |
| 398 | 402 |
| 399 class ShelfAppBrowserTestNoDefaultBrowser : public ShelfAppBrowserTest { | 403 class ShelfAppBrowserTestNoDefaultBrowser : public ShelfAppBrowserTest { |
| 400 protected: | 404 protected: |
| 401 ShelfAppBrowserTestNoDefaultBrowser() {} | 405 ShelfAppBrowserTestNoDefaultBrowser() {} |
| 402 ~ShelfAppBrowserTestNoDefaultBrowser() override {} | 406 ~ShelfAppBrowserTestNoDefaultBrowser() override {} |
| 403 | 407 |
| 404 void SetUpCommandLine(base::CommandLine* command_line) override { | 408 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 405 ShelfAppBrowserTest::SetUpCommandLine(command_line); | 409 ShelfAppBrowserTest::SetUpCommandLine(command_line); |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 } | 897 } |
| 894 | 898 |
| 895 // Launches an app in the background and then tries to open it. This is test for | 899 // Launches an app in the background and then tries to open it. This is test for |
| 896 // a crash we had. | 900 // a crash we had. |
| 897 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchInBackground) { | 901 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchInBackground) { |
| 898 TabStripModel* tab_strip = browser()->tab_strip_model(); | 902 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 899 int tab_count = tab_strip->count(); | 903 int tab_count = tab_strip->count(); |
| 900 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_TAB, | 904 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_TAB, |
| 901 NEW_BACKGROUND_TAB); | 905 NEW_BACKGROUND_TAB); |
| 902 EXPECT_EQ(++tab_count, tab_strip->count()); | 906 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 903 ChromeLauncherController::instance()->LaunchApp(last_loaded_extension_id(), | 907 controller_->LaunchApp(last_loaded_extension_id(), |
| 904 ash::LAUNCH_FROM_UNKNOWN, | 908 ash::LAUNCH_FROM_UNKNOWN, |
| 905 0); | 909 0); |
| 906 } | 910 } |
| 907 | 911 |
| 908 // Confirm that clicking a icon for an app running in one of 2 maxmized windows | 912 // Confirm that clicking a icon for an app running in one of 2 maxmized windows |
| 909 // activates the right window. | 913 // activates the right window. |
| 910 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchMaximized) { | 914 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchMaximized) { |
| 911 aura::Window* window1 = browser()->window()->GetNativeWindow(); | 915 aura::Window* window1 = browser()->window()->GetNativeWindow(); |
| 912 ash::wm::WindowState* window1_state = ash::wm::GetWindowState(window1); | 916 ash::wm::WindowState* window1_state = ash::wm::GetWindowState(window1); |
| 913 window1_state->Maximize(); | 917 window1_state->Maximize(); |
| 914 content::WindowedNotificationObserver open_observer( | 918 content::WindowedNotificationObserver open_observer( |
| 915 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 919 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 935 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); | 939 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); |
| 936 } | 940 } |
| 937 | 941 |
| 938 // Activating the same app multiple times should launch only a single copy. | 942 // Activating the same app multiple times should launch only a single copy. |
| 939 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, ActivateApp) { | 943 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, ActivateApp) { |
| 940 TabStripModel* tab_strip = browser()->tab_strip_model(); | 944 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 941 int tab_count = tab_strip->count(); | 945 int tab_count = tab_strip->count(); |
| 942 const Extension* extension = | 946 const Extension* extension = |
| 943 LoadExtension(test_data_dir_.AppendASCII("app1")); | 947 LoadExtension(test_data_dir_.AppendASCII("app1")); |
| 944 | 948 |
| 945 ChromeLauncherController::instance()->ActivateApp(extension->id(), | 949 controller_->ActivateApp(extension->id(), |
| 946 ash::LAUNCH_FROM_UNKNOWN, | 950 ash::LAUNCH_FROM_UNKNOWN, |
| 947 0); | 951 0); |
| 948 EXPECT_EQ(++tab_count, tab_strip->count()); | 952 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 949 ChromeLauncherController::instance()->ActivateApp(extension->id(), | 953 controller_->ActivateApp(extension->id(), |
| 950 ash::LAUNCH_FROM_UNKNOWN, | 954 ash::LAUNCH_FROM_UNKNOWN, |
| 951 0); | 955 0); |
| 952 EXPECT_EQ(tab_count, tab_strip->count()); | 956 EXPECT_EQ(tab_count, tab_strip->count()); |
| 953 } | 957 } |
| 954 | 958 |
| 955 // Launching the same app multiple times should launch a copy for each call. | 959 // Launching the same app multiple times should launch a copy for each call. |
| 956 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchApp) { | 960 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchApp) { |
| 957 TabStripModel* tab_strip = browser()->tab_strip_model(); | 961 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 958 int tab_count = tab_strip->count(); | 962 int tab_count = tab_strip->count(); |
| 959 const Extension* extension = | 963 const Extension* extension = |
| 960 LoadExtension(test_data_dir_.AppendASCII("app1")); | 964 LoadExtension(test_data_dir_.AppendASCII("app1")); |
| 961 | 965 |
| 962 ChromeLauncherController::instance()->LaunchApp(extension->id(), | 966 controller_->LaunchApp(extension->id(), |
| 963 ash::LAUNCH_FROM_UNKNOWN, | 967 ash::LAUNCH_FROM_UNKNOWN, |
| 964 0); | 968 0); |
| 965 EXPECT_EQ(++tab_count, tab_strip->count()); | 969 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 966 ChromeLauncherController::instance()->LaunchApp(extension->id(), | 970 controller_->LaunchApp(extension->id(), |
| 967 ash::LAUNCH_FROM_UNKNOWN, | 971 ash::LAUNCH_FROM_UNKNOWN, |
| 968 0); | 972 0); |
| 969 EXPECT_EQ(++tab_count, tab_strip->count()); | 973 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 970 } | 974 } |
| 971 | 975 |
| 972 // Launch 2 apps and toggle which is active. | 976 // Launch 2 apps and toggle which is active. |
| 973 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, MultipleApps) { | 977 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, MultipleApps) { |
| 974 int item_count = model_->item_count(); | 978 int item_count = model_->item_count(); |
| 975 TabStripModel* tab_strip = browser()->tab_strip_model(); | 979 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 976 int tab_count = tab_strip->count(); | 980 int tab_count = tab_strip->count(); |
| 977 ash::ShelfID shortcut1 = CreateShortcut("app1"); | 981 ash::ShelfID shortcut1 = CreateShortcut("app1"); |
| 978 EXPECT_EQ(++item_count, model_->item_count()); | 982 EXPECT_EQ(++item_count, model_->item_count()); |
| (...skipping 1312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2291 // Close all windows. | 2295 // Close all windows. |
| 2292 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); | 2296 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); |
| 2293 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); | 2297 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); |
| 2294 | 2298 |
| 2295 // Check if "Close" is removed from the context menu. | 2299 // Check if "Close" is removed from the context menu. |
| 2296 std::unique_ptr<LauncherContextMenu> menu2 = | 2300 std::unique_ptr<LauncherContextMenu> menu2 = |
| 2297 CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT); | 2301 CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT); |
| 2298 ASSERT_FALSE( | 2302 ASSERT_FALSE( |
| 2299 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); | 2303 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); |
| 2300 } | 2304 } |
| OLD | NEW |