Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc

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

Powered by Google App Engine
This is Rietveld 408576698