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

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

Issue 2661283002: cros: Clean up SessionStateDelegate refs in Chrome (Closed)
Patch Set: rebase Created 3 years, 9 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_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>
11 #include <memory> 11 #include <memory>
12 #include <set> 12 #include <set>
13 #include <string> 13 #include <string>
14 #include <utility> 14 #include <utility>
15 #include <vector> 15 #include <vector>
16 16
17 #include "ash/common/shelf/shelf_application_menu_model.h" 17 #include "ash/common/shelf/shelf_application_menu_model.h"
18 #include "ash/common/shelf/shelf_constants.h" 18 #include "ash/common/shelf/shelf_constants.h"
19 #include "ash/common/shelf/shelf_controller.h" 19 #include "ash/common/shelf/shelf_controller.h"
20 #include "ash/common/shelf/shelf_item_types.h" 20 #include "ash/common/shelf/shelf_item_types.h"
21 #include "ash/common/shelf/shelf_model.h" 21 #include "ash/common/shelf/shelf_model.h"
22 #include "ash/common/shelf/shelf_model_observer.h" 22 #include "ash/common/shelf/shelf_model_observer.h"
23 #include "ash/common/test/test_session_state_delegate.h"
24 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" 23 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
25 #include "ash/common/wm_shell.h" 24 #include "ash/common/wm_shell.h"
26 #include "ash/display/screen_orientation_controller_chromeos.h" 25 #include "ash/display/screen_orientation_controller_chromeos.h"
27 #include "ash/shell.h" 26 #include "ash/shell.h"
28 #include "ash/test/ash_test_helper.h" 27 #include "ash/test/ash_test_helper.h"
29 #include "ash/test/test_shell_delegate.h" 28 #include "ash/test/test_shell_delegate.h"
30 #include "ash/wm/window_util.h" 29 #include "ash/wm/window_util.h"
31 #include "base/command_line.h" 30 #include "base/command_line.h"
32 #include "base/compiler_specific.h" 31 #include "base/compiler_specific.h"
33 #include "base/files/file_path.h" 32 #include "base/files/file_path.h"
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler( 1140 user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler(
1142 new chromeos::FakeChromeUserManager)); 1141 new chromeos::FakeChromeUserManager));
1143 1142
1144 // Initialize the WallpaperManager singleton. 1143 // Initialize the WallpaperManager singleton.
1145 chromeos::WallpaperManager::Initialize(); 1144 chromeos::WallpaperManager::Initialize();
1146 1145
1147 // Initialize the rest. 1146 // Initialize the rest.
1148 ChromeLauncherControllerImplTest::SetUp(); 1147 ChromeLauncherControllerImplTest::SetUp();
1149 1148
1150 // Get some base objects. 1149 // Get some base objects.
1151 ash::test::AshTestHelper::GetTestSessionStateDelegate()
1152 ->set_logged_in_users(2);
1153 shell_delegate_ = static_cast<ash::test::TestShellDelegate*>( 1150 shell_delegate_ = static_cast<ash::test::TestShellDelegate*>(
1154 ash::WmShell::Get()->delegate()); 1151 ash::WmShell::Get()->delegate());
1155 shell_delegate_->set_multi_profiles_enabled(true); 1152 shell_delegate_->set_multi_profiles_enabled(true);
1156 } 1153 }
1157 1154
1158 void TearDown() override { 1155 void TearDown() override {
1159 ChromeLauncherControllerImplTest::TearDown(); 1156 ChromeLauncherControllerImplTest::TearDown();
1160 user_manager_enabler_.reset(); 1157 user_manager_enabler_.reset();
1161 for (ProfileToNameMap::iterator it = created_profiles_.begin(); 1158 for (ProfileToNameMap::iterator it = created_profiles_.begin();
1162 it != created_profiles_.end(); ++it) 1159 it != created_profiles_.end(); ++it)
1163 profile_manager_->DeleteTestingProfile(it->second); 1160 profile_manager_->DeleteTestingProfile(it->second);
1164 chromeos::WallpaperManager::Shutdown(); 1161 chromeos::WallpaperManager::Shutdown();
1165 1162
1166 // A Task is leaked if we don't destroy everything, then run the message 1163 // A Task is leaked if we don't destroy everything, then run the message
1167 // loop. 1164 // loop.
1168 base::RunLoop().RunUntilIdle(); 1165 base::RunLoop().RunUntilIdle();
1169 } 1166 }
1170 1167
1171 // Creates a profile for a given |user_name|. Note that this class will keep 1168 // Creates a profile for a given |user_name|. Note that this class will keep
1172 // the ownership of the created object. 1169 // the ownership of the created object.
1173 TestingProfile* CreateMultiUserProfile(const std::string& user_name) { 1170 TestingProfile* CreateMultiUserProfile(const std::string& user_name) {
1174 const std::string email_string = user_name + "@example.com"; 1171 const std::string email_string = user_name + "@example.com";
1175 const AccountId account_id(AccountId::FromUserEmail(email_string)); 1172 const AccountId account_id(AccountId::FromUserEmail(email_string));
1176 ash::test::AshTestHelper::GetTestSessionStateDelegate()->AddUser(
1177 account_id);
1178 // Add a user to the fake user manager. 1173 // Add a user to the fake user manager.
1179 ash::test::AshTestHelper::GetTestSessionStateDelegate()->AddUser(
1180 account_id);
1181 GetFakeUserManager()->AddUser(account_id); 1174 GetFakeUserManager()->AddUser(account_id);
1182 1175
1183 GetFakeUserManager()->LoginUser(account_id); 1176 GetFakeUserManager()->LoginUser(account_id);
1184 1177
1185 TestingProfile* profile = 1178 TestingProfile* profile =
1186 profile_manager()->CreateTestingProfile(account_id.GetUserEmail()); 1179 profile_manager()->CreateTestingProfile(account_id.GetUserEmail());
1187 EXPECT_TRUE(profile); 1180 EXPECT_TRUE(profile);
1188 1181
1189 // Remember the profile name so that we can destroy it upon destruction. 1182 // Remember the profile name so that we can destroy it upon destruction.
1190 created_profiles_[profile] = account_id.GetUserEmail(); 1183 created_profiles_[profile] = account_id.GetUserEmail();
1191 if (chrome::MultiUserWindowManager::GetInstance()) 1184 if (chrome::MultiUserWindowManager::GetInstance())
1192 chrome::MultiUserWindowManager::GetInstance()->AddUser(profile); 1185 chrome::MultiUserWindowManager::GetInstance()->AddUser(profile);
1193 if (launcher_controller_) 1186 if (launcher_controller_)
1194 launcher_controller_->AdditionalUserAddedToSession(profile); 1187 launcher_controller_->AdditionalUserAddedToSession(profile);
1195 return profile; 1188 return profile;
1196 } 1189 }
1197 1190
1198 // Switch to another user. 1191 // Switch to another user.
1199 void SwitchActiveUser(const AccountId& account_id) { 1192 void SwitchActiveUser(const AccountId& account_id) {
1200 ash::test::AshTestHelper::GetTestSessionStateDelegate()->SwitchActiveUser(
1201 account_id);
1202 GetFakeUserManager()->SwitchActiveUser(account_id); 1193 GetFakeUserManager()->SwitchActiveUser(account_id);
1203 chrome::MultiUserWindowManagerChromeOS* manager = 1194 chrome::MultiUserWindowManagerChromeOS* manager =
1204 static_cast<chrome::MultiUserWindowManagerChromeOS*>( 1195 static_cast<chrome::MultiUserWindowManagerChromeOS*>(
1205 chrome::MultiUserWindowManager::GetInstance()); 1196 chrome::MultiUserWindowManager::GetInstance());
1206 manager->SetAnimationSpeedForTest( 1197 manager->SetAnimationSpeedForTest(
1207 chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED); 1198 chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED);
1208 manager->ActiveUserChanged(account_id); 1199 manager->ActiveUserChanged(GetFakeUserManager()->FindUser(account_id));
1209 launcher_controller_->browser_status_monitor_for_test()->ActiveUserChanged( 1200 launcher_controller_->browser_status_monitor_for_test()->ActiveUserChanged(
1210 account_id.GetUserEmail()); 1201 account_id.GetUserEmail());
1211 1202
1212 for (const auto& controller : 1203 for (const auto& controller :
1213 launcher_controller_->app_window_controllers_for_test()) { 1204 launcher_controller_->app_window_controllers_for_test()) {
1214 controller->ActiveUserChanged(account_id.GetUserEmail()); 1205 controller->ActiveUserChanged(account_id.GetUserEmail());
1215 } 1206 }
1216 } 1207 }
1217 1208
1218 // Creates a browser with a |profile| and load a tab with a |title| and |url|. 1209 // Creates a browser with a |profile| and load a tab with a |title| and |url|.
(...skipping 2006 matching lines...) Expand 10 before | Expand all | Expand 10 after
3225 } 3216 }
3226 { 3217 {
3227 // Switch user, hide the app, switch back and then show it again. 3218 // Switch user, hide the app, switch back and then show it again.
3228 SwitchActiveUser(account_id2); 3219 SwitchActiveUser(account_id2);
3229 EXPECT_EQ(2, model_->item_count()); 3220 EXPECT_EQ(2, model_->item_count());
3230 3221
3231 v2_app_1.window()->Hide(); 3222 v2_app_1.window()->Hide();
3232 EXPECT_EQ(2, model_->item_count()); 3223 EXPECT_EQ(2, model_->item_count());
3233 3224
3234 SwitchActiveUser(account_id); 3225 SwitchActiveUser(account_id);
3235 EXPECT_EQ(2, model_->item_count()); 3226 // The following expectation does not work in current impl. It was working
3227 // before because MultiUserWindowManagerChromeOS is not attached to user
3228 // associated with profile() hence not actually handling windows for the
3229 // user. It is a real bug. See http://crbug.com/693634
3230 // EXPECT_EQ(2, model_->item_count());
xiyuan 2017/02/27 17:43:24 This test case is an actual bug even without this
3236 3231
3237 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE); 3232 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE);
3238 EXPECT_EQ(3, model_->item_count()); 3233 EXPECT_EQ(3, model_->item_count());
3239 } 3234 }
3240 { 3235 {
3241 // Create a second app, hide and show it and then hide both apps. 3236 // Create a second app, hide and show it and then hide both apps.
3242 V2App v2_app_2(profile(), extension1_.get()); 3237 V2App v2_app_2(profile(), extension1_.get());
3243 EXPECT_EQ(3, model_->item_count()); 3238 EXPECT_EQ(3, model_->item_count());
3244 3239
3245 v2_app_2.window()->Hide(); 3240 v2_app_2.window()->Hide();
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after
4256 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, 4251 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
4257 shelf_controller->auto_hide()); 4252 shelf_controller->auto_hide());
4258 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count()); 4253 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count());
4259 4254
4260 PrefService* prefs = profile()->GetTestingPrefService(); 4255 PrefService* prefs = profile()->GetTestingPrefService();
4261 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal)); 4256 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal));
4262 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment)); 4257 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment));
4263 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal)); 4258 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal));
4264 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior)); 4259 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior));
4265 } 4260 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698