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

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

Issue 1428213004: This CL replaces std::string user_id in ash/* with AccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. Created 5 years, 1 month 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 <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 20 matching lines...) Expand all
31 #include "chrome/browser/ui/browser_commands.h" 31 #include "chrome/browser/ui/browser_commands.h"
32 #include "chrome/browser/ui/browser_finder.h" 32 #include "chrome/browser/ui/browser_finder.h"
33 #include "chrome/browser/ui/browser_list.h" 33 #include "chrome/browser/ui/browser_list.h"
34 #include "chrome/browser/ui/browser_tabstrip.h" 34 #include "chrome/browser/ui/browser_tabstrip.h"
35 #include "chrome/browser/ui/host_desktop.h" 35 #include "chrome/browser/ui/host_desktop.h"
36 #include "chrome/browser/ui/tabs/tab_strip_model.h" 36 #include "chrome/browser/ui/tabs/tab_strip_model.h"
37 #include "chrome/common/extensions/extension_constants.h" 37 #include "chrome/common/extensions/extension_constants.h"
38 #include "chrome/common/pref_names.h" 38 #include "chrome/common/pref_names.h"
39 #include "chrome/test/base/browser_with_test_window_test.h" 39 #include "chrome/test/base/browser_with_test_window_test.h"
40 #include "chrome/test/base/testing_profile.h" 40 #include "chrome/test/base/testing_profile.h"
41 #include "components/signin/core/account_id/account_id.h"
41 #include "components/syncable_prefs/testing_pref_service_syncable.h" 42 #include "components/syncable_prefs/testing_pref_service_syncable.h"
42 #include "content/public/browser/web_contents.h" 43 #include "content/public/browser/web_contents.h"
43 #include "extensions/common/extension.h" 44 #include "extensions/common/extension.h"
44 #include "extensions/common/manifest_constants.h" 45 #include "extensions/common/manifest_constants.h"
45 #include "testing/gtest/include/gtest/gtest.h" 46 #include "testing/gtest/include/gtest/gtest.h"
46 #include "ui/aura/client/window_tree_client.h" 47 #include "ui/aura/client/window_tree_client.h"
47 #include "ui/base/models/menu_model.h" 48 #include "ui/base/models/menu_model.h"
48 49
49 #if defined(OS_CHROMEOS) 50 #if defined(OS_CHROMEOS)
50 #include "ash/test/test_session_state_delegate.h" 51 #include "ash/test/test_session_state_delegate.h"
51 #include "ash/test/test_shell_delegate.h" 52 #include "ash/test/test_shell_delegate.h"
52 #include "chrome/browser/apps/scoped_keep_alive.h" 53 #include "chrome/browser/apps/scoped_keep_alive.h"
53 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" 54 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
54 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 55 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
55 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 56 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
56 #include "chrome/browser/ui/apps/chrome_app_delegate.h" 57 #include "chrome/browser/ui/apps/chrome_app_delegate.h"
57 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" 58 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h"
58 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" 59 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h"
59 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 60 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
60 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 61 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
61 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" 62 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h"
62 #include "chrome/common/chrome_constants.h" 63 #include "chrome/common/chrome_constants.h"
63 #include "chrome/common/chrome_switches.h" 64 #include "chrome/common/chrome_switches.h"
64 #include "chrome/test/base/testing_browser_process.h" 65 #include "chrome/test/base/testing_browser_process.h"
65 #include "chrome/test/base/testing_profile_manager.h" 66 #include "chrome/test/base/testing_profile_manager.h"
66 #include "components/signin/core/account_id/account_id.h"
67 #include "components/user_manager/fake_user_manager.h" 67 #include "components/user_manager/fake_user_manager.h"
68 #include "content/public/browser/web_contents_observer.h" 68 #include "content/public/browser/web_contents_observer.h"
69 #include "content/public/test/test_utils.h" 69 #include "content/public/test/test_utils.h"
70 #include "extensions/browser/app_window/app_window_contents.h" 70 #include "extensions/browser/app_window/app_window_contents.h"
71 #include "extensions/browser/app_window/app_window_registry.h" 71 #include "extensions/browser/app_window/app_window_registry.h"
72 #include "extensions/browser/app_window/native_app_window.h" 72 #include "extensions/browser/app_window/native_app_window.h"
73 #include "ui/aura/window.h" 73 #include "ui/aura/window.h"
74 #endif 74 #endif
75 75
76 #if defined(USE_AURA) 76 #if defined(USE_AURA)
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 index); 604 index);
605 } 605 }
606 606
607 // Remember the order of unpinned but running applications for the current 607 // Remember the order of unpinned but running applications for the current
608 // user. 608 // user.
609 void RememberUnpinnedRunningApplicationOrder() { 609 void RememberUnpinnedRunningApplicationOrder() {
610 launcher_controller_->RememberUnpinnedRunningApplicationOrder(); 610 launcher_controller_->RememberUnpinnedRunningApplicationOrder();
611 } 611 }
612 612
613 // Restore the order of running but unpinned applications for a given user. 613 // Restore the order of running but unpinned applications for a given user.
614 void RestoreUnpinnedRunningApplicationOrder(const std::string& user_id) { 614 void RestoreUnpinnedRunningApplicationOrder(const AccountId& account_id) {
615 launcher_controller_->RestoreUnpinnedRunningApplicationOrder(user_id); 615 launcher_controller_->RestoreUnpinnedRunningApplicationOrder(
616 account_id.GetUserEmail());
616 } 617 }
617 618
618 // Needed for extension service & friends to work. 619 // Needed for extension service & friends to work.
619 scoped_refptr<Extension> extension1_; 620 scoped_refptr<Extension> extension1_;
620 scoped_refptr<Extension> extension2_; 621 scoped_refptr<Extension> extension2_;
621 scoped_refptr<Extension> extension3_; 622 scoped_refptr<Extension> extension3_;
622 scoped_refptr<Extension> extension4_; 623 scoped_refptr<Extension> extension4_;
623 scoped_refptr<Extension> extension5_; 624 scoped_refptr<Extension> extension5_;
624 scoped_refptr<Extension> extension6_; 625 scoped_refptr<Extension> extension6_;
625 scoped_refptr<Extension> extension7_; 626 scoped_refptr<Extension> extension7_;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 base::MessageLoop::current()->Run(); 807 base::MessageLoop::current()->Run();
807 } 808 }
808 809
809 // Creates a profile for a given |user_name|. Note that this class will keep 810 // Creates a profile for a given |user_name|. Note that this class will keep
810 // the ownership of the created object. 811 // the ownership of the created object.
811 TestingProfile* CreateMultiUserProfile(const std::string& user_name) { 812 TestingProfile* CreateMultiUserProfile(const std::string& user_name) {
812 const std::string email_string = user_name + "@example.com"; 813 const std::string email_string = user_name + "@example.com";
813 const AccountId account_id(AccountId::FromUserEmail(email_string)); 814 const AccountId account_id(AccountId::FromUserEmail(email_string));
814 static_cast<ash::test::TestSessionStateDelegate*>( 815 static_cast<ash::test::TestSessionStateDelegate*>(
815 ash::Shell::GetInstance()->session_state_delegate()) 816 ash::Shell::GetInstance()->session_state_delegate())
816 ->AddUser(account_id.GetUserEmail()); 817 ->AddUser(account_id);
817 // Add a user to the fake user manager. 818 // Add a user to the fake user manager.
818 session_delegate()->AddUser(account_id.GetUserEmail()); 819 session_delegate()->AddUser(account_id);
819 GetFakeUserManager()->AddUser(account_id); 820 GetFakeUserManager()->AddUser(account_id);
820 821
821 GetFakeUserManager()->LoginUser(account_id); 822 GetFakeUserManager()->LoginUser(account_id);
822 823
823 TestingProfile* profile = 824 TestingProfile* profile =
824 profile_manager()->CreateTestingProfile(account_id.GetUserEmail()); 825 profile_manager()->CreateTestingProfile(account_id.GetUserEmail());
825 EXPECT_TRUE(profile); 826 EXPECT_TRUE(profile);
826 827
827 // Remember the profile name so that we can destroy it upon destruction. 828 // Remember the profile name so that we can destroy it upon destruction.
828 created_profiles_[profile] = account_id.GetUserEmail(); 829 created_profiles_[profile] = account_id.GetUserEmail();
829 if (chrome::MultiUserWindowManager::GetInstance()) 830 if (chrome::MultiUserWindowManager::GetInstance())
830 chrome::MultiUserWindowManager::GetInstance()->AddUser(profile); 831 chrome::MultiUserWindowManager::GetInstance()->AddUser(profile);
831 if (launcher_controller_) 832 if (launcher_controller_)
832 launcher_controller_->AdditionalUserAddedToSession(profile); 833 launcher_controller_->AdditionalUserAddedToSession(profile);
833 return profile; 834 return profile;
834 } 835 }
835 836
836 // Switch to another user. 837 // Switch to another user.
837 void SwitchActiveUser(const std::string& name) { 838 void SwitchActiveUser(const AccountId& account_id) {
838 const AccountId account_id(AccountId::FromUserEmail(name)); 839 session_delegate()->SwitchActiveUser(account_id);
839 session_delegate()->SwitchActiveUser(account_id.GetUserEmail());
840 GetFakeUserManager()->SwitchActiveUser(account_id); 840 GetFakeUserManager()->SwitchActiveUser(account_id);
841 chrome::MultiUserWindowManagerChromeOS* manager = 841 chrome::MultiUserWindowManagerChromeOS* manager =
842 static_cast<chrome::MultiUserWindowManagerChromeOS*>( 842 static_cast<chrome::MultiUserWindowManagerChromeOS*>(
843 chrome::MultiUserWindowManager::GetInstance()); 843 chrome::MultiUserWindowManager::GetInstance());
844 manager->SetAnimationSpeedForTest( 844 manager->SetAnimationSpeedForTest(
845 chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED); 845 chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED);
846 manager->ActiveUserChanged(account_id.GetUserEmail()); 846 manager->ActiveUserChanged(account_id);
847 launcher_controller_->browser_status_monitor_for_test()->ActiveUserChanged( 847 launcher_controller_->browser_status_monitor_for_test()->ActiveUserChanged(
848 account_id.GetUserEmail()); 848 account_id.GetUserEmail());
849 launcher_controller_->app_window_controller_for_test()->ActiveUserChanged( 849 launcher_controller_->app_window_controller_for_test()->ActiveUserChanged(
850 account_id.GetUserEmail()); 850 account_id.GetUserEmail());
851 } 851 }
852 852
853 // Creates a browser with a |profile| and load a tab with a |title| and |url|. 853 // Creates a browser with a |profile| and load a tab with a |title| and |url|.
854 scoped_ptr<Browser> CreateBrowserAndTabWithProfile(Profile* profile, 854 scoped_ptr<Browser> CreateBrowserAndTabWithProfile(Profile* profile,
855 const std::string& title, 855 const std::string& title,
856 const std::string& url) { 856 const std::string& url) {
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 // Add a few running applications. 1276 // Add a few running applications.
1277 launcher_controller_->LockV1AppWithID(extension1_->id()); 1277 launcher_controller_->LockV1AppWithID(extension1_->id());
1278 launcher_controller_->LockV1AppWithID(extension2_->id()); 1278 launcher_controller_->LockV1AppWithID(extension2_->id());
1279 launcher_controller_->LockV1AppWithID(extension3_->id()); 1279 launcher_controller_->LockV1AppWithID(extension3_->id());
1280 EXPECT_EQ(5, model_->item_count()); 1280 EXPECT_EQ(5, model_->item_count());
1281 // Note that this not only checks the order of applications but also the 1281 // Note that this not only checks the order of applications but also the
1282 // running type. 1282 // running type.
1283 EXPECT_EQ("AppList, Chrome, app1, app2, app3", GetPinnedAppStatus()); 1283 EXPECT_EQ("AppList, Chrome, app1, app2, app3", GetPinnedAppStatus());
1284 1284
1285 // Remember the current order of applications for the current user. 1285 // Remember the current order of applications for the current user.
1286 const std::string& current_user_id = 1286 const AccountId& current_account_id =
1287 multi_user_util::GetUserIDFromProfile(profile()); 1287 multi_user_util::GetAccountIdFromProfile(profile());
1288 RememberUnpinnedRunningApplicationOrder(); 1288 RememberUnpinnedRunningApplicationOrder();
1289 1289
1290 // Switch some items and check that restoring a user which was not yet 1290 // Switch some items and check that restoring a user which was not yet
1291 // remembered changes nothing. 1291 // remembered changes nothing.
1292 model_->Move(2, 3); 1292 model_->Move(2, 3);
1293 EXPECT_EQ("AppList, Chrome, app2, app1, app3", GetPinnedAppStatus()); 1293 EXPECT_EQ("AppList, Chrome, app2, app1, app3", GetPinnedAppStatus());
1294 RestoreUnpinnedRunningApplicationOrder("second-fake-user@fake.com"); 1294 const AccountId second_fake_account_id(
1295 AccountId::FromUserEmail("second-fake-user@fake.com"));
1296 RestoreUnpinnedRunningApplicationOrder(second_fake_account_id);
1295 EXPECT_EQ("AppList, Chrome, app2, app1, app3", GetPinnedAppStatus()); 1297 EXPECT_EQ("AppList, Chrome, app2, app1, app3", GetPinnedAppStatus());
1296 1298
1297 // Restoring the stored user should however do the right thing. 1299 // Restoring the stored user should however do the right thing.
1298 RestoreUnpinnedRunningApplicationOrder(current_user_id); 1300 RestoreUnpinnedRunningApplicationOrder(current_account_id);
1299 EXPECT_EQ("AppList, Chrome, app1, app2, app3", GetPinnedAppStatus()); 1301 EXPECT_EQ("AppList, Chrome, app1, app2, app3", GetPinnedAppStatus());
1300 1302
1301 // Switch again some items and even delete one - making sure that the missing 1303 // Switch again some items and even delete one - making sure that the missing
1302 // item gets properly handled. 1304 // item gets properly handled.
1303 model_->Move(3, 4); 1305 model_->Move(3, 4);
1304 launcher_controller_->UnlockV1AppWithID(extension1_->id()); 1306 launcher_controller_->UnlockV1AppWithID(extension1_->id());
1305 EXPECT_EQ("AppList, Chrome, app3, app2", GetPinnedAppStatus()); 1307 EXPECT_EQ("AppList, Chrome, app3, app2", GetPinnedAppStatus());
1306 RestoreUnpinnedRunningApplicationOrder(current_user_id); 1308 RestoreUnpinnedRunningApplicationOrder(current_account_id);
1307 EXPECT_EQ("AppList, Chrome, app2, app3", GetPinnedAppStatus()); 1309 EXPECT_EQ("AppList, Chrome, app2, app3", GetPinnedAppStatus());
1308 1310
1309 // Check that removing more items does not crash and changes nothing. 1311 // Check that removing more items does not crash and changes nothing.
1310 launcher_controller_->UnlockV1AppWithID(extension2_->id()); 1312 launcher_controller_->UnlockV1AppWithID(extension2_->id());
1311 RestoreUnpinnedRunningApplicationOrder(current_user_id); 1313 RestoreUnpinnedRunningApplicationOrder(current_account_id);
1312 EXPECT_EQ("AppList, Chrome, app3", GetPinnedAppStatus()); 1314 EXPECT_EQ("AppList, Chrome, app3", GetPinnedAppStatus());
1313 launcher_controller_->UnlockV1AppWithID(extension3_->id()); 1315 launcher_controller_->UnlockV1AppWithID(extension3_->id());
1314 RestoreUnpinnedRunningApplicationOrder(current_user_id); 1316 RestoreUnpinnedRunningApplicationOrder(current_account_id);
1315 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 1317 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
1316 } 1318 }
1317 1319
1318 // Check that with multi profile V1 apps are properly added / removed from the 1320 // Check that with multi profile V1 apps are properly added / removed from the
1319 // shelf. 1321 // shelf.
1320 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 1322 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
1321 V1AppUpdateOnUserSwitch) { 1323 V1AppUpdateOnUserSwitch) {
1322 // Create a browser item in the LauncherController. 1324 // Create a browser item in the LauncherController.
1323 InitLauncherController(); 1325 InitLauncherController();
1324 EXPECT_EQ(2, model_->item_count()); 1326 EXPECT_EQ(2, model_->item_count());
1325 { 1327 {
1326 // Create a "windowed gmail app". 1328 // Create a "windowed gmail app".
1327 scoped_ptr<V1App> v1_app(CreateRunningV1App( 1329 scoped_ptr<V1App> v1_app(CreateRunningV1App(
1328 profile(), extension_misc::kGmailAppId, gmail_url)); 1330 profile(), extension_misc::kGmailAppId, gmail_url));
1329 EXPECT_EQ(3, model_->item_count()); 1331 EXPECT_EQ(3, model_->item_count());
1330 1332
1331 // After switching to a second user the item should be gone. 1333 // After switching to a second user the item should be gone.
1332 std::string user2 = "user2"; 1334 std::string user2 = "user2";
1333 TestingProfile* profile2 = CreateMultiUserProfile(user2); 1335 TestingProfile* profile2 = CreateMultiUserProfile(user2);
1334 SwitchActiveUser(profile2->GetProfileUserName()); 1336 const AccountId account_id2(
1337 multi_user_util::GetAccountIdFromProfile(profile2));
1338 const AccountId account_id(
1339 multi_user_util::GetAccountIdFromProfile(profile()));
1340 SwitchActiveUser(account_id2);
1335 EXPECT_EQ(2, model_->item_count()); 1341 EXPECT_EQ(2, model_->item_count());
1336 1342
1337 // After switching back the item should be back. 1343 // After switching back the item should be back.
1338 SwitchActiveUser(profile()->GetProfileUserName()); 1344 SwitchActiveUser(account_id);
1339 EXPECT_EQ(3, model_->item_count()); 1345 EXPECT_EQ(3, model_->item_count());
1340 // Note we destroy now the gmail app with the closure end. 1346 // Note we destroy now the gmail app with the closure end.
1341 } 1347 }
1342 EXPECT_EQ(2, model_->item_count()); 1348 EXPECT_EQ(2, model_->item_count());
1343 } 1349 }
1344 1350
1345 // Check edge cases with multi profile V1 apps in the shelf. 1351 // Check edge cases with multi profile V1 apps in the shelf.
1346 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 1352 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
1347 V1AppUpdateOnUserSwitchEdgecases) { 1353 V1AppUpdateOnUserSwitchEdgecases) {
1348 // Create a browser item in the LauncherController. 1354 // Create a browser item in the LauncherController.
1349 InitLauncherController(); 1355 InitLauncherController();
1350 1356
1351 // First test: Create an app when the user is not active. 1357 // First test: Create an app when the user is not active.
1352 std::string user2 = "user2"; 1358 std::string user2 = "user2";
1353 TestingProfile* profile2 = CreateMultiUserProfile(user2); 1359 TestingProfile* profile2 = CreateMultiUserProfile(user2);
1360 const AccountId account_id2(
1361 multi_user_util::GetAccountIdFromProfile(profile2));
1362 const AccountId account_id(
1363 multi_user_util::GetAccountIdFromProfile(profile()));
1354 { 1364 {
1355 // Create a "windowed gmail app". 1365 // Create a "windowed gmail app".
1356 scoped_ptr<V1App> v1_app(CreateRunningV1App( 1366 scoped_ptr<V1App> v1_app(CreateRunningV1App(
1357 profile2, extension_misc::kGmailAppId, gmail_url)); 1367 profile2, extension_misc::kGmailAppId, gmail_url));
1358 EXPECT_EQ(2, model_->item_count()); 1368 EXPECT_EQ(2, model_->item_count());
1359 1369
1360 // However - switching to the user should show it. 1370 // However - switching to the user should show it.
1361 SwitchActiveUser(profile2->GetProfileUserName()); 1371 SwitchActiveUser(account_id2);
1362 EXPECT_EQ(3, model_->item_count()); 1372 EXPECT_EQ(3, model_->item_count());
1363 1373
1364 // Second test: Remove the app when the user is not active and see that it 1374 // Second test: Remove the app when the user is not active and see that it
1365 // works. 1375 // works.
1366 SwitchActiveUser(profile()->GetProfileUserName()); 1376 SwitchActiveUser(account_id);
1367 EXPECT_EQ(2, model_->item_count()); 1377 EXPECT_EQ(2, model_->item_count());
1368 // Note: the closure ends and the browser will go away. 1378 // Note: the closure ends and the browser will go away.
1369 } 1379 }
1370 EXPECT_EQ(2, model_->item_count()); 1380 EXPECT_EQ(2, model_->item_count());
1371 SwitchActiveUser(profile2->GetProfileUserName()); 1381 SwitchActiveUser(account_id2);
1372 EXPECT_EQ(2, model_->item_count()); 1382 EXPECT_EQ(2, model_->item_count());
1373 SwitchActiveUser(profile()->GetProfileUserName()); 1383 SwitchActiveUser(account_id);
1374 EXPECT_EQ(2, model_->item_count()); 1384 EXPECT_EQ(2, model_->item_count());
1375 } 1385 }
1376 1386
1377 // Check edge case where a visiting V1 app gets closed (crbug.com/321374). 1387 // Check edge case where a visiting V1 app gets closed (crbug.com/321374).
1378 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 1388 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
1379 V1CloseOnVisitingDesktop) { 1389 V1CloseOnVisitingDesktop) {
1380 // Create a browser item in the LauncherController. 1390 // Create a browser item in the LauncherController.
1381 InitLauncherController(); 1391 InitLauncherController();
1382 1392
1383 chrome::MultiUserWindowManager* manager = 1393 chrome::MultiUserWindowManager* manager =
1384 chrome::MultiUserWindowManager::GetInstance(); 1394 chrome::MultiUserWindowManager::GetInstance();
1385 1395
1386 // First create an app when the user is active. 1396 // First create an app when the user is active.
1387 std::string user2 = "user2"; 1397 std::string user2 = "user2";
1388 TestingProfile* profile2 = CreateMultiUserProfile(user2); 1398 TestingProfile* profile2 = CreateMultiUserProfile(user2);
1399 const AccountId account_id(
1400 multi_user_util::GetAccountIdFromProfile(profile()));
1401 const AccountId account_id2(
1402 multi_user_util::GetAccountIdFromProfile(profile2));
1389 { 1403 {
1390 // Create a "windowed gmail app". 1404 // Create a "windowed gmail app".
1391 scoped_ptr<V1App> v1_app(CreateRunningV1App( 1405 scoped_ptr<V1App> v1_app(CreateRunningV1App(
1392 profile(), 1406 profile(),
1393 extension_misc::kGmailAppId, 1407 extension_misc::kGmailAppId,
1394 kGmailLaunchURL)); 1408 kGmailLaunchURL));
1395 EXPECT_EQ(3, model_->item_count()); 1409 EXPECT_EQ(3, model_->item_count());
1396 1410
1397 // Transfer the app to the other screen and switch users. 1411 // Transfer the app to the other screen and switch users.
1398 manager->ShowWindowForUser(v1_app->browser()->window()->GetNativeWindow(), 1412 manager->ShowWindowForUser(v1_app->browser()->window()->GetNativeWindow(),
1399 user2); 1413 account_id2);
1400 EXPECT_EQ(3, model_->item_count()); 1414 EXPECT_EQ(3, model_->item_count());
1401 SwitchActiveUser(profile2->GetProfileUserName()); 1415 SwitchActiveUser(account_id2);
1402 EXPECT_EQ(2, model_->item_count()); 1416 EXPECT_EQ(2, model_->item_count());
1403 } 1417 }
1404 // After the app was destroyed, switch back. (which caused already a crash). 1418 // After the app was destroyed, switch back. (which caused already a crash).
1405 SwitchActiveUser(profile()->GetProfileUserName()); 1419 SwitchActiveUser(account_id);
1406 1420
1407 // Create the same app again - which was also causing the crash. 1421 // Create the same app again - which was also causing the crash.
1408 EXPECT_EQ(2, model_->item_count()); 1422 EXPECT_EQ(2, model_->item_count());
1409 { 1423 {
1410 // Create a "windowed gmail app". 1424 // Create a "windowed gmail app".
1411 scoped_ptr<V1App> v1_app(CreateRunningV1App( 1425 scoped_ptr<V1App> v1_app(CreateRunningV1App(
1412 profile(), 1426 profile(),
1413 extension_misc::kGmailAppId, 1427 extension_misc::kGmailAppId,
1414 kGmailLaunchURL)); 1428 kGmailLaunchURL));
1415 EXPECT_EQ(3, model_->item_count()); 1429 EXPECT_EQ(3, model_->item_count());
1416 } 1430 }
1417 SwitchActiveUser(profile2->GetProfileUserName()); 1431 SwitchActiveUser(account_id2);
1418 EXPECT_EQ(2, model_->item_count()); 1432 EXPECT_EQ(2, model_->item_count());
1419 } 1433 }
1420 1434
1421 // Check edge cases with multi profile V1 apps in the shelf. 1435 // Check edge cases with multi profile V1 apps in the shelf.
1422 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 1436 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
1423 V1AppUpdateOnUserSwitchEdgecases2) { 1437 V1AppUpdateOnUserSwitchEdgecases2) {
1424 // Create a browser item in the LauncherController. 1438 // Create a browser item in the LauncherController.
1425 InitLauncherController(); 1439 InitLauncherController();
1426 TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl; 1440 TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl;
1427 SetAppTabHelper(app_tab_helper); 1441 SetAppTabHelper(app_tab_helper);
1428 1442
1429 // First test: Create an app when the user is not active. 1443 // First test: Create an app when the user is not active.
1430 std::string user2 = "user2"; 1444 std::string user2 = "user2";
1431 TestingProfile* profile2 = CreateMultiUserProfile(user2); 1445 TestingProfile* profile2 = CreateMultiUserProfile(user2);
1432 SwitchActiveUser(profile2->GetProfileUserName()); 1446 const AccountId account_id(
1447 multi_user_util::GetAccountIdFromProfile(profile()));
1448 const AccountId account_id2(
1449 multi_user_util::GetAccountIdFromProfile(profile2));
1450 SwitchActiveUser(account_id2);
1433 { 1451 {
1434 // Create a "windowed gmail app". 1452 // Create a "windowed gmail app".
1435 scoped_ptr<V1App> v1_app(CreateRunningV1App( 1453 scoped_ptr<V1App> v1_app(CreateRunningV1App(
1436 profile(), extension_misc::kGmailAppId, gmail_url)); 1454 profile(), extension_misc::kGmailAppId, gmail_url));
1437 EXPECT_EQ(2, model_->item_count()); 1455 EXPECT_EQ(2, model_->item_count());
1438 1456
1439 // However - switching to the user should show it. 1457 // However - switching to the user should show it.
1440 SwitchActiveUser(profile()->GetProfileUserName()); 1458 SwitchActiveUser(account_id);
1441 EXPECT_EQ(3, model_->item_count()); 1459 EXPECT_EQ(3, model_->item_count());
1442 1460
1443 // Second test: Remove the app when the user is not active and see that it 1461 // Second test: Remove the app when the user is not active and see that it
1444 // works. 1462 // works.
1445 SwitchActiveUser(profile2->GetProfileUserName()); 1463 SwitchActiveUser(account_id2);
1446 EXPECT_EQ(2, model_->item_count()); 1464 EXPECT_EQ(2, model_->item_count());
1447 v1_app.reset(); 1465 v1_app.reset();
1448 } 1466 }
1449 EXPECT_EQ(2, model_->item_count()); 1467 EXPECT_EQ(2, model_->item_count());
1450 SwitchActiveUser(profile()->GetProfileUserName()); 1468 SwitchActiveUser(account_id);
1451 EXPECT_EQ(2, model_->item_count()); 1469 EXPECT_EQ(2, model_->item_count());
1452 SwitchActiveUser(profile2->GetProfileUserName()); 1470 SwitchActiveUser(account_id2);
1453 EXPECT_EQ(2, model_->item_count()); 1471 EXPECT_EQ(2, model_->item_count());
1454 } 1472 }
1455 1473
1456 // Check that activating an item which is on another user's desktop, will bring 1474 // Check that activating an item which is on another user's desktop, will bring
1457 // it back. 1475 // it back.
1458 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 1476 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
1459 TestLauncherActivationPullsBackWindow) { 1477 TestLauncherActivationPullsBackWindow) {
1460 // Create a browser item in the LauncherController. 1478 // Create a browser item in the LauncherController.
1461 InitLauncherController(); 1479 InitLauncherController();
1462 chrome::MultiUserWindowManager* manager = 1480 chrome::MultiUserWindowManager* manager =
1463 chrome::MultiUserWindowManager::GetInstance(); 1481 chrome::MultiUserWindowManager::GetInstance();
1464 1482
1465 // Create a second test profile. The first is the one in profile() created in 1483 // Create a second test profile. The first is the one in profile() created in
1466 // BrowserWithTestWindowTest::SetUp(). 1484 // BrowserWithTestWindowTest::SetUp().
1467 // No need to add the profiles to the MultiUserWindowManager here. 1485 // No need to add the profiles to the MultiUserWindowManager here.
1468 // CreateMultiUserProfile() already does that. 1486 // CreateMultiUserProfile() already does that.
1469 TestingProfile* profile2 = CreateMultiUserProfile("user2"); 1487 TestingProfile* profile2 = CreateMultiUserProfile("user2");
1470 const std::string& current_user = 1488 const AccountId current_user =
1471 multi_user_util::GetUserIDFromProfile(profile()); 1489 multi_user_util::GetAccountIdFromProfile(profile());
1472 1490
1473 // Create a browser window with a native window for the current user. 1491 // Create a browser window with a native window for the current user.
1474 Browser::CreateParams params(profile(), chrome::HOST_DESKTOP_TYPE_ASH); 1492 Browser::CreateParams params(profile(), chrome::HOST_DESKTOP_TYPE_ASH);
1475 scoped_ptr<Browser> browser( 1493 scoped_ptr<Browser> browser(
1476 chrome::CreateBrowserWithAuraTestWindowForParams(nullptr, &params)); 1494 chrome::CreateBrowserWithAuraTestWindowForParams(nullptr, &params));
1477 BrowserWindow* browser_window = browser->window(); 1495 BrowserWindow* browser_window = browser->window();
1478 aura::Window* window = browser_window->GetNativeWindow(); 1496 aura::Window* window = browser_window->GetNativeWindow();
1479 manager->SetWindowOwner(window, current_user); 1497 manager->SetWindowOwner(window, current_user);
1480 1498
1481 // Check that an activation of the window on its owner's desktop does not 1499 // Check that an activation of the window on its owner's desktop does not
1482 // change the visibility to another user. 1500 // change the visibility to another user.
1483 launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window, false); 1501 launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window, false);
1484 EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user)); 1502 EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user));
1485 1503
1486 // Transfer the window to another user's desktop and check that activating it 1504 // Transfer the window to another user's desktop and check that activating it
1487 // does pull it back to that user. 1505 // does pull it back to that user.
1488 manager->ShowWindowForUser(window, 1506 manager->ShowWindowForUser(
1489 multi_user_util::GetUserIDFromProfile(profile2)); 1507 window, multi_user_util::GetAccountIdFromProfile(profile2));
1490 EXPECT_FALSE(manager->IsWindowOnDesktopOfUser(window, current_user)); 1508 EXPECT_FALSE(manager->IsWindowOnDesktopOfUser(window, current_user));
1491 launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window, false); 1509 launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window, false);
1492 EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user)); 1510 EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user));
1493 } 1511 }
1494 #endif 1512 #endif
1495 1513
1496 // Check that lock -> pin -> unlock -> unpin does properly transition. 1514 // Check that lock -> pin -> unlock -> unpin does properly transition.
1497 TEST_F(ChromeLauncherControllerTest, CheckLockPinUnlockUnpin) { 1515 TEST_F(ChromeLauncherControllerTest, CheckLockPinUnlockUnpin) {
1498 InitLauncherController(); 1516 InitLauncherController();
1499 // Model should only contain the browser shortcut and app list items. 1517 // Model should only contain the browser shortcut and app list items.
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 base::string16 title1 = ASCIIToUTF16("Test1"); 2013 base::string16 title1 = ASCIIToUTF16("Test1");
1996 NavigateAndCommitActiveTabWithTitle(browser(), GURL("http://test1"), title1); 2014 NavigateAndCommitActiveTabWithTitle(browser(), GURL("http://test1"), title1);
1997 base::string16 one_menu_item1[] = { title1 }; 2015 base::string16 one_menu_item1[] = { title1 };
1998 EXPECT_TRUE(CheckMenuCreation( 2016 EXPECT_TRUE(CheckMenuCreation(
1999 launcher_controller_.get(), item_browser, 1, one_menu_item1, true)); 2017 launcher_controller_.get(), item_browser, 1, one_menu_item1, true));
2000 2018
2001 // Create a browser for another user and check that it is not included in the 2019 // Create a browser for another user and check that it is not included in the
2002 // users running browser list. 2020 // users running browser list.
2003 std::string user2 = "user2"; 2021 std::string user2 = "user2";
2004 TestingProfile* profile2 = CreateMultiUserProfile(user2); 2022 TestingProfile* profile2 = CreateMultiUserProfile(user2);
2023 const AccountId account_id2(
2024 multi_user_util::GetAccountIdFromProfile(profile2));
2005 scoped_ptr<Browser> browser2( 2025 scoped_ptr<Browser> browser2(
2006 CreateBrowserAndTabWithProfile(profile2, user2, "http://test2")); 2026 CreateBrowserAndTabWithProfile(profile2, user2, "http://test2"));
2007 base::string16 one_menu_item2[] = { ASCIIToUTF16(user2) }; 2027 base::string16 one_menu_item2[] = { ASCIIToUTF16(user2) };
2008 EXPECT_TRUE(CheckMenuCreation( 2028 EXPECT_TRUE(CheckMenuCreation(
2009 launcher_controller_.get(), item_browser, 1, one_menu_item1, true)); 2029 launcher_controller_.get(), item_browser, 1, one_menu_item1, true));
2010 2030
2011 // Switch to the other user and make sure that only that browser window gets 2031 // Switch to the other user and make sure that only that browser window gets
2012 // shown. 2032 // shown.
2013 SwitchActiveUser(profile2->GetProfileUserName()); 2033 SwitchActiveUser(account_id2);
2014 EXPECT_TRUE(CheckMenuCreation( 2034 EXPECT_TRUE(CheckMenuCreation(
2015 launcher_controller_.get(), item_browser, 1, one_menu_item2, true)); 2035 launcher_controller_.get(), item_browser, 1, one_menu_item2, true));
2016 2036
2017 // Transferred browsers of other users should not show up in the list. 2037 // Transferred browsers of other users should not show up in the list.
2018 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser( 2038 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser(
2019 browser()->window()->GetNativeWindow(), 2039 browser()->window()->GetNativeWindow(), account_id2);
2020 user2);
2021 EXPECT_TRUE(CheckMenuCreation( 2040 EXPECT_TRUE(CheckMenuCreation(
2022 launcher_controller_.get(), item_browser, 1, one_menu_item2, true)); 2041 launcher_controller_.get(), item_browser, 1, one_menu_item2, true));
2023 2042
2024 chrome::CloseTab(browser2.get()); 2043 chrome::CloseTab(browser2.get());
2025 } 2044 }
2026 #endif // defined(OS_CHROMEOS) 2045 #endif // defined(OS_CHROMEOS)
2027 2046
2028 // Check that V1 apps are correctly reflected in the launcher menu using the 2047 // Check that V1 apps are correctly reflected in the launcher menu using the
2029 // refocus logic. 2048 // refocus logic.
2030 // Note that the extension matching logic is tested by the extension system 2049 // Note that the extension matching logic is tested by the extension system
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2134 base::string16 title1 = ASCIIToUTF16("Test1"); 2153 base::string16 title1 = ASCIIToUTF16("Test1");
2135 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1); 2154 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1);
2136 2155
2137 base::string16 one_menu_item[] = { title1 }; 2156 base::string16 one_menu_item[] = { title1 };
2138 EXPECT_TRUE(CheckMenuCreation( 2157 EXPECT_TRUE(CheckMenuCreation(
2139 launcher_controller_.get(), item_gmail, 1, one_menu_item, false)); 2158 launcher_controller_.get(), item_gmail, 1, one_menu_item, false));
2140 2159
2141 // Create a second profile and switch to that user. 2160 // Create a second profile and switch to that user.
2142 std::string user2 = "user2"; 2161 std::string user2 = "user2";
2143 TestingProfile* profile2 = CreateMultiUserProfile(user2); 2162 TestingProfile* profile2 = CreateMultiUserProfile(user2);
2144 SwitchActiveUser(profile2->GetProfileUserName()); 2163 const AccountId account_id2(
2164 multi_user_util::GetAccountIdFromProfile(profile2));
2165 SwitchActiveUser(account_id2);
2145 2166
2146 // No item should have content yet. 2167 // No item should have content yet.
2147 EXPECT_TRUE(CheckMenuCreation( 2168 EXPECT_TRUE(CheckMenuCreation(
2148 launcher_controller_.get(), item_browser, 0, NULL, true)); 2169 launcher_controller_.get(), item_browser, 0, NULL, true));
2149 EXPECT_TRUE(CheckMenuCreation( 2170 EXPECT_TRUE(CheckMenuCreation(
2150 launcher_controller_.get(), item_gmail, 0, NULL, false)); 2171 launcher_controller_.get(), item_gmail, 0, NULL, false));
2151 2172
2152 // Transfer the browser of the first user - it should still not show up. 2173 // Transfer the browser of the first user - it should still not show up.
2153 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser( 2174 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser(
2154 browser()->window()->GetNativeWindow(), 2175 browser()->window()->GetNativeWindow(), account_id2);
2155 user2);
2156 2176
2157 EXPECT_TRUE(CheckMenuCreation( 2177 EXPECT_TRUE(CheckMenuCreation(
2158 launcher_controller_.get(), item_browser, 0, NULL, true)); 2178 launcher_controller_.get(), item_browser, 0, NULL, true));
2159 EXPECT_TRUE(CheckMenuCreation( 2179 EXPECT_TRUE(CheckMenuCreation(
2160 launcher_controller_.get(), item_gmail, 0, NULL, false)); 2180 launcher_controller_.get(), item_gmail, 0, NULL, false));
2161 } 2181 }
2162 2182
2163 // Check that V2 applications are creating items properly in the launcher when 2183 // Check that V2 applications are creating items properly in the launcher when
2164 // instantiated by the current user. 2184 // instantiated by the current user.
2165 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2185 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
2166 V2AppHandlingTwoUsers) { 2186 V2AppHandlingTwoUsers) {
2167 InitLauncherController(); 2187 InitLauncherController();
2168 // Create a profile for our second user (will be destroyed by the framework). 2188 // Create a profile for our second user (will be destroyed by the framework).
2169 TestingProfile* profile2 = CreateMultiUserProfile("user2"); 2189 TestingProfile* profile2 = CreateMultiUserProfile("user2");
2190 const AccountId account_id(
2191 multi_user_util::GetAccountIdFromProfile(profile()));
2192 const AccountId account_id2(
2193 multi_user_util::GetAccountIdFromProfile(profile2));
2170 // Check that there is a browser and a app launcher. 2194 // Check that there is a browser and a app launcher.
2171 EXPECT_EQ(2, model_->item_count()); 2195 EXPECT_EQ(2, model_->item_count());
2172 2196
2173 // Add a v2 app. 2197 // Add a v2 app.
2174 V2App v2_app(profile(), extension1_.get()); 2198 V2App v2_app(profile(), extension1_.get());
2175 EXPECT_EQ(3, model_->item_count()); 2199 EXPECT_EQ(3, model_->item_count());
2176 2200
2177 // After switching users the item should go away. 2201 // After switching users the item should go away.
2178 SwitchActiveUser(profile2->GetProfileUserName()); 2202 SwitchActiveUser(account_id2);
2179 EXPECT_EQ(2, model_->item_count()); 2203 EXPECT_EQ(2, model_->item_count());
2180 2204
2181 // And it should come back when switching back. 2205 // And it should come back when switching back.
2182 SwitchActiveUser(profile()->GetProfileUserName()); 2206 SwitchActiveUser(account_id);
2183 EXPECT_EQ(3, model_->item_count()); 2207 EXPECT_EQ(3, model_->item_count());
2184 } 2208 }
2185 2209
2186 // Check that V2 applications are creating items properly in edge cases: 2210 // Check that V2 applications are creating items properly in edge cases:
2187 // a background user creates a V2 app, gets active and inactive again and then 2211 // a background user creates a V2 app, gets active and inactive again and then
2188 // deletes the app. 2212 // deletes the app.
2189 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2213 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
2190 V2AppHandlingTwoUsersEdgeCases) { 2214 V2AppHandlingTwoUsersEdgeCases) {
2191 InitLauncherController(); 2215 InitLauncherController();
2192 // Create a profile for our second user (will be destroyed by the framework). 2216 // Create a profile for our second user (will be destroyed by the framework).
2193 TestingProfile* profile2 = CreateMultiUserProfile("user2"); 2217 TestingProfile* profile2 = CreateMultiUserProfile("user2");
2218 const AccountId account_id(
2219 multi_user_util::GetAccountIdFromProfile(profile()));
2220 const AccountId account_id2(
2221 multi_user_util::GetAccountIdFromProfile(profile2));
2194 // Check that there is a browser and a app launcher. 2222 // Check that there is a browser and a app launcher.
2195 EXPECT_EQ(2, model_->item_count()); 2223 EXPECT_EQ(2, model_->item_count());
2196 2224
2197 // Switch to an inactive user. 2225 // Switch to an inactive user.
2198 SwitchActiveUser(profile2->GetProfileUserName()); 2226 SwitchActiveUser(account_id2);
2199 EXPECT_EQ(2, model_->item_count()); 2227 EXPECT_EQ(2, model_->item_count());
2200 2228
2201 // Add the v2 app to the inactive user and check that no item was added to 2229 // Add the v2 app to the inactive user and check that no item was added to
2202 // the launcher. 2230 // the launcher.
2203 { 2231 {
2204 V2App v2_app(profile(), extension1_.get()); 2232 V2App v2_app(profile(), extension1_.get());
2205 EXPECT_EQ(2, model_->item_count()); 2233 EXPECT_EQ(2, model_->item_count());
2206 2234
2207 // Switch to the primary user and check that the item is shown. 2235 // Switch to the primary user and check that the item is shown.
2208 SwitchActiveUser(profile()->GetProfileUserName()); 2236 SwitchActiveUser(account_id);
2209 EXPECT_EQ(3, model_->item_count()); 2237 EXPECT_EQ(3, model_->item_count());
2210 2238
2211 // Switch to the second user and check that the item goes away - even if the 2239 // Switch to the second user and check that the item goes away - even if the
2212 // item gets closed. 2240 // item gets closed.
2213 SwitchActiveUser(profile2->GetProfileUserName()); 2241 SwitchActiveUser(account_id2);
2214 EXPECT_EQ(2, model_->item_count()); 2242 EXPECT_EQ(2, model_->item_count());
2215 } 2243 }
2216 2244
2217 // After the application was killed there should be still 2 items. 2245 // After the application was killed there should be still 2 items.
2218 EXPECT_EQ(2, model_->item_count()); 2246 EXPECT_EQ(2, model_->item_count());
2219 2247
2220 // Switching then back to the default user should not show the additional item 2248 // Switching then back to the default user should not show the additional item
2221 // anymore. 2249 // anymore.
2222 SwitchActiveUser(profile()->GetProfileUserName()); 2250 SwitchActiveUser(account_id);
2223 EXPECT_EQ(2, model_->item_count()); 2251 EXPECT_EQ(2, model_->item_count());
2224 } 2252 }
2225 2253
2226 // Check that V2 applications will be made visible on the target desktop if 2254 // Check that V2 applications will be made visible on the target desktop if
2227 // another window of the same type got previously teleported there. 2255 // another window of the same type got previously teleported there.
2228 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2256 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
2229 V2AppFollowsTeleportedWindow) { 2257 V2AppFollowsTeleportedWindow) {
2230 InitLauncherController(); 2258 InitLauncherController();
2231 chrome::MultiUserWindowManager* manager = 2259 chrome::MultiUserWindowManager* manager =
2232 chrome::MultiUserWindowManager::GetInstance(); 2260 chrome::MultiUserWindowManager::GetInstance();
2233 2261
2234 // Create and add three users / profiles, and go to #1's desktop. 2262 // Create and add three users / profiles, and go to #1's desktop.
2235 TestingProfile* profile1 = CreateMultiUserProfile("user-1"); 2263 TestingProfile* profile1 = CreateMultiUserProfile("user-1");
2236 TestingProfile* profile2 = CreateMultiUserProfile("user-2"); 2264 TestingProfile* profile2 = CreateMultiUserProfile("user-2");
2237 TestingProfile* profile3 = CreateMultiUserProfile("user-3"); 2265 TestingProfile* profile3 = CreateMultiUserProfile("user-3");
2238 SwitchActiveUser(profile1->GetProfileUserName()); 2266 const AccountId account_id1(
2267 multi_user_util::GetAccountIdFromProfile(profile1));
2268 const AccountId account_id2(
2269 multi_user_util::GetAccountIdFromProfile(profile2));
2270 const AccountId account_id3(
2271 multi_user_util::GetAccountIdFromProfile(profile3));
2272 SwitchActiveUser(account_id1);
2239 2273
2240 // A v2 app for user #1 should be shown first and get hidden when switching to 2274 // A v2 app for user #1 should be shown first and get hidden when switching to
2241 // desktop #2. 2275 // desktop #2.
2242 V2App v2_app_1(profile1, extension1_.get()); 2276 V2App v2_app_1(profile1, extension1_.get());
2243 EXPECT_TRUE(v2_app_1.window()->GetNativeWindow()->IsVisible()); 2277 EXPECT_TRUE(v2_app_1.window()->GetNativeWindow()->IsVisible());
2244 SwitchActiveUser(profile2->GetProfileUserName()); 2278 SwitchActiveUser(account_id2);
2245 EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible()); 2279 EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible());
2246 2280
2247 // Add a v2 app for user #1 while on desktop #2 should not be shown. 2281 // Add a v2 app for user #1 while on desktop #2 should not be shown.
2248 V2App v2_app_2(profile1, extension1_.get()); 2282 V2App v2_app_2(profile1, extension1_.get());
2249 EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible()); 2283 EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible());
2250 EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible()); 2284 EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible());
2251 2285
2252 // Teleport the app from user #1 to the desktop #2 should show it. 2286 // Teleport the app from user #1 to the desktop #2 should show it.
2253 manager->ShowWindowForUser(v2_app_1.window()->GetNativeWindow(), 2287 manager->ShowWindowForUser(v2_app_1.window()->GetNativeWindow(), account_id2);
2254 profile2->GetProfileUserName());
2255 EXPECT_TRUE(v2_app_1.window()->GetNativeWindow()->IsVisible()); 2288 EXPECT_TRUE(v2_app_1.window()->GetNativeWindow()->IsVisible());
2256 EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible()); 2289 EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible());
2257 2290
2258 // Creating a new application for user #1 on desktop #2 should teleport it 2291 // Creating a new application for user #1 on desktop #2 should teleport it
2259 // there automatically. 2292 // there automatically.
2260 V2App v2_app_3(profile1, extension1_.get()); 2293 V2App v2_app_3(profile1, extension1_.get());
2261 EXPECT_TRUE(v2_app_1.window()->GetNativeWindow()->IsVisible()); 2294 EXPECT_TRUE(v2_app_1.window()->GetNativeWindow()->IsVisible());
2262 EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible()); 2295 EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible());
2263 EXPECT_TRUE(v2_app_3.window()->GetNativeWindow()->IsVisible()); 2296 EXPECT_TRUE(v2_app_3.window()->GetNativeWindow()->IsVisible());
2264 2297
2265 // Switching back to desktop#1 and creating an app for user #1 should move 2298 // Switching back to desktop#1 and creating an app for user #1 should move
2266 // the app on desktop #1. 2299 // the app on desktop #1.
2267 SwitchActiveUser(profile1->GetProfileUserName()); 2300 SwitchActiveUser(account_id1);
2268 V2App v2_app_4(profile1, extension1_.get()); 2301 V2App v2_app_4(profile1, extension1_.get());
2269 EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible()); 2302 EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible());
2270 EXPECT_TRUE(v2_app_2.window()->GetNativeWindow()->IsVisible()); 2303 EXPECT_TRUE(v2_app_2.window()->GetNativeWindow()->IsVisible());
2271 EXPECT_FALSE(v2_app_3.window()->GetNativeWindow()->IsVisible()); 2304 EXPECT_FALSE(v2_app_3.window()->GetNativeWindow()->IsVisible());
2272 EXPECT_TRUE(v2_app_4.window()->GetNativeWindow()->IsVisible()); 2305 EXPECT_TRUE(v2_app_4.window()->GetNativeWindow()->IsVisible());
2273 2306
2274 // Switching to desktop #3 and create an app for user #1 there should land on 2307 // Switching to desktop #3 and create an app for user #1 there should land on
2275 // his own desktop (#1). 2308 // his own desktop (#1).
2276 SwitchActiveUser(profile3->GetProfileUserName()); 2309 SwitchActiveUser(account_id3);
2277 V2App v2_app_5(profile1, extension1_.get()); 2310 V2App v2_app_5(profile1, extension1_.get());
2278 EXPECT_FALSE(v2_app_5.window()->GetNativeWindow()->IsVisible()); 2311 EXPECT_FALSE(v2_app_5.window()->GetNativeWindow()->IsVisible());
2279 SwitchActiveUser(profile1->GetProfileUserName()); 2312 SwitchActiveUser(account_id1);
2280 EXPECT_TRUE(v2_app_5.window()->GetNativeWindow()->IsVisible()); 2313 EXPECT_TRUE(v2_app_5.window()->GetNativeWindow()->IsVisible());
2281 2314
2282 // Switching to desktop #2, hiding the app window and creating an app should 2315 // Switching to desktop #2, hiding the app window and creating an app should
2283 // teleport there automatically. 2316 // teleport there automatically.
2284 SwitchActiveUser(profile2->GetProfileUserName()); 2317 SwitchActiveUser(account_id2);
2285 v2_app_1.window()->Hide(); 2318 v2_app_1.window()->Hide();
2286 V2App v2_app_6(profile1, extension1_.get()); 2319 V2App v2_app_6(profile1, extension1_.get());
2287 EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible()); 2320 EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible());
2288 EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible()); 2321 EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible());
2289 EXPECT_TRUE(v2_app_6.window()->GetNativeWindow()->IsVisible()); 2322 EXPECT_TRUE(v2_app_6.window()->GetNativeWindow()->IsVisible());
2290 } 2323 }
2291 2324
2292 // Check that V2 applications hide correctly on the shelf when the app window 2325 // Check that V2 applications hide correctly on the shelf when the app window
2293 // is hidden. 2326 // is hidden.
2294 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2327 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
2295 V2AppHiddenWindows) { 2328 V2AppHiddenWindows) {
2296 InitLauncherController(); 2329 InitLauncherController();
2297 2330
2298 TestingProfile* profile2 = CreateMultiUserProfile("user-2"); 2331 TestingProfile* profile2 = CreateMultiUserProfile("user-2");
2299 SwitchActiveUser(profile()->GetProfileUserName()); 2332 const AccountId account_id(
2333 multi_user_util::GetAccountIdFromProfile(profile()));
2334 const AccountId account_id2(
2335 multi_user_util::GetAccountIdFromProfile(profile2));
2336 SwitchActiveUser(account_id);
2300 EXPECT_EQ(2, model_->item_count()); 2337 EXPECT_EQ(2, model_->item_count());
2301 2338
2302 V2App v2_app_1(profile(), extension1_.get()); 2339 V2App v2_app_1(profile(), extension1_.get());
2303 EXPECT_EQ(3, model_->item_count()); 2340 EXPECT_EQ(3, model_->item_count());
2304 { 2341 {
2305 // Hide and show the app. 2342 // Hide and show the app.
2306 v2_app_1.window()->Hide(); 2343 v2_app_1.window()->Hide();
2307 EXPECT_EQ(2, model_->item_count()); 2344 EXPECT_EQ(2, model_->item_count());
2308 2345
2309 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE); 2346 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE);
2310 EXPECT_EQ(3, model_->item_count()); 2347 EXPECT_EQ(3, model_->item_count());
2311 } 2348 }
2312 { 2349 {
2313 // Switch user, hide and show the app and switch back. 2350 // Switch user, hide and show the app and switch back.
2314 SwitchActiveUser(profile2->GetProfileUserName()); 2351 SwitchActiveUser(account_id2);
2315 EXPECT_EQ(2, model_->item_count()); 2352 EXPECT_EQ(2, model_->item_count());
2316 2353
2317 v2_app_1.window()->Hide(); 2354 v2_app_1.window()->Hide();
2318 EXPECT_EQ(2, model_->item_count()); 2355 EXPECT_EQ(2, model_->item_count());
2319 2356
2320 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE); 2357 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE);
2321 EXPECT_EQ(2, model_->item_count()); 2358 EXPECT_EQ(2, model_->item_count());
2322 2359
2323 SwitchActiveUser(profile()->GetProfileUserName()); 2360 SwitchActiveUser(account_id);
2324 EXPECT_EQ(3, model_->item_count()); 2361 EXPECT_EQ(3, model_->item_count());
2325 } 2362 }
2326 { 2363 {
2327 // Switch user, hide the app, switch back and then show it again. 2364 // Switch user, hide the app, switch back and then show it again.
2328 SwitchActiveUser(profile2->GetProfileUserName()); 2365 SwitchActiveUser(account_id2);
2329 EXPECT_EQ(2, model_->item_count()); 2366 EXPECT_EQ(2, model_->item_count());
2330 2367
2331 v2_app_1.window()->Hide(); 2368 v2_app_1.window()->Hide();
2332 EXPECT_EQ(2, model_->item_count()); 2369 EXPECT_EQ(2, model_->item_count());
2333 2370
2334 SwitchActiveUser(profile()->GetProfileUserName()); 2371 SwitchActiveUser(account_id);
2335 EXPECT_EQ(2, model_->item_count()); 2372 EXPECT_EQ(2, model_->item_count());
2336 2373
2337 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE); 2374 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE);
2338 EXPECT_EQ(3, model_->item_count()); 2375 EXPECT_EQ(3, model_->item_count());
2339 } 2376 }
2340 { 2377 {
2341 // Create a second app, hide and show it and then hide both apps. 2378 // Create a second app, hide and show it and then hide both apps.
2342 V2App v2_app_2(profile(), extension1_.get()); 2379 V2App v2_app_2(profile(), extension1_.get());
2343 EXPECT_EQ(3, model_->item_count()); 2380 EXPECT_EQ(3, model_->item_count());
2344 2381
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
2676 2713
2677 EXPECT_EQ(1, app_icon_loader->fetch_count()); 2714 EXPECT_EQ(1, app_icon_loader->fetch_count());
2678 ASSERT_EQ(initial_size + 1, model_->items().size()); 2715 ASSERT_EQ(initial_size + 1, model_->items().size());
2679 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 2716 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
2680 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); 2717 EXPECT_FALSE(launcher_controller_->IsAppPinned("0"));
2681 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); 2718 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type);
2682 2719
2683 launcher_controller_->UnpinAppWithID("1"); 2720 launcher_controller_->UnpinAppWithID("1");
2684 ASSERT_EQ(initial_size, model_->items().size()); 2721 ASSERT_EQ(initial_size, model_->items().size());
2685 } 2722 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698