| 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.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "ash/public/cpp/shelf_item_delegate.h" | 9 #include "ash/public/cpp/shelf_item_delegate.h" |
| 10 #include "ash/public/cpp/window_properties.h" | 10 #include "ash/public/cpp/window_properties.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "chrome/browser/ui/browser_commands.h" | 44 #include "chrome/browser/ui/browser_commands.h" |
| 45 #include "chrome/browser/ui/browser_dialogs.h" | 45 #include "chrome/browser/ui/browser_dialogs.h" |
| 46 #include "chrome/browser/ui/browser_finder.h" | 46 #include "chrome/browser/ui/browser_finder.h" |
| 47 #include "chrome/browser/ui/browser_list.h" | 47 #include "chrome/browser/ui/browser_list.h" |
| 48 #include "chrome/browser/ui/browser_window.h" | 48 #include "chrome/browser/ui/browser_window.h" |
| 49 #include "chrome/browser/ui/chrome_pages.h" | 49 #include "chrome/browser/ui/chrome_pages.h" |
| 50 #include "chrome/browser/ui/extensions/app_launch_params.h" | 50 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| 51 #include "chrome/browser/ui/extensions/application_launch.h" | 51 #include "chrome/browser/ui/extensions/application_launch.h" |
| 52 #include "chrome/browser/ui/settings_window_manager.h" | 52 #include "chrome/browser/ui/settings_window_manager.h" |
| 53 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 53 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 54 #include "chrome/browser/ui/test/test_app_window_icon_observer.h" |
| 54 #include "chrome/browser/web_applications/web_app.h" | 55 #include "chrome/browser/web_applications/web_app.h" |
| 55 #include "chrome/common/chrome_switches.h" | 56 #include "chrome/common/chrome_switches.h" |
| 56 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 57 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 57 #include "chrome/test/base/ui_test_utils.h" | 58 #include "chrome/test/base/ui_test_utils.h" |
| 58 #include "components/crx_file/id_util.h" | 59 #include "components/crx_file/id_util.h" |
| 59 #include "content/public/browser/notification_service.h" | 60 #include "content/public/browser/notification_service.h" |
| 60 #include "content/public/browser/notification_source.h" | 61 #include "content/public/browser/notification_source.h" |
| 61 #include "content/public/browser/web_contents.h" | 62 #include "content/public/browser/web_contents.h" |
| 62 #include "content/public/test/browser_test_utils.h" | 63 #include "content/public/test/browser_test_utils.h" |
| 63 #include "extensions/browser/app_window/app_window.h" | 64 #include "extensions/browser/app_window/app_window.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 class TestEvent : public ui::Event { | 124 class TestEvent : public ui::Event { |
| 124 public: | 125 public: |
| 125 explicit TestEvent(ui::EventType type) | 126 explicit TestEvent(ui::EventType type) |
| 126 : ui::Event(type, base::TimeTicks(), 0) {} | 127 : ui::Event(type, base::TimeTicks(), 0) {} |
| 127 ~TestEvent() override {} | 128 ~TestEvent() override {} |
| 128 | 129 |
| 129 private: | 130 private: |
| 130 DISALLOW_COPY_AND_ASSIGN(TestEvent); | 131 DISALLOW_COPY_AND_ASSIGN(TestEvent); |
| 131 }; | 132 }; |
| 132 | 133 |
| 133 class TestAppWindowRegistryObserver | |
| 134 : public extensions::AppWindowRegistry::Observer { | |
| 135 public: | |
| 136 explicit TestAppWindowRegistryObserver(Profile* profile) | |
| 137 : profile_(profile), icon_updates_(0) { | |
| 138 extensions::AppWindowRegistry::Get(profile_)->AddObserver(this); | |
| 139 } | |
| 140 | |
| 141 ~TestAppWindowRegistryObserver() override { | |
| 142 extensions::AppWindowRegistry::Get(profile_)->RemoveObserver(this); | |
| 143 } | |
| 144 | |
| 145 // Overridden from AppWindowRegistry::Observer: | |
| 146 void OnAppWindowIconChanged(AppWindow* app_window) override { | |
| 147 ++icon_updates_; | |
| 148 } | |
| 149 | |
| 150 int icon_updates() { return icon_updates_; } | |
| 151 | |
| 152 private: | |
| 153 Profile* profile_; | |
| 154 int icon_updates_; | |
| 155 | |
| 156 DISALLOW_COPY_AND_ASSIGN(TestAppWindowRegistryObserver); | |
| 157 }; | |
| 158 | |
| 159 // Click the "All Apps" button from the app launcher start page. Assumes that | 134 // Click the "All Apps" button from the app launcher start page. Assumes that |
| 160 // the app launcher is open to the start page. | 135 // the app launcher is open to the start page. |
| 161 // |display_origin| is the top-left corner of the active display, in screen | 136 // |display_origin| is the top-left corner of the active display, in screen |
| 162 // coordinates. | 137 // coordinates. |
| 163 void ClickAllAppsButtonFromStartPage(ui::test::EventGenerator* generator, | 138 void ClickAllAppsButtonFromStartPage(ui::test::EventGenerator* generator, |
| 164 const gfx::Point& display_origin) { | 139 const gfx::Point& display_origin) { |
| 165 AppListServiceAshTestApi service_test; | 140 AppListServiceAshTestApi service_test; |
| 166 | 141 |
| 167 app_list::StartPageView* start_page_view = service_test.GetStartPageView(); | 142 app_list::StartPageView* start_page_view = service_test.GetStartPageView(); |
| 168 DCHECK(start_page_view); | 143 DCHECK(start_page_view); |
| (...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 ASSERT_EQ(item_count, shelf_model()->item_count()); | 821 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 847 const ash::ShelfItem& item1 = GetLastLauncherItem(); | 822 const ash::ShelfItem& item1 = GetLastLauncherItem(); |
| 848 ash::ShelfID item_id1 = item1.id; | 823 ash::ShelfID item_id1 = item1.id; |
| 849 EXPECT_EQ(ash::TYPE_APP, item1.type); | 824 EXPECT_EQ(ash::TYPE_APP, item1.type); |
| 850 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 825 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 851 | 826 |
| 852 ash::wm::ActivateWindow(browser()->window()->GetNativeWindow()); | 827 ash::wm::ActivateWindow(browser()->window()->GetNativeWindow()); |
| 853 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status); | 828 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status); |
| 854 } | 829 } |
| 855 | 830 |
| 856 // Flaky on Linux ChromiumOS bot -- crbug/720601. | |
| 857 // Test that opening an app sets the correct icon | 831 // Test that opening an app sets the correct icon |
| 858 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, DISABLED_SetIcon) { | 832 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, SetIcon) { |
| 859 TestAppWindowRegistryObserver test_observer(browser()->profile()); | 833 TestAppWindowIconObserver test_observer(browser()->profile()); |
| 860 | 834 |
| 861 // Enable experimental APIs to allow panel creation. | 835 // Enable experimental APIs to allow panel creation. |
| 862 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 836 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 863 extensions::switches::kEnableExperimentalExtensionApis); | 837 extensions::switches::kEnableExperimentalExtensionApis); |
| 864 | 838 |
| 865 int base_shelf_item_count = shelf_model()->item_count(); | 839 int base_shelf_item_count = shelf_model()->item_count(); |
| 866 ExtensionTestMessageListener completed_listener("Completed", false); | 840 ExtensionTestMessageListener ready_listener("ready", true); |
| 867 LoadAndLaunchPlatformApp("app_icon", "Launched"); | 841 LoadAndLaunchPlatformApp("app_icon", "Launched"); |
| 868 | 842 |
| 869 ASSERT_TRUE(completed_listener.WaitUntilSatisfied()); | 843 // Create panel window. |
| 844 ready_listener.WaitUntilSatisfied(); |
| 845 ready_listener.Reply("createPanelWindow"); |
| 846 ready_listener.Reset(); |
| 847 // Default app icon + extension icon updates. |
| 848 test_observer.WaitForIconUpdates(2); |
| 870 | 849 |
| 871 // Now wait until the WebContent has decoded the icons and chrome has | 850 // Set panel window icon. |
| 872 // processed it. This needs to be in a loop since the renderer runs in a | 851 ready_listener.WaitUntilSatisfied(); |
| 873 // different process. | 852 ready_listener.Reply("setPanelWindowIcon"); |
| 874 while (test_observer.icon_updates() < 4) { | 853 ready_listener.Reset(); |
| 875 base::RunLoop run_loop; | 854 // Custom icon update. |
| 876 run_loop.RunUntilIdle(); | 855 test_observer.WaitForIconUpdate(); |
| 877 } | 856 |
| 857 // Create non-shelf window. |
| 858 ready_listener.WaitUntilSatisfied(); |
| 859 ready_listener.Reply("createNonShelfWindow"); |
| 860 ready_listener.Reset(); |
| 861 // Default app icon + extension icon updates. |
| 862 test_observer.WaitForIconUpdates(2); |
| 863 |
| 864 // Create shelf window. |
| 865 ready_listener.WaitUntilSatisfied(); |
| 866 ready_listener.Reply("createShelfWindow"); |
| 867 ready_listener.Reset(); |
| 868 // Default app icon + extension icon updates. |
| 869 test_observer.WaitForIconUpdates(2); |
| 870 |
| 871 // Set shelf window icon. |
| 872 ready_listener.WaitUntilSatisfied(); |
| 873 ready_listener.Reply("setShelfWindowIcon"); |
| 874 ready_listener.Reset(); |
| 875 // Custom icon update. |
| 876 test_observer.WaitForIconUpdate(); |
| 878 | 877 |
| 879 // This test creates one app window, one app window with custom icon and one | 878 // This test creates one app window, one app window with custom icon and one |
| 880 // panel window. | 879 // panel window. |
| 881 int shelf_item_count = shelf_model()->item_count(); | 880 int shelf_item_count = shelf_model()->item_count(); |
| 882 ASSERT_EQ(base_shelf_item_count + 3, shelf_item_count); | 881 ASSERT_EQ(base_shelf_item_count + 3, shelf_item_count); |
| 883 // The Panel will be the last item, the app second-to-last. | 882 // The Panel will be the last item, the app second-to-last. |
| 884 const ash::ShelfItem& app_item = shelf_model()->items()[shelf_item_count - 3]; | 883 const ash::ShelfItem& app_item = shelf_model()->items()[shelf_item_count - 3]; |
| 885 const ash::ShelfItem& app_custom_icon_item = | 884 const ash::ShelfItem& app_custom_icon_item = |
| 886 shelf_model()->items()[shelf_item_count - 2]; | 885 shelf_model()->items()[shelf_item_count - 2]; |
| 887 const ash::ShelfItem& panel_item = | 886 const ash::ShelfItem& panel_item = |
| 888 shelf_model()->items()[shelf_item_count - 1]; | 887 shelf_model()->items()[shelf_item_count - 1]; |
| 889 | 888 |
| 890 // Icons for Apps are set by the AppWindowLauncherController, so | 889 // Icons for Apps are set by the AppWindowLauncherController, so |
| 891 // image_set_by_controller() should be set. | 890 // image_set_by_controller() should be set. |
| 892 const ash::ShelfItemDelegate* app_item_delegate = | 891 const ash::ShelfItemDelegate* app_item_delegate = |
| 893 GetShelfItemDelegate(app_item.id); | 892 GetShelfItemDelegate(app_item.id); |
| 894 ASSERT_TRUE(app_item_delegate); | 893 ASSERT_TRUE(app_item_delegate); |
| 895 EXPECT_FALSE(app_item_delegate->image_set_by_controller()); | 894 EXPECT_TRUE(app_item_delegate->image_set_by_controller()); |
| 896 | 895 |
| 897 const ash::ShelfItemDelegate* app_custom_icon_item_delegate = | 896 const ash::ShelfItemDelegate* app_custom_icon_item_delegate = |
| 898 GetShelfItemDelegate(app_custom_icon_item.id); | 897 GetShelfItemDelegate(app_custom_icon_item.id); |
| 899 ASSERT_TRUE(app_custom_icon_item_delegate); | 898 ASSERT_TRUE(app_custom_icon_item_delegate); |
| 900 EXPECT_TRUE(app_custom_icon_item_delegate->image_set_by_controller()); | 899 EXPECT_TRUE(app_custom_icon_item_delegate->image_set_by_controller()); |
| 901 | 900 |
| 902 // Ensure icon heights are correct (see test.js in app_icon/ test directory) | 901 // Ensure icon heights are correct (see test.js in app_icon/ test directory) |
| 902 #if defined(USE_ASH) |
| 903 EXPECT_EQ(ash::kShelfSize, app_item.image.height()); |
| 904 #else |
| 903 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALL, app_item.image.height()); | 905 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALL, app_item.image.height()); |
| 906 #endif |
| 904 EXPECT_EQ(extension_misc::EXTENSION_ICON_LARGE, | 907 EXPECT_EQ(extension_misc::EXTENSION_ICON_LARGE, |
| 905 app_custom_icon_item.image.height()); | 908 app_custom_icon_item.image.height()); |
| 906 EXPECT_EQ(64, panel_item.image.height()); | 909 EXPECT_EQ(64, panel_item.image.height()); |
| 910 |
| 911 // No more icon updates. |
| 912 base::RunLoop().RunUntilIdle(); |
| 913 EXPECT_EQ(8, test_observer.icon_updates()); |
| 914 |
| 915 // Exit. |
| 916 ready_listener.WaitUntilSatisfied(); |
| 917 ready_listener.Reply("exit"); |
| 918 ready_listener.Reset(); |
| 907 } | 919 } |
| 908 | 920 |
| 909 // Test that we can launch an app with a shortcut. | 921 // Test that we can launch an app with a shortcut. |
| 910 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchPinned) { | 922 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchPinned) { |
| 911 TabStripModel* tab_strip = browser()->tab_strip_model(); | 923 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 912 int tab_count = tab_strip->count(); | 924 int tab_count = tab_strip->count(); |
| 913 ash::ShelfID shortcut_id = CreateShortcut("app1"); | 925 ash::ShelfID shortcut_id = CreateShortcut("app1"); |
| 914 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); | 926 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); |
| 915 Shelf::ActivateShelfItem(model_->ItemIndexByID(shortcut_id)); | 927 Shelf::ActivateShelfItem(model_->ItemIndexByID(shortcut_id)); |
| 916 EXPECT_EQ(++tab_count, tab_strip->count()); | 928 EXPECT_EQ(++tab_count, tab_strip->count()); |
| (...skipping 1587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2504 | 2516 |
| 2505 // Chrome's ShelfModel should have AppList and browser items and delegates. | 2517 // Chrome's ShelfModel should have AppList and browser items and delegates. |
| 2506 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, ShelfModelInitialization) { | 2518 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, ShelfModelInitialization) { |
| 2507 ash::ShelfModel* model = controller_->shelf_model(); | 2519 ash::ShelfModel* model = controller_->shelf_model(); |
| 2508 EXPECT_EQ(2, model->item_count()); | 2520 EXPECT_EQ(2, model->item_count()); |
| 2509 EXPECT_EQ(ash::kAppListId, model->items()[0].id.app_id); | 2521 EXPECT_EQ(ash::kAppListId, model->items()[0].id.app_id); |
| 2510 EXPECT_TRUE(model->GetShelfItemDelegate(model->items()[0].id)); | 2522 EXPECT_TRUE(model->GetShelfItemDelegate(model->items()[0].id)); |
| 2511 EXPECT_EQ(extension_misc::kChromeAppId, model->items()[1].id.app_id); | 2523 EXPECT_EQ(extension_misc::kChromeAppId, model->items()[1].id.app_id); |
| 2512 EXPECT_TRUE(model->GetShelfItemDelegate(model->items()[1].id)); | 2524 EXPECT_TRUE(model->GetShelfItemDelegate(model->items()[1].id)); |
| 2513 } | 2525 } |
| OLD | NEW |