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

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

Powered by Google App Engine
This is Rietveld 408576698