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

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

Issue 2540433002: Reland "Propagate information about how ARC apps are launched" (Closed)
Patch Set: Fixed use-after-free Created 4 years 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_impl.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 <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 #include "extensions/browser/app_window/native_app_window.h" 98 #include "extensions/browser/app_window/native_app_window.h"
99 #include "extensions/common/extension.h" 99 #include "extensions/common/extension.h"
100 #include "extensions/common/manifest_constants.h" 100 #include "extensions/common/manifest_constants.h"
101 #include "testing/gtest/include/gtest/gtest.h" 101 #include "testing/gtest/include/gtest/gtest.h"
102 #include "ui/aura/client/window_parenting_client.h" 102 #include "ui/aura/client/window_parenting_client.h"
103 #include "ui/aura/window.h" 103 #include "ui/aura/window.h"
104 #include "ui/base/models/menu_model.h" 104 #include "ui/base/models/menu_model.h"
105 #include "ui/display/display.h" 105 #include "ui/display/display.h"
106 #include "ui/display/display_switches.h" 106 #include "ui/display/display_switches.h"
107 #include "ui/display/screen.h" 107 #include "ui/display/screen.h"
108 #include "ui/events/event_constants.h"
108 #include "ui/views/widget/widget.h" 109 #include "ui/views/widget/widget.h"
109 110
110 using base::ASCIIToUTF16; 111 using base::ASCIIToUTF16;
111 using extensions::Extension; 112 using extensions::Extension;
112 using extensions::Manifest; 113 using extensions::Manifest;
113 using extensions::UnloadedExtensionInfo; 114 using extensions::UnloadedExtensionInfo;
114 using arc::mojom::OrientationLock; 115 using arc::mojom::OrientationLock;
115 116
116 namespace { 117 namespace {
117 const char* offline_gmail_url = "https://mail.google.com/mail/mu/u"; 118 const char* offline_gmail_url = "https://mail.google.com/mail/mu/u";
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 bool arc_managed, 814 bool arc_managed,
814 arc::ArcSessionManager::State state, 815 arc::ArcSessionManager::State state,
815 const std::string& pin_status) { 816 const std::string& pin_status) {
816 EXPECT_EQ(arc_managed, arc_test_.arc_session_manager()->IsArcManaged()); 817 EXPECT_EQ(arc_managed, arc_test_.arc_session_manager()->IsArcManaged());
817 EXPECT_EQ(arc_enabled, arc_test_.arc_session_manager()->IsArcEnabled()); 818 EXPECT_EQ(arc_enabled, arc_test_.arc_session_manager()->IsArcEnabled());
818 EXPECT_EQ(state, arc_test_.arc_session_manager()->state()); 819 EXPECT_EQ(state, arc_test_.arc_session_manager()->state());
819 EXPECT_EQ(pin_status, GetPinnedAppStatus()); 820 EXPECT_EQ(pin_status, GetPinnedAppStatus());
820 } 821 }
821 822
822 // Creates app window and set optional Arc application id. 823 // Creates app window and set optional Arc application id.
823 views::Widget* CreateArcWindow(std::string& window_app_id) { 824 views::Widget* CreateArcWindow(const std::string& window_app_id) {
824 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 825 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
825 params.bounds = gfx::Rect(5, 5, 20, 20); 826 params.bounds = gfx::Rect(5, 5, 20, 20);
826 params.context = GetContext(); 827 params.context = GetContext();
827 views::Widget* widget = new views::Widget(); 828 views::Widget* widget = new views::Widget();
828 widget->Init(params); 829 widget->Init(params);
829 // Set Arc id before showing the window to be recognized in 830 // Set Arc id before showing the window to be recognized in
830 // ArcAppWindowLauncherController. 831 // ArcAppWindowLauncherController.
831 exo::ShellSurface::SetApplicationId(widget->GetNativeWindow(), 832 exo::ShellSurface::SetApplicationId(widget->GetNativeWindow(),
832 window_app_id); 833 window_app_id);
833 widget->Show(); 834 widget->Show();
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 1198
1198 ash::test::TestShellDelegate* shell_delegate_; 1199 ash::test::TestShellDelegate* shell_delegate_;
1199 1200
1200 ProfileToNameMap created_profiles_; 1201 ProfileToNameMap created_profiles_;
1201 1202
1202 DISALLOW_COPY_AND_ASSIGN( 1203 DISALLOW_COPY_AND_ASSIGN(
1203 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest); 1204 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest);
1204 }; 1205 };
1205 1206
1206 class ChromeLauncherControllerImplMultiProfileWithArcTest 1207 class ChromeLauncherControllerImplMultiProfileWithArcTest
1207 : public MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest { 1208 : public MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest { // NOLINT(whitespace/line_length)
1208 protected: 1209 protected:
1209 ChromeLauncherControllerImplMultiProfileWithArcTest() { 1210 ChromeLauncherControllerImplMultiProfileWithArcTest() {
1210 auto_start_arc_test_ = true; 1211 auto_start_arc_test_ = true;
1211 } 1212 }
1212 ~ChromeLauncherControllerImplMultiProfileWithArcTest() override {} 1213 ~ChromeLauncherControllerImplMultiProfileWithArcTest() override {}
1213 1214
1214 private: 1215 private:
1215 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerImplMultiProfileWithArcTest); 1216 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerImplMultiProfileWithArcTest);
1216 }; 1217 };
1217 1218
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 1777
1777 arc_test_.StopArcInstance(); 1778 arc_test_.StopArcInstance();
1778 1779
1779 EXPECT_EQ(ash::kInvalidShelfID, 1780 EXPECT_EQ(ash::kInvalidShelfID,
1780 launcher_controller_->GetShelfIDForAppID(arc_app_id1)); 1781 launcher_controller_->GetShelfIDForAppID(arc_app_id1));
1781 EXPECT_EQ(ash::kInvalidShelfID, 1782 EXPECT_EQ(ash::kInvalidShelfID,
1782 launcher_controller_->GetShelfIDForAppID(arc_app_id2)); 1783 launcher_controller_->GetShelfIDForAppID(arc_app_id2));
1783 EXPECT_EQ(ash::kInvalidShelfID, 1784 EXPECT_EQ(ash::kInvalidShelfID,
1784 launcher_controller_->GetShelfIDForAppID(arc_app_id3)); 1785 launcher_controller_->GetShelfIDForAppID(arc_app_id3));
1785 1786
1786 arc::LaunchApp(profile(), arc_app_id1); 1787 arc::LaunchApp(profile(), arc_app_id1, ui::EF_LEFT_MOUSE_BUTTON);
1787 arc::LaunchApp(profile(), arc_app_id1); 1788 arc::LaunchApp(profile(), arc_app_id1, ui::EF_LEFT_MOUSE_BUTTON);
1788 arc::LaunchApp(profile(), arc_app_id2); 1789 arc::LaunchApp(profile(), arc_app_id2, ui::EF_LEFT_MOUSE_BUTTON);
1789 arc::LaunchApp(profile(), arc_app_id3); 1790 arc::LaunchApp(profile(), arc_app_id3, ui::EF_LEFT_MOUSE_BUTTON);
1790 arc::LaunchApp(profile(), arc_app_id3); 1791 arc::LaunchApp(profile(), arc_app_id3, ui::EF_LEFT_MOUSE_BUTTON);
1791 1792
1792 const ash::ShelfID shelf_id_app_1 = 1793 const ash::ShelfID shelf_id_app_1 =
1793 launcher_controller_->GetShelfIDForAppID(arc_app_id1); 1794 launcher_controller_->GetShelfIDForAppID(arc_app_id1);
1794 const ash::ShelfID shelf_id_app_2 = 1795 const ash::ShelfID shelf_id_app_2 =
1795 launcher_controller_->GetShelfIDForAppID(arc_app_id2); 1796 launcher_controller_->GetShelfIDForAppID(arc_app_id2);
1796 const ash::ShelfID shelf_id_app_3 = 1797 const ash::ShelfID shelf_id_app_3 =
1797 launcher_controller_->GetShelfIDForAppID(arc_app_id3); 1798 launcher_controller_->GetShelfIDForAppID(arc_app_id3);
1798 EXPECT_NE(ash::kInvalidShelfID, shelf_id_app_1); 1799 EXPECT_NE(ash::kInvalidShelfID, shelf_id_app_1);
1799 EXPECT_NE(ash::kInvalidShelfID, shelf_id_app_2); 1800 EXPECT_NE(ash::kInvalidShelfID, shelf_id_app_2);
1800 EXPECT_NE(ash::kInvalidShelfID, shelf_id_app_3); 1801 EXPECT_NE(ash::kInvalidShelfID, shelf_id_app_3);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1938 arc_test_.app_instance()->SendTaskCreated(3, arc_test_.fake_apps()[0]); 1939 arc_test_.app_instance()->SendTaskCreated(3, arc_test_.fake_apps()[0]);
1939 EXPECT_NE(ash::kInvalidShelfID, 1940 EXPECT_NE(ash::kInvalidShelfID,
1940 launcher_controller_->GetShelfIDForAppID(arc_app_id)); 1941 launcher_controller_->GetShelfIDForAppID(arc_app_id));
1941 arc_test_.StopArcInstance(); 1942 arc_test_.StopArcInstance();
1942 base::RunLoop().RunUntilIdle(); 1943 base::RunLoop().RunUntilIdle();
1943 EXPECT_EQ(ash::kInvalidShelfID, 1944 EXPECT_EQ(ash::kInvalidShelfID,
1944 launcher_controller_->GetShelfIDForAppID(arc_app_id)); 1945 launcher_controller_->GetShelfIDForAppID(arc_app_id));
1945 } 1946 }
1946 1947
1947 // Test race creation/deletion of Arc app. 1948 // Test race creation/deletion of Arc app.
1948 // TODO (khmel): Remove after moving everything to wayland protocol. 1949 // TODO(khmel): Remove after moving everything to wayland protocol.
1949 TEST_F(ChromeLauncherControllerImplWithArcTest, ArcRaceCreateClose) { 1950 TEST_F(ChromeLauncherControllerImplWithArcTest, ArcRaceCreateClose) {
1950 InitLauncherController(); 1951 InitLauncherController();
1951 1952
1952 const std::string arc_app_id1 = 1953 const std::string arc_app_id1 =
1953 ArcAppTest::GetAppId(arc_test_.fake_apps()[0]); 1954 ArcAppTest::GetAppId(arc_test_.fake_apps()[0]);
1954 const std::string arc_app_id2 = 1955 const std::string arc_app_id2 =
1955 ArcAppTest::GetAppId(arc_test_.fake_apps()[1]); 1956 ArcAppTest::GetAppId(arc_test_.fake_apps()[1]);
1956 SendListOfArcApps(); 1957 SendListOfArcApps();
1957 1958
1958 // Arc window created before and closed after mojom notification. 1959 // Arc window created before and closed after mojom notification.
(...skipping 1999 matching lines...) Expand 10 before | Expand all | Expand 10 after
3958 3959
3959 ArcAppListPrefs* const prefs = arc_test_.arc_app_list_prefs(); 3960 ArcAppListPrefs* const prefs = arc_test_.arc_app_list_prefs();
3960 EnableArc(false); 3961 EnableArc(false);
3961 EXPECT_FALSE(arc_test_.arc_session_manager()->IsArcEnabled()); 3962 EXPECT_FALSE(arc_test_.arc_session_manager()->IsArcEnabled());
3962 ASSERT_TRUE(prefs->GetAppIds().size()); 3963 ASSERT_TRUE(prefs->GetAppIds().size());
3963 3964
3964 const std::string app_id = 3965 const std::string app_id =
3965 ArcAppTest::GetAppId(arc_test_.fake_default_apps()[0]); 3966 ArcAppTest::GetAppId(arc_test_.fake_default_apps()[0]);
3966 EXPECT_EQ(ash::kInvalidShelfID, 3967 EXPECT_EQ(ash::kInvalidShelfID,
3967 launcher_controller_->GetShelfIDForAppID(app_id)); 3968 launcher_controller_->GetShelfIDForAppID(app_id));
3968 EXPECT_TRUE(arc::LaunchApp(profile(), app_id)); 3969 EXPECT_TRUE(arc::LaunchApp(profile(), app_id, ui::EF_LEFT_MOUSE_BUTTON));
3969 EXPECT_TRUE(arc_test_.arc_session_manager()->IsArcEnabled()); 3970 EXPECT_TRUE(arc_test_.arc_session_manager()->IsArcEnabled());
3970 EXPECT_NE(ash::kInvalidShelfID, 3971 EXPECT_NE(ash::kInvalidShelfID,
3971 launcher_controller_->GetShelfIDForAppID(app_id)); 3972 launcher_controller_->GetShelfIDForAppID(app_id));
3972 3973
3973 // Stop Arc again. Shelf item should go away. 3974 // Stop Arc again. Shelf item should go away.
3974 EnableArc(false); 3975 EnableArc(false);
3975 EXPECT_EQ(ash::kInvalidShelfID, 3976 EXPECT_EQ(ash::kInvalidShelfID,
3976 launcher_controller_->GetShelfIDForAppID(app_id)); 3977 launcher_controller_->GetShelfIDForAppID(app_id));
3977 3978
3978 EXPECT_TRUE(arc::LaunchApp(profile(), app_id)); 3979 EXPECT_TRUE(arc::LaunchApp(profile(), app_id, ui::EF_LEFT_MOUSE_BUTTON));
3979 EXPECT_TRUE(arc_test_.arc_session_manager()->IsArcEnabled()); 3980 EXPECT_TRUE(arc_test_.arc_session_manager()->IsArcEnabled());
3980 3981
3981 EXPECT_NE(ash::kInvalidShelfID, 3982 EXPECT_NE(ash::kInvalidShelfID,
3982 launcher_controller_->GetShelfIDForAppID(app_id)); 3983 launcher_controller_->GetShelfIDForAppID(app_id));
3983 EXPECT_TRUE(launcher_controller_->GetArcDeferredLauncher()->HasApp(app_id)); 3984 EXPECT_TRUE(launcher_controller_->GetArcDeferredLauncher()->HasApp(app_id));
3984 3985
3985 std::string window_app_id("org.chromium.arc.1"); 3986 std::string window_app_id("org.chromium.arc.1");
3986 CreateArcWindow(window_app_id); 3987 CreateArcWindow(window_app_id);
3987 arc_test_.app_instance()->SendTaskCreated(1, 3988 arc_test_.app_instance()->SendTaskCreated(1,
3988 arc_test_.fake_default_apps()[0]); 3989 arc_test_.fake_default_apps()[0]);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
4066 4067
4067 // Pinned state should not change. 4068 // Pinned state should not change.
4068 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); 4069 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus());
4069 launcher_controller_->UnpinAppWithID(extension2_->id()); 4070 launcher_controller_->UnpinAppWithID(extension2_->id());
4070 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 4071 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
4071 4072
4072 // Resume syncing and sync information overrides local copy. 4073 // Resume syncing and sync information overrides local copy.
4073 StartAppSyncService(copy_sync_list); 4074 StartAppSyncService(copy_sync_list);
4074 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); 4075 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus());
4075 } 4076 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698