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_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 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 account_id); | 1143 account_id); |
1144 GetFakeUserManager()->SwitchActiveUser(account_id); | 1144 GetFakeUserManager()->SwitchActiveUser(account_id); |
1145 chrome::MultiUserWindowManagerChromeOS* manager = | 1145 chrome::MultiUserWindowManagerChromeOS* manager = |
1146 static_cast<chrome::MultiUserWindowManagerChromeOS*>( | 1146 static_cast<chrome::MultiUserWindowManagerChromeOS*>( |
1147 chrome::MultiUserWindowManager::GetInstance()); | 1147 chrome::MultiUserWindowManager::GetInstance()); |
1148 manager->SetAnimationSpeedForTest( | 1148 manager->SetAnimationSpeedForTest( |
1149 chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED); | 1149 chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED); |
1150 manager->ActiveUserChanged(account_id); | 1150 manager->ActiveUserChanged(account_id); |
1151 launcher_controller_->browser_status_monitor_for_test()->ActiveUserChanged( | 1151 launcher_controller_->browser_status_monitor_for_test()->ActiveUserChanged( |
1152 account_id.GetUserEmail()); | 1152 account_id.GetUserEmail()); |
1153 launcher_controller_->app_window_controller_for_test()->ActiveUserChanged( | 1153 |
1154 account_id.GetUserEmail()); | 1154 for (const auto& controller : |
| 1155 launcher_controller_->app_window_controllers_for_test()) { |
| 1156 controller->ActiveUserChanged(account_id.GetUserEmail()); |
| 1157 } |
1155 } | 1158 } |
1156 | 1159 |
1157 // Creates a browser with a |profile| and load a tab with a |title| and |url|. | 1160 // Creates a browser with a |profile| and load a tab with a |title| and |url|. |
1158 std::unique_ptr<Browser> CreateBrowserAndTabWithProfile( | 1161 std::unique_ptr<Browser> CreateBrowserAndTabWithProfile( |
1159 Profile* profile, | 1162 Profile* profile, |
1160 const std::string& title, | 1163 const std::string& title, |
1161 const std::string& url) { | 1164 const std::string& url) { |
1162 std::unique_ptr<Browser> browser( | 1165 std::unique_ptr<Browser> browser( |
1163 CreateBrowserWithTestWindowForProfile(profile)); | 1166 CreateBrowserWithTestWindowForProfile(profile)); |
1164 chrome::NewTab(browser.get()); | 1167 chrome::NewTab(browser.get()); |
1165 | 1168 |
1166 browser->window()->Show(); | 1169 browser->window()->Show(); |
1167 NavigateAndCommitActiveTabWithTitle(browser.get(), GURL(url), | 1170 NavigateAndCommitActiveTabWithTitle(browser.get(), GURL(url), |
1168 ASCIIToUTF16(title)); | 1171 ASCIIToUTF16(title)); |
1169 return browser; | 1172 return browser; |
1170 } | 1173 } |
1171 | 1174 |
1172 // Creates a running V1 application. | 1175 // Creates a running V1 application. |
1173 // Note that with the use of the launcher_controller_helper as done below, | 1176 // Note that with the use of the launcher_controller_helper as done below, |
1174 // this is only usable with a single v1 application. | 1177 // this is only usable with a single v1 application. |
1175 V1App* CreateRunningV1App(Profile* profile, | 1178 V1App* CreateRunningV1App(Profile* profile, |
1176 const std::string& app_name, | 1179 const std::string& app_name, |
1177 const std::string& url) { | 1180 const std::string& url) { |
1178 V1App* v1_app = new V1App(profile, app_name); | 1181 V1App* v1_app = new V1App(profile, app_name); |
1179 // Create a new launcher controller helper and assign it to the launcher so | 1182 // Create a new launcher controller helper and assign it to the launcher so |
1180 // that this app gets properly detected. | 1183 // that this app gets properly detected. |
1181 // TODO(skuhne): Create a more intelligent launcher contrller helper that is | 1184 // TODO(skuhne): Create a more intelligent launcher controller helper that |
1182 // able to detect all running apps properly. | 1185 // is able to detect all running apps properly. |
1183 TestLauncherControllerHelper* helper = new TestLauncherControllerHelper; | 1186 TestLauncherControllerHelper* helper = new TestLauncherControllerHelper; |
1184 helper->SetAppID(v1_app->browser()->tab_strip_model()->GetWebContentsAt(0), | 1187 helper->SetAppID(v1_app->browser()->tab_strip_model()->GetWebContentsAt(0), |
1185 app_name); | 1188 app_name); |
1186 SetLauncherControllerHelper(helper); | 1189 SetLauncherControllerHelper(helper); |
1187 | 1190 |
1188 NavigateAndCommitActiveTabWithTitle( | 1191 NavigateAndCommitActiveTabWithTitle( |
1189 v1_app->browser(), GURL(url), ASCIIToUTF16("")); | 1192 v1_app->browser(), GURL(url), ASCIIToUTF16("")); |
1190 return v1_app; | 1193 return v1_app; |
1191 } | 1194 } |
1192 | 1195 |
(...skipping 23 matching lines...) Expand all Loading... |
1216 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | 1219 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
1217 | 1220 |
1218 ash::test::TestShellDelegate* shell_delegate_; | 1221 ash::test::TestShellDelegate* shell_delegate_; |
1219 | 1222 |
1220 ProfileToNameMap created_profiles_; | 1223 ProfileToNameMap created_profiles_; |
1221 | 1224 |
1222 DISALLOW_COPY_AND_ASSIGN( | 1225 DISALLOW_COPY_AND_ASSIGN( |
1223 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest); | 1226 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest); |
1224 }; | 1227 }; |
1225 | 1228 |
| 1229 class ChromeLauncherControllerImplMultiProfileWithArcTest |
| 1230 : public MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest
{ |
| 1231 protected: |
| 1232 ChromeLauncherControllerImplMultiProfileWithArcTest() { |
| 1233 auto_start_arc_test_ = true; |
| 1234 } |
| 1235 ~ChromeLauncherControllerImplMultiProfileWithArcTest() override {} |
| 1236 |
| 1237 private: |
| 1238 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerImplMultiProfileWithArcTest); |
| 1239 }; |
| 1240 |
1226 TEST_F(ChromeLauncherControllerImplTest, DefaultApps) { | 1241 TEST_F(ChromeLauncherControllerImplTest, DefaultApps) { |
1227 InitLauncherController(); | 1242 InitLauncherController(); |
1228 // Model should only contain the browser shortcut and app list items. | 1243 // Model should only contain the browser shortcut and app list items. |
1229 EXPECT_EQ(2, model_->item_count()); | 1244 EXPECT_EQ(2, model_->item_count()); |
1230 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); | 1245 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); |
1231 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); | 1246 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); |
1232 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); | 1247 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); |
1233 | 1248 |
1234 // Installing |extension3_| should add it to the launcher - behind the | 1249 // Installing |extension3_| should add it to the launcher - behind the |
1235 // chrome icon. | 1250 // chrome icon. |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1827 | 1842 |
1828 const arc::FakeAppInstance::Request* request1 = | 1843 const arc::FakeAppInstance::Request* request1 = |
1829 arc_test_.app_instance()->launch_requests()[0]; | 1844 arc_test_.app_instance()->launch_requests()[0]; |
1830 const arc::FakeAppInstance::Request* request2 = | 1845 const arc::FakeAppInstance::Request* request2 = |
1831 arc_test_.app_instance()->launch_requests()[1]; | 1846 arc_test_.app_instance()->launch_requests()[1]; |
1832 | 1847 |
1833 EXPECT_TRUE((request1->IsForApp(app2) && request2->IsForApp(app3)) || | 1848 EXPECT_TRUE((request1->IsForApp(app2) && request2->IsForApp(app3)) || |
1834 (request1->IsForApp(app3) && request2->IsForApp(app2))); | 1849 (request1->IsForApp(app3) && request2->IsForApp(app2))); |
1835 } | 1850 } |
1836 | 1851 |
| 1852 TEST_F(ChromeLauncherControllerImplMultiProfileWithArcTest, ArcMultiUser) { |
| 1853 SendListOfArcApps(); |
| 1854 |
| 1855 InitLauncherController(); |
| 1856 SetLauncherControllerHelper(new TestLauncherControllerHelper); |
| 1857 |
| 1858 // App1 exists all the time. |
| 1859 // App2 is created when primary user is active and destroyed when secondary |
| 1860 // user is active. |
| 1861 // App3 created when secondary user is active. |
| 1862 |
| 1863 const std::string user2 = "user2"; |
| 1864 TestingProfile* profile2 = CreateMultiUserProfile(user2); |
| 1865 const AccountId account_id( |
| 1866 multi_user_util::GetAccountIdFromProfile(profile())); |
| 1867 const AccountId account_id2( |
| 1868 multi_user_util::GetAccountIdFromProfile(profile2)); |
| 1869 |
| 1870 const std::string arc_app_id1 = |
| 1871 ArcAppTest::GetAppId(arc_test_.fake_apps()[0]); |
| 1872 const std::string arc_app_id2 = |
| 1873 ArcAppTest::GetAppId(arc_test_.fake_apps()[1]); |
| 1874 const std::string arc_app_id3 = |
| 1875 ArcAppTest::GetAppId(arc_test_.fake_apps()[2]); |
| 1876 |
| 1877 std::string window_app_id1("org.chromium.arc.1"); |
| 1878 views::Widget* arc_window1 = CreateArcWindow(window_app_id1); |
| 1879 arc_test_.app_instance()->SendTaskCreated(1, arc_test_.fake_apps()[0]); |
| 1880 EXPECT_NE(0, launcher_controller_->GetShelfIDForAppID(arc_app_id1)); |
| 1881 |
| 1882 std::string window_app_id2("org.chromium.arc.2"); |
| 1883 views::Widget* arc_window2 = CreateArcWindow(window_app_id2); |
| 1884 arc_test_.app_instance()->SendTaskCreated(2, arc_test_.fake_apps()[1]); |
| 1885 EXPECT_NE(0, launcher_controller_->GetShelfIDForAppID(arc_app_id2)); |
| 1886 |
| 1887 launcher_controller_->SetProfileForTest(profile2); |
| 1888 SwitchActiveUser(account_id2); |
| 1889 |
| 1890 EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(arc_app_id1)); |
| 1891 EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(arc_app_id2)); |
| 1892 |
| 1893 std::string window_app_id3("org.chromium.arc.3"); |
| 1894 views::Widget* arc_window3 = CreateArcWindow(window_app_id3); |
| 1895 arc_test_.app_instance()->SendTaskCreated(3, arc_test_.fake_apps()[2]); |
| 1896 EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(arc_app_id3)); |
| 1897 |
| 1898 arc_window2->CloseNow(); |
| 1899 arc_test_.app_instance()->SendTaskDestroyed(2); |
| 1900 |
| 1901 launcher_controller_->SetProfileForTest(profile()); |
| 1902 SwitchActiveUser(account_id); |
| 1903 |
| 1904 EXPECT_NE(0, launcher_controller_->GetShelfIDForAppID(arc_app_id1)); |
| 1905 EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(arc_app_id2)); |
| 1906 EXPECT_NE(0, launcher_controller_->GetShelfIDForAppID(arc_app_id3)); |
| 1907 |
| 1908 // Close active window to let test passes. |
| 1909 arc_window1->CloseNow(); |
| 1910 arc_window3->CloseNow(); |
| 1911 } |
| 1912 |
1837 TEST_F(ChromeLauncherControllerImplWithArcTest, ArcRunningApp) { | 1913 TEST_F(ChromeLauncherControllerImplWithArcTest, ArcRunningApp) { |
1838 InitLauncherController(); | 1914 InitLauncherController(); |
1839 | 1915 |
1840 const std::string arc_app_id = ArcAppTest::GetAppId(arc_test_.fake_apps()[0]); | 1916 const std::string arc_app_id = ArcAppTest::GetAppId(arc_test_.fake_apps()[0]); |
1841 SendListOfArcApps(); | 1917 SendListOfArcApps(); |
1842 EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(arc_app_id)); | 1918 EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(arc_app_id)); |
1843 | 1919 |
1844 // Normal flow, create/destroy tasks. | 1920 // Normal flow, create/destroy tasks. |
1845 std::string window_app_id1("org.chromium.arc.1"); | 1921 std::string window_app_id1("org.chromium.arc.1"); |
1846 std::string window_app_id2("org.chromium.arc.2"); | 1922 std::string window_app_id2("org.chromium.arc.2"); |
(...skipping 1986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3833 EXPECT_TRUE(launcher_controller_->GetArcDeferredLauncher()->HasApp(app_id)); | 3909 EXPECT_TRUE(launcher_controller_->GetArcDeferredLauncher()->HasApp(app_id)); |
3834 | 3910 |
3835 std::string window_app_id("org.chromium.arc.1"); | 3911 std::string window_app_id("org.chromium.arc.1"); |
3836 CreateArcWindow(window_app_id); | 3912 CreateArcWindow(window_app_id); |
3837 arc_test_.app_instance()->SendTaskCreated(1, | 3913 arc_test_.app_instance()->SendTaskCreated(1, |
3838 arc_test_.fake_default_apps()[0]); | 3914 arc_test_.fake_default_apps()[0]); |
3839 | 3915 |
3840 EXPECT_NE(0, launcher_controller_->GetShelfIDForAppID(app_id)); | 3916 EXPECT_NE(0, launcher_controller_->GetShelfIDForAppID(app_id)); |
3841 EXPECT_FALSE(launcher_controller_->GetArcDeferredLauncher()->HasApp(app_id)); | 3917 EXPECT_FALSE(launcher_controller_->GetArcDeferredLauncher()->HasApp(app_id)); |
3842 } | 3918 } |
OLD | NEW |