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

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

Issue 2596273002: Move ArcSessionRunner from ArcBridgeService to ArcSessionManager. (Closed)
Patch Set: Rebase and update comments. Created 3 years, 12 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 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/chromeos/profiles/profile_helper.h" 22 #include "chrome/browser/chromeos/profiles/profile_helper.h"
23 #include "chrome/browser/prefs/pref_service_syncable_util.h" 23 #include "chrome/browser/prefs/pref_service_syncable_util.h"
24 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" 25 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
26 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 26 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
27 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
28 #include "chrome/test/base/testing_profile.h" 28 #include "chrome/test/base/testing_profile.h"
29 #include "chromeos/chromeos_switches.h" 29 #include "chromeos/chromeos_switches.h"
30 #include "chromeos/dbus/dbus_thread_manager.h" 30 #include "chromeos/dbus/dbus_thread_manager.h"
31 #include "chromeos/dbus/fake_session_manager_client.h" 31 #include "chromeos/dbus/fake_session_manager_client.h"
32 #include "components/arc/arc_bridge_service.h"
33 #include "components/arc/arc_service_manager.h" 32 #include "components/arc/arc_service_manager.h"
34 #include "components/arc/arc_session_runner.h" 33 #include "components/arc/arc_session_runner.h"
35 #include "components/arc/test/fake_arc_session.h" 34 #include "components/arc/test/fake_arc_session.h"
36 #include "components/prefs/pref_service.h" 35 #include "components/prefs/pref_service.h"
37 #include "components/signin/core/account_id/account_id.h" 36 #include "components/signin/core/account_id/account_id.h"
38 #include "components/sync/model/fake_sync_change_processor.h" 37 #include "components/sync/model/fake_sync_change_processor.h"
39 #include "components/sync/model/sync_error_factory_mock.h" 38 #include "components/sync/model/sync_error_factory_mock.h"
40 #include "components/sync_preferences/testing_pref_service_syncable.h" 39 #include "components/sync_preferences/testing_pref_service_syncable.h"
41 #include "components/user_manager/user_manager.h" 40 #include "components/user_manager/user_manager.h"
42 #include "components/user_manager/user_names.h" 41 #include "components/user_manager/user_names.h"
(...skipping 24 matching lines...) Expand all
67 ArcSessionManager::DisableUIForTesting(); 66 ArcSessionManager::DisableUIForTesting();
68 67
69 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 68 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
70 TestingProfile::Builder profile_builder; 69 TestingProfile::Builder profile_builder;
71 profile_builder.SetProfileName("user@gmail.com"); 70 profile_builder.SetProfileName("user@gmail.com");
72 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile")); 71 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile"));
73 72
74 profile_ = profile_builder.Build(); 73 profile_ = profile_builder.Build();
75 StartPreferenceSyncing(); 74 StartPreferenceSyncing();
76 75
77 ArcServiceManager::SetArcSessionRunnerForTesting(
78 base::MakeUnique<ArcSessionRunner>(base::Bind(FakeArcSession::Create)));
79 arc_service_manager_ = base::MakeUnique<ArcServiceManager>(nullptr); 76 arc_service_manager_ = base::MakeUnique<ArcServiceManager>(nullptr);
80 arc_session_manager_ = base::MakeUnique<ArcSessionManager>( 77 arc_session_manager_ = base::MakeUnique<ArcSessionManager>(
81 arc_service_manager_->arc_bridge_service()); 78 base::MakeUnique<ArcSessionRunner>(base::Bind(FakeArcSession::Create)));
82 79
83 // Check initial conditions. 80 // Check initial conditions.
84 EXPECT_TRUE(bridge_service()->stopped()); 81 EXPECT_TRUE(arc_session_manager_->IsSessionStopped());
85 82
86 chromeos::WallpaperManager::Initialize(); 83 chromeos::WallpaperManager::Initialize();
87 } 84 }
88 85
89 void TearDown() override { 86 void TearDown() override {
90 chromeos::WallpaperManager::Shutdown(); 87 chromeos::WallpaperManager::Shutdown();
91 arc_session_manager_.reset(); 88 arc_session_manager_.reset();
92 arc_service_manager_.reset(); 89 arc_service_manager_.reset();
93 chromeos::DBusThreadManager::Shutdown(); 90 chromeos::DBusThreadManager::Shutdown();
94 } 91 }
95 92
96 chromeos::FakeChromeUserManager* GetFakeUserManager() const { 93 chromeos::FakeChromeUserManager* GetFakeUserManager() const {
97 return static_cast<chromeos::FakeChromeUserManager*>( 94 return static_cast<chromeos::FakeChromeUserManager*>(
98 user_manager::UserManager::Get()); 95 user_manager::UserManager::Get());
99 } 96 }
100 97
101 protected: 98 protected:
102 Profile* profile() { return profile_.get(); } 99 Profile* profile() { return profile_.get(); }
103 ArcBridgeService* bridge_service() { 100
104 return arc_service_manager_->arc_bridge_service();
105 }
106 ArcSessionManager* arc_session_manager() { 101 ArcSessionManager* arc_session_manager() {
107 return arc_session_manager_.get(); 102 return arc_session_manager_.get();
108 } 103 }
109 104
110 bool WaitForDataRemoved(ArcSessionManager::State expected_state) { 105 bool WaitForDataRemoved(ArcSessionManager::State expected_state) {
111 if (arc_session_manager()->state() != 106 if (arc_session_manager()->state() !=
112 ArcSessionManager::State::REMOVING_DATA_DIR) 107 ArcSessionManager::State::REMOVING_DATA_DIR)
113 return false; 108 return false;
114 109
115 base::RunLoop().RunUntilIdle(); 110 base::RunLoop().RunUntilIdle();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 arc_session_manager()->Shutdown(); 214 arc_session_manager()->Shutdown();
220 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 215 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
221 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, 216 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
222 arc_session_manager()->state()); 217 arc_session_manager()->state());
223 218
224 // Correctly stop service. 219 // Correctly stop service.
225 arc_session_manager()->Shutdown(); 220 arc_session_manager()->Shutdown();
226 } 221 }
227 222
228 TEST_F(ArcSessionManagerTest, BaseWorkflow) { 223 TEST_F(ArcSessionManagerTest, BaseWorkflow) {
229 ASSERT_FALSE(bridge_service()->ready()); 224 ASSERT_TRUE(arc_session_manager()->IsSessionStopped());
230 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, 225 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
231 arc_session_manager()->state()); 226 arc_session_manager()->state());
232 227
233 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 228 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
234 229
235 // By default ARC is not enabled. 230 // By default ARC is not enabled.
236 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); 231 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED));
237 232
238 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 233 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
239 base::RunLoop().RunUntilIdle(); 234 base::RunLoop().RunUntilIdle();
240 235
241 // Setting profile and pref initiates a code fetching process. 236 // Setting profile and pref initiates a code fetching process.
242 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 237 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
243 arc_session_manager()->state()); 238 arc_session_manager()->state());
244 239
245 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE -> 240 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE ->
246 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager. 241 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager.
247 arc_session_manager()->StartArc(); 242 arc_session_manager()->StartArc();
248 243
249 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 244 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
250 ASSERT_TRUE(bridge_service()->ready()); 245 ASSERT_TRUE(arc_session_manager()->IsSessionRunning());
251 246
252 arc_session_manager()->Shutdown(); 247 arc_session_manager()->Shutdown();
253 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, 248 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
254 arc_session_manager()->state()); 249 arc_session_manager()->state());
255 ASSERT_FALSE(bridge_service()->ready()); 250 ASSERT_TRUE(arc_session_manager()->IsSessionStopped());
256 251
257 // Send profile and don't provide a code. 252 // Send profile and don't provide a code.
258 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 253 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
259 254
260 // Setting profile initiates a code fetching process. 255 // Setting profile initiates a code fetching process.
261 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 256 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
262 arc_session_manager()->state()); 257 arc_session_manager()->state());
263 258
264 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 259 content::BrowserThread::GetBlockingPool()->FlushForTesting();
265 base::RunLoop().RunUntilIdle(); 260 base::RunLoop().RunUntilIdle();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 327 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
333 prefs->SetBoolean(prefs::kArcEnabled, true); 328 prefs->SetBoolean(prefs::kArcEnabled, true);
334 329
335 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 330 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
336 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 331 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
337 arc_session_manager()->state()); 332 arc_session_manager()->state());
338 // Emulate to accept the terms of service. 333 // Emulate to accept the terms of service.
339 prefs->SetBoolean(prefs::kArcTermsAccepted, true); 334 prefs->SetBoolean(prefs::kArcTermsAccepted, true);
340 arc_session_manager()->StartArc(); 335 arc_session_manager()->StartArc();
341 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 336 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
342 EXPECT_TRUE(bridge_service()->ready()); 337 EXPECT_TRUE(arc_session_manager()->IsSessionRunning());
343 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 338 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
344 arc_session_manager()->OnProvisioningFinished(ProvisioningResult::SUCCESS); 339 arc_session_manager()->OnProvisioningFinished(ProvisioningResult::SUCCESS);
345 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); 340 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn));
346 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 341 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
347 EXPECT_TRUE(bridge_service()->ready()); 342 EXPECT_TRUE(arc_session_manager()->IsSessionRunning());
348 343
349 // Second start, no fetching code is expected. 344 // Second start, no fetching code is expected.
350 arc_session_manager()->Shutdown(); 345 arc_session_manager()->Shutdown();
351 EXPECT_EQ(ArcSessionManager::State::NOT_INITIALIZED, 346 EXPECT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
352 arc_session_manager()->state()); 347 arc_session_manager()->state());
353 EXPECT_FALSE(bridge_service()->ready()); 348 EXPECT_TRUE(arc_session_manager()->IsSessionStopped());
354 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 349 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
355 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); 350 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn));
356 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 351 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
357 EXPECT_TRUE(bridge_service()->ready()); 352 EXPECT_TRUE(arc_session_manager()->IsSessionRunning());
358 353
359 // Report failure. 354 // Report failure.
360 arc_session_manager()->OnProvisioningFinished( 355 arc_session_manager()->OnProvisioningFinished(
361 ProvisioningResult::GMS_NETWORK_ERROR); 356 ProvisioningResult::GMS_NETWORK_ERROR);
362 // On error, UI to send feedback is showing. In that case, 357 // On error, UI to send feedback is showing. In that case,
363 // the ARC is still necessary to run on background for gathering the logs. 358 // the ARC is still necessary to run on background for gathering the logs.
364 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); 359 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn));
365 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 360 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
366 EXPECT_TRUE(bridge_service()->ready()); 361 EXPECT_TRUE(arc_session_manager()->IsSessionRunning());
367 362
368 // Correctly stop service. 363 // Correctly stop service.
369 arc_session_manager()->Shutdown(); 364 arc_session_manager()->Shutdown();
370 } 365 }
371 366
372 TEST_F(ArcSessionManagerTest, DisabledForDeviceLocalAccount) { 367 TEST_F(ArcSessionManagerTest, DisabledForDeviceLocalAccount) {
373 PrefService* const prefs = profile()->GetPrefs(); 368 PrefService* const prefs = profile()->GetPrefs();
374 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 369 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
375 prefs->SetBoolean(prefs::kArcEnabled, true); 370 prefs->SetBoolean(prefs::kArcEnabled, true);
376 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 371 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 bool terminated = false; 520 bool terminated = false;
526 arc_session_manager()->SetAttemptUserExitCallbackForTesting( 521 arc_session_manager()->SetAttemptUserExitCallbackForTesting(
527 base::Bind([](bool* terminated) { *terminated = true; }, &terminated)); 522 base::Bind([](bool* terminated) { *terminated = true; }, &terminated));
528 523
529 arc_session_manager()->OnProvisioningFinished( 524 arc_session_manager()->OnProvisioningFinished(
530 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); 525 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR);
531 EXPECT_TRUE(terminated); 526 EXPECT_TRUE(terminated);
532 } 527 }
533 528
534 } // namespace arc 529 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698