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