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

Side by Side Diff: chrome/browser/chromeos/arc/arc_session_manager_browsertest.cc

Issue 2723073002: Extract kArcEnabled preference from ArcSessionManager part 2. (Closed)
Patch Set: address comments 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chromeos/arc/arc_auth_notification.h"
17 #include "chrome/browser/chromeos/arc/arc_service_launcher.h" 18 #include "chrome/browser/chromeos/arc/arc_service_launcher.h"
18 #include "chrome/browser/chromeos/arc/arc_session_manager.h" 19 #include "chrome/browser/chromeos/arc/arc_session_manager.h"
19 #include "chrome/browser/chromeos/arc/test/arc_data_removed_waiter.h" 20 #include "chrome/browser/chromeos/arc/test/arc_data_removed_waiter.h"
20 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" 21 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
21 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 22 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
22 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 23 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
23 #include "chrome/browser/policy/cloud/test_request_interceptor.h" 24 #include "chrome/browser/policy/cloud/test_request_interceptor.h"
24 #include "chrome/browser/policy/profile_policy_connector.h" 25 #include "chrome/browser/policy/profile_policy_connector.h"
25 #include "chrome/browser/policy/profile_policy_connector_factory.h" 26 #include "chrome/browser/policy/profile_policy_connector_factory.h"
26 #include "chrome/browser/policy/test/local_policy_test_server.h" 27 #include "chrome/browser/policy/test/local_policy_test_server.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 base::CommandLine::ForCurrentProcess(); 118 base::CommandLine::ForCurrentProcess();
118 command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl, 119 command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl,
119 url); 120 url);
120 } 121 }
121 122
122 void SetUpOnMainThread() override { 123 void SetUpOnMainThread() override {
123 user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler( 124 user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler(
124 new chromeos::FakeChromeUserManager)); 125 new chromeos::FakeChromeUserManager));
125 // Init ArcSessionManager for testing. 126 // Init ArcSessionManager for testing.
126 ArcSessionManager::DisableUIForTesting(); 127 ArcSessionManager::DisableUIForTesting();
128 ArcAuthNotification::DisableForTesting();
127 ArcSessionManager::EnableCheckAndroidManagementForTesting(); 129 ArcSessionManager::EnableCheckAndroidManagementForTesting();
128 ArcSessionManager::Get()->SetArcSessionRunnerForTesting( 130 ArcSessionManager::Get()->SetArcSessionRunnerForTesting(
129 base::MakeUnique<ArcSessionRunner>(base::Bind(FakeArcSession::Create))); 131 base::MakeUnique<ArcSessionRunner>(base::Bind(FakeArcSession::Create)));
130 132
131 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 133 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
132 134
133 // Create test profile. 135 // Create test profile.
134 TestingProfile::Builder profile_builder; 136 TestingProfile::Builder profile_builder;
135 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile")); 137 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile"));
136 profile_builder.SetProfileName(kFakeUserName); 138 profile_builder.SetProfileName(kFakeUserName);
137 profile_builder.AddTestingFactory( 139 profile_builder.AddTestingFactory(
138 ProfileOAuth2TokenServiceFactory::GetInstance(), 140 ProfileOAuth2TokenServiceFactory::GetInstance(),
139 BuildFakeProfileOAuth2TokenService); 141 BuildFakeProfileOAuth2TokenService);
140 profile_ = profile_builder.Build(); 142 profile_ = profile_builder.Build();
141 token_service_ = static_cast<FakeProfileOAuth2TokenService*>( 143 token_service_ = static_cast<FakeProfileOAuth2TokenService*>(
142 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())); 144 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()));
143 token_service_->UpdateCredentials("", kRefreshToken); 145 token_service_->UpdateCredentials("", kRefreshToken);
144 146
145 profile()->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true); 147 profile()->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true);
146 profile()->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); 148 profile()->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true);
147 149
148 const AccountId account_id( 150 const AccountId account_id(
149 AccountId::FromUserEmailGaiaId(kFakeUserName, kFakeGaiaId)); 151 AccountId::FromUserEmailGaiaId(kFakeUserName, kFakeGaiaId));
150 GetFakeUserManager()->AddUser(account_id); 152 GetFakeUserManager()->AddUser(account_id);
151 GetFakeUserManager()->LoginUser(account_id); 153 GetFakeUserManager()->LoginUser(account_id);
152 154
153 // Set up ARC for test profile. 155 // Set up ARC for test profile.
156 // Currently, ArcSessionManager is singleton and set up with the original
157 // Profile instance. This re-initializes the ArcServiceLauncher by
158 // overwriting Profile with profile().
159 // TODO(hidehiko): This way several ArcService instances created with
160 // the original Profile instance on Browser creatuion are kept in the
161 // ArcServiceManager. For proper overwriting, those should be removed.
154 ArcServiceLauncher::Get()->OnPrimaryUserProfilePrepared(profile()); 162 ArcServiceLauncher::Get()->OnPrimaryUserProfilePrepared(profile());
155 } 163 }
156 164
157 void TearDownOnMainThread() override { 165 void TearDownOnMainThread() override {
158 // Explicitly removing the user is required; otherwise ProfileHelper keeps 166 // Explicitly removing the user is required; otherwise ProfileHelper keeps
159 // a dangling pointer to the User. 167 // a dangling pointer to the User.
160 // TODO(nya): Consider removing all users from ProfileHelper in the 168 // TODO(nya): Consider removing all users from ProfileHelper in the
161 // destructor of FakeChromeUserManager. 169 // destructor of FakeChromeUserManager.
162 const AccountId account_id( 170 const AccountId account_id(
163 AccountId::FromUserEmailGaiaId(kFakeUserName, kFakeGaiaId)); 171 AccountId::FromUserEmailGaiaId(kFakeUserName, kFakeGaiaId));
164 GetFakeUserManager()->RemoveUserFromList(account_id); 172 GetFakeUserManager()->RemoveUserFromList(account_id);
165 ArcSessionManager::Get()->Shutdown(); 173 // Since ArcServiceLauncher is (re-)set up with profile() in
166 ArcServiceManager::Get()->Shutdown(); 174 // SetUpOnMainThread() it is necessary to Shutdown() before the profile()
175 // is destroyed. ArcServiceLauncher::Shutdown() will be called again on
176 // fixture destruction (because it is initialized with the original Profile
177 // instance in fixture, once), but it should be no op.
178 // TODO(hidehiko): Think about a way to test the code cleanly.
179 ArcServiceLauncher::Get()->Shutdown();
167 profile_.reset(); 180 profile_.reset();
168 user_manager_enabler_.reset(); 181 user_manager_enabler_.reset();
169 test_server_.reset(); 182 test_server_.reset();
170 } 183 }
171 184
172 chromeos::FakeChromeUserManager* GetFakeUserManager() const { 185 chromeos::FakeChromeUserManager* GetFakeUserManager() const {
173 return static_cast<chromeos::FakeChromeUserManager*>( 186 return static_cast<chromeos::FakeChromeUserManager*>(
174 user_manager::UserManager::Get()); 187 user_manager::UserManager::Get());
175 } 188 }
176 189
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 base::Time::Max()); 242 base::Time::Max());
230 ArcPlayStoreDisabledWaiter().Wait(); 243 ArcPlayStoreDisabledWaiter().Wait();
231 ASSERT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, 244 ASSERT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR,
232 ArcSessionManager::Get()->state()); 245 ArcSessionManager::Get()->state());
233 ArcDataRemovedWaiter().Wait(); 246 ArcDataRemovedWaiter().Wait();
234 ASSERT_EQ(ArcSessionManager::State::STOPPED, 247 ASSERT_EQ(ArcSessionManager::State::STOPPED,
235 ArcSessionManager::Get()->state()); 248 ArcSessionManager::Get()->state());
236 } 249 }
237 250
238 } // namespace arc 251 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_session_manager.cc ('k') | chrome/browser/chromeos/arc/arc_session_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698